From 705227e1706231313be8543463e879d48607d892 Mon Sep 17 00:00:00 2001 From: termg Date: Thu, 29 Oct 2026 19:36:53 +0000 Subject: [PATCH] usb: gadget: f_ncm: retry the TX timer flush when the IN queue is busy ncm_wrap_ntb() only starts task_timer when it begins a new NTB, and ncm_tx_timeout() then flushes the pending NTB by calling eth_start_xmit() with a NULL skb. If all IN requests are in flight at that moment, eth_start_xmit() finds tx_reqs empty and returns NETDEV_TX_BUSY; the timer is not restarted, so the partly filled NTB stays queued until enough frames arrive to fill it (TX_MAX_NUM_DPE datagrams or the NTB size). With an NFS root over NCM this happened a few hundred times per boot after traffic bursts and stalled device->host traffic for 0.5-27 s (ping replies held back and delivered together, "nfs: server not responding"); when no further frames arrive, the NTB is never sent. Restart the timer when the flush gets NETDEV_TX_BUSY, unless the port is suspended (eth_start_xmit() then returns busy while waking the host). With this, the same workload shows no stalls: ping p99 0.47 ms, max 0.75 ms. Assisted-By: LLM Signed-off-by: termg --- drivers/usb/gadget/function/f_ncm.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c index 500c9c19c78b4..e52923653a81a 100644 --- a/drivers/usb/gadget/function/f_ncm.c +++ b/drivers/usb/gadget/function/f_ncm.c @@ -1158,7 +1158,17 @@ static enum hrtimer_restart ncm_tx_timeout(struct hrtimer *data) * * This will call directly into u_ether's eth_start_xmit() */ - netdev->netdev_ops->ndo_start_xmit(NULL, netdev); + if (netdev->netdev_ops->ndo_start_xmit(NULL, netdev) == NETDEV_TX_BUSY && + !ncm->port.is_suspend) { + /* + * All IN requests are in flight, so the pending NTB + * was not sent. The timer is only started for a new + * NTB, so nothing would send this one until it fills + * up: try again after another timeout. + */ + hrtimer_forward_now(data, TX_TIMEOUT_NSECS); + return HRTIMER_RESTART; + } } return HRTIMER_NORESTART; }