kfence: skip DMA allocations
Subsystems (3)
Alexander Potapenko
maintainerPATCH 1/1 kfence: skip DMA allocations
Allocation requests with __GFP_DMA/__GFP_DMA32 or SLAB_CACHE_DMA/SLAB_CACHE_DMA32 cannot be fulfilled by KFENCE, because they must reside in low memory, whereas KFENCE memory pool is located in high memory.
Skip such allocations to avoid crashes where DMAable memory is expected.
Fixes 0ce20dd84089 ("mm: add Kernel Electric-Fence infrastructure")
Cc Andrew Morton <[email protected]>
Cc Dmitry Vyukov <[email protected]>
Cc Marco Elver <[email protected]>
Cc [email protected] # 5.12+
Signed-off-by Alexander Potapenko <[email protected]>
--- mm/kfence/core.c | 8 ++++++++ 1 file changed, 8 insertions(+)
mm/kfence/core.c +8 -0
@@ -760,6 +760,14 @@ void *__kfence_alloc(struct kmem_cache *s, size_t size, gfp_t flags)if (size >PAGE_SIZE )return NULL ; +/* +* Skip DMA allocations. These must reside in the low memory, which we +* cannot guarantee. +*/ +if (flags & (__GFP_DMA | __GFP_DMA32) || + (s->flags & (SLAB_CACHE_DMA |SLAB_CACHE_DMA32 ))) +return NULL ; +return kfence_guarded_alloc (s, size, flags); }
Signature · 1 line
2.32.0.93.g670b81a890-goog
Marco Elver
maintainerOn Tue, 29 Jun 2021 at 15:00, Alexander Potapenko <[email protected]> wrote:
[...]
mm/kfence/core.c void *__kfence_alloc(struct kmem_cache *s, size_t size, gfp_t flags) · line 767
Quoted 5 lines
mm/kfence/core.c +5
-0+/* +* Skip DMA allocations. These must reside in the low memory, which we +* cannot guarantee. +*/ + if (flags & (__GFP_DMA | __GFP_DMA32) ||
I think we want braces around "flags & (...)", so that this becomes:
if ((flags & (...)) ||
mm/kfence/core.c void *__kfence_alloc(struct kmem_cache *s, size_t size, gfp_t flags) · line 769
Quoted 2 lines
mm/kfence/core.c +2
-0+ (s->flags & (SLAB_CACHE_DMA | SLAB_CACHE_DMA32))) +return NULL ;
Thanks,
-- Marco