From: Herbert Xu <herbert@gondor.apana.org.au>
To: Uladzislau Rezki <urezki@gmail.com>
Cc: Thomas Graf <tgraf@suug.ch>,
oe-lkp@lists.linux.dev, lkp@intel.com,
linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
Michal Hocko <mhocko@suse.com>, Baoquan He <bhe@redhat.com>,
Alexander Potapenko <glider@google.com>,
Andrey Ryabinin <ryabinin.a.a@gmail.com>,
Marco Elver <elver@google.com>, Michal Hocko <mhocko@kernel.org>,
linux-mm@kvack.org,
Linux Crypto Mailing List <linux-crypto@vger.kernel.org>
Subject: [PATCH] rhashtable: Check for vmalloc in emergency rehash error path
Date: Wed, 22 Apr 2026 16:18:16 +0800 [thread overview]
Message-ID: <aeiESGghexEuKbEV@gondor.apana.org.au> (raw)
In-Reply-To: <aeh_2WwIb8nAIcy2@gondor.apana.org.au>
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
next prev parent reply other threads:[~2026-04-22 8:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-21 7:45 [linus:master] [mm] c6307674ed: BUG:sleeping_function_called_from_invalid_context_at_mm/vmalloc.c kernel test robot
2026-04-21 12:36 ` Uladzislau Rezki
2026-04-22 5:32 ` Herbert Xu
2026-04-22 7:17 ` Uladzislau Rezki
2026-04-22 7:59 ` Herbert Xu
2026-04-22 8:18 ` Herbert Xu [this message]
2026-04-22 8:32 ` Uladzislau Rezki
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=aeiESGghexEuKbEV@gondor.apana.org.au \
--to=herbert@gondor.apana.org.au \
--cc=akpm@linux-foundation.org \
--cc=bhe@redhat.com \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lkp@intel.com \
--cc=mhocko@kernel.org \
--cc=mhocko@suse.com \
--cc=oe-lkp@lists.linux.dev \
--cc=ryabinin.a.a@gmail.com \
--cc=tgraf@suug.ch \
--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