mm/vmalloc: Bail out if in softirq context
Subsystems (2)
Uladzislau Rezki (Sony)
maintainerPATCH v2 1/1 mm/vmalloc: Bail out if in softirq context
vmalloc() is not allowed to be invoked from the NMI, hard-irq and softirq contexts because doing so may deadlock on internal locks.
Commit 04aa71da5f35 ("mm/vmalloc: do not trigger BUG() on BH disabled context") replaced the deprecated in_interrupt() macro with explicit in_nmi() and in_hardirq() checks, but unintentionally dropped the softirq context check.
Example:
<snip>vzalloc() in a task
spin_lock(&vn->busy.lock)
<------ Hard irq
irq_exit()
process softirq on the same CPU
vmalloc()
spin_lock(&vn->busy.lock)
spins forever
<snip>
Restore the original context restriction including BH-disabled task context.
Use WARN_ON_ONCE() and return NULL instead of BUG_ON(), so invalid callers are reported without triggering a BUG.
--- mm/vmalloc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
mm/vmalloc.c +6 -1
@@ -3258,7 +3258,12 @@ struct vm_struct *__get_vm_area_node(unsigned long size,struct vm_struct *area;unsigned long requested_size = size; -BUG_ON (in_nmi () ||in_hardirq ()); +/* +* Reject interrupt contexts, including BH-disabled task context. +*/ +if (WARN_ON_ONCE (in_nmi () ||in_hardirq () ||softirq_count ())) +return NULL ; + size =ALIGN (size,1ul << shift);if (unlikely (!size))return NULL ;
Signature · 1 line
2.47.3
+ mm-vmalloc-bail-out-if-in-softirq-context.patch added to mm-hotfixes-unstable branch
The patch titled Subject: mm/vmalloc: bail out if in softirq context has been added to the -mm mm-hotfixes-unstable branch. Its filename is mm-vmalloc-bail-out-if-in-softirq-context.patch
The patch titled
Subject: mm/vmalloc: bail out if in softirq context
has been added to the -mm mm-hotfixes-unstable branch. Its filename is
mm-vmalloc-bail-out-if-in-softirq-context.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-vmalloc-bail-out-if-in-softirq-context.patch
This patch will later appear in the mm-hotfixes-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: "Uladzislau Rezki (Sony)" <[email protected]>
Subject: mm/vmalloc: bail out if in softirq context
Date: Tue, 1 Dec 2026 18:37:27 +0100
vmalloc() is not allowed to be invoked from the NMI, hard-irq and softirq contexts because doing so may deadlock on internal locks.
Commit 04aa71da5f35 ("mm/vmalloc: do not trigger BUG() on BH disabled context") replaced the deprecated in_interrupt() macro with explicit in_nmi() and in_hardirq() checks, but unintentionally dropped the softirq context check.
Example:
<snip>vzalloc() in a task
spin_lock(&vn->busy.lock)
<------ Hard irq
irq_exit()
process softirq on the same CPU
vmalloc()
spin_lock(&vn->busy.lock)
spins forever
<snip>
Restore the original context restriction including BH-disabled task context.
Use WARN_ON_ONCE() and return NULL instead of BUG_ON(), so invalid callers are reported without triggering a BUG.
mm/vmalloc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
mm/vmalloc.c renamed from mm/vmalloc.c~mm-vmalloc-bail-out-if-in-softirq-context +6 -1
@@ -3266,7 +3266,12 @@ struct vm_struct *__get_vm_area_node(unsstruct vm_struct *area;unsigned long requested_size = size; -BUG_ON (in_nmi () ||in_hardirq ()); +/* +* Reject interrupt contexts, including BH-disabled task context. +*/ +if (WARN_ON_ONCE (in_nmi () ||in_hardirq () ||softirq_count ())) +return NULL ; + size =ALIGN (size,1ul << shift);if (unlikely (!size))return NULL ;
_
Patches currently in -mm which might be from [email protected] are
mm-vmalloc-use-dedicated-unbound-workqueues-for-vmap-drain.patch mm-vmalloc-bail-out-if-in-softirq-context.patch
Quoted 40 lines · Uladzislau Rezki (Sony)
vmalloc()is not allowed to be invoked from the NMI, hard-irq and softirq contexts because doing so may deadlock on internal locks.Commit
04aa71da5f35("mm/vmalloc: do not triggerBUG()on BH disabled context") replaced the deprecatedin_interrupt()macro with explicitin_nmi()andin_hardirq()checks, but unintentionally dropped the softirq context check.Example:
<snip>
vzalloc()in a task
spin_lock(&vn->busy.lock)
<------ Hard irq
irq_exit()
process softirq on the same CPU
vmalloc()
spin_lock(&vn->busy.lock)
spins forever
<snip>Restore the original context restriction including BH-disabled task context.
Use
WARN_ON_ONCE()and return NULL instead ofBUG_ON(), so invalid callers are reported without triggering a BUG.Cc David Hildenbrand (Arm) <[email protected]>Fixes 04aa71da5f35 ("mm/vmalloc: do not trigger BUG() on BH disabled context")Signed-off-by Uladzislau Rezki (Sony) <[email protected]>--- mm/vmalloc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)mm/vmalloc.c +0
-0
mm/vmalloc.c struct vm_struct *__get_vm_area_node(unsigned long size, · line 3265
Quoted 9 lines
mm/vmalloc.c +5
-1@@ -3258,7 +3258,12 @@ struct vm_struct *__get_vm_area_node(unsigned long size,struct vm_struct *area;unsigned long requested_size = size; -BUG_ON (in_nmi () ||in_hardirq ()); +/* +* Reject interrupt contexts, including BH-disabled task context. +*/ +if (WARN_ON_ONCE (in_nmi () ||in_hardirq () ||softirq_count ())) +return NULL ;
Do we need bail out for irqs_disabled() case? I saw kvmalloc() made this:
commit 693c2e04e3f1 ("mm: kvmalloc: Bail if called with soft or hard IRQs disabled")
Quoted 7 lines
mm/vmalloc.c +1
-0+ size =ALIGN (size,1ul << shift);if (unlikely (!size))return NULL ;Signature · 1 line
2.47.3