Re: [PATCH] mm: kvmalloc: Bail if called with soft or hard IRQs disabled
From: Linus Torvalds
Date: Fri Nov 13 2026 - 14:21:15 EST
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;
and yes, that would give a warning, but it would actually fix *two*
bugs at once: it would fix the bogus BUG_ON(), and it would deal
correctly with broken code that thought it was ok to do vmalloc in
softirq context.
Linus