Skip to content

mm: fix nested allocation context filtering

Dave Chinner linux-mm linux-xfs 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 6 repliesIn review 2 of 3 applied

Patches in v1 2 of 3 applied

#Subject and filesSizeRepliesApplied
1/3mm: lift gfp_kmemleak_mask() to gfp.hinclude/linux/gfp.h mm/kmemleak.c+27 -81 reply
2/3stackdepot: use gfp_nested_mask() instead of open coded maskinglib/stackdepot.c+2 -91 replyApplied
3/3mm/page-owner: use gfp_nested_mask() instead of open coded maskingmm/page_owner.c+1 -60 repliesApplied

Reviews trailers per patch

2 of 3 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchChristoph HellwigVlastimil BabkaMarco ElverOscar Salvador
SeriesR-b R-b R-b
1/3R-b
2/3R-b
3/3

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v1 thread

Cover letter [PATCH 0/3] mm: fix nested allocation context filtering

This patchset is the followup to the comment I made earlier today:

https://lore.kernel.org/linux-xfs/[email protected]/

Tl;dr: Memory allocations that are done inside the public memory allocation API need to obey the reclaim recursion constraints placed on the allocation by the original caller, including the "don't track recursion for this allocation" case defined by __GFP_NOLOCKDEP.

These nested allocations are generally in debug code that is tracking something about the allocation (kmemleak, KASAN, etc) and so are allocating private kernel objects that only that debug system will use.

Neither the page-owner code nor the stack depot code get this right. They also also clear GFP_ZONEMASK as a separate operation, which is completely redundant because the constraint filter applied immediately after guarantees that GFP_ZONEMASK bits are cleared.

kmemleak gets this filtering right. It preserves the allocation constraints for deadlock prevention and clears all other context flags whilst also ensuring that the nested allocation will fail quickly, silently and without depleting emergency kernel reserves if there is no memory available.

This can be made much more robust, immune to whack-a-mole games and the code greatly simplified by lifting gfp_kmemleak_mask() to include/linux/gfp.h and using that everywhere. Also document it so that there is no excuse for not knowing about it when writing new debug code that nests allocations.

Tested with lockdep, KASAN + page_owner=on and kmemleak=on over multiple fstests runs with XFS.