Skip to contentSkip to conversation

mm/vmalloc: Do not trigger BUG() on BH disabled context

PATCH Applied Uladzislau Rezki (Sony) 3 participants 5 messages May 15 – May 19

Subsystems (2)
lore
Share & tools
lore

Uladzislau Rezki (Sony)

author maintainer
#0 lore raw

PATCH 1/1 mm/vmalloc: Do not trigger BUG() on BH disabled context

__get_vm_area_node() currently triggers a BUG() if in_interrupt() returns true. However, in_interrupt() also reports true when BH are disabled.

The bridge code can call rhashtable_lookup_insert_fast() with bottom halves disabled:

__vlan_add()
-> br_fdb_add_local()
spin_lock_bh(&br->hash_lock); <-- Disable BH
-> fdb_add_local()

    -> fdb_create()
     -> rhashtable_lookup_insert_fast()
      -> kvmalloc()
       -> vmalloc()
        -> __get_vm_area_node()
         -> BUG_ON(in_interrupt())

spin_unlock_bh(&br->hash_lock)

this triggers the BUG() despite the caller not being in NMI or hard IRQ context.

Replace the in_interrupt() check with in_nmi() || in_hardirq().

Cc Ido Schimmel <[email protected]>
Fixes c6307674ed82 ("mm: kvmalloc: add non-blocking support for vmalloc")
Reported-by [email protected]
---
 mm/vmalloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vmalloc.c +1 -1
index 676851d5cfe7..273bbe49eaef 100644
@@ -3209,7 +3209,7 @@ struct vm_struct *__get_vm_area_node(unsigned long size,
 	struct vm_struct *area;
 	unsigned long requested_size = size;
 
-	BUG_ON(in_interrupt());
+	BUG_ON(in_nmi() || in_hardirq());
 	size = ALIGN(size, 1ul << shift);
 	if (unlikely(!size))
 		return NULL;
Signature · 1 line
2.47.3
maintainer
#1 lore raw
Quoted 19 lines · On Fri, 15 May 2026 17:30:09 +0200 "Uladzislau Rezki (Sony)"…

__get_vm_area_node() currently triggers a BUG() if in_interrupt() returns true. However, in_interrupt() also reports true when BH are disabled.

The bridge code can call rhashtable_lookup_insert_fast() with bottom halves disabled:

__vlan_add()
-> br_fdb_add_local()
spin_lock_bh(&br->hash_lock); <-- Disable BH
-> fdb_add_local()

    -> fdb_create()
     -> rhashtable_lookup_insert_fast()
      -> kvmalloc()
       -> vmalloc()
        -> __get_vm_area_node()
         -> BUG_ON(in_interrupt())

spin_unlock_bh(&br->hash_lock)

Quoted 7 lines

this triggers the BUG() despite the caller not being in NMI or hard IRQ context.

Replace the in_interrupt() check with in_nmi() || in_hardirq().

Cc Ido Schimmel <[email protected]>
Fixes c6307674ed82 ("mm: kvmalloc: add non-blocking support for vmalloc")

Was added in 6.19 so I assumed we want cc:stable on this.

Quoted 3 lines
author maintainer
#2 lore raw
Quoted 24 lines · Andrew Morton
Quoted 22 lines · On Fri, 15 May 2026 17:30:09 +0200 "Uladzislau Rezki (Sony)"…

__get_vm_area_node() currently triggers a BUG() if in_interrupt() returns true. However, in_interrupt() also reports true when BH are disabled.

The bridge code can call rhashtable_lookup_insert_fast() with bottom halves disabled:

__vlan_add()
-> br_fdb_add_local()
spin_lock_bh(&br->hash_lock); <-- Disable BH
-> fdb_add_local()

    -> fdb_create()
     -> rhashtable_lookup_insert_fast()
      -> kvmalloc()
       -> vmalloc()
        -> __get_vm_area_node()
         -> BUG_ON(in_interrupt())

spin_unlock_bh(&br->hash_lock)

this triggers the BUG() despite the caller not being in NMI or hard IRQ context.

Quoted 7 lines
Quoted 4 lines

Replace the in_interrupt() check with in_nmi() || in_hardirq().

Cc Ido Schimmel <[email protected]>
Fixes c6307674ed82 ("mm: kvmalloc: add non-blocking support for vmalloc")

Was added in 6.19 so I assumed we want cc:stable on this.

Thank you. Yep, we want cc:stable!

--
Uladzislau Rezki

Reviewed-by on v1 1/1
#3 lore raw
In reply to Uladzislau Rezki (Sony)
Quoted 17 lines · Uladzislau Rezki (Sony)

__get_vm_area_node() currently triggers a BUG() if in_interrupt() returns true. However, in_interrupt() also reports true when BH are disabled.

The bridge code can call rhashtable_lookup_insert_fast() with bottom halves disabled:

__vlan_add()
-> br_fdb_add_local()
spin_lock_bh(&br->hash_lock); <-- Disable BH
-> fdb_add_local()

    -> fdb_create()
     -> rhashtable_lookup_insert_fast()
      -> kvmalloc()
       -> vmalloc()
        -> __get_vm_area_node()
         -> BUG_ON(in_interrupt())
Quoted 4 lines

spin_unlock_bh(&br->hash_lock)

this triggers the BUG() despite the caller not being in NMI or hard IRQ context.

Because the current vmalloc supports non-blocking allocation, so we need to skip disabled BH or in_serving_softirq() cases to avoid unwanted BUG(). This change looks great to me, not sure if I undersand it correctly.

Thanks
Baoquan

Quoted 28 lines

Replace the in_interrupt() check with in_nmi() || in_hardirq().

Cc Ido Schimmel <[email protected]>
Fixes c6307674ed82 ("mm: kvmalloc: add non-blocking support for vmalloc")
Reported-by [email protected]
---
 mm/vmalloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vmalloc.c +1 -1
index 676851d5cfe7..273bbe49eaef 100644
@@ -3209,7 +3209,7 @@ struct vm_struct *__get_vm_area_node(unsigned long size,
 	struct vm_struct *area;
 	unsigned long requested_size = size;
 
-	BUG_ON(in_interrupt());
+	BUG_ON(in_nmi() || in_hardirq());
 	size = ALIGN(size, 1ul << shift);
 	if (unlikely(!size))
 		return NULL;
Signature · 1 line
2.47.3
author maintainer
#4 lore raw
Quoted 23 lines · Baoquan He
Quoted 17 lines · Uladzislau Rezki (Sony)

__get_vm_area_node() currently triggers a BUG() if in_interrupt() returns true. However, in_interrupt() also reports true when BH are disabled.

The bridge code can call rhashtable_lookup_insert_fast() with bottom halves disabled:

__vlan_add()
-> br_fdb_add_local()
spin_lock_bh(&br->hash_lock); <-- Disable BH
-> fdb_add_local()

    -> fdb_create()
     -> rhashtable_lookup_insert_fast()
      -> kvmalloc()
       -> vmalloc()
        -> __get_vm_area_node()
         -> BUG_ON(in_interrupt())
Quoted 4 lines

spin_unlock_bh(&br->hash_lock)

this triggers the BUG() despite the caller not being in NMI or hard IRQ context.

Quoted 7 lines

Because the current vmalloc supports non-blocking allocation, so we need to skip disabled BH or in_serving_softirq() cases to avoid unwanted BUG(). This change looks great to me, not sure if I undersand it correctly.

Thank you!

--
Uladzislau Rezki