Linux USB
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: william@wkennington.com
Cc: oliver@neukum.org, andrew+netdev@lunn.ch, davem@davemloft.net,
	edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
	linux-usb@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v2] net: usb: cdc_ncm: send the NTB once another datagram would not fit
Date: Sat, 28 Nov 2026 11:07:47 +0000	[thread overview]
Message-ID: <179586406785.3135.9027128089065565502@kernel.org> (raw)
In-Reply-To: <20261127110521.1235409-1-william@wkennington.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The patch only narrows one way that a datagram ends up parked in
  ctx->tx_rem_skb.
- [Medium] Other usbnet queue stops cause the same drop, and a heuristic
  based on NTB size cannot prevent them.
- [Low] The new early-close check in cdc_ncm_fill_tx_frame()
  (drivers/net/usb/cdc_ncm.c:1382-1383) adds VLAN_HLEN to every reserved…

--

net: usb: cdc_ncm: send the NTB once another datagram would not fit

With this patch, cdc_ncm_fill_tx_frame() sends the current NTB as soon
as another MTU-sized datagram (with Ethernet and VLAN headers) would no
longer fit, as long as nothing is parked in tx_rem_skb. The goal is
that no datagram is held in tx_rem_skb when usbnet stops the TX queue,
so the timer flush in cdc_ncm_txpath_bh() no longer drops it into a
stopped queue.

> diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
> index e92dc7f011ea7..7fbce4846a044 100644
> --- a/drivers/net/usb/cdc_ncm.c
> +++ b/drivers/net/usb/cdc_ncm.c

[ ... ]

> @@ -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) {

[Severity: High]
Does this check cover every way a datagram can still be parked in
ctx->tx_rem_skb? It only reserves room for a same-signature datagram of
up to mtu + eth_hlen + VLAN_HLEN. The "no room for skb - store for
later" branch in cdc_ncm_fill_tx_frame() still looks reachable:

	ctx->tx_rem_skb = skb;
	ctx->tx_rem_sign = sign;
	skb = NULL;
	ready2send = 1;

Here are a few cases where that seems to happen.

MBIM with several IPS/DSS sessions, without NDP_TO_END. The first
datagram of a new session needs NDP alignment plus max_ndp_size, which
cdc_ncm_ndp16() and cdc_ncm_ndp32() check:

	if (skb->len + reserve + ctx->max_ndp_size > ctx->tx_curr_size)
		return NULL;

The new check doesn't reserve that space, so an MTU-sized datagram for
a new session can still be parked.

Devices with CDC_NCM_FLAG_NDP_TO_END, such as cdc_mbim_info_ndp_to_end
or any device with the ndp_to_end sysfs flag set. cdc_ncm_ndp16() and
cdc_ncm_ndp32() return NULL for any second signature, whatever the free
space:

	else if (ctx->delayed_ndp16->dwSignature)
		return NULL;

The comment above cdc_mbim_info_ndp_to_end says multiplexed sessions
cannot share an NTB. So each session switch parks a datagram.

Frames longer than mtu + ETH_HLEN + VLAN_HLEN on plain cdc_ncm. cdc_ncm
doesn't set NETIF_F_HW_VLAN_CTAG_TX. Stacked 802.1ad/802.1Q devices
inherit the real device's MTU, so they send inline frames of mtu + 22
bytes. Frames queued before an MTU decrease also qualify, because
READ_ONCE(dev->net->mtu) returns the new, smaller value. These pass the
new check and then fail the real fit check, which uses skb->len.

In each case, the NTB returned with ready2send = 1 can be the one that
brings txq.qlen up to TX_QLEN in usbnet_start_xmit():

	if (dev->txq.qlen >= TX_QLEN (dev))
		netif_stop_queue (net);

The hrtimer then fires, and the following runs:

cdc_ncm_txpath_bh()
  usbnet_start_xmit(NULL, dev->net)
    info->tx_fixup()    /* builds an NTB from the parked datagram */
    netif_queue_stopped(net) -> goto drop

Isn't this the same tx_dropped path that the commit message and the
Fixes tag describe? cdc_mbim and huawei_cdc_ncm share this code.

The commit message also says:

  tx_rem_skb is still used when a datagram needs a new NDP that does not
  fit, as with several MBIM sessions.

For NDP_TO_END devices the datagram is parked whether or not it fits.
Is "does not fit" accurate there?

Would it be more robust to fix this in the flush path? One option is to
check netif_queue_stopped() in cdc_ncm_txpath_bh() under netif_tx_lock
and re-arm the timer instead of flushing. Another is to keep usbnet
from consuming tx_fixup(NULL) data while the queue is stopped.

[Severity: Low]
Should VLAN_HLEN be added for MBIM? cdc_ncm_eth_hlen() returns 0 for
MBIM because the datagrams are raw L3. cdc_mbim sets
NETIF_F_HW_VLAN_CTAG_TX. Also, cdc_mbim_tx_fixup() strips the L2 header
before calling cdc_ncm_fill_tx_frame():

	if (vlan_get_tag(skb, &tci) < 0 && skb->len > VLAN_ETH_HLEN &&
	    __vlan_get_tag(skb, &tci) == 0) {
		...
		skb_pull(skb, VLAN_ETH_HLEN);
	} else {
		...
		skb_pull(skb, ETH_HLEN);
	}

So the largest MBIM datagram is mtu, but this check reserves mtu + 4.
Inside a 4-byte window, an MBIM NTB gets closed even though another
full-size datagram would still fit.

Would adding VLAN_HLEN only when cdc_ncm_eth_hlen(dev) is non-zero
match the header model that the helper encodes?

> +			ready2send = 1;
> +			ctx->tx_reason_ntb_full++;	/* count reason for transmitting */
> +			n++;
> +			break;
> +		}
>  	}

[Severity: Medium]
Can other kinds of queue stop still lose datagrams through the same
flush path? For -EPROTO, -ETIME and -EILSEQ, tx_complete() stops the
queue and arms dev->delay for THROTTLE_JIFFIES (HZ/8). EHCI hosts can
report these errors:

	case -EPROTO:
	case -ETIME:
	case -EILSEQ:
		...
		netif_stop_queue(dev->net);
		break;

usbnet_start_xmit() also stops the queue on -EPIPE and for
EVENT_DEV_ASLEEP.

After this patch, cdc_ncm_fill_tx_frame() still holds partially filled
NTBs in ctx->tx_curr_skb with the hrtimer armed. The flush interval is
about 400 us plus a few re-arms through tx_timer_pending. That is much
shorter than the 125 ms throttle window, so
cdc_ncm_txpath_bh()->usbnet_start_xmit(NULL) would build an NTB from
every held datagram and drop it at the netif_queue_stopped() check.

The commit message says "every drop came from cdc_ncm_txpath_bh()
calling usbnet_start_xmit(NULL, ...) into a stopped TX queue". That
diagnosis and the Fixes tag cover these stops too, since ad70411a978d
added the stopped-queue drop for every stop reason. This patch only
addresses stops caused by a full TX queue.

Would a flush-path fix that re-arms the timer instead of flushing into
a stopped queue cover these cases as well?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127110521.1235409-1-william%40wkennington.com

      parent reply	other threads:[~2026-11-28 11:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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
2026-11-28 11:07 ` netdev-bot+sashiko [this message]

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=179586406785.3135.9027128089065565502@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --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 \
    --cc=william@wkennington.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