From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.50 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796202720; b=syC9VFOX83+JnlqRQxu/GeWobnQTYURJ00PcyVmEjpFDm6P+qoNKyhWnwa7O+Jdh4lyn VGKP3Sk3iMXtq4ZZE9Kix5FHRs6BQNxLDUayughykVHtZYVMzjeByv/G15vrQg47O91x0 rFj5LO1e3cjwo+v2fIL2BjzTdg6WOPWic2ayQhQDvwR69x6vJdjb+n6IZHKR1ZImCridy HTov7Y3fBnHhH8PNggwmBIyZhHVn0M9KBV94th3+H/E6wGJNaTPcNjCD8KJdyeqMbvaN/ 6PRcrIUZsBtZlDztEacIwd2mnBmyA7XRrUq3J4cA0mz0zyQqVbbFx/wcgSfb2mUDEQQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796202720; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Date:From:To:Cc: Subject:Message-ID:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=h4XyRaq4FZbAeJWhINSeAR0n4hf2YidrgcmyezolTJE=; b=EehhDkBk+yU7l46fZt0zKZWTlnFqNunJEQwSnlGviqx/TLAfwvhsBSEaByqmfcWjLIdV g0v4cAOFNsjZuPuBNiwooPPgQWwhw62wrVcQ8Yvxuqz2Zq1qi9KWZ9XT3SfnrqLP+nyB1 zbmrFhaLZ4ZNsTn2p7inkqpTrkhHH/3vUgOYWb2bs9pWH1JVvh/hxnNoJHw6RXTFniMCM ei1kKpSDNlODqvzODkUHXcGBvTaEc5VYSHMrzFxeQkdtIzjYNtc0VXYLAxhS7/XnJ9ypd LP5HG/pKGVlgLSkuDIB5NjSlJdbK4WGCGzXQJFtnbNSWz2avBqgbSNlyAQABe5CORkA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=T7OrGC72; arc=none smtp.remote-ip=209.85.221.50 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 285A2606A335 for ; Wed, 2 Dec 2026 09:12:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 285A2606A335 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=T7OrGC72 Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-4acb44dcd7bso11197669f8f.0 for ; Wed, 02 Dec 2026 01:11:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796202719; x=1796807519; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=h4XyRaq4FZbAeJWhINSeAR0n4hf2YidrgcmyezolTJE=; b=T7OrGC72GBTfzeCvdnNw/3f3mLeOC7Kv9iQgeKzOED++nSTTNx3fXDB3v6qhmTa4r9 lFS1wzQOCMF/HxjFH82sS6mAGgAMh/8lsK0ZQ9uMUsYMx1U04DH4QcUQUO/XleJNA4Zw qy8QAifBwXYkgM1HIlPim1PprT1pghv+VMWcxRQUpeIxR1qH+/cdClL7oQ/OEsEpVh8S 7vmA8Ne2+VbpqpthasQLrM5ZRGk80KHYws5KNZuudXhRpuXVVMp5Hn8b2EM6sBx/x3uw r1Xt1wG6NWUm2aR8bWGYLgj1DQHvdzWf2F4dI5BwxjSt2vI9G4XCzEFniAg/kYp1a83a 08Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796202719; x=1796807519; h=content-transfer-encoding:content-type:mime-version:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=h4XyRaq4FZbAeJWhINSeAR0n4hf2YidrgcmyezolTJE=; b=PH2slTDBmvL2zQS7UiBn7GXHuGJ7nJXZbpM5pA7/DTUBBZ6fOfTs9174nghTi993Mu xfttqJI0fZM7Oz6kz0xqbGUtoXcaJ/fTAx+a4wPBh91XXkYsCaCuAXtcezwLV6iIgIto f0la1sJVTgFdRBYrS/0Sl6QOje/fBMsN67PsxcAxd6lhiCfsMKF2GhIGiXm2PqNbrIlj ui6TAiw5/wVt+D90VuzbZPT9q/SyEq6PKoY3rEAnI/YNXF0g7yLBVP1UDh7sgou0Som+ kWDwWw2dkKUoaNH6YnZ9bwj/9wW481KZTYY8y6TQznTrld03mR02alj+uk6V/65/T7ie uopQ== X-Gm-Message-State: APuU4Z86JV4UPbhggtiLWBKjxMqVuodD8nGnIVzkf4margZS3YdAfGO2 Gr3rCGVUEC8Cy0Oww87hyMCVT2BiXy8QCcnb2rgN6glv4B5MY9CHGvwC X-Gm-Gg: AZFdTZfZi5S8cs1pZCfyY4cv3KCZJB52t/dgIR1eKNQWOx/pzroarAVfA9mkiNeguQ/ mhhewuMBUVJSxkoZrfMUZmTUqJcrm/5WWJ0bpgXL3S3BJZAo+7BTuGDTlto1ykPusR/938PK2aZ hpU6y05XPRuIhS2hslkv4L5sSPZ9RO2E5GXVqgxFy10EFR0texeJfEUdIvpw9igwHSPZPlTNc9k t9kWl7iha4RUYSbk6lxm7vQc2Wx63mWbbhy7uARFfyseaAcH39BKCEqMGiULcCoVcGrdbm8I/v2 i5LtGf24/Nii8FpZfA01uJ4AachhSyOm15PkAcpvwOw9AM7RBTzxWFTZ3ZeFAMgbZwMBIEKETj9 TIJxtdAhZXPHuOK+Lx7EC0APsFr7ylz2fkvYIh+46gND42lZXM9ejVj0JRi6ZDzz1T7BNfX0WjZ 2z57IVzuIhUg9qGYib0xVKxapMf6Dekz6Mp+fjRQZ+FzklaTGK70hjjs5oOmDlxhO4gvwn/ah2C Jfavwbxmdn3YL7LzUj1Fb2Hv/Gec0ntYidCz1xuyNcPq1M5hWFydWKZ4Qpdi6vp2TvyU4SAuSLL 1WdZ2SzwIZ5RHfHAngAHdq0HjpFYCi0fJgEklg== X-Received: by 2002:a05:6000:4617:b0:48b:9d2:1a6a with SMTP id ffacd0b85a97d-4abab5ea335mr78400053f8f.1.1796202718435; Wed, 02 Dec 2026 01:11:58 -0800 (PST) Received: from foxbook (bfj60.neoplus.adsl.tpnet.pl. [83.28.47.60]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4b34e9c3ffesm63225411f8f.19.2026.12.02.01.11.57 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 02 Dec 2026 01:11:58 -0800 (PST) Date: Wed, 2 Dec 2026 10:12:00 +0100 From: Michal Pecio To: Mathias Nyman , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org Subject: [PATCH] usb: xhci: Work around the ASM3142 bulk UVC bug Message-ID: <20261202101200.726fc9e3.michal.pecio@gmail.com> X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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 Closes: https://bugzilla.kernel.org/show_bug.cgi?id=222328 Cc: stable@vger.kernel.org Signed-off-by: Michal Pecio --- 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