* [PATCH v2] mm/vmalloc: Bail out if in softirq context
@ 2026-12-01 17:37 Uladzislau Rezki (Sony)
2026-12-02 2:31 ` Baoquan He
0 siblings, 1 reply; 3+ messages in thread
From: Uladzislau Rezki (Sony) @ 2026-12-01 17:37 UTC (permalink / raw)
To: linux-mm, Andrew Morton
Cc: Baoquan He, LKML, Uladzislau Rezki, David Hildenbrand (Arm)
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.
Cc: David Hildenbrand (Arm) <david@kernel.org>
Fixes: 04aa71da5f35 ("mm/vmalloc: do not trigger BUG() on BH disabled context")
Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
---
mm/vmalloc.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index a4c22c569b1d..fe5bdb4fde52 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -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;
--
2.47.3
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v2] mm/vmalloc: Bail out if in softirq context
2026-12-01 17:37 [PATCH v2] mm/vmalloc: Bail out if in softirq context Uladzislau Rezki (Sony)
@ 2026-12-02 2:31 ` Baoquan He
2026-12-06 14:24 ` Uladzislau Rezki
0 siblings, 1 reply; 3+ messages in thread
From: Baoquan He @ 2026-12-02 2:31 UTC (permalink / raw)
To: Uladzislau Rezki (Sony)
Cc: linux-mm, Andrew Morton, LKML, David Hildenbrand (Arm)
On 12/01/26 at 06:37pm, Uladzislau Rezki (Sony) wrote:
> 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.
>
> Cc: David Hildenbrand (Arm) <david@kernel.org>
> Fixes: 04aa71da5f35 ("mm/vmalloc: do not trigger BUG() on BH disabled context")
> Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
> ---
> mm/vmalloc.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index a4c22c569b1d..fe5bdb4fde52 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -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")
> +
> size = ALIGN(size, 1ul << shift);
> if (unlikely(!size))
> return NULL;
> --
> 2.47.3
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v2] mm/vmalloc: Bail out if in softirq context
2026-12-02 2:31 ` Baoquan He
@ 2026-12-06 14:24 ` Uladzislau Rezki
0 siblings, 0 replies; 3+ messages in thread
From: Uladzislau Rezki @ 2026-12-06 14:24 UTC (permalink / raw)
To: Baoquan He
Cc: Uladzislau Rezki (Sony),
linux-mm, Andrew Morton, LKML, David Hildenbrand (Arm)
On Wed, Dec 02, 2026 at 10:31:47AM +0800, Baoquan He wrote:
> On 12/01/26 at 06:37pm, Uladzislau Rezki (Sony) wrote:
> > 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.
> >
> > Cc: David Hildenbrand (Arm) <david@kernel.org>
> > Fixes: 04aa71da5f35 ("mm/vmalloc: do not trigger BUG() on BH disabled context")
> > Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
> > ---
> > mm/vmalloc.c | 7 ++++++-
> > 1 file changed, 6 insertions(+), 1 deletion(-)
> >
> > diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> > index a4c22c569b1d..fe5bdb4fde52 100644
> > --- a/mm/vmalloc.c
> > +++ b/mm/vmalloc.c
> > @@ -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")
>
We can't just bail out if irq_disabled() because we will break the
Linux boot. There is a vmalloc() call during the boot where IRQs are
disabled.
This patch restores the original behaviour with one exception it does
not stop the kernel.
--
Uladzislau Rezki
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-06 14:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01 17:37 [PATCH v2] mm/vmalloc: Bail out if in softirq context Uladzislau Rezki (Sony)
2026-12-02 2:31 ` Baoquan He
2026-12-06 14:24 ` Uladzislau Rezki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®