From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796207451; b=jea2PEvhN0F4F8QITkl8M0mks3xW4JV0F3C+ATQOa3NPvUqBrHAd5Pn/QJ/fshkF2OdX iBjcq4OpOylzPEKDp6S8eiS3cV9ZvwC5QjoY2rFq6G2j6WR6s36GHemhVkvhVHzL6VkmK zdlLMSSpiJxO66zk7rqHDzyQvEOhXxhBN7Ip6fDATDKiY3ctk4tgcv+8ecqRi3D2n89p7 5sBiENTG0ZX51KBb8tO5qi34QS+haXi/bpHqBYHz8Qdp2YnVitxvxhOEo7YHP6E4nadm/ NeWuEsTAjMx+6Fj4G4DMaNU6+N9e3L7DtTq9WxtUW45F90+DnfrxZDYI0ixapo+OJtQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796207451; 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:In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=sPiPuABZXQewBaVl4thPnH71MJHKmmbkfbSNFDh7hvc=; b=zmJpD1JhWZNgoahP22XGXmhmW5ubPdx1BU3EhN/b7HjX9CCnWkC8Li06JcHcKoaWCjPi lxhszFijYv0rPKO6AwlaIwKUec/GMz/XVwtE2jcuPUjsjAWIRznnwJVaNoxP08ZjIr7Gw OieDe2HI6Yc/EPBnv6Bbr/BPElidNnl5MDojNY3eqdFRl/C6cMThz6XFada09hYbmN7jE kTLb5izSe/IYBNtkM3q49qrifXH2FjdMwVVCuW/kX7XDzdgc5ZOr8qmsHutx5I+ul9BgL BNNCvB8vJoH9t65bE/A6Nj/cEln8PYPFmcGF8AVzh+b72D3d3euF3k9lbkjwSiUfbWQ== 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=E3if3sdL; arc=none smtp.remote-ip=209.85.221.49 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (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 1156A606A329 for ; Wed, 2 Dec 2026 10:30:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1156A606A329 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) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=E3if3sdL Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-49412eb1474so8655754f8f.3 for ; Wed, 02 Dec 2026 02:30:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796207449; x=1796812249; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=sPiPuABZXQewBaVl4thPnH71MJHKmmbkfbSNFDh7hvc=; b=E3if3sdLipPrsmO2dibfHkQoGIi2fY2irHWoMCw7x3jFPoY9jA0lqgxj1ZZrIPBGAw vYDJdv7QYajWqJ56dkNMlLdQiSL7sBmy0vdAfzAEb0EEJ/JIdv6XSu+oBAkx/U5sUYnu 6JxOuqWkI088UCtBD9S3ECiODy/ehoUAnh5h7K48nW91j+w3RylmeyHdPwIKHrUjnkoV IRAsVMpCAXtoQA2L2q/fU3Cu+Cis+t3Sp7jdXxv0vsP0tnDpMz1hFI6KWm3RJlkCCWDe fLddv7hyV7DctwmTRvC4rE4Sq14i8NpbPtkz9YDKzkei4bamc5eBiY2v9sOVvx/a8h6a 9LMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796207449; x=1796812249; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to: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=sPiPuABZXQewBaVl4thPnH71MJHKmmbkfbSNFDh7hvc=; b=q1uuThLwyRPl4bMltURHG2ontO3y0cbQ2mlcMHQ5y/XtOHRaIYCm6nFpsTyHyZbpmb dem8rBwAUdzAaZNPxCx3NcVrue2F81tHGzX1WrdzXLjtkAonp1FA5kMDDPvhyqL/mqbk tYSnKuO3sNWruQCUmJ+y4pG1xKGGg7g8xSInDqZQLldeXCYp/ZFj2N9LZit9Zecx1SZt GG9j5a8X1VuE/33KLz8Kr1z3aVq4k2/j72wt0cajKfeDt7QaoFsXcxYHXKUnsDJpq9ac A2NLvPz2FtttG55/W7XGHEOdxxaTqCSfN/2JQD4SvzaPCGjGBJqderEBWxyL1CTMvoy2 GYWw== X-Gm-Message-State: APuU4Z9qxlyJi7HDaHmy0Uia79IDpzAZW5fhpF50rQCnJBTizx0nsuKE 3M7PMFqMjWvqXI77qd0Giysplu3cQjiBqW+Fe1ByHVV32P9B7JavS5vZ X-Gm-Gg: AZFdTZcBip/HEKY13gLSmwOhrvKXZ4Ck2yg55WoFQYT94zIgfr7GEs77NfAD2/EJW2A XHL0IScA9656UyJ4Sn64/4sihKOk+oCHErlPBwZNOqQre2KWh75FTqgHSQ0lXOsPh35vap6dW8O tgWBd77QXFRp8s7AcsboR05rVyxzt1vp9hoeBh4s5c3RpWYNZ89FPs0+EOnG8J4LYsX/YoEej/C vFfdz00q78wlNAqbRrM6z7uj6wuaJXXdAjlikWfPfYuguFIVEiOFfSDrCChLVJn7yHH41m9SyB+ 6pnN7AmunpjLG6/FAiBD2uv3yIhEVH5EBzxcYt+9tV3AcU1rQdBjbbW1cwpxaVML/8EqL88Y147 PNUfVAq1QLbZXqCzCZiLVLX/7Dq1mAF6x7MqRoKT2tTEcLnSpt25L1SxGj4j431Q8u9q3wLvHMU efFACmK9RfdhHgDmqaAhyq4jRUIksvvY3DWhLcLDAVaVw1tzmcDVrYUzKz7nOehWUbn1UYtyxLW sBObd3x+387zA+Q9jAUjMayxouGYikF5MemlUPGTDQ05H1QbqnG36XOr7p5UOKlgGb2mjIzht2F m9WBTABxPbBJNDKhHrBsdsjMvVMFjXs60JDb/g== X-Received: by 2002:a05:6000:4812:b0:4aa:8da8:4bbc with SMTP id ffacd0b85a97d-4abb5702827mr70807140f8f.36.1796207449138; Wed, 02 Dec 2026 02:30:49 -0800 (PST) Received: from foxbook (bfj60.neoplus.adsl.tpnet.pl. [83.28.47.60]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4b70c05b9desm52362972f8f.54.2026.12.02.02.30.48 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 02 Dec 2026 02:30:48 -0800 (PST) Date: Wed, 2 Dec 2026 11:30:51 +0100 From: Michal Pecio To: Mathias Nyman , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org Subject: [PATCH v2] usb: xhci: Work around the ASM3142 bulk UVC bug Message-ID: <20261202113051.7587a314.michal.pecio@gmail.com> In-Reply-To: <20261202101200.726fc9e3.michal.pecio@gmail.com> References: <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 --- 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