From: Michal Pecio <michal.pecio@gmail.com>
To: Mathias Nyman <mathias.nyman@intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org
Subject: [PATCH] usb: xhci: Work around the ASM3142 bulk UVC bug
Date: Wed, 2 Dec 2026 10:12:00 +0100 [thread overview]
Message-ID: <20261202101200.726fc9e3.michal.pecio@gmail.com> (raw)
ASM3142 occasionally generates no event for a single-TRB bulk TD which
is directly followed by a Link TRB. This affects USB3 UVC devices and
makes them stop streaming within a few seconds with logs like:
Event dma 0xffe5e000 for ep 6 comp_code 1 not part of TD at ffd0cfe0 - ffd0cfe0
Event dma 0xffe5e010 for ep 6 comp_code 1 not part of TD at ffd0cfe0 - ffd0cfe0
Event dma 0xffe5e020 for ep 6 comp_code 1 not part of TD at ffd0cfe0 - ffd0cfe0
Event dma 0xffe5e030 for ep 6 comp_code 1 not part of TD at ffd0cfe0 - ffd0cfe0
Only one line appears if the Link TRB toggles cycle; it seems that the
HC fails to toggle its cycle state and stops processing queued TDs, but
it ignores cycle of the first TRB in the segment and produces an event.
If subsequent TRBs are stale and match the wrong cycle state, the whole
ring is executed again - reliably triggered by keeping 2 URBs queued.
Regardless of cycle issues, the first event is always bogus - a canary
pattern written to the transfer buffer survives, while canary of the TD
which was passed silently is fully overwritten (short transfers appear
to mitigate this bug). The link target seems treated as chained to the
completed prior TD, although no chain bits exist anywhere on the ring.
The bug doesn't affect drivers that only keep one URB queued at a time,
even if xhci-hcd is patched to call inc_enq_past_link() after queuing.
It seems to be triggered by fetching a TRB with current cycle from the
next segment. Keeping 800 URBs queued in advance and skipping ringing
the doorbell doesn't help, it looks like an internal race.
Multi-TRB TDs are also affected if they end before a link, but chained
links in multi-TRB TDs are handled correctly, including cycle toggle.
It seems this can be avoided by ensuring that no TD ends before a link.
If that's about to happen, insert a No-Op TRB to shift the TD one slot
forward so that it ends in the next segment. No solution exists yet for
cases when TD fragment alignment shortens the TD. If we fail to stop
the bug, prevent execution of stale URBs by adding a No-Op before the
next TD so that 2nd TRB of the segment can't be stale.
This bug hasn't been observed in ASM1142, ASM3242 and AMD B350 and A520
chipsets. ASM3142 PCI ID is same as ASM2142, differences are unknown.
Reported-and-tested-by: Alfie Frost <alfie@nightmail.uk>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=222328
Cc: stable@vger.kernel.org
Signed-off-by: Michal Pecio <michal.pecio@gmail.com>
---
It seems this is the best we can do without significantly reworking
the queuing code (to also support TD alignment cases). I tried many
simpler changes and found no way to prevent this bug, it seems to be
triggered solely by the layout of TDs wrt segment boundaries.
The only other viable workaround is to queue normally, and if the TD
ends before a link, set the chain bit and add some junk in the next
segment. But no junk is innocent: semantics of zero-length TRBs are
unclear when chained to a TD, No-Ops cannot legally be chained,
Event Data generate junk events, double links are forbidden, etc.
I am unable to test all HCs with this PCI ID and I would prefer to
avoid breaking workloads unaffected by the bug, such as storage.
drivers/usb/host/xhci-pci.c | 4 ++++
drivers/usb/host/xhci-ring.c | 18 ++++++++++++++++++
drivers/usb/host/xhci.h | 1 +
3 files changed, 23 insertions(+)
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 4923a9563354..4bd40af61a03 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -482,6 +482,10 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
pdev->device == PCI_DEVICE_ID_ASMEDIA_3242_XHCI))
xhci->quirks |= XHCI_NO_64BIT_SUPPORT;
+ if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
+ pdev->device == PCI_DEVICE_ID_ASMEDIA_2142_XHCI)
+ xhci->quirks |= XHCI_NO_LINK_AFTER_TD;
+
if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
pdev->device == PCI_DEVICE_ID_ASMEDIA_1042A_XHCI)
xhci->quirks |= XHCI_ASMEDIA_MODIFY_FLOWCONTROL;
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index c1cdc7ed010a..94e2fcbfa7ed 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -3721,6 +3721,20 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
addr = (u64) urb->transfer_dma;
block_len = full_len;
}
+
+ if (xhci->quirks & XHCI_NO_LINK_AFTER_TD) {
+ /*
+ * Prepend a No-Op if our TD would end before a Link TRB, or if
+ * previous TD failed to prevent this and the HW bug may occur.
+ * FIXME: multi-segment TD and/or TD shortened by alignment.
+ */
+ if (last_trb_on_seg(ring->enq_seg, ring->enqueue + num_trbs) ||
+ last_trb_on_seg(ring->enq_seg, ring->enqueue)) {
+ num_trbs++;
+ first_trb = false;
+ }
+ }
+
ret = prepare_transfer(xhci, xhci->devs[slot_id],
ep_index, urb->stream_id,
num_trbs, urb, 0, mem_flags);
@@ -3744,6 +3758,10 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
start_cycle = ring->cycle_state;
send_addr = addr;
+ if (!first_trb) /* see XHCI_NO_LINK_AFTER_TD */
+ queue_trb(xhci, ring, true, 0, 0, TRB_INTR_TARGET(0),
+ TRB_TYPE(TRB_TR_NOOP) | (ring->cycle_state ^ TRB_CYCLE));
+
/* Queue the TRBs, even if they are zero-length */
for (enqd_len = 0; first_trb || enqd_len < full_len;
enqd_len += trb_buff_len) {
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 56493f1aa86d..ff038fe6c8b3 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1653,6 +1653,7 @@ struct xhci_hcd {
#define XHCI_CDNS_SCTX_QUIRK BIT_ULL(48)
#define XHCI_ETRON_HOST BIT_ULL(49)
#define XHCI_LIMIT_ENDPOINT_INTERVAL_9 BIT_ULL(50)
+#define XHCI_NO_LINK_AFTER_TD BIT_ULL(51)
unsigned int num_active_eps;
unsigned int limit_active_eps;
--
2.48.1
next reply other threads:[~2026-12-02 9:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 9:12 Michal Pecio [this message]
2026-12-02 9:21 ` [PATCH] usb: xhci: Work around the ASM3142 bulk UVC bug sashiko-bot
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=20261202101200.726fc9e3.michal.pecio@gmail.com \
--to=michal.pecio@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.