mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net] net: usb: cdc_ncm: don't flush the TX timer into a stopped queue
@ 2026-11-18  3:41 William A. Kennington III
  0 siblings, 0 replies; only message in thread
From: William A. Kennington III @ 2026-11-18  3:41 UTC (permalink / raw)
  To: Oliver Neukum, Andrew Lunn, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Jan Klötzke, linux-usb, netdev, linux-kernel,
	William A. Kennington III

cdc_ncm_txpath_bh() calls usbnet_start_xmit() directly without checking
whether usbnet has stopped the netdev TX queue. Since commit
ad70411a978d ("usbnet: fix kernel crash after disconnect"),
usbnet_start_xmit() frees any NTB submitted while the queue is stopped
and increments tx_dropped.

This triggers routinely under bulk load. With the default 16 KiB NTBs,
usbnet only allows MAX_QUEUE_MEMORY / tx_max = 5 TX URBs in flight, so a
bulk TCP stream stops the queue constantly. The TX timer is armed while
an NTB is partly filled and keeps running after a subsequent packet
sends that NTB out full; when the timer fires while all 5 URBs are still
in flight, any frame left in tx_rem_skb or tx_curr_skb is flushed into a
new NTB and dropped by usbnet, causing steady tx_dropped increments and
TCP retransmits.

While TX URBs are in flight (dev->txq) or completed and awaiting
usbnet_bh() (dev->done), usbnet will wake the queue again. When the
queue is stopped under those conditions and cdc_ncm has buffered TX
frames, restart the timer instead of flushing into usbnet_start_xmit().
Keep the existing flush path when nothing is queued to wake the device,
the interface is down, or the timer is disabled (tx_timer_usecs = 0), so
the timer cannot rearm indefinitely.

Check the state under ctx->mtx inside netif_tx_lock_bh(), matching the
lock order on the transmit path and keeping tx_reason_timeout
serialized.

Fixes: ad70411a978d ("usbnet: fix kernel crash after disconnect")
Signed-off-by: William A. Kennington III <william@wkennington.com>
---
 drivers/net/usb/cdc_ncm.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index e92dc7f011ea..e5d659dd7436 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -1509,9 +1509,26 @@ static void cdc_ncm_txpath_bh(struct tasklet_struct *t)
 		cdc_ncm_tx_timeout_start(ctx);
 		spin_unlock(&ctx->mtx);
 	} else if (dev->net != NULL) {
-		ctx->tx_reason_timeout++;	/* count reason for transmitting */
 		spin_unlock(&ctx->mtx);
 		netif_tx_lock_bh(dev->net);
+		spin_lock(&ctx->mtx);
+		/* usbnet drops the whole NTB if its queue is stopped. While
+		 * TX URBs are in flight, or completed but not yet reaped by
+		 * usbnet_bh(), the queue will be woken again, so keep any
+		 * buffered frames and retry a timer interval later.
+		 */
+		if (ctx->timer_interval &&
+		    (ctx->tx_curr_skb || ctx->tx_rem_skb) &&
+		    netif_running(dev->net) && netif_queue_stopped(dev->net) &&
+		    (skb_queue_len_lockless(&dev->txq) ||
+		     skb_queue_len_lockless(&dev->done))) {
+			cdc_ncm_tx_timeout_start(ctx);
+			spin_unlock(&ctx->mtx);
+			netif_tx_unlock_bh(dev->net);
+			return;
+		}
+		ctx->tx_reason_timeout++;
+		spin_unlock(&ctx->mtx);
 		usbnet_start_xmit(NULL, dev->net);
 		netif_tx_unlock_bh(dev->net);
 	} else {

base-commit: 2a324a58a084c5cfd7e5a2f55e0786bee170a4a5
-- 
2.56.1.703.gf848ed807c-goog


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-18  3:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18  3:41 [PATCH net] net: usb: cdc_ncm: don't flush the TX timer into a stopped queue William A. Kennington III

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®