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: linux-usb@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org,
"William A. Kennington III" <william@wkennington.com>
Subject: [PATCH net v2] net: usb: cdc_ncm: send the NTB once another datagram would not fit
Date: Fri, 27 Nov 2026 11:05:21 +0000 [thread overview]
Message-ID: <20261127110521.1235409-1-william@wkennington.com> (raw)
Observed on BMCs in real use communicating with a USB NCM gadget over an
EHCI host controller, where bulk TCP traffic caused steady tx_dropped
growth and retransmits. Tracing the link with kprobes and the kfree_skb
tracepoint during iperf3 TCP runs confirmed that every drop came from
cdc_ncm_txpath_bh() calling usbnet_start_xmit(NULL, ...) into a stopped
TX queue.
cdc_ncm_fill_tx_frame() only learns that an NTB is full when it is given
a datagram that no longer fits. It then hands the NTB to usbnet and
parks that datagram in tx_rem_skb for the next NTB. If the stack sends
nothing more, only the TX timer is left to send it.
With 16 KiB NTBs usbnet allows 5 TX URBs in flight at high speed. When
the NTB that was just handed over is the fifth, usbnet stops the TX
queue. The timer then builds an NTB for the parked datagram and calls
usbnet_start_xmit(NULL, ...) directly, bypassing the qdisc. Since commit
ad70411a978d ("usbnet: fix kernel crash after disconnect")
usbnet_start_xmit() frees what it is given while the queue is stopped,
so the datagram is lost and counted in tx_dropped. A bulk TCP sender
hits this several times per second.
Send the NTB as soon as another datagram of the interface MTU, with a
VLAN tag, would not fit, provided no datagram is still parked in
tx_rem_skb. Nothing is parked on that path, so cdc_ncm holds no
datagram when usbnet stops the queue for a full TX queue, and the timer
has nothing to flush into it. An NTB also no longer waits for the next
datagram to arrive before it is sent.
tx_rem_skb is still used when a datagram needs a new NDP that does not
fit, as with several MBIM sessions.
The cost is that an NTB is closed while it could still take a datagram
smaller than the MTU. With 16 KiB NTBs and a 1500 byte MTU this does
not change the 10 full size frames per NTB.
Tested on an NPCM730 BMC (EHCI host, Linux 7.3.6 with BQL and fq_codel)
running 30 s iperf3 IPv6 TCP streams to an NCM gadget, same board
before and after:
tx_dropped Mbit/s (before -> after)
1 stream, fwd 106 -> 0 119.8 -> 141.0
4 streams, fwd 128 -> 0 164.3 -> 172.4
1 stream, bidir 51 -> 0 39.5/118.3 -> 73.0/107.7
4 streams, bidir 62 -> 0 36.7/150.3 -> 78.0/130.2
4 streams, MSS 512 81 -> 0 129.2 -> 152.8
Fixes: ad70411a978d ("usbnet: fix kernel crash after disconnect")
Signed-off-by: William A. Kennington III <william@wkennington.com>
---
v2:
- Replace the timer re-arm polling from v1 with closing the NTB as
soon as another full-MTU (plus VLAN) datagram would not fit, so no
datagram is parked in tx_rem_skb when usbnet stops the TX queue.
- Add real-hardware discovery/trace validation and same-board Linux
7.3.6 (with BQL and fq_codel) test results. Mainline usbnet BQL
still hits these drops because DQL's limit exceeds the 5-URB
(80 KiB) TX ring cap.
v1: https://lore.kernel.org/r/20261118034122.315979-1-william@wkennington.com
drivers/net/usb/cdc_ncm.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index e92dc7f011ea..7fbce4846a04 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -43,6 +43,7 @@
#include <linux/ctype.h>
#include <linux/etherdevice.h>
#include <linux/ethtool.h>
+#include <linux/if_vlan.h>
#include <linux/kstrtox.h>
#include <linux/workqueue.h>
#include <linux/mii.h>
@@ -1369,6 +1370,22 @@ cdc_ncm_fill_tx_frame(struct usbnet *dev, struct sk_buff *skb, __le32 sign)
ctx->tx_reason_ndp_full++; /* count reason for transmitting */
break;
}
+
+ /* Send now if another full size datagram would not fit.
+ * Accepting one more would park it in tx_rem_skb after
+ * this NTB has been handed to usbnet. If that NTB fills
+ * the TX queue, usbnet stops the queue and drops the NTB
+ * the timer builds for the parked datagram.
+ */
+ if (!ctx->tx_rem_skb && n + 1 < ctx->tx_max_datagrams &&
+ skb_out->len + ctx->tx_modulus + ctx->tx_remainder +
+ READ_ONCE(dev->net->mtu) + cdc_ncm_eth_hlen(dev) +
+ VLAN_HLEN + delayed_ndp_size > ctx->tx_curr_size) {
+ ready2send = 1;
+ ctx->tx_reason_ntb_full++; /* count reason for transmitting */
+ n++;
+ break;
+ }
}
/* free up any dangling skb */
--
2.56.1.839.g22a8290db9-goog
reply other threads:[~2026-11-27 11:05 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=20261127110521.1235409-1-william@wkennington.com \
--to=william@wkennington.com \
--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 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®