Skip to content

Commit 236e9f1

Browse files
ramosian-glidertorvalds
authored andcommitted
kfence: skip all GFP_ZONEMASK allocations
Allocation requests outside ZONE_NORMAL (MOVABLE, HIGHMEM or DMA) cannot be fulfilled by KFENCE, because KFENCE memory pool is located in a zone different from the requested one. Because callers of kmem_cache_alloc() may actually rely on the allocation to reside in the requested zone (e.g. memory allocations done with __GFP_DMA must be DMAable), skip all allocations done with GFP_ZONEMASK and/or respective SLAB flags (SLAB_CACHE_DMA and SLAB_CACHE_DMA32). Link: https://lkml.kernel.org/r/[email protected] Fixes: 0ce20dd ("mm: add Kernel Electric-Fence infrastructure") Signed-off-by: Alexander Potapenko <[email protected]> Reviewed-by: Marco Elver <[email protected]> Acked-by: Souptick Joarder <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Souptick Joarder <[email protected]> Cc: <[email protected]> [5.12+] Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 235a85c commit 236e9f1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

mm/kfence/core.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,15 @@ void *__kfence_alloc(struct kmem_cache *s, size_t size, gfp_t flags)
740740
if (size > PAGE_SIZE)
741741
return NULL;
742742

743+
/*
744+
* Skip allocations from non-default zones, including DMA. We cannot
745+
* guarantee that pages in the KFENCE pool will have the requested
746+
* properties (e.g. reside in DMAable memory).
747+
*/
748+
if ((flags & GFP_ZONEMASK) ||
749+
(s->flags & (SLAB_CACHE_DMA | SLAB_CACHE_DMA32)))
750+
return NULL;
751+
743752
/*
744753
* allocation_gate only needs to become non-zero, so it doesn't make
745754
* sense to continue writing to it and pay the associated contention

0 commit comments

Comments
 (0)