summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLiam R. Howlett (Oracle) <liam@infradead.org>2026-06-30 15:08:38 -0400
committerAndrew Morton <akpm@linux-foundation.org>2026-07-22 21:11:57 -0700
commitd28d688f79a3b54c5d8a0a2e448c1e2e6990d3a1 (patch)
tree0fdcdd1f9a2651cb59d5036c004a1e56f5e177f4 /lib
parentd6da1f8b6472d57bf9ee855ec9e11977fd8d0e9f (diff)
downloadlinux-next-d28d688f79a3b54c5d8a0a2e448c1e2e6990d3a1.tar.gz
linux-next-d28d688f79a3b54c5d8a0a2e448c1e2e6990d3a1.zip
maple_tree: WARN_ON_ONCE when allocations fail
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. Link: https://lore.kernel.org/20260630190843.3563858-15-liam@infradead.org Signed-off-by: Liam R. Howlett (Oracle) <liam@infradead.org> Cc: Rik van Riel <riel@surriel.com> Cc: Jason Gunthorpe <jgg@ziepe.ca> Cc: Boqun Feng <boqun.feng@gmail.com> Cc: Chris Mason <clm@meta.com> Cc: Chuck Lever <cel@kernel.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Joe Perches <joe@perches.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Waiman Long <longman@redhat.com> Cc: Will Deacon <will@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/maple_tree.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/maple_tree.c b/lib/maple_tree.c
index 15e8081f6180..afe65ff0f8a6 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);