From ef09da0af168b88e3ab71da39769bcc1eee792c4 Mon Sep 17 00:00:00 2001 From: LeoLiu-oc Date: Thu, 13 Nov 2025 14:52:02 +0800 Subject: [PATCH] xhci: Fix TRB prefetch issue of ZHAOXIN hosts mainline inclusion from mainline-v6.4-rc5 commit 2a865a652299f5666f3b785cbe758c5f57453036 ------------------- On some ZHAOXIN hosts, xHCI will prefetch TRB for performance improvement. However this TRB prefetch mechanism may cross page boundary, which may access memory not allocated by xHCI driver. In order to fix this issue, two pages was allocated for a segment and only the first page will be used. And add a quirk XHCI_ZHAOXIN_TRB_FETCH for this issue. Cc: stable@vger.kernel.org Signed-off-by: Weitao Wang Signed-off-by: Mathias Nyman Message-ID: <20230602144009.1225632-10-mathias.nyman@linux.intel.com> Signed-off-by: Greg Kroah-Hartman Signed-off-by: LeoLiu-oc --- drivers/usb/host/xhci-mem.c | 12 ++++-------- drivers/usb/host/xhci-pci.c | 16 +++++++++------- drivers/usb/host/xhci.h | 8 ++++---- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index fe0827e4701b..fbacaa156251 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2475,16 +2475,12 @@ 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. */ - /* With xHCI TRB prefetch patch:To fix cross page boundary access issue - * in IOV environment - */ - if (xhci->quirks & XHCI_ZHAOXIN_TRB_FETCH) { + if (xhci->quirks & XHCI_ZHAOXIN_TRB_FETCH) xhci->segment_pool = dma_pool_create("xHCI ring segments", dev, - TRB_SEGMENT_SIZE*2, TRB_SEGMENT_SIZE*2, xhci->page_size*2); - } else { + TRB_SEGMENT_SIZE * 2, TRB_SEGMENT_SIZE * 2, xhci->page_size * 2); + else xhci->segment_pool = dma_pool_create("xHCI ring segments", dev, - TRB_SEGMENT_SIZE, TRB_SEGMENT_SIZE, xhci->page_size); - } + TRB_SEGMENT_SIZE, TRB_SEGMENT_SIZE, xhci->page_size); /* See Table 46 and Note on Figure 55 */ xhci->device_pool = dma_pool_create("xHCI input/output contexts", dev, diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index a556f040af5f..71ca6df73a2b 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c @@ -305,11 +305,6 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) xhci->quirks |= XHCI_EP_CTX_BROKEN_DCS; } - if (pdev->vendor == PCI_VENDOR_ID_ZHAOXIN && - (pdev->device == 0x9202 || - pdev->device == 0x9203)) - xhci->quirks |= XHCI_ZHAOXIN_TRB_FETCH; - if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA && pdev->device == PCI_DEVICE_ID_ASMEDIA_1042_XHCI) { /* @@ -337,8 +332,15 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) if (pdev->vendor == PCI_VENDOR_ID_TI && pdev->device == 0x8241) xhci->quirks |= XHCI_LIMIT_ENDPOINT_INTERVAL_7; - if (pdev->vendor == PCI_VENDOR_ID_ZHAOXIN && pdev->device == 0x9202) - xhci->quirks |= XHCI_RESET_ON_RESUME; + if (pdev->vendor == PCI_VENDOR_ID_ZHAOXIN) { + if (pdev->device == 0x9202) { + xhci->quirks |= XHCI_RESET_ON_RESUME; + xhci->quirks |= XHCI_ZHAOXIN_TRB_FETCH; + } + + if (pdev->device == 0x9203) + xhci->quirks |= XHCI_ZHAOXIN_TRB_FETCH; + } if ((pdev->vendor == PCI_VENDOR_ID_BROADCOM || pdev->vendor == PCI_VENDOR_ID_CAVIUM) && diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index e4fa4300bee0..86c2b247cf8e 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1905,10 +1905,10 @@ struct xhci_hcd { #define XHCI_SG_TRB_CACHE_SIZE_QUIRK BIT_ULL(39) #define XHCI_NO_SOFT_RETRY BIT_ULL(40) #define XHCI_ZHAOXIN_HOST BIT_ULL(41) -#define XHCI_ZHAOXIN_TRB_FETCH BIT_ULL(42) -#define XHCI_EP_CTX_BROKEN_DCS BIT_ULL(43) -#define XHCI_SUSPEND_RESUME_CLKS BIT_ULL(44) -#define XHCI_RESET_TO_DEFAULT BIT_ULL(45) +#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) unsigned int num_active_eps; unsigned int limit_active_eps; -- Gitee