Re: [PATCH 4/4] rhashtable: fix vmalloc() deadlock in atomic rehash

From: Uladzislau Rezki

Date: Thu Nov 05 2026 - 12:43:20 EST


On Thu, Nov 05, 2026 at 08:22:52AM -0800, Linus Torvalds wrote:
> On Thu, 5 Nov 2026 at 00:51, Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx> wrote:
> >
> > On Wed, Nov 04, 2026 at 12:11:24PM +0100, Uladzislau Rezki wrote:
> > >
> > > There are users in kernel. For example:
> >
> > Thanks for the list.
> >
> > > drivers/GPU
> > > /* Allocate the file in vmalloc memory, it's likely to be big */
> > > iter.start = __vmalloc(file_size, GFP_NOWAIT);
> > >
> > > AMD-GPU:
> > > kvzalloc(size, GFP_NOWAIT);
> > > kvzalloc_objs(struct amdgpu_coredump_ring, GFP_NOWAIT);
> > > kvzalloc(ring->ring_size, GFP_NOWAIT);
> >
> > These appear to be executing out of process context without spin
> > locks so they're not really GFP_ATOMIC.
>
> Historically, GFP_ATOMIC and GFP_NOWAIT have been largely the same
> except for GFP_ATOMIC eating into reserves.
>
> But I wonder if we might be able to soften that a bit, or add a new
> form, because it looks like the AMD-GPU case at least doesn't really
> care about any kind of "don't sleep", what it really just wants is an
> "optimistic allocation" - try to get the memory, but don't spend
> effort on freeing things if there is not enough memort.
>
> The AMD code in question literally has a comment that says
>
> /* Dump ring content if memory allocation succeeds. */
>
> so while it's possible that it has some atomicity requirements, it
> doesn't look that way to me from a very quick look.
>
> The etnaviv case looks to be the exact same thing: it is definitely
> called in normal process context (that code takes a mutex lock around
> it all).
>
> So those two cases really don't looke like they are about "atomicity" at all.
>
> > > net/ipv4/udp.c:
> > > err = bpf_iter_udp_realloc_batch(iter, batch_sks, GFP_NOWAIT);
> >
> > This looks buggy in exactly the same way as rhashtable. It's
> > called under spin_lock_bh, and the same lock can be taken on
> > the softirq path on another CPU.
>
> Yeah, that case is definitely actually atomic and holds a lock. Not great.
>
> Is there any way to limit the vmalloc() case to the actuall atomic one
> and just fail when it needs to busy-wait?
>
Probably it is not easy. vmalloc() takes several locks including
during page-table setup.

Probably the simplest option is to return NULL for non-blocking vmalloc()
allocations when BH are disabled. That would address the reported
rhashtable deadlock.

--
Uladzislau Rezki