* [PATCH] rhashtable: Check for vmalloc in emergency rehash error path
[not found] ` <aeh_2WwIb8nAIcy2@gondor.apana.org.au>
@ 2026-04-22 8:18 ` Herbert Xu
0 siblings, 0 replies; only message in thread
From: Herbert Xu @ 2026-04-22 8:18 UTC (permalink / raw)
To: Uladzislau Rezki
Cc: Thomas Graf, oe-lkp, lkp, linux-kernel, Andrew Morton,
Michal Hocko, Baoquan He, Alexander Potapenko, Andrey Ryabinin,
Marco Elver, Michal Hocko, linux-mm, Linux Crypto Mailing List
On Wed, Apr 22, 2026 at 03:59:21PM +0800, Herbert Xu wrote:
>
> Why is kvmalloc returning vmalloc memory under GFP_ATOMIC?
> Is there a new GFP flag to tell it to not return vmalloc memory?
>
> This has been working for over a decade, what changed?
Nevermind, I found your commit to add vmalloc support for GFP_ATOMIC.
---8<---
As kvmalloc with GFP_ATOMIC can now return vmalloc memory, check
for it when freeing while in the same context so that vfree isn't
called in an atomic context.
Use RCU to defer the freeing if the memory came from vmalloc.
Reported-by: Uladzislau Rezki <urezki@gmail.com>
Fixes: c6307674ed82 ("mm: kvmalloc: add non-blocking support for vmalloc")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index 6074ed5f66f3..c386f456e417 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -119,6 +119,16 @@ static void bucket_table_free_rcu(struct rcu_head *head)
bucket_table_free(container_of(head, struct bucket_table, rcu));
}
+static void bucket_table_free_atomic(struct bucket_table *tbl)
+{
+ if (is_vmalloc_addr(tbl)) {
+ call_rcu(&tbl->rcu, bucket_table_free_rcu);
+ return;
+ }
+
+ bucket_table_free(tbl);
+}
+
static union nested_table *nested_table_alloc(struct rhashtable *ht,
union nested_table __rcu **prev,
bool leaf)
@@ -473,7 +483,7 @@ static int rhashtable_insert_rehash(struct rhashtable *ht,
err = rhashtable_rehash_attach(ht, tbl, new_tbl);
if (err) {
- bucket_table_free(new_tbl);
+ bucket_table_free_atomic(new_tbl);
if (err == -EEXIST)
err = 0;
} else
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply related [flat|nested] only message in thread