From patchwork Wed Oct 28 20:31:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 11865123 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9262A921 for ; Thu, 29 Oct 2020 02:45:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7B26420791 for ; Thu, 29 Oct 2020 02:45:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726002AbgJ1Vd1 (ORCPT ); Wed, 28 Oct 2020 17:33:27 -0400 Received: from mga03.intel.com ([134.134.136.65]:44643 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725993AbgJ1VdS (ORCPT ); Wed, 28 Oct 2020 17:33:18 -0400 IronPort-SDR: Nyh3sPdc13gtjEHHKxA5z5266K6gch2GmUdgD4zVX57+xaTXe7+QgasEpTexBGDs95v2HJAiF4 5FEjkYd5Bgkw== X-IronPort-AV: E=McAfee;i="6000,8403,9788"; a="168432566" X-IronPort-AV: E=Sophos;i="5.77,428,1596524400"; d="scan'208";a="168432566" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2020 13:30:04 -0700 IronPort-SDR: YPbDCuQ5i2O3EksLaTWIKp54qm2T8Tt2WFIAKFv+ae52X6RGF//4dfuZHrzlm6JSVdpoDNmuJN l0Lw+a/jqspQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,428,1596524400"; d="scan'208";a="323467777" Received: from mattu-haswell.fi.intel.com ([10.237.72.170]) by orsmga006.jf.intel.com with ESMTP; 28 Oct 2020 13:30:02 -0700 From: Mathias Nyman To: Cc: , Colin Ian King , Mathias Nyman Subject: [PATCH 1/3] xhci: Fix sizeof() mismatch Date: Wed, 28 Oct 2020 22:31:22 +0200 Message-Id: <20201028203124.375344-2-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201028203124.375344-1-mathias.nyman@linux.intel.com> References: <20201028203124.375344-1-mathias.nyman@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Colin Ian King An incorrect sizeof() is being used, sizeof(rhub->ports) is not correct, it should be sizeof(*rhub->ports). This bug did not cause any issues because it just so happens the sizes are the same. Addresses-Coverity: ("Sizeof not portable (SIZEOF_MISMATCH)") Fixes: bcaa9d5c5900 ("xhci: Create new structures to store xhci port information") Signed-off-by: Colin Ian King Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-mem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index fe405cd38dbc..138ba4528dd3 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -2252,8 +2252,8 @@ static void xhci_create_rhub_port_array(struct xhci_hcd *xhci, if (!rhub->num_ports) return; - rhub->ports = kcalloc_node(rhub->num_ports, sizeof(rhub->ports), flags, - dev_to_node(dev)); + rhub->ports = kcalloc_node(rhub->num_ports, sizeof(*rhub->ports), + flags, dev_to_node(dev)); for (i = 0; i < HCS_MAX_PORTS(xhci->hcs_params1); i++) { if (xhci->hw_ports[i].rhub != rhub || xhci->hw_ports[i].hcd_portnum == DUPLICATE_ENTRY) From patchwork Wed Oct 28 20:31:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 11865119 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7F011921 for ; Thu, 29 Oct 2020 02:45:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6864D20829 for ; Thu, 29 Oct 2020 02:45:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725933AbgJ1Vdb (ORCPT ); Wed, 28 Oct 2020 17:33:31 -0400 Received: from mga03.intel.com ([134.134.136.65]:44639 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725989AbgJ1VdT (ORCPT ); Wed, 28 Oct 2020 17:33:19 -0400 IronPort-SDR: WWBH5O8v8CYXUns7dXSpcexJ0VURWOB7b3Huie9MIWTt9Lx+SpuJusVTJktKB3KqKfEEQ0H50I DS0Z/RnA2oMw== X-IronPort-AV: E=McAfee;i="6000,8403,9788"; a="168432576" X-IronPort-AV: E=Sophos;i="5.77,428,1596524400"; d="scan'208";a="168432576" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2020 13:30:06 -0700 IronPort-SDR: sPi8l1Pu+Wzuww4eNKfwbtJ+KGlavjQFFWFeEJJtYsIzyWnMm3q9FrCXnPuJOWjoOR+ttuOJdZ 8++KmUPG7hvQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,428,1596524400"; d="scan'208";a="323467805" Received: from mattu-haswell.fi.intel.com ([10.237.72.170]) by orsmga006.jf.intel.com with ESMTP; 28 Oct 2020 13:30:04 -0700 From: Mathias Nyman To: Cc: , Sandeep Singh , Sanket Goswami , stable@vger.kernel.org, Mathias Nyman Subject: [PATCH 2/3] usb: xhci: Workaround for S3 issue on AMD SNPS 3.0 xHC Date: Wed, 28 Oct 2020 22:31:23 +0200 Message-Id: <20201028203124.375344-3-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201028203124.375344-1-mathias.nyman@linux.intel.com> References: <20201028203124.375344-1-mathias.nyman@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Sandeep Singh On some platform of AMD, S3 fails with HCE and SRE errors. To fix this, need to disable a bit which is enable in sparse controller. Signed-off-by: Sanket Goswami Signed-off-by: Sandeep Singh Cc: stable@vger.kernel.org#v4.19+ Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci-pci.c | 17 +++++++++++++++++ drivers/usb/host/xhci.h | 1 + 2 files changed, 18 insertions(+) diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c index c26c06e5c88c..bf89172c43ca 100644 --- a/drivers/usb/host/xhci-pci.c +++ b/drivers/usb/host/xhci-pci.c @@ -23,6 +23,8 @@ #define SSIC_PORT_CFG2_OFFSET 0x30 #define PROG_DONE (1 << 30) #define SSIC_PORT_UNUSED (1 << 31) +#define SPARSE_DISABLE_BIT 17 +#define SPARSE_CNTL_ENABLE 0xC12C /* Device for a quirk */ #define PCI_VENDOR_ID_FRESCO_LOGIC 0x1b73 @@ -161,6 +163,9 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci) (pdev->device == 0x15e0 || pdev->device == 0x15e1)) xhci->quirks |= XHCI_SNPS_BROKEN_SUSPEND; + if (pdev->vendor == PCI_VENDOR_ID_AMD && pdev->device == 0x15e5) + xhci->quirks |= XHCI_DISABLE_SPARSE; + if (pdev->vendor == PCI_VENDOR_ID_AMD) xhci->quirks |= XHCI_TRUST_TX_LENGTH; @@ -498,6 +503,15 @@ static void xhci_pme_quirk(struct usb_hcd *hcd) readl(reg); } +static void xhci_sparse_control_quirk(struct usb_hcd *hcd) +{ + u32 reg; + + reg = readl(hcd->regs + SPARSE_CNTL_ENABLE); + reg &= ~BIT(SPARSE_DISABLE_BIT); + writel(reg, hcd->regs + SPARSE_CNTL_ENABLE); +} + static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup) { struct xhci_hcd *xhci = hcd_to_xhci(hcd); @@ -517,6 +531,9 @@ static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup) if (xhci->quirks & XHCI_SSIC_PORT_UNUSED) xhci_ssic_port_unused_quirk(hcd, true); + if (xhci->quirks & XHCI_DISABLE_SPARSE) + xhci_sparse_control_quirk(hcd); + ret = xhci_suspend(xhci, do_wakeup); if (ret && (xhci->quirks & XHCI_SSIC_PORT_UNUSED)) xhci_ssic_port_unused_quirk(hcd, false); diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 8be88379c0fb..ebb359ebb261 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -1877,6 +1877,7 @@ struct xhci_hcd { #define XHCI_SNPS_BROKEN_SUSPEND BIT_ULL(35) #define XHCI_RENESAS_FW_QUIRK BIT_ULL(36) #define XHCI_SKIP_PHY_INIT BIT_ULL(37) +#define XHCI_DISABLE_SPARSE BIT_ULL(38) unsigned int num_active_eps; unsigned int limit_active_eps; From patchwork Wed Oct 28 20:31:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 11865121 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 066D492C for ; Thu, 29 Oct 2020 02:45:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E50A420782 for ; Thu, 29 Oct 2020 02:45:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726085AbgJ1Vda (ORCPT ); Wed, 28 Oct 2020 17:33:30 -0400 Received: from mga03.intel.com ([134.134.136.65]:44643 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726025AbgJ1VdT (ORCPT ); Wed, 28 Oct 2020 17:33:19 -0400 IronPort-SDR: q7iquxM/ondJh42HI3aA42p4TxoMCWn74xZ2OjpQibp0R+Bq29dDE80LDUeuhLTFCUCPoCfujb QszYg0aEFZ9Q== X-IronPort-AV: E=McAfee;i="6000,8403,9788"; a="168432581" X-IronPort-AV: E=Sophos;i="5.77,428,1596524400"; d="scan'208";a="168432581" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2020 13:30:08 -0700 IronPort-SDR: rO3kI377EHDBcOhlUBqeSJDQbQTsStpR+rzc6r+365XZ5H/OKoIxf+36GFSl5FxlvQU+X5XdUJ vqhmivUJMx9Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,428,1596524400"; d="scan'208";a="323467833" Received: from mattu-haswell.fi.intel.com ([10.237.72.170]) by orsmga006.jf.intel.com with ESMTP; 28 Oct 2020 13:30:07 -0700 From: Mathias Nyman To: Cc: , Mathias Nyman , Hans de Goede , Mike Galbraith , Li Jun Subject: [PATCH 3/3] xhci: Don't create stream debugfs files with spinlock held. Date: Wed, 28 Oct 2020 22:31:24 +0200 Message-Id: <20201028203124.375344-4-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201028203124.375344-1-mathias.nyman@linux.intel.com> References: <20201028203124.375344-1-mathias.nyman@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Creating debugfs files while loding the spin_lock_irqsave(xhci->lock) creates a lock dependecy that could possibly deadlock. Lockdep warns: ===================================================== WARNING: HARDIRQ-safe -> HARDIRQ-unsafe lock order detected 5.10.0-rc1pdx86+ #8 Not tainted ----------------------------------------------------- systemd-udevd/386 [HC0[0]:SC0[0]:HE0:SE1] is trying to acquire: ffffffffb1a94038 (pin_fs_lock){+.+.}-{2:2}, at: simple_pin_fs+0x22/0xa0 and this task is already holding: ffff9e7b87fbc430 (&xhci->lock){-.-.}-{2:2}, at: xhci_alloc_streams+0x5f9/0x810 which would create a new lock dependency: (&xhci->lock){-.-.}-{2:2} -> (pin_fs_lock){+.+.}-{2:2} Create the files a bit later after lock is released. Reported-by: Hans de Goede Reported-by: Mike Galbraith Tested-by: Hans de Goede CC: Li Jun Fixes: 673d74683627 ("usb: xhci: add debugfs support for ep with stream") Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 482fe8c5e3b4..d4a8d0efbbc4 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -3533,11 +3533,14 @@ static int xhci_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev, xhci_dbg(xhci, "Slot %u ep ctx %u now has streams.\n", udev->slot_id, ep_index); vdev->eps[ep_index].ep_state |= EP_HAS_STREAMS; - xhci_debugfs_create_stream_files(xhci, vdev, ep_index); } xhci_free_command(xhci, config_cmd); spin_unlock_irqrestore(&xhci->lock, flags); + for (i = 0; i < num_eps; i++) { + ep_index = xhci_get_endpoint_index(&eps[i]->desc); + xhci_debugfs_create_stream_files(xhci, vdev, ep_index); + } /* Subtract 1 for stream 0, which drivers can't use */ return num_streams - 1;