From: Nicola Lunghi <nick83ola@gmail.com>
To: mathias.nyman@intel.com, michal.pecio@gmail.com,
niklas.neronin@linux.intel.com, gregkh@linuxfoundation.org
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
Nicola Lunghi <nick83ola@gmail.com>
Subject: [PATCH 2/2] usb: xhci: fix CFC sequential scheduling lost on ring drain race
Date: Tue, 5 May 2026 01:31:44 +0200 [thread overview]
Message-ID: <20260504233143.10242-4-nick83ola@gmail.com> (raw)
In-Reply-To: <20260504233143.10242-2-nick83ola@gmail.com>
On CFC-capable xHCI controllers, xhci_queue_isoc_tx_prepare() uses
next_frame_id for sequential isochronous scheduling only when the
endpoint ring is non-empty and the endpoint is running. If all TDs are
returned before the next URB is submitted (a ring drain race made more
likely by fast TD-skip on xHCI 1.1+ controllers), the condition fails
and the URB is scheduled ASAP — potentially many frames ahead of where
the stream should continue, creating a gap.
Extend the condition to also use next_frame_id when a periodic
completion is in progress for the endpoint, covering the transient
window where the ring is empty but the stream has not actually stopped.
Guard with URB_ISO_ASAP to preserve explicit ASAP scheduling.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=220748
Assisted-by: Claude:claude-sonnet-4-6 sparse checkpatch
Signed-off-by: Nicola Lunghi <nick83ola@gmail.com>
---
drivers/usb/host/xhci-ring.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 03e47db82092..116a2dcd0bb2 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -4308,14 +4308,24 @@ int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags,
*/
check_interval(urb, ep_ctx);
- /* Calculate the start frame and put it in urb->start_frame. */
- if ((xhci->hcc_params & HCC_CFC) && !list_empty(&ep_ring->td_list)) {
- if (GET_EP_CTX_STATE(ep_ctx) == EP_STATE_RUNNING) {
- urb->start_frame = xep->next_frame_id;
- goto skip_start_over;
- }
+ /*
+ * Calculate the start frame and put it in urb->start_frame.
+ * On CFC-capable controllers, use sequential scheduling from
+ * next_frame_id whenever the stream is running or a completion
+ * is in progress (ring transiently empty due to drain race).
+ * Skip this for explicit URB_ISO_ASAP requests.
+ */
+ if ((xhci->hcc_params & HCC_CFC) &&
+ !(urb->transfer_flags & URB_ISO_ASAP) &&
+ (!list_empty(&ep_ring->td_list) ||
+ hcd_periodic_completion_in_progress(xhci_to_hcd(xhci), urb->ep))) {
+ urb->start_frame = xep->next_frame_id;
+ goto skip_start_over;
}
+ xhci_dbg(xhci, "isoc: CFC sequential skipped for slot %u ep %u (ring_empty=%d), using ASAP\n",
+ slot_id, ep_index, list_empty(&ep_ring->td_list));
+
start_frame = readl(&xhci->run_regs->microframe_index);
start_frame &= 0x3fff;
/*
--
2.51.0
prev parent reply other threads:[~2026-05-04 23:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-04 23:31 [PATCH 0/2] xhci: Fix isochronous scheduling gaps on CFC controllers Nicola Lunghi
2026-05-04 23:31 ` [PATCH 1/2] usb: xhci: fix isoc silent reschedule creating stream gap " Nicola Lunghi
2026-05-05 13:32 ` Mathias Nyman
2026-05-04 23:31 ` Nicola Lunghi [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=20260504233143.10242-4-nick83ola@gmail.com \
--to=nick83ola@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@intel.com \
--cc=michal.pecio@gmail.com \
--cc=niklas.neronin@linux.intel.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