* [PATCH net v2] net: usb: cdc_ncm: send the NTB once another datagram would not fit
@ 2026-11-27 11:05 William A. Kennington III
2026-11-27 11:10 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: William A. Kennington III @ 2026-11-27 11:05 UTC (permalink / raw)
To: Oliver Neukum, Andrew Lunn, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
Cc: linux-usb, netdev, linux-kernel, William A. Kennington III
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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH net v2] net: usb: cdc_ncm: send the NTB once another datagram would not fit
2026-11-27 11:05 [PATCH net v2] net: usb: cdc_ncm: send the NTB once another datagram would not fit William A. Kennington III
@ 2026-11-27 11:10 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-27 11:10 UTC (permalink / raw)
To: William A. Kennington III; +Cc: linux-usb
> 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
> [ ... ]
> 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>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127110521.1235409-1-william@wkennington.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-27 11:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 11:05 [PATCH net v2] net: usb: cdc_ncm: send the NTB once another datagram would not fit William A. Kennington III
2026-11-27 11:10 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox