Re: [PATCH v2] kfence: skip DMA allocations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 29 Jun 2021 at 18:17, Alexander Potapenko <glider@xxxxxxxxxx> wrote:
> 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 <akpm@xxxxxxxxxxxxxxxxxxxx>
> Cc: Dmitry Vyukov <dvyukov@xxxxxxxxxx>
> Cc: Marco Elver <elver@xxxxxxxxxx>
> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> Cc: stable@xxxxxxxxxxxxxxx # 5.12+
> Signed-off-by: Alexander Potapenko <glider@xxxxxxxxxx>

Reviewed-by: Marco Elver <elver@xxxxxxxxxx>

Thanks!


> ---
>
> v2:
>  - added parentheses around the GFP clause, as requested by Marco
> ---
>  mm/kfence/core.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/mm/kfence/core.c b/mm/kfence/core.c
> index 4d21ac44d5d35..f7ce3d876bc9e 100644
> --- a/mm/kfence/core.c
> +++ b/mm/kfence/core.c
> @@ -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);
>  }
>
> --
> 2.32.0.93.g670b81a890-goog
>




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux