* [PATCH] mm/vmalloc: Bail out if in softirq context
@ 2026-10-26 10:25 Uladzislau Rezki (Sony)
2026-10-26 16:04 ` Andrew Morton
2026-10-27 0:57 ` Baoquan He
0 siblings, 2 replies; 4+ messages in thread
From: Uladzislau Rezki (Sony) @ 2026-10-26 10:25 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 check by checking the caller's context with
the in_serving_softirq() helper. Note that, it is still
allowed to invoke vmalloc() with disabled bottom halves.
Replace BUG_ON() with WARN_ON_ONCE() for in_nmi() and
in_hardirq() case.
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 | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 7521b9b3bfd2..36e6e3be6ba4 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -3252,7 +3252,13 @@ 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());
+ /* IRQ re-entrancy -> irq_exit() -> process softirq. */
+ if (in_serving_softirq())
+ return NULL;
+
+ if (WARN_ON_ONCE(in_nmi() || in_hardirq()))
+ return NULL;
+
size = ALIGN(size, 1ul << shift);
if (unlikely(!size))
return NULL;
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/vmalloc: Bail out if in softirq context
2026-10-26 10:25 [PATCH] mm/vmalloc: Bail out if in softirq context Uladzislau Rezki (Sony)
@ 2026-10-26 16:04 ` Andrew Morton
2026-10-26 17:39 ` Uladzislau Rezki
2026-10-27 0:57 ` Baoquan He
1 sibling, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2026-10-26 16:04 UTC (permalink / raw)
To: Uladzislau Rezki (Sony)
Cc: linux-mm, Baoquan He, LKML, David Hildenbrand (Arm)
On Mon, 26 Oct 2026 11:25:03 +0100 "Uladzislau Rezki (Sony)" <urezki@gmail.com> 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 check by checking the caller's context with
> the in_serving_softirq() helper. Note that, it is still
> allowed to invoke vmalloc() with disabled bottom halves.
>
> Replace BUG_ON() with WARN_ON_ONCE() for in_nmi() and
> in_hardirq() case.
>
> Cc: David Hildenbrand (Arm) <david@kernel.org>
> Fixes: 04aa71da5f35 ("mm/vmalloc: do not trigger BUG() on BH disabled context")
Sounds like a cc:stable is needed?
> Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
> ---
> mm/vmalloc.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 7521b9b3bfd2..36e6e3be6ba4 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -3252,7 +3252,13 @@ 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());
> + /* IRQ re-entrancy -> irq_exit() -> process softirq. */
> + if (in_serving_softirq())
> + return NULL;
> +
> + if (WARN_ON_ONCE(in_nmi() || in_hardirq()))
> + return NULL;
WARN does a lot of stuff and I rather doubt that it's all nmi-safe. I
don't think this matters much - it'll probably work out and as long as
*something* gets printed, it did its job.
> size = ALIGN(size, 1ul << shift);
> if (unlikely(!size))
> return NULL;
> --
> 2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/vmalloc: Bail out if in softirq context
2026-10-26 16:04 ` Andrew Morton
@ 2026-10-26 17:39 ` Uladzislau Rezki
0 siblings, 0 replies; 4+ messages in thread
From: Uladzislau Rezki @ 2026-10-26 17:39 UTC (permalink / raw)
To: Andrew Morton
Cc: Uladzislau Rezki (Sony),
linux-mm, Baoquan He, LKML, David Hildenbrand (Arm)
On Mon, Oct 26, 2026 at 09:04:21AM -0700, Andrew Morton wrote:
> On Mon, 26 Oct 2026 11:25:03 +0100 "Uladzislau Rezki (Sony)" <urezki@gmail.com> 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 check by checking the caller's context with
> > the in_serving_softirq() helper. Note that, it is still
> > allowed to invoke vmalloc() with disabled bottom halves.
> >
> > Replace BUG_ON() with WARN_ON_ONCE() for in_nmi() and
> > in_hardirq() case.
> >
> > Cc: David Hildenbrand (Arm) <david@kernel.org>
> > Fixes: 04aa71da5f35 ("mm/vmalloc: do not trigger BUG() on BH disabled context")
>
> Sounds like a cc:stable is needed?
>
Yes. Should i resend and put cc:stable?
> > Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
> > ---
> > mm/vmalloc.c | 8 +++++++-
> > 1 file changed, 7 insertions(+), 1 deletion(-)
> >
> > diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> > index 7521b9b3bfd2..36e6e3be6ba4 100644
> > --- a/mm/vmalloc.c
> > +++ b/mm/vmalloc.c
> > @@ -3252,7 +3252,13 @@ 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());
> > + /* IRQ re-entrancy -> irq_exit() -> process softirq. */
> > + if (in_serving_softirq())
> > + return NULL;
> > +
> > + if (WARN_ON_ONCE(in_nmi() || in_hardirq()))
> > + return NULL;
>
> WARN does a lot of stuff and I rather doubt that it's all nmi-safe. I
> don't think this matters much - it'll probably work out and as long as
> *something* gets printed, it did its job.
>
Yep. I checked before the kernel sources and saw that people use it
with WARN. I thought switching from BUG() to WARN() is better.
--
Uladzislau Rezki
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mm/vmalloc: Bail out if in softirq context
2026-10-26 10:25 [PATCH] mm/vmalloc: Bail out if in softirq context Uladzislau Rezki (Sony)
2026-10-26 16:04 ` Andrew Morton
@ 2026-10-27 0:57 ` Baoquan He
1 sibling, 0 replies; 4+ messages in thread
From: Baoquan He @ 2026-10-27 0:57 UTC (permalink / raw)
To: Uladzislau Rezki (Sony)
Cc: linux-mm, Andrew Morton, LKML, David Hildenbrand (Arm)
On 10/26/26 at 11:25am, 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 check by checking the caller's context with
> the in_serving_softirq() helper. Note that, it is still
> allowed to invoke vmalloc() with disabled bottom halves.
>
> Replace BUG_ON() with WARN_ON_ONCE() for in_nmi() and
> in_hardirq() case.
>
> 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 | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 7521b9b3bfd2..36e6e3be6ba4 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -3252,7 +3252,13 @@ 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());
> + /* IRQ re-entrancy -> irq_exit() -> process softirq. */
> + if (in_serving_softirq())
> + return NULL;
> +
> + if (WARN_ON_ONCE(in_nmi() || in_hardirq()))
> + return NULL;
> +
LGTM,
Reviewed-by: Baoquan He <baoquan.he@linux.dev>
> size = ALIGN(size, 1ul << shift);
> if (unlikely(!size))
> return NULL;
> --
> 2.47.3
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-10-27 0:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-26 10:25 [PATCH] mm/vmalloc: Bail out if in softirq context Uladzislau Rezki (Sony)
2026-10-26 16:04 ` Andrew Morton
2026-10-26 17:39 ` Uladzislau Rezki
2026-10-27 0:57 ` Baoquan He
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®