Skip to contentSkip to conversation

net: usb: cdc_ncm/cdc_mbim: fix netpoll lockup in tx_fixup

PATCH Applied Nicolai Buchwitz 3 participants 6 messages Oct 24 – Oct 27

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v3 cover net: usb: cdc_ncm/cdc_mbim: fix netpoll lockup in tx_fixup

Mikkel reported lockups with netconsole on a cdc_ncm device. Further analysis showed that netpoll calls ndo_start_xmit() with IRQs off but BHs on while holding the txq lock, and the spin_unlock_bh() in the tx_fixup paths runs pending softirqs. A transmit from one of them then spins on that txq lock.

Patch 1 fixes cdc_ncm. Mikkel tested the v2 version of it. Patch 2 fixes the same code in cdc_mbim and is untested.

Changes in v3:
- Use plain spin_lock() instead of spin_lock_irqsave() (Jakub)
- Drop Tested-by and Reviewed-by tags since the locking changed
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Reverse xmas in patch 1
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Nicolai Buchwitz (2):
net: usb: cdc_ncm: don't enable BHs in tx_fixup under netpoll
net: usb: cdc_mbim: don't enable BHs in tx_fixup under netpoll

 drivers/net/usb/cdc_mbim.c | 5 +++--
 drivers/net/usb/cdc_ncm.c  | 7 +++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

---
base-commit: 044ad3c90d9d2df2c5cb3325ae17b4e9603a311f
change-id: 20261020-cdc-ncm-netpoll-d7a7f69dd2cc

Best regards,

Signature · 1 line
Nicolai Buchwitz <[email protected]>
#1 lore raw

PATCH v3 1/2 net: usb: cdc_ncm: don't enable BHs in tx_fixup under netpoll

netpoll holds the txq lock and calls ndo_start_xmit() with IRQs off but BHs on. The spin_unlock_bh() in cdc_ncm_tx_fixup() then runs pending softirqs. If one of them transmits, it spins on the txq lock that netpoll holds. With netconsole on a cdc_ncm device this ends in a soft or hard lockup.

Every caller of cdc_ncm_tx_fixup() holds the txq lock with BHs or IRQs off, so the softirq user of ctx->mtx cannot interrupt it. Use plain spin_lock().

---
 drivers/net/usb/cdc_ncm.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/usb/cdc_ncm.c +5 -2
index 35db38cb3e4a2..3bd7cb66f3fc3 100644
@@ -1535,14 +1535,17 @@ cdc_ncm_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
 	if (ctx == NULL)
 		goto error;
 
-	spin_lock_bh(&ctx->mtx);
+	/* BHs or IRQs are always off here. netpoll only disables IRQs, and
+	 * spin_unlock_bh() would then run softirqs with the txq lock held.
+	 */
+	spin_lock(&ctx->mtx);
 
 	if (ctx->is_ndp16)
 		skb_out = cdc_ncm_fill_tx_frame(dev, skb, cpu_to_le32(USB_CDC_NCM_NDP16_NOCRC_SIGN));
 	else
 		skb_out = cdc_ncm_fill_tx_frame(dev, skb, cpu_to_le32(USB_CDC_NCM_NDP32_NOCRC_SIGN));
 
-	spin_unlock_bh(&ctx->mtx);
+	spin_unlock(&ctx->mtx);
 	return skb_out;
 
 error:
Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH net v3 1/2] net: usb: cdc_ncm: don't enable BHs in tx_fixup under netpoll

Sashiko has reviewed this patch and found no issues.
Quoted 6 lines

netpoll holds the txq lock and calls ndo_start_xmit() with IRQs off but BHs on. The spin_unlock_bh() in cdc_ncm_tx_fixup() then runs pending softirqs. If one of them transmits, it spins on the txq lock that netpoll holds. With netconsole on a cdc_ncm device this ends in a soft or hard lockup.

Quoted 8 lines

Every caller of cdc_ncm_tx_fixup() holds the txq lock with BHs or IRQs off, so the softirq user of ctx->mtx cannot interrupt it. Use plain spin_lock().

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

PATCH v3 2/2 net: usb: cdc_mbim: don't enable BHs in tx_fixup under netpoll

In reply to Nicolai Buchwitz

cdc_mbim_tx_fixup() has the same spin_unlock_bh() as cdc_ncm_tx_fixup(). Under netpoll it runs pending softirqs while the txq lock is held, and a transmit from one of them spins on that lock.

Use plain spin_lock() as in cdc_ncm.

Fixes 9bf211a30b3f ("net: cdc_mbim: adding MBIM driver")
---
 drivers/net/usb/cdc_mbim.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/usb/cdc_mbim.c +3 -2
index a7010a0664c7d..8f5734ac35b8c 100644
@@ -289,9 +289,10 @@ static struct sk_buff *cdc_mbim_tx_fixup(struct usbnet *dev, struct sk_buff *skb
 		}
 	}
 
-	spin_lock_bh(&ctx->mtx);
+	/* BHs or IRQs are always off here, see cdc_ncm_tx_fixup() */
+	spin_lock(&ctx->mtx);
 	skb_out = cdc_ncm_fill_tx_frame(dev, skb, sign);
-	spin_unlock_bh(&ctx->mtx);
+	spin_unlock(&ctx->mtx);
 	return skb_out;
 
 error:
Signature · 1 line
2.53.0
#4 lore raw

Re: [PATCH net v3 2/2] net: usb: cdc_mbim: don't enable BHs in tx_fixup under netpoll

Sashiko has reviewed this patch and found no issues.
Quoted 8 lines

cdc_mbim_tx_fixup() has the same spin_unlock_bh() as cdc_ncm_tx_fixup(). Under netpoll it runs pending softirqs while the txq lock is held, and a transmit from one of them spins on that lock.

Use plain spin_lock() as in cdc_ncm.

Fixes 9bf211a30b3f ("net: cdc_mbim: adding MBIM driver")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#5 lore raw
In reply to Nicolai Buchwitz
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Sat, 24 Oct 2026 15:23:05 +0200 you wrote:

Mikkel reported lockups with netconsole on a cdc_ncm device. Further analysis showed that netpoll calls ndo_start_xmit() with IRQs off but BHs on while holding the txq lock, and the spin_unlock_bh() in the tx_fixup paths runs pending softirqs. A transmit from one of them then spins on that txq lock.

Patch 1 fixes cdc_ncm. Mikkel tested the v2 version of it. Patch 2 fixes the same code in cdc_mbim and is untested.

[...]

Here is the summary with links:
- [net,v3,1/2] net: usb: cdc_ncm: don't enable BHs in tx_fixup under netpoll

    https://git.kernel.org/netdev/net/c/108ca34cf4b4
  - [net,v3,2/2] net: usb: cdc_mbim: don't enable BHs in tx_fixup under netpoll
    https://git.kernel.org/netdev/net/c/bfd7ced012c7

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html