Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp167687rwr; Wed, 19 Apr 2023 19:59:23 -0700 (PDT) X-Google-Smtp-Source: AKy350b3CgG2GNO049BWHkpE2s/87RRUgZQgxtMrKMKrgTYK85vnApfWsHCNlXrPyzgai7ZiL33A X-Received: by 2002:a05:6870:d1c7:b0:187:e40a:dda3 with SMTP id b7-20020a056870d1c700b00187e40adda3mr90663oac.51.1681959563205; Wed, 19 Apr 2023 19:59:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681959563; cv=none; d=google.com; s=arc-20160816; b=rmf6cQwbTrPg9yU2y/A6o1kR6Pe9w32/dZ2r1f2ZX+yjLZj06YVDwUQ4SKlI/j84sV 7+y8j+A85CzX6bODDxU6cXObJ8ACIwzUrOEIiE8x+etz4h6QIuWk2gwP6eYIuuuY4OVk xfKVSFCxU4TSAbq6yhP8heJkI7m3BHWVwaBqDlzqlq3Mx0cYDdfjaEnvqdN0UYWUihQC Au2VjZ9oTQ662VKaJEaeZS4s+rG0O8Ldhz9W2WKm56vWquFb6HvR+tVWt04RjHtzaO/V 561DR63eVhLAvHw47GfP5tbVYh6MHuzBOAtUnaf6AfN4WyOxtWV2SRw7HEAJ6rLQA7Zx 0kcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=4xIgvvMJMXWMjyvzfPFEa2Ot92v9wJzIeMP7fCzIHwc=; b=CZrZAnr4zQfw3C9mzLlRzuGxDelSdtGoxrKXWdS55Msxf2hfii4UJFzUrO9Z7RbcAD 0+58cp9LTVKrJUesh58ENcjrwtO7j1uN+MolHHj7mZrilatLhRhnePwwWBE2+cOGHELz KQZemNK+0VE9cjtnCiIYi/rrzusDoKyFNRFHH+rOQrPh5k5COsXikrTTYsOJdhCthFiB QFzSw95EfeObBXCvIzuqr4ywu4coAFJwt/SVpAtEM1gFX5JYdJ/Q4/n5efUs6kO64MWp c+PoQS/ITu6g39fzH9z7L7PKOGCvN39ln+st/wH/pAt9gciTtuJgvmQcSqDfpYXJr9hz GmOA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q30-20020a056870829e00b001880deff089si786067oae.281.2023.04.19.19.59.09; Wed, 19 Apr 2023 19:59:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232593AbjDTCtM (ORCPT + 99 others); Wed, 19 Apr 2023 22:49:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229965AbjDTCtK (ORCPT ); Wed, 19 Apr 2023 22:49:10 -0400 Received: from mx2.zhaoxin.com (mx2.zhaoxin.com [203.110.167.99]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64F2B65BF for ; Wed, 19 Apr 2023 19:48:31 -0700 (PDT) X-ASG-Debug-ID: 1681958908-1eb14e63892afd0001-xx1T2L Received: from ZXSHMBX1.zhaoxin.com (ZXSHMBX1.zhaoxin.com [10.28.252.163]) by mx2.zhaoxin.com with ESMTP id 7E5f0aIabXyZq2Dy (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Thu, 20 Apr 2023 10:48:28 +0800 (CST) X-Barracuda-Envelope-From: WeitaoWang-oc@zhaoxin.com X-Barracuda-RBL-Trusted-Forwarder: 10.28.252.163 Received: from zxbjmbx1.zhaoxin.com (10.29.252.163) by ZXSHMBX1.zhaoxin.com (10.28.252.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Thu, 20 Apr 2023 10:48:27 +0800 Received: from L440.zhaoxin.com (10.29.8.21) by zxbjmbx1.zhaoxin.com (10.29.252.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Thu, 20 Apr 2023 10:48:26 +0800 X-Barracuda-RBL-Trusted-Forwarder: 10.28.252.163 From: Weitao Wang X-Barracuda-RBL-Trusted-Forwarder: 10.29.252.163 To: , , , CC: , Subject: [PATCH] xhci: fix issue of cross page boundary in TRB prefetch Date: Thu, 20 Apr 2023 18:48:26 +0800 X-ASG-Orig-Subj: [PATCH] xhci: fix issue of cross page boundary in TRB prefetch Message-ID: <20230420104826.4727-1-WeitaoWang-oc@zhaoxin.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.29.8.21] X-ClientProxiedBy: zxbjmbx1.zhaoxin.com (10.29.252.163) To zxbjmbx1.zhaoxin.com (10.29.252.163) X-Barracuda-Connect: ZXSHMBX1.zhaoxin.com[10.28.252.163] X-Barracuda-Start-Time: 1681958908 X-Barracuda-Encrypted: ECDHE-RSA-AES128-GCM-SHA256 X-Barracuda-URL: https://10.28.252.36:4443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at zhaoxin.com X-Barracuda-Scan-Msg-Size: 2546 X-Barracuda-BRTS-Status: 1 X-Barracuda-Bayes: INNOCENT GLOBAL 0.0000 1.0000 -2.0209 X-Barracuda-Spam-Score: 1.09 X-Barracuda-Spam-Status: No, SCORE=1.09 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests=DATE_IN_FUTURE_06_12, DATE_IN_FUTURE_06_12_2 X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.107661 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.01 DATE_IN_FUTURE_06_12 Date: is 6 to 12 hours after Received: date 3.10 DATE_IN_FUTURE_06_12_2 DATE_IN_FUTURE_06_12_2 X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On some Zhaoxin platforms, 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 TRB and only the first page will be used. Signed-off-by: Weitao Wang --- drivers/usb/host/xhci-mem.c | 6 +++++- drivers/usb/host/xhci-pci.c | 5 +++++ drivers/usb/host/xhci.h | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index d0a9467aa5fc..69f8d44d2c9f 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2369,7 +2369,11 @@ 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. */ - xhci->segment_pool = dma_pool_create("xHCI ring segments", dev, + 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 + xhci->segment_pool = dma_pool_create("xHCI ring segments", dev, TRB_SEGMENT_SIZE, TRB_SEGMENT_SIZE, xhci->page_size); /* See Table 46 and Note on Figure 55 */ diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index 6db07ca419c3..3b3bff36def3 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c @@ -334,6 +334,11 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) pdev->device == PCI_DEVICE_ID_AMD_PROMONTORYA_4)) xhci->quirks |= XHCI_NO_SOFT_RETRY; + if (pdev->vendor == PCI_VENDOR_ID_ZHAOXIN && + (pdev->device == 0x9202 || + pdev->device == 0x9203)) + xhci->quirks |= XHCI_ZHAOXIN_TRB_FETCH; + /* xHC spec requires PCI devices to support D3hot and D3cold */ if (xhci->hci_version >= 0x120) xhci->quirks |= XHCI_DEFAULT_PM_RUNTIME_ALLOW; diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 786002bb35db..ed1f2f894af6 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1905,6 +1905,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) unsigned int num_active_eps; unsigned int limit_active_eps; -- 2.32.0