public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* FAILED: patch "[PATCH] usb: xhci: Enable the TRB overfetch quirk on VIA VL805" failed to apply to 5.10-stable tree
@ 2025-03-09 20:22 gregkh
  2025-03-09 23:02 ` [PATCH 5.10.y] usb: xhci: Enable the TRB overfetch quirk on VIA VL805 Michal Pecio
  0 siblings, 1 reply; 3+ messages in thread
From: gregkh @ 2025-03-09 20:22 UTC (permalink / raw)
  To: michal.pecio, gregkh, mathias.nyman; +Cc: stable


The patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x c133ec0e5717868c9967fa3df92a55e537b1aead
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2025030901-banshee-unwomanly-f19e@gregkh' --subject-prefix 'PATCH 5.10.y' HEAD^..

Possible dependencies:



thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From c133ec0e5717868c9967fa3df92a55e537b1aead Mon Sep 17 00:00:00 2001
From: Michal Pecio <michal.pecio@gmail.com>
Date: Tue, 25 Feb 2025 11:59:27 +0200
Subject: [PATCH] usb: xhci: Enable the TRB overfetch quirk on VIA VL805

Raspberry Pi is a major user of those chips and they discovered a bug -
when the end of a transfer ring segment is reached, up to four TRBs can
be prefetched from the next page even if the segment ends with link TRB
and on page boundary (the chip claims to support standard 4KB pages).

It also appears that if the prefetched TRBs belong to a different ring
whose doorbell is later rung, they may be used without refreshing from
system RAM and the endpoint will stay idle if their cycle bit is stale.

Other users complain about IOMMU faults on x86 systems, unsurprisingly.

Deal with it by using existing quirk which allocates a dummy page after
each transfer ring segment. This was seen to resolve both problems. RPi
came up with a more efficient solution, shortening each segment by four
TRBs, but it complicated the driver and they ditched it for this quirk.

Also rename the quirk and add VL805 device ID macro.

Signed-off-by: Michal Pecio <michal.pecio@gmail.com>
Link: https://github.com/raspberrypi/linux/issues/4685
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=215906
CC: stable@vger.kernel.org
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20250225095927.2512358-2-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 92703efda1f7..fdf0c1008225 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -2437,7 +2437,8 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 	 * and our use of dma addresses in the trb_address_map radix tree needs
 	 * TRB_SEGMENT_SIZE alignment, so we pick the greater alignment need.
 	 */
-	if (xhci->quirks & XHCI_ZHAOXIN_TRB_FETCH)
+	if (xhci->quirks & XHCI_TRB_OVERFETCH)
+		/* Buggy HC prefetches beyond segment bounds - allocate dummy space at the end */
 		xhci->segment_pool = dma_pool_create("xHCI ring segments", dev,
 				TRB_SEGMENT_SIZE * 2, TRB_SEGMENT_SIZE * 2, xhci->page_size * 2);
 	else
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index ad0ff356f6fa..54460d11f7ee 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -38,6 +38,8 @@
 #define PCI_DEVICE_ID_ETRON_EJ168		0x7023
 #define PCI_DEVICE_ID_ETRON_EJ188		0x7052
 
+#define PCI_DEVICE_ID_VIA_VL805			0x3483
+
 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI		0x8c31
 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI		0x9c31
 #define PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_XHCI	0x9cb1
@@ -418,8 +420,10 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
 			pdev->device == 0x3432)
 		xhci->quirks |= XHCI_BROKEN_STREAMS;
 
-	if (pdev->vendor == PCI_VENDOR_ID_VIA && pdev->device == 0x3483)
+	if (pdev->vendor == PCI_VENDOR_ID_VIA && pdev->device == PCI_DEVICE_ID_VIA_VL805) {
 		xhci->quirks |= XHCI_LPM_SUPPORT;
+		xhci->quirks |= XHCI_TRB_OVERFETCH;
+	}
 
 	if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
 		pdev->device == PCI_DEVICE_ID_ASMEDIA_1042_XHCI) {
@@ -467,11 +471,11 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
 
 		if (pdev->device == 0x9202) {
 			xhci->quirks |= XHCI_RESET_ON_RESUME;
-			xhci->quirks |= XHCI_ZHAOXIN_TRB_FETCH;
+			xhci->quirks |= XHCI_TRB_OVERFETCH;
 		}
 
 		if (pdev->device == 0x9203)
-			xhci->quirks |= XHCI_ZHAOXIN_TRB_FETCH;
+			xhci->quirks |= XHCI_TRB_OVERFETCH;
 	}
 
 	if (pdev->vendor == PCI_VENDOR_ID_CDNS &&
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 8c164340a2c3..779b01dee068 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1632,7 +1632,7 @@ struct xhci_hcd {
 #define XHCI_EP_CTX_BROKEN_DCS	BIT_ULL(42)
 #define XHCI_SUSPEND_RESUME_CLKS	BIT_ULL(43)
 #define XHCI_RESET_TO_DEFAULT	BIT_ULL(44)
-#define XHCI_ZHAOXIN_TRB_FETCH	BIT_ULL(45)
+#define XHCI_TRB_OVERFETCH	BIT_ULL(45)
 #define XHCI_ZHAOXIN_HOST	BIT_ULL(46)
 #define XHCI_WRITE_64_HI_LO	BIT_ULL(47)
 #define XHCI_CDNS_SCTX_QUIRK	BIT_ULL(48)


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 5.10.y] usb: xhci: Enable the TRB overfetch quirk on VIA VL805
  2025-03-09 20:22 FAILED: patch "[PATCH] usb: xhci: Enable the TRB overfetch quirk on VIA VL805" failed to apply to 5.10-stable tree gregkh
@ 2025-03-09 23:02 ` Michal Pecio
  2025-03-13  9:08   ` Sasha Levin
  0 siblings, 1 reply; 3+ messages in thread
From: Michal Pecio @ 2025-03-09 23:02 UTC (permalink / raw)
  To: stable; +Cc: gregkh, mathias.nyman

Raspberry Pi is a major user of those chips and they discovered a bug -
when the end of a transfer ring segment is reached, up to four TRBs can
be prefetched from the next page even if the segment ends with link TRB
and on page boundary (the chip claims to support standard 4KB pages).

It also appears that if the prefetched TRBs belong to a different ring
whose doorbell is later rung, they may be used without refreshing from
system RAM and the endpoint will stay idle if their cycle bit is stale.

Other users complain about IOMMU faults on x86 systems, unsurprisingly.

Deal with it by using existing quirk which allocates a dummy page after
each transfer ring segment. This was seen to resolve both problems. RPi
came up with a more efficient solution, shortening each segment by four
TRBs, but it complicated the driver and they ditched it for this quirk.

Also rename the quirk and add VL805 device ID macro.

Signed-off-by: Michal Pecio <michal.pecio@gmail.com>
Link: https://github.com/raspberrypi/linux/issues/4685
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=215906
CC: stable@vger.kernel.org
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Link: https://lore.kernel.org/r/20250225095927.2512358-2-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit c133ec0e5717868c9967fa3df92a55e537b1aead)
[ Michal: merge conflict with white space and an unrelated quirk ]
Signed-off-by: Michal Pecio <michal.pecio@gmail.com>
---
 drivers/usb/host/xhci-mem.c | 3 ++-
 drivers/usb/host/xhci-pci.c | 9 ++++++---
 drivers/usb/host/xhci.h     | 2 +-
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 006e1b15fbda..cdf9806c87a4 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -2492,7 +2492,8 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 	 * and our use of dma addresses in the trb_address_map radix tree needs
 	 * TRB_SEGMENT_SIZE alignment, so we pick the greater alignment need.
 	 */
-	if (xhci->quirks & XHCI_ZHAOXIN_TRB_FETCH)
+	if (xhci->quirks & XHCI_TRB_OVERFETCH)
+		/* Buggy HC prefetches beyond segment bounds - allocate dummy space at the end */
 		xhci->segment_pool = dma_pool_create("xHCI ring segments", dev,
 				TRB_SEGMENT_SIZE * 2, TRB_SEGMENT_SIZE * 2, xhci->page_size * 2);
 	else
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 030e2383f025..6dc0c22268ca 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -37,6 +37,8 @@
 #define PCI_DEVICE_ID_EJ168		0x7023
 #define PCI_DEVICE_ID_EJ188		0x7052
 
+#define PCI_DEVICE_ID_VIA_VL805			0x3483
+
 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI	0x8c31
 #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI	0x9c31
 #define PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_XHCI	0x9cb1
@@ -296,8 +298,9 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
 			pdev->device == 0x3432)
 		xhci->quirks |= XHCI_BROKEN_STREAMS;
 
-	if (pdev->vendor == PCI_VENDOR_ID_VIA && pdev->device == 0x3483) {
+	if (pdev->vendor == PCI_VENDOR_ID_VIA && pdev->device == PCI_DEVICE_ID_VIA_VL805) {
 		xhci->quirks |= XHCI_LPM_SUPPORT;
+		xhci->quirks |= XHCI_TRB_OVERFETCH;
 		xhci->quirks |= XHCI_EP_CTX_BROKEN_DCS;
 	}
 
@@ -347,11 +350,11 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
 
 		if (pdev->device == 0x9202) {
 			xhci->quirks |= XHCI_RESET_ON_RESUME;
-			xhci->quirks |= XHCI_ZHAOXIN_TRB_FETCH;
+			xhci->quirks |= XHCI_TRB_OVERFETCH;
 		}
 
 		if (pdev->device == 0x9203)
-			xhci->quirks |= XHCI_ZHAOXIN_TRB_FETCH;
+			xhci->quirks |= XHCI_TRB_OVERFETCH;
 	}
 
 	/* xHC spec requires PCI devices to support D3hot and D3cold */
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 6304e9b00ecc..165f57911d94 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1897,7 +1897,7 @@ struct xhci_hcd {
 #define XHCI_EP_CTX_BROKEN_DCS	BIT_ULL(42)
 #define XHCI_SUSPEND_RESUME_CLKS	BIT_ULL(43)
 #define XHCI_RESET_TO_DEFAULT	BIT_ULL(44)
-#define XHCI_ZHAOXIN_TRB_FETCH	BIT_ULL(45)
+#define XHCI_TRB_OVERFETCH	BIT_ULL(45)
 #define XHCI_ZHAOXIN_HOST	BIT_ULL(46)
 
 	unsigned int		num_active_eps;
-- 
2.48.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 5.10.y] usb: xhci: Enable the TRB overfetch quirk on VIA VL805
  2025-03-09 23:02 ` [PATCH 5.10.y] usb: xhci: Enable the TRB overfetch quirk on VIA VL805 Michal Pecio
