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 6D9D0426D03 for ; Mon, 29 Jun 2026 14:42:55 +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=1782744176; cv=none; b=AfKQn1CN/0mnH5+FYP4aKOzMt1nZYNMI84mDEntlBjxq+E/X5ZHUyxdw1D10VXEc3LOMxFpril02QG+k6F8DOwDiLvQIg1rZ2ITUL/NbmkMCmdBQEXiFRig4EfrdGF2YrK5UVFpkBVmNKlQnvFwiiDXegCxroPgp9QygZq3siJ8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782744176; c=relaxed/simple; bh=i4MzvseG41RPS1SS9ppS02as+k4kp590etLf8SE2zlA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UIodyd/wEd63NP3b/p2EG5wwbtqOd3gdKqScHsWRnhyu24LSsD3EY6QLWNs2h2CeIKG1eYSf3ZvVhLfjhijymbSoRYm84/5DR3fs52gtaskH5w7HMEgP9CN77W9uBW/8mMavUDmS8uptYk+duiPUNqSYIJxxBhwiI1JCLo8KMjI= 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=QTltAxsp; 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="QTltAxsp" 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=8J0QSGS65Sv3OwylyYJKeZ8VAnRaGM9NHIx0pjG92jc=; b=QTltAxspSWOX5++01JE3kxh3YT ZgGVOaA9mUPxgzE63StDKGng0Pto2z4+BSoaKrGvsPmsE6O4X44JsDmee7yETOU4Z7kgNIp4nCUCa ekIuyzv//oOcCeFG/y+6bD6OBSb8jUoefg6l2KyaUlTLJb9l8smAWQeTlUgUNOhuaUjxRSVhuIoWx WR1pVTG0/v+XWI+sDbixbXbTeT96y+1oVUnbMZY1kJWMOpnmZ/NYSdtLaxqvmibz5SclTjBuakYAp UhyvnT556Dzvi4afX4M5u8Ci3EG8ikm97BiWzKmlEreqDsVpYDoSpNaRKgMYaGJQS48NCWzgTKw0G vDbMPzJQ==; Received: from [38.23.173.23] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.99.1 #2 (Red Hat Linux)) id 1weDCI-0000000EufR-3Egq; Mon, 29 Jun 2026 14:42:54 +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 14/18] maple_tree: WARN_ON_ONCE when allocations fail Date: Mon, 29 Jun 2026 10:41:41 -0400 Message-ID: <20260629144145.1572283-15-liam@infradead.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260629144145.1572283-1-liam@infradead.org> References: <20260629144145.1572283-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 c5efa3e2f7461..94f2d5b9bc881 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -5747,6 +5747,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); @@ -5757,9 +5761,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