From: "William A. Kennington III" <william@wkennington.com>
To: Oliver Neukum <oliver@neukum.org>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: "Jan Klötzke" <Jan.Kloetzke@preh.de>,
linux-usb@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
"William A. Kennington III" <william@wkennington.com>
Subject: [PATCH net] net: usb: cdc_ncm: don't flush the TX timer into a stopped queue
Date: Wed, 18 Nov 2026 03:41:22 +0000 [thread overview]
Message-ID: <20261118034122.315979-1-william@wkennington.com> (raw)
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
reply other threads:[~2026-11-18 3:41 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261118034122.315979-1-william@wkennington.com \
--to=william@wkennington.com \
--cc=Jan.Kloetzke@preh.de \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=oliver@neukum.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.