From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10D7447CC89 for ; Tue, 30 Jun 2026 19:09:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782846554; cv=none; b=JShG+e58zAXRlTeqtzJOWJwn2KT2xsEmQ0uxQ7DaF4K0Ct+L68k2UdZFHzR/ladoIXSHFoxXblMrfmQ4dCYbs60d/SQojI/F/tjGPyeDQa9b7u+zvRGGmXlsTAcXGSSi8CROq620ao/nN/2UAvNvQEPP4Z/fRAS/xBWZAhnuK64= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782846554; c=relaxed/simple; bh=5p24UBtfFe5XPJxQHy6oE/iT9ohA799oPS2ukvFgJOU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F/cW3yCPtizoAf6CqQJiSiS0b1i71OKrU2cYdao6yv/Gxw+jiTinpBnjVXHzjMfweiD1eYga9KWP4IYHeXFuwNeYZbPxfcHV6KtV8qZpK7y+Uu9r65eRPvj8xEgvvS33VgcUIZH6aAgcZVEyIPx3evt6UkijHOYKcRc3KAGpGo4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=pass smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=xbP9/VeK; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="xbP9/VeK" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=UVdDh/i0Qoj61MXqfLH5G8oTfqVJrR+R2Vzd+OLqy/Y=; b=xbP9/VeK8Yg5UT2PWkYOw1eEHV MVGGeVY38zzh5iUeC8rnd0qGODrAW5BQ9ysV8TIvuHihzHvjDnV/ewRRi5AO8iLudyc4wTCjGOyDK nPfOFUZwqAclgJfw/ina/4EyzU6jE6pTTBAjQJXQsgkbt79zPBCmRps96NfWHFcWYasIUC96G+fvj CmsmW933crq/+nS2VOtcLBCZAKO0lwyPI1TqlOscpwjoeoFaLH7FSnStA4c4TvYRM6gXpxUw+5yHa lKICN5vXvx9QT/chF0c/28qETvjcF2dBuIsnj+xbiIo9rk0Jy8eHUtRLz8LQmrhKdRy3Zm1rkUj6b hLVgum8A==; Received: from [38.23.173.23] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.99.1 #2 (Red Hat Linux)) id 1wedpY-0000000060B-1fHT; Tue, 30 Jun 2026 19:09:12 +0000 From: "Liam R. Howlett (Oracle)" To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, "Liam R. Howlett (Oracle)" , Rik van Riel , Jason Gunthorpe Subject: [PATCH v2 14/19] maple_tree: WARN_ON_ONCE when allocations fail Date: Tue, 30 Jun 2026 15:08:38 -0400 Message-ID: <20260630190843.3563858-15-liam@infradead.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260630190843.3563858-1-liam@infradead.org> References: <20260630190843.3563858-1-liam@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Allocations should never fail in the circumstances that are expected to occur. Add checks in the code to ensure the circumstances are correctly set up by the user and warn if they are not. Also add a warning on failure to allocate, which should never happen. Cc: Rik van Riel Cc: Jason Gunthorpe Signed-off-by: Liam R. Howlett (Oracle) --- lib/maple_tree.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 15e8081f61808..afe65ff0f8a6f 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -5720,6 +5720,10 @@ bool mas_nomem(struct ma_state *mas, gfp_t gfp) if (likely(mas->node != MA_ERROR(-ENOMEM))) return false; + /* Allocations can fail, don't do this. */ + WARN_ON_ONCE(!gfpflags_allow_blocking(gfp) && + mt_external_lock(mas->tree)); + if (gfpflags_allow_blocking(gfp) && !mt_external_lock(mas->tree)) { mtree_unlock(mas->tree); mas_alloc_nodes(mas, gfp); @@ -5730,9 +5734,12 @@ bool mas_nomem(struct ma_state *mas, gfp_t gfp) /* * Return false on zero forward progress. Partial allocations are kept - * so the retry path will attempt to get the rest. + * so the retry path will attempt to get the rest. The failure should + * not happen as we try our best to reclaim. The user would need an + * external lock with a non-blocking gfp in a low memory situation - + * which would have triggered the first warning in this function. */ - if (!mas->sheaf && !mas->alloc) + if (WARN_ON_ONCE(!mas->sheaf && !mas->alloc)) return false; mas_reset(mas); -- 2.47.3