Re: [PATCH] mm: kvmalloc: Bail if called with soft or hard IRQs disabled

From: Uladzislau Rezki

Date: Sat Nov 14 2026 - 08:48:33 EST


On Fri, Nov 13, 2026 at 09:47:13AM -0800, Linus Torvalds wrote:
> On Fri, 13 Nov 2026 at 05:03, Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx> wrote:
> >
> > OK let's try this patch:
>
> I don't think this is wrong, but I do wonder if we should at least
> have *some* way to detect these cases and report them.
>
> Also, it turns out that in __get_vm_area_node(), we have
>
> BUG_ON(in_nmi() || in_hardirq());
>
> so this call sequence already has a *limited* test for this all. It's
> just that it explicitly allows softirqs, probably because it used that
> bogus BUG_ON() pattern, so it wasn't a debug aid, it was a "the
> machine is dead"
>
> I wish people would stop using BUG_ON() and friends. They are *only*
> valid for things where "something bad happened, I can't recover".
>
> That __get_vm_area_node() is not such a case. That function has a
> perfectly well-defined "what to do in case of errors". It already does
> it for lots of other cases: just return NULL.
>
> So using BUG_ON() is wrong, wrong, WRONG. Commit 04aa71da5f35
> ("mm/vmalloc: do not trigger BUG() on BH disabled context") was simply
> not the correct thing to do.
>
> The correct thing to do was to replace the buggy sh*t-for-brains
> BUG_ON() with the right sequence:
>
> - BUG_ON(in_interrupt());
> + if (WARN_ON_ONCE(in_interrupt())
> + return NULL;
>
I agree with this. The vmalloc() used to BUG_ON() if in_interrupt().
The easiest is to restore the old context restriction and replace
BUG_ON() with WARN_ON_ONCE() followed by returning NULL.

That would not stop machine but would show invalid callers.
If there are no objections i can send a patch.

--
Uladzislau Rezki