* [PATCH] usb: xhci: Work around the ASM3142 bulk UVC bug
@ 2026-12-02 9:12 Michal Pecio
2026-12-02 9:21 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Michal Pecio @ 2026-12-02 9:12 UTC (permalink / raw)
To: Mathias Nyman, Greg Kroah-Hartman; +Cc: linux-usb
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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] usb: xhci: Work around the ASM3142 bulk UVC bug
2026-12-02 9:12 [PATCH] usb: xhci: Work around the ASM3142 bulk UVC bug Michal Pecio
@ 2026-12-02 9:21 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-02 9:21 UTC (permalink / raw)
To: Michal Pecio; +Cc: linux-usb
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] usb: xhci: skipped TRB loop for zero-length URBs in
xhci_queue_bulk_tx()
--
commit 771a636094579efceb79700d7566c1836f19f8ac
Author: Michal Pecio <michal.pecio@gmail.com>
usb: xhci: Work around the ASM3142 bulk UVC bug
This commit adds the XHCI_NO_LINK_AFTER_TD quirk for ASMedia 2142/3142
controllers to prepend a No-Op TRB in xhci_queue_bulk_tx() when a bulk TD
would end right before a segment Link TRB or start on one.
> diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
> index 7ccd89a4b9951..9230db6f8bc2c 100644
> --- a/drivers/usb/host/xhci-ring.c
> +++ b/drivers/usb/host/xhci-ring.c
> @@ -3700,6 +3700,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);
> @@ -3723,6 +3737,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) {
[Severity: High]
Does setting first_trb = false skip the TRB loop completely for a
zero-length URB (full_len == 0)?
When first_trb is false and full_len is 0, only the TRB_TR_NOOP is queued:
no TRB_NORMAL with TRB_IOC is emitted, and td->end_trb and td->end_seg are
left NULL on a TD already linked into ep_ring->td_list. The URB will never
complete, and the next transfer event or URB dequeue on the ring will hit a
NULL pointer dereference in trb_in_td() -> dma_in_range() ->
trb_to_pos(td->end_seg, td->end_trb).
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202101200.726fc9e3.michal.pecio@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-02 9:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 9:12 [PATCH] usb: xhci: Work around the ASM3142 bulk UVC bug Michal Pecio
2026-12-02 9:21 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox