[PATCH net] net: usb: cdc_ncm: don't flush the TX timer into a stopped queue

From: William A. Kennington III

Date: Tue Nov 17 2026 - 22:41:32 EST


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@xxxxxxxxxxxxxxx>
---
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