* [PATCH] usb: xhci: Work around the ASM3142 bulk UVC bug
@ 2026-12-02 9:12 Michal Pecio
2026-12-02 9:21 ` sashiko-bot
2026-12-02 10:30 ` [PATCH v2] " Michal Pecio
0 siblings, 2 replies; 6+ 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] 6+ 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
2026-12-02 10:30 ` [PATCH v2] " Michal Pecio
1 sibling, 0 replies; 6+ 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] 6+ messages in thread
* [PATCH v2] 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
@ 2026-12-02 10:30 ` Michal Pecio
2026-12-02 10:39 ` sashiko-bot
2026-12-03 12:23 ` Mathias Nyman
1 sibling, 2 replies; 6+ messages in thread
From: Michal Pecio @ 2026-12-02 10:30 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>
---
New in v2:
Abusing 'first_trb' broke zero length URBs, create a dedicated flag.
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 | 27 +++++++++++++++++++++++----
drivers/usb/host/xhci.h | 1 +
3 files changed, 28 insertions(+), 4 deletions(-)
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..ea58da5acb59 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -3694,6 +3694,7 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
bool more_trbs_coming = true;
bool need_zero_pkt = false;
bool first_trb = true;
+ bool add_noop = false;
unsigned int num_trbs;
unsigned int start_cycle, num_sgs = 0;
unsigned int enqd_len, block_len, trb_buff_len, full_len;
@@ -3721,6 +3722,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++;
+ add_noop = true;
+ }
+ }
+
ret = prepare_transfer(xhci, xhci->devs[slot_id],
ep_index, urb->stream_id,
num_trbs, urb, 0, mem_flags);
@@ -3744,6 +3759,10 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
start_cycle = ring->cycle_state;
send_addr = addr;
+ if (add_noop)
+ 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) {
@@ -3757,12 +3776,12 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
trb_buff_len = full_len - enqd_len;
/* Don't change the cycle bit of the first TRB until later */
+ field |= ring->cycle_state;
if (first_trb) {
first_trb = false;
- if (start_cycle == 0)
- field |= TRB_CYCLE;
- } else
- field |= ring->cycle_state;
+ if (&ring->enqueue->generic == start_trb)
+ field ^= TRB_CYCLE;
+ }
/* Chain all the TRBs together; clear the chain bit in the last
* TRB to indicate it's the last TRB in the chain.
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] 6+ messages in thread
* Re: [PATCH v2] usb: xhci: Work around the ASM3142 bulk UVC bug
2026-12-02 10:30 ` [PATCH v2] " Michal Pecio
@ 2026-12-02 10:39 ` sashiko-bot
2026-12-03 12:23 ` Mathias Nyman
1 sibling, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-02 10:39 UTC (permalink / raw)
To: Michal Pecio; +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.
>
> [ ... ]
>
> 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>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202113051.7587a314.michal.pecio@gmail.com?part=1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] usb: xhci: Work around the ASM3142 bulk UVC bug
2026-12-02 10:30 ` [PATCH v2] " Michal Pecio
2026-12-02 10:39 ` sashiko-bot
@ 2026-12-03 12:23 ` Mathias Nyman
2026-12-03 16:56 ` Michal Pecio
1 sibling, 1 reply; 6+ messages in thread
From: Mathias Nyman @ 2026-12-03 12:23 UTC (permalink / raw)
To: Michal Pecio, Mathias Nyman, Greg Kroah-Hartman; +Cc: linux-usb
On 12/2/26 12:30, Michal Pecio wrote:
> 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.
Could there have a been old chain bit set from previous cycle due to
splitting last TD over the link? Does giving the Link TRB to HW immediately
after the last TRB help? i.e. always call inc_enq_past_link() .
I noticed that the buffer in that last TRB ended at exactly 64k boundary,
and was also max packet aligned. Was this true for all those cases where
event is lost?
>
> 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.
Would force-splitting a TD over the link TRB then be an option?
Requires original 'last' TRB buffer size to be over a max packet.
Thanks
Mathias
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] usb: xhci: Work around the ASM3142 bulk UVC bug
2026-12-03 12:23 ` Mathias Nyman
@ 2026-12-03 16:56 ` Michal Pecio
0 siblings, 0 replies; 6+ messages in thread
From: Michal Pecio @ 2026-12-03 16:56 UTC (permalink / raw)
To: Mathias Nyman; +Cc: Mathias Nyman, Greg Kroah-Hartman, linux-usb
On Thu, 3 Dec 2026 14:23:00 +0200, Mathias Nyman wrote:
> On 12/2/26 12:30, Michal Pecio wrote:
> > 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.
>
> Could there have a been old chain bit set from previous cycle due to
> splitting last TD over the link?
Doesn't seem so. Following patch makes no difference, but it does have
the expected effect on storage:
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -3722,6 +3722,9 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
addr = (u64) urb->transfer_dma;
block_len = full_len;
}
+ if (num_trbs > 1)
+ xhci_err(xhci, "multi-trb on %d/%d\n", slot_id, ep_index);
+
ret = prepare_transfer(xhci, xhci->devs[slot_id],
ep_index, urb->stream_id,
num_trbs, urb, 0, mem_flags);
Besides, all these URBs are very boring. Five cyclically repeating
data buffers, all 15KB in size (16KB for the reporter's device) and
aligned. There is no reason for any chaining here.
Resubmission loop stops, so the ring can be inspected with debugfs:
[ 4488.879590] uvcvideo 19-2.2:1.0: Allocated 5 URB buffers of 15x1024 bytes each
[ 4494.171672] xhci_hcd 0000:0c:00.0: Event dma 0xffda8000 for ep 6 comp_code 1 not part of TD at ffda4fe0 - ffda4fe0, missed 1
[ 4494.171925] xhci_hcd 0000:0c:00.0: Event dma 0xffda8010 for ep 6 comp_code 1 not part of TD at ffda4fe0 - ffda4fe0, missed 2
[ 4494.172175] xhci_hcd 0000:0c:00.0: Event dma 0xffda8020 for ep 6 comp_code 1 not part of TD at ffda4fe0 - ffda4fe0, missed 3
[ 4494.172434] xhci_hcd 0000:0c:00.0: Event dma 0xffda8030 for ep 6 comp_code 1 not part of TD at ffda4fe0 - ffda4fe0, missed 4
0 0x00000000ffda4f50: Buffer 00000000ffbb8000 length 15360 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
0 0x00000000ffda4f60: Buffer 00000000ffbd0000 length 15360 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
0 0x00000000ffda4f70: Buffer 00000000ffbc0000 length 15360 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
0 0x00000000ffda4f80: Buffer 00000000ffbb0000 length 15360 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
0 0x00000000ffda4f90: Buffer 00000000ffbc8000 length 15360 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
0 0x00000000ffda4fa0: Buffer 00000000ffbb8000 length 15360 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
0 0x00000000ffda4fb0: Buffer 00000000ffbd0000 length 15360 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
0 0x00000000ffda4fc0: Buffer 00000000ffbc0000 length 15360 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
0 0x00000000ffda4fd0: Buffer 00000000ffbb0000 length 15360 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
0 0x00000000ffda4fe0: Buffer 00000000ffbc8000 length 15360 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
0 0x00000000ffda4ff0: LINK 00000000ffda8000 intr 0 type 'Link' flags i:c:t:c
1 0x00000000ffda8000: Buffer 00000000ffbb8000 length 15360 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
1 0x00000000ffda8010: Buffer 00000000ffbd0000 length 15360 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
1 0x00000000ffda8020: Buffer 00000000ffbc0000 length 15360 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
1 0x00000000ffda8030: Buffer 00000000ffbb0000 length 15360 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:c
1 0x00000000ffda8040: Buffer 00000000ffbd0000 length 15360 TD size 0 intr 0 type 'Normal' flags b:i:I:c:s:I:e:C <- old cycle
> Does giving the Link TRB to HW immediately after the last TRB help?
> i.e. always call inc_enq_past_link() .
I hoped it would, but no. Even a queue of over 3 segments forward,
likely well ahead of the HC's prefetcher, makes no difference.
> I noticed that the buffer in that last TRB ended at exactly 64k
> boundary, and was also max packet aligned. Was this true for all
> those cases where event is lost?
64K - not in the run above.
max_packet - not sure because UVC's URBs are max_packet-aligned.
> Would force-splitting a TD over the link TRB then be an option?
> Requires original 'last' TRB buffer size to be over a max packet.
Reducing TRB_MAX_BUFF_SIZE to 8KB limits the bug to unchained links,
so yes, this should work. But not sure if it's easier or better.
Still ends up wasting one TRB slot.
Also, 4.11.5.1:
A TD Fragment shall not span segments. Refer to section 4.11.7.1.
And, of course, 4.11.7.1 doesn't agree:
A TD Fragment should not span Transfer Ring Segments.
But then 6.2.3:
The requirement that TD Fragments shall not span Transfer Ring
Segments places a lower limit on the value of Average TRB Length.
TD Fragments must be aligned to burst payload (16KB for my device).
Make of it whatever you want. So far, packet alignment seems to have
been sufficient, at least to the extent of avoiding total breakage
(not sure about performance). But it's not clear if links unaligned
to burst payload are permitted at all.
Regards,
Michal
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-12-03 16:56 UTC | newest]
Thread overview: 6+ 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
2026-12-02 10:30 ` [PATCH v2] " Michal Pecio
2026-12-02 10:39 ` sashiko-bot
2026-12-03 12:23 ` Mathias Nyman
2026-12-03 16:56 ` Michal Pecio
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox