Skip to content

Commit 70c435c

Browse files
Dave Chinnerakpm00
authored andcommitted
stackdepot: use gfp_nested_mask() instead of open coded masking
The stackdepot code is used by KASAN and lockdep for recoding stack traces. Both of these track allocation context information, and so their internal allocations must obey the caller allocation contexts to avoid generating their own false positive warnings that have nothing to do with the code they are instrumenting/tracking. We also don't want recording stack traces to deplete emergency memory reserves - debug code is useless if it creates new issues that can't be replicated when the debug code is disabled. Switch the stackdepot allocation masking to use gfp_nested_mask() to address these issues. gfp_nested_mask() also strips GFP_ZONEMASK naturally, so that greatly simplifies this code. Link: https://lkml.kernel.org/r/20240430054604.4169568-3-david@fromorbit.com Signed-off-by: Dave Chinner <dchinner@redhat.com> Reviewed-by: Marco Elver <elver@google.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Vlastimil Babka <vbabka@suse.cz> Reviewed-by: Oscar Salvador <osalvador@suse.de> Cc: Andrey Konovalov <andreyknvl@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 1c00f93 commit 70c435c

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

lib/stackdepot.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -624,15 +624,8 @@ depot_stack_handle_t stack_depot_save_flags(unsigned long *entries,
624624
* we won't be able to do that under the lock.
625625
*/
626626
if (unlikely(can_alloc && !READ_ONCE(new_pool))) {
627-
/*
628-
* Zero out zone modifiers, as we don't have specific zone
629-
* requirements. Keep the flags related to allocation in atomic
630-
* contexts, I/O, nolockdep.
631-
*/
632-
alloc_flags &= ~GFP_ZONEMASK;
633-
alloc_flags &= (GFP_ATOMIC | GFP_KERNEL | __GFP_NOLOCKDEP);
634-
alloc_flags |= __GFP_NOWARN;
635-
page = alloc_pages(alloc_flags, DEPOT_POOL_ORDER);
627+
page = alloc_pages(gfp_nested_mask(alloc_flags),
628+
DEPOT_POOL_ORDER);
636629
if (page)
637630
prealloc = page_address(page);
638631
}

0 commit comments

Comments
 (0)