@ 2025-03-13  9:08   ` Sasha Levin
  0 siblings, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2025-03-13  9:08 UTC (permalink / raw)
  To: stable, michal.pecio; +Cc: Sasha Levin

[ Sasha's backport helper bot ]

Hi,

Summary of potential issues:
⚠️ Found matching upstream commit but patch is missing proper reference to it

Found matching upstream commit: c133ec0e5717868c9967fa3df92a55e537b1aead

Status in newer kernel trees:
6.13.y | Present (different SHA1: b273b3dc3b5c)
6.12.y | Present (different SHA1: 43115ac4e752)
6.6.y | Present (different SHA1: 2a3d68873fc2)
6.1.y | Present (different SHA1: bd139706d043)
5.15.y | Present (different SHA1: e256a546d03d)

Note: The patch differs from the upstream commit:
---
1:  c133ec0e57178 ! 1:  3d064d3287ee6 usb: xhci: Enable the TRB overfetch quirk on VIA VL805
    @@ Commit message
         Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
         Link: https://lore.kernel.org/r/20250225095927.2512358-2-mathias.nyman@linux.intel.com
         Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    +    (cherry picked from commit c133ec0e5717868c9967fa3df92a55e537b1aead)
    +    [ Michal: merge conflict with white space and an unrelated quirk ]
    +    Signed-off-by: Michal Pecio <michal.pecio@gmail.com>
     
      ## drivers/usb/host/xhci-mem.c ##
     @@ drivers/usb/host/xhci-mem.c: int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
    @@ drivers/usb/host/xhci-mem.c: int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flag
     
      ## drivers/usb/host/xhci-pci.c ##
     @@
    - #define PCI_DEVICE_ID_ETRON_EJ168		0x7023
    - #define PCI_DEVICE_ID_ETRON_EJ188		0x7052
    + #define PCI_DEVICE_ID_EJ168		0x7023
    + #define PCI_DEVICE_ID_EJ188		0x7052
      
     +#define PCI_DEVICE_ID_VIA_VL805			0x3483
     +
    - #define PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI		0x8c31
    - #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI		0x9c31
    + #define PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI	0x8c31
    + #define PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI	0x9c31
      #define PCI_DEVICE_ID_INTEL_WILDCATPOINT_LP_XHCI	0x9cb1
     @@ drivers/usb/host/xhci-pci.c: static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
      			pdev->device == 0x3432)
      		xhci->quirks |= XHCI_BROKEN_STREAMS;
      
    --	if (pdev->vendor == PCI_VENDOR_ID_VIA && pdev->device == 0x3483)
    +-	if (pdev->vendor == PCI_VENDOR_ID_VIA && pdev->device == 0x3483) {
     +	if (pdev->vendor == PCI_VENDOR_ID_VIA && pdev->device == PCI_DEVICE_ID_VIA_VL805) {
      		xhci->quirks |= XHCI_LPM_SUPPORT;
     +		xhci->quirks |= XHCI_TRB_OVERFETCH;
    -+	}
    + 		xhci->quirks |= XHCI_EP_CTX_BROKEN_DCS;
    + 	}
      
    - 	if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
    - 		pdev->device == PCI_DEVICE_ID_ASMEDIA_1042_XHCI) {
     @@ drivers/usb/host/xhci-pci.c: static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
      
      		if (pdev->device == 0x9202) {
    @@ drivers/usb/host/xhci-pci.c: static void xhci_pci_quirks(struct device *dev, str
     +			xhci->quirks |= XHCI_TRB_OVERFETCH;
      	}
      
    - 	if (pdev->vendor == PCI_VENDOR_ID_CDNS &&
    + 	/* xHC spec requires PCI devices to support D3hot and D3cold */
     
      ## drivers/usb/host/xhci.h ##
     @@ drivers/usb/host/xhci.h: struct xhci_hcd {
    @@ drivers/usb/host/xhci.h: struct xhci_hcd {
     -#define XHCI_ZHAOXIN_TRB_FETCH	BIT_ULL(45)
     +#define XHCI_TRB_OVERFETCH	BIT_ULL(45)
      #define XHCI_ZHAOXIN_HOST	BIT_ULL(46)
    - #define XHCI_WRITE_64_HI_LO	BIT_ULL(47)
    - #define XHCI_CDNS_SCTX_QUIRK	BIT_ULL(48)
    + 
    + 	unsigned int		num_active_eps;
---

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-5.10.y       |  Success    |  Success   |

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-03-13  9:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-09 20:22 FAILED: patch "[PATCH] usb: xhci: Enable the TRB overfetch quirk on VIA VL805" failed to apply to 5.10-stable tree gregkh
2025-03-09 23:02 ` [PATCH 5.10.y] usb: xhci: Enable the TRB overfetch quirk on VIA VL805 Michal Pecio
2025-03-13  9:08   ` Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox