All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] mm/vmalloc: Bail out if in softirq context
@ 2026-12-01 17:37 Uladzislau Rezki (Sony)
  2026-12-01 18:21 ` + mm-vmalloc-bail-out-if-in-softirq-context.patch added to mm-hotfixes-unstable branch Andrew Morton
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ 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 related	[flat|nested] 4+ messages in thread

* + mm-vmalloc-bail-out-if-in-softirq-context.patch added to mm-hotfixes-unstable branch
  2026-12-01 17:37 [PATCH v2] mm/vmalloc: Bail out if in softirq context Uladzislau Rezki (Sony)
@ 2026-12-01 18:21 ` Andrew Morton
  2026-12-02  2:31 ` [PATCH v2] mm/vmalloc: Bail out if in softirq context Baoquan He
  2026-12-02 17:37 ` sashiko-bot
  2 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2026-12-01 18:21 UTC (permalink / raw)
  To: mm-commits, david, baoquan.he, urezki, akpm


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)" <urezki@gmail.com>
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.

Link: https://patch.msgid.link/20261201173727.90526-1-urezki@gmail.com
Fixes: 04aa71da5f35 ("mm/vmalloc: do not trigger BUG() on BH disabled context")
Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: David Hildenbrand (Arm) <david@kernel.org>
Cc: Baoquan He <baoquan.he@linux.dev>

 mm/vmalloc.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

--- a/mm/vmalloc.c~mm-vmalloc-bail-out-if-in-softirq-context
+++ a/mm/vmalloc.c
@@ -3266,7 +3266,12 @@ struct vm_struct *__get_vm_area_node(uns
 	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;
_

Patches currently in -mm which might be from urezki@gmail.com are

mm-vmalloc-use-dedicated-unbound-workqueues-for-vmap-drain.patch
mm-vmalloc-bail-out-if-in-softirq-context.patch


^ permalink raw reply	[flat|nested] 4+ 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-01 18:21 ` + mm-vmalloc-bail-out-if-in-softirq-context.patch added to mm-hotfixes-unstable branch Andrew Morton
@ 2026-12-02  2:31 ` Baoquan He
  2026-12-02 17:37 ` sashiko-bot
  2 siblings, 0 replies; 4+ 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] 4+ 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-01 18:21 ` + mm-vmalloc-bail-out-if-in-softirq-context.patch added to mm-hotfixes-unstable branch Andrew Morton
  2026-12-02  2:31 ` [PATCH v2] mm/vmalloc: Bail out if in softirq context Baoquan He
@ 2026-12-02 17:37 ` sashiko-bot
  2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-02 17:37 UTC (permalink / raw)
  To: Uladzislau Rezki (Sony), linux-mm, Andrew Morton
  Cc: Baoquan He, David Hildenbrand (Arm)

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] mm/vmalloc: WARN_ON_ONCE in __get_vm_area_node() on atomic
  kvmalloc()
--

commit b5a4024f17bff0a7c18243c940b773dd42c4d2f1
Author: Uladzislau Rezki (Sony) <urezki@gmail.com>

mm/vmalloc: Bail out if in softirq context

This commit replaces the BUG_ON(in_nmi() || in_hardirq()) check in
__get_vm_area_node() with a WARN_ON_ONCE() check that also rejects softirq
and BH-disabled contexts and returns NULL.

> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index a4c22c569b1de..fe5bdb4fde52b 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;

[Severity: Medium]
Can this trigger a WARN_ON_ONCE() splat on valid atomic kvmalloc() calls in
softirq or BH-disabled context?

Since commit c6307674ed82 ("mm: kvmalloc: add non-blocking support for
vmalloc"), __kvmalloc_node_noprof() falls back to
__vmalloc_node_range_noprof() whenever a multi-page __do_kmalloc_node()
attempt fails, even for GFP_ATOMIC callers:

mm/slub.c:__kvmalloc_node_noprof() {
    ...
	ret = __do_kmalloc_node(size, kmalloc_gfp_adjust(flags, size), node,
				_RET_IP_);
	if (ret || size <= PAGE_SIZE)
		return ret;
    ...
	return __vmalloc_node_range_noprof(size, align, VMALLOC_START, VMALLOC_END,
			flags, PAGE_KERNEL, allow_block ? VM_ALLOW_HUGE_VMAP:0,
			node, __builtin_return_address(0));
}

Callers such as br_fdb_add_local() (holding spin_lock_bh(&br->hash_lock))
and br_fdb_update() (in softirq) call rhashtable_lookup_insert_fast() ->
rhashtable_insert_rehash() -> bucket_table_alloc() with GFP_ATOMIC |
__GFP_NOWARN, expecting kvmalloc() to return NULL silently on failure so
bucket_table_alloc() can fall back to nested_bucket_table_alloc().  When the
initial kmalloc attempt fails, falling through to __get_vm_area_node() hits
this WARN_ON_ONCE() (and crashes systems with panic_on_warn enabled, such as
syzbot, on the same BH-disabled path that commit 04aa71da5f35 ("mm/vmalloc:
do not trigger BUG() on BH disabled context") addressed).  If an atomic
caller does not pass __GFP_NOWARN, __vmalloc_node_range_noprof() also emits
a warn_alloc() splat when __get_vm_area_node() returns NULL because
kmalloc_gfp_adjust() only applies __GFP_NOWARN to __do_kmalloc_node().

Should __kvmalloc_node_noprof() avoid the vmalloc fallback when
in_interrupt() is true?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201173727.90526-1-urezki@gmail.com?part=1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-12-02 17:37 UTC | newest]

Thread overview: 4+ 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-01 18:21 ` + mm-vmalloc-bail-out-if-in-softirq-context.patch added to mm-hotfixes-unstable branch Andrew Morton
2026-12-02  2:31 ` [PATCH v2] mm/vmalloc: Bail out if in softirq context Baoquan He
2026-12-02 17:37 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.