🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
6 messages
6 total messages Started by Nicolai Buchwitz Wed, 21 Oct 2026 07:56
[PATCH net v2 0/2] net: usb: cdc_ncm/cdc_mbim: fix netpoll lockup in tx_fixup
#5912
Author: Nicolai Buchwitz
Date: Wed, 21 Oct 2026 07:56
30 lines
9570 bytes
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 reproduced the lockup and tested the fix.
Patch 2 fixes the same code in cdc_mbim and is untested.

Changes in v2:
- Reverse xmas in patch 1
- Link to v1: https://lore.kernel.org/r/20261020-cdc-ncm-netpoll-v1-0-682184384b49@tipi-net.de

Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>
---
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 |  6 ++++--
 drivers/net/usb/cdc_ncm.c  | 10 +++++++---
 2 files changed, 11 insertions(+), 5 deletions(-)
---
base-commit: 044ad3c90d9d2df2c5cb3325ae17b4e9603a311f
change-id: 20261020-cdc-ncm-netpoll-d7a7f69dd2cc

Best regards,
--  
Nicolai Buchwitz <nb@tipi-net.de>
[PATCH net v2 1/2] net: usb: cdc_ncm: don't enable BHs in tx_fixup under netpoll
#5910
Author: Nicolai Buchwitz
Date: Wed, 21 Oct 2026 07:56
57 lines
10399 bytes
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.

Use spin_lock_irqsave(), which is safe both under netpoll and on the
normal xmit path.

Fixes: c84ff1d6dff3 ("cdc_ncm: reduce driver latency in the data path")
Reported-by: Mikkel Eskildsen <mke@visotia.com>
Closes: https://lore.kernel.org/netdev/PRAP189MB185019A5A8D411482BB6E0CDA9982@PRAP189MB1850.EURP189.PROD.OUTLOOK.COM/
Tested-by: Mikkel Eskildsen <mke@visotia.com>
Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>
---
 drivers/net/usb/cdc_ncm.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index 35db38cb3e4a2..fed0b117a42f1 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -1522,8 +1522,9 @@ static void cdc_ncm_txpath_bh(struct tasklet_struct *t)
 struct sk_buff *
 cdc_ncm_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
 {
-	struct sk_buff *skb_out;
 	struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
+	struct sk_buff *skb_out;
+	unsigned long irqflags;
 
 	/*
 	 * The Ethernet API we are using does not support transmitting
@@ -1535,14 +1536,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);
+	/* netpoll calls this with IRQs off and BHs on, so unlocking with
+	 * spin_unlock_bh() would run softirqs that need the held txq lock.
+	 */
+	spin_lock_irqsave(&ctx->mtx, irqflags);
 
 	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_irqrestore(&ctx->mtx, irqflags);
 	return skb_out;
 
 error:

-- 
2.53.0
[PATCH net v2 2/2] net: usb: cdc_mbim: don't enable BHs in tx_fixup under netpoll
#5909
Author: Nicolai Buchwitz
Date: Wed, 21 Oct 2026 07:56
41 lines
9665 bytes
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 spin_lock_irqsave() as in cdc_ncm.

Fixes: 9bf211a30b3f ("net: cdc_mbim: adding MBIM driver")
Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>
---
 drivers/net/usb/cdc_mbim.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/usb/cdc_mbim.c b/drivers/net/usb/cdc_mbim.c
index a7010a0664c7d..7158716c1f106 100644
--- a/drivers/net/usb/cdc_mbim.c
+++ b/drivers/net/usb/cdc_mbim.c
@@ -223,6 +223,7 @@ static struct sk_buff *cdc_mbim_tx_fixup(struct usbnet *dev, struct sk_buff *skb
 	struct cdc_mbim_state *info = (void *)&dev->data;
 	struct cdc_ncm_ctx *ctx = info->ctx;
 	__le32 sign = cpu_to_le32(USB_CDC_MBIM_NDP16_IPS_SIGN);
+	unsigned long irqflags;
 	u16 tci = 0;
 	bool is_ip;
 	u8 *c;
@@ -289,9 +290,10 @@ static struct sk_buff *cdc_mbim_tx_fixup(struct usbnet *dev, struct sk_buff *skb
 		}
 	}
 
-	spin_lock_bh(&ctx->mtx);
+	/* IRQs are off and BHs on under netpoll, see cdc_ncm_tx_fixup() */
+	spin_lock_irqsave(&ctx->mtx, irqflags);
 	skb_out = cdc_ncm_fill_tx_frame(dev, skb, sign);
-	spin_unlock_bh(&ctx->mtx);
+	spin_unlock_irqrestore(&ctx->mtx, irqflags);
 	return skb_out;
 
 error:

-- 
2.53.0
Re: [PATCH net v2 1/2] net: usb: cdc_ncm: don't enable BHs in tx_fixup under netpoll
#6444
Author: Simon Horman
Date: Thu, 22 Oct 2026 12:58
18 lines
8957 bytes
On Wed, Oct 21, 2026 at 09:56:18AM +0200, Nicolai Buchwitz wrote:
> 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.
> 
> Use spin_lock_irqsave(), which is safe both under netpoll and on the
> normal xmit path.
> 
> Fixes: c84ff1d6dff3 ("cdc_ncm: reduce driver latency in the data path")
> Reported-by: Mikkel Eskildsen <mke@visotia.com>
> Closes: https://lore.kernel.org/netdev/PRAP189MB185019A5A8D411482BB6E0CDA9982@PRAP189MB1850.EURP189.PROD.OUTLOOK.COM/
> Tested-by: Mikkel Eskildsen <mke@visotia.com>
> Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>

Reviewed-by: Simon Horman <horms@kernel.org>
Re: [PATCH net v2 2/2] net: usb: cdc_mbim: don't enable BHs in tx_fixup under netpoll
#6445
Author: Simon Horman
Date: Thu, 22 Oct 2026 12:58
12 lines
8524 bytes
On Wed, Oct 21, 2026 at 09:56:19AM +0200, Nicolai Buchwitz wrote:
> 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 spin_lock_irqsave() as in cdc_ncm.
> 
> Fixes: 9bf211a30b3f ("net: cdc_mbim: adding MBIM driver")
> Signed-off-by: Nicolai Buchwitz <nb@tipi-net.de>

Reviewed-by: Simon Horman <horms@kernel.org>
Re: [PATCH net v2 2/2] net: usb: cdc_mbim: don't enable BHs in tx_fixup under netpoll
#6933
Author: Jakub Kicinski
Date: Fri, 23 Oct 2026 20:46
13 lines
8506 bytes
On Wed, 21 Oct 2026 09:56:19 +0200 Nicolai Buchwitz wrote:
> -	spin_lock_bh(&ctx->mtx);
> +	/* IRQs are off and BHs on under netpoll, see cdc_ncm_tx_fixup() */
> +	spin_lock_irqsave(&ctx->mtx, irqflags);
>  	skb_out = cdc_ncm_fill_tx_frame(dev, skb, sign);

Sashiko is concerned that we are now running cdc_ncm_fill_tx_frame()
with IRQs disabled, I think the suggestion to use plain spin_lock()
would work? The xmit lock shields us from recursion here.
Same for patch 1.
-- 
pw-bot: cr
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads