From: Vlastimil Babka <vbabka@suse.com>
To: "Uladzislau Rezki (Sony)" <urezki@gmail.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
linux-crypto@vger.kernel.org,
"Harry Yoo (Oracle)" <harry@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Hao Li <hao.li@linux.dev>
Subject: Re: [PATCH 1/2] mm/slab: Add kvfree_atomic() helper
Date: Wed, 29 Apr 2026 10:28:02 +0200 [thread overview]
Message-ID: <2d996917-60bb-4ef9-b397-65decf3b296d@suse.com> (raw)
In-Reply-To: <20260428161419.94695-1-urezki@gmail.com>
+Cc SLAB maintainers. Please use get_maintainers.pl next time.
On 4/28/26 18:14, Uladzislau Rezki (Sony) wrote:
> kvmalloc() now supports non-sleeping GFP flags, including
> the vmalloc fallback path. This means it may return vmalloc
> memory even for GFP_ATOMIC and GFP_NOWAIT allocations.
>
> Freeing such memory with kvfree() may then end up calling
> vfree(), which is not safe for non-sleeping contexts.
>
> Introduce kvfree_atomic() helper for such cases. It mirrors
> kvfree(), but uses vfree_atomic() for vmalloced memory.
>
> Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
Acked-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
> ---
> include/linux/slab.h | 3 +++
> mm/slub.c | 16 ++++++++++++++++
> 2 files changed, 19 insertions(+)
>
> diff --git a/include/linux/slab.h b/include/linux/slab.h
> index 15a60b501b95..2b5ab488e96b 100644
> --- a/include/linux/slab.h
> +++ b/include/linux/slab.h
> @@ -1234,6 +1234,9 @@ void *kvrealloc_node_align_noprof(const void *p, size_t size, unsigned long alig
> extern void kvfree(const void *addr);
> DEFINE_FREE(kvfree, void *, if (!IS_ERR_OR_NULL(_T)) kvfree(_T))
>
> +extern void kvfree_atomic(const void *addr);
> +DEFINE_FREE(kvfree_atomic, void *, if (!IS_ERR_OR_NULL(_T)) kvfree_atomic(_T))
> +
> extern void kvfree_sensitive(const void *addr, size_t len);
>
> unsigned int kmem_cache_size(struct kmem_cache *s);
> diff --git a/mm/slub.c b/mm/slub.c
> index 2b2d33cc735c..b096677c8152 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -6802,6 +6802,22 @@ void kvfree(const void *addr)
> }
> EXPORT_SYMBOL(kvfree);
>
> +/**
> + * kvfree_atomic() - Free memory.
> + * @addr: Pointer to allocated memory.
> + *
> + * Same as kvfree(), but uses vfree_atomic() for vmalloc
> + * backed memory. Must not be called from NMI context.
> + */
> +void kvfree_atomic(const void *addr)
> +{
> + if (is_vmalloc_addr(addr))
> + vfree_atomic(addr);
> + else
> + kfree(addr);
> +}
> +EXPORT_SYMBOL(kvfree_atomic);
> +
> /**
> * kvfree_sensitive - Free a data object containing sensitive information.
> * @addr: address of the data object to be freed.
next prev parent reply other threads:[~2026-04-29 8:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-28 16:14 [PATCH 1/2] mm/slab: Add kvfree_atomic() helper Uladzislau Rezki (Sony)
2026-04-28 16:14 ` [PATCH 2/2] rhashtable: Add bucket_table_free_atomic() helper Uladzislau Rezki (Sony)
2026-04-29 8:28 ` Vlastimil Babka [this message]
2026-04-29 8:58 ` [PATCH 1/2] mm/slab: Add kvfree_atomic() helper Uladzislau Rezki
2026-04-29 11:19 ` Harry Yoo (Oracle)
2026-05-05 9:30 ` Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2d996917-60bb-4ef9-b397-65decf3b296d@suse.com \
--to=vbabka@suse.com \
--cc=akpm@linux-foundation.org \
--cc=hao.li@linux.dev \
--cc=harry@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=urezki@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox