Message ID | 20230321233849.3408339-1-david.e.box@linux.intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp2068031wrt; Tue, 21 Mar 2023 16:42:07 -0700 (PDT) X-Google-Smtp-Source: AK7set9PkBvKl/ZVohANsvJifG461WFsLymYLZIXY+O99eJP/XUwi3zkqRA/2rDb50fZizv25fCa X-Received: by 2002:a50:ed93:0:b0:501:d52d:7f88 with SMTP id h19-20020a50ed93000000b00501d52d7f88mr4747534edr.10.1679442127289; Tue, 21 Mar 2023 16:42:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679442127; cv=none; d=google.com; s=arc-20160816; b=mhFrZtaj9ctU0bopZFIhjZSJGeSE99yieoZkXHw7QHAJyVbFQlWm1d/32P5Cpr2ZdW 8XQORZxvFWAM5/qomg+mPcvdmYuFCRazRdvBmfrjudU91rkM4xinngvL1JjCXyxaLoWt 3w69re63sy6S281FE/3gTToqAxmFo5I25DCsGZnQ3VAvqtpsj3Bf8juzVmrVAKZvUXR2 IynAz6EgpCBTu1kznXGT/5psxMx3hUJ+WqSshoquNx1n9N8Nu/AnCguCE1pVXh34wZLz P0LM4abd94SoJjkJ3Qni2TkwcnRlzcire4mHX6toz3HBj+uxcbYIlmeDih/ChoehoSDJ pazQ== 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:dkim-signature; bh=rgtMoD8FKDPe4PelA8ofAM24T19vme7ssDPfidyAigI=; b=d+2yszc+uB+JuMnpNZBBGPuhR6nrHQUZCcVAh4fGRJGXTwCxJ3LnCcQCooKhgxUzMT nokxfvOZ7yTnfAndmlysBEGyyLiNEGXjAVZc+ZZmdXFQQlXRF8VmSsz0p3U9Zeyj7Nu+ csBBjIplIqbneDu1xnLoOOlGy++gOfk9kpm6Y9RaGY2RFWe2hHxJ+G6BdKWRB6ncENiH Z/SUf8g1ltmOVIWv7ReHn9reFlVN6nmREkAyLjOATYl7zp1jVHf1NXPTjLuEKjehQRrA Y/zygc7ji6H6GplMWW+G+lONgvAxmlZ0WHqt9sJHKYiZJhC4gtvE/pXOISeTnD5NlIDh LB+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jKObHg6J; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n21-20020aa7db55000000b004ab092142e1si14095663edt.406.2023.03.21.16.41.43; Tue, 21 Mar 2023 16:42:07 -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; dkim=pass header.i=@intel.com header.s=Intel header.b=jKObHg6J; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229975AbjCUXi4 (ORCPT <rfc822;ezelljr.billy@gmail.com> + 99 others); Tue, 21 Mar 2023 19:38:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229791AbjCUXiy (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 21 Mar 2023 19:38:54 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 331311589F; Tue, 21 Mar 2023 16:38:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679441933; x=1710977933; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=QyMwH+TpTkKRII7zXw6wfHJaKJbJT+IwvyS0aWpk6So=; b=jKObHg6JGwhin2O+u2uKi1TQMsIIjIVQTARC/5NX9uTxvf8p8jF3+w+m R766w/TWmo8v7CBcz14a4vToGaFcezyJr3BRbprvqvbKaZQ9yxRet2vMN Q6cfUE2pNmxpSIW8y8u0owjXM45lldpQQErRNFcz49XEt1OKfLqEFBt9s n2/iGWfuhmwPSl0GXFLWsU7G60qxpsyouvTLgxDVPGMp7X0QilJMWv/gd UeHCnBWn1NFEtpAGLxNRuBqpd/RNnOVy7DubfJfJT8i5PIlVpiv64sJRN eF9gFWZf04YXUEpd51KC8FrUKimy+XmTEAF6x/tjVuORW8VgWIw6f9Pct g==; X-IronPort-AV: E=McAfee;i="6600,9927,10656"; a="322926126" X-IronPort-AV: E=Sophos;i="5.98,280,1673942400"; d="scan'208";a="322926126" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Mar 2023 16:38:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10656"; a="770840396" X-IronPort-AV: E=Sophos;i="5.98,280,1673942400"; d="scan'208";a="770840396" Received: from linux.intel.com ([10.54.29.200]) by FMSMGA003.fm.intel.com with ESMTP; 21 Mar 2023 16:38:52 -0700 Received: from debox1-desk4.intel.com (unknown [10.251.1.45]) by linux.intel.com (Postfix) with ESMTP id A9C495805CB; Tue, 21 Mar 2023 16:38:51 -0700 (PDT) From: "David E. Box" <david.e.box@linux.intel.com> To: david.e.box@linux.intel.com, ville.syrjala@linux.intel.com, nirmal.patel@linux.intel.com, jonathan.derrick@linux.dev, lorenzo.pieralisi@arm.com, hch@infradead.org, kw@linux.com, robh@kernel.org, bhelgaas@google.com, michael.a.bottini@intel.com, rafael@kernel.org Cc: me@adhityamohan.in, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org Subject: [PATCH] PCI/ASPM: pci_enable_link_state: Add argument to acquire bus lock Date: Tue, 21 Mar 2023 16:38:49 -0700 Message-Id: <20230321233849.3408339-1-david.e.box@linux.intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE,URIBL_BLOCKED autolearn=unavailable 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761022707642848550?= X-GMAIL-MSGID: =?utf-8?q?1761022707642848550?= |
Series |
PCI/ASPM: pci_enable_link_state: Add argument to acquire bus lock
|
|
Commit Message
David E. Box
March 21, 2023, 11:38 p.m. UTC
The VMD driver calls pci_enabled_link_state as a callback from
pci_bus_walk. Both will acquire the pci_bus_sem lock leading to a lockdep
warning. Add an argument to pci_enable_link_state to set whether the lock
should be acquired. In the VMD driver, set the argument to false since the
lock will already be obtained by pci_bus_walk.
Reported-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Fixes: de82f60f9c86 ("PCI/ASPM: Add pci_enable_link_state()")
Link: https://lore.kernel.org/linux-pci/ZBjko%2FifunIwsK2v@intel.com/
Signed-off-by: David E. Box <david.e.box@linux.intel.com>
---
drivers/pci/controller/vmd.c | 2 +-
drivers/pci/pcie/aspm.c | 9 ++++++---
include/linux/pci.h | 5 +++--
3 files changed, 10 insertions(+), 6 deletions(-)
Comments
Hi David, On Tue, Mar 21, 2023 at 04:38:49PM -0700, David E. Box wrote: > The VMD driver calls pci_enabled_link_state as a callback from > pci_bus_walk. Both will acquire the pci_bus_sem lock leading to a lockdep > warning. Add an argument to pci_enable_link_state to set whether the lock > should be acquired. In the VMD driver, set the argument to false since the > lock will already be obtained by pci_bus_walk. > > Reported-by: Ville Syrjälä <ville.syrjala@linux.intel.com> > Fixes: de82f60f9c86 ("PCI/ASPM: Add pci_enable_link_state()") This means "if your kernel includes de82f60f9c86, you probably want to backport this fix to it." But that's not the case here. This patch is not fixing an issue with de82f60f9c86, so I don't think there's a reason to include a "Fixes" line. This patch is adding functionality that is only needed by some other patch, and it should be part of a series that also includes the patch that uses it to make sure they go together. Nit: I prefer to add "()" after function names in the commit log to make it more obvious that they're functions and help distinguish them from variables. > Link: https://lore.kernel.org/linux-pci/ZBjko%2FifunIwsK2v@intel.com/ > Signed-off-by: David E. Box <david.e.box@linux.intel.com> > --- > drivers/pci/controller/vmd.c | 2 +- > drivers/pci/pcie/aspm.c | 9 ++++++--- > include/linux/pci.h | 5 +++-- > 3 files changed, 10 insertions(+), 6 deletions(-) > > diff --git a/drivers/pci/controller/vmd.c b/drivers/pci/controller/vmd.c > index 990630ec57c6..45aa35744eae 100644 > --- a/drivers/pci/controller/vmd.c > +++ b/drivers/pci/controller/vmd.c > @@ -737,7 +737,7 @@ static int vmd_pm_enable_quirk(struct pci_dev *pdev, void *userdata) > if (!(features & VMD_FEAT_BIOS_PM_QUIRK)) > return 0; > > - pci_enable_link_state(pdev, PCIE_LINK_STATE_ALL); > + pci_enable_link_state(pdev, PCIE_LINK_STATE_ALL, false); > > pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_LTR); > if (!pos) > diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c > index 66d7514ca111..5b5a600bb864 100644 > --- a/drivers/pci/pcie/aspm.c > +++ b/drivers/pci/pcie/aspm.c > @@ -1147,8 +1147,9 @@ EXPORT_SYMBOL(pci_disable_link_state); > * > * @pdev: PCI device > * @state: Mask of ASPM link states to enable > + * @sem: Boolean to acquire/release pci_bus_sem > */ > -int pci_enable_link_state(struct pci_dev *pdev, int state) > +int pci_enable_link_state(struct pci_dev *pdev, int state, bool sem) > { > struct pcie_link_state *link = pcie_aspm_get_link(pdev); > > @@ -1165,7 +1166,8 @@ int pci_enable_link_state(struct pci_dev *pdev, int state) > return -EPERM; > } > > - down_read(&pci_bus_sem); > + if (sem) > + down_read(&pci_bus_sem); > mutex_lock(&aspm_lock); > link->aspm_default = 0; > if (state & PCIE_LINK_STATE_L0S) > @@ -1186,7 +1188,8 @@ int pci_enable_link_state(struct pci_dev *pdev, int state) > link->clkpm_default = (state & PCIE_LINK_STATE_CLKPM) ? 1 : 0; > pcie_set_clkpm(link, policy_to_clkpm_state(link)); > mutex_unlock(&aspm_lock); > - up_read(&pci_bus_sem); > + if (sem) > + up_read(&pci_bus_sem); > > return 0; > } > diff --git a/include/linux/pci.h b/include/linux/pci.h > index fafd8020c6d7..a6f9f24b39fd 100644 > --- a/include/linux/pci.h > +++ b/include/linux/pci.h > @@ -1707,7 +1707,7 @@ extern bool pcie_ports_native; > #ifdef CONFIG_PCIEASPM > int pci_disable_link_state(struct pci_dev *pdev, int state); > int pci_disable_link_state_locked(struct pci_dev *pdev, int state); > -int pci_enable_link_state(struct pci_dev *pdev, int state); > +int pci_enable_link_state(struct pci_dev *pdev, int state, bool sem); > void pcie_no_aspm(void); > bool pcie_aspm_support_enabled(void); > bool pcie_aspm_enabled(struct pci_dev *pdev); > @@ -1716,7 +1716,8 @@ static inline int pci_disable_link_state(struct pci_dev *pdev, int state) > { return 0; } > static inline int pci_disable_link_state_locked(struct pci_dev *pdev, int state) > { return 0; } > -static inline int pci_enable_link_state(struct pci_dev *pdev, int state) > +static inline int > +pci_enable_link_state(struct pci_dev *pdev, int state, bool sem) > { return 0; } > static inline void pcie_no_aspm(void) { } > static inline bool pcie_aspm_support_enabled(void) { return false; } > -- > 2.34.1 >
On Wed, Mar 22, 2023 at 03:45:01PM -0500, Bjorn Helgaas wrote: > Hi David, > > On Tue, Mar 21, 2023 at 04:38:49PM -0700, David E. Box wrote: > > The VMD driver calls pci_enabled_link_state as a callback from > > pci_bus_walk. Both will acquire the pci_bus_sem lock leading to a lockdep > > warning. Add an argument to pci_enable_link_state to set whether the lock > > should be acquired. In the VMD driver, set the argument to false since the > > lock will already be obtained by pci_bus_walk. > > > > Reported-by: Ville Syrjälä <ville.syrjala@linux.intel.com> > > Fixes: de82f60f9c86 ("PCI/ASPM: Add pci_enable_link_state()") > > This means "if your kernel includes de82f60f9c86, you probably want to > backport this fix to it." But that's not the case here. This patch > is not fixing an issue with de82f60f9c86, so I don't think there's a > reason to include a "Fixes" line. Oops, sorry, forgot to engage brain before hitting "send". I think the "Fixes" line should reference f492edb40b54 ("PCI: vmd: Add quirk to configure PCIe ASPM and LTR") instead, since that's where the locking problem started. > This patch is adding functionality that is only needed by some other > patch, and it should be part of a series that also includes the patch > that uses it to make sure they go together. And I see that the use *is* included in this patch. But I don't really like this pattern: vmd_probe vmd_enable_domain vmd->bus = pci_create_root_bus(...); pci_scan_child_bus(vmd->bus); pci_walk_bus(vmd->bus, vmd_pm_enable_quirk, &features); because pci_walk_bus() makes locking complicated (as this issue shows) and it doesn't work for hot-added devices (I don't know if that's an issue for VMD, but the pattern gets copied to places where it *is*). Normally vmd_pm_enable_quirk() would be done by making it an actual DECLARE_PCI_FIXUP_HEADER() or DECLARE_PCI_FIXUP_FINAL(), so it would be called automatically by the PCI core when a new device is enumerated. Would that work here? If it would, I don't think you'd need to add the extra flag to pci_enable_link_state(). > > Link: https://lore.kernel.org/linux-pci/ZBjko%2FifunIwsK2v@intel.com/ > > Signed-off-by: David E. Box <david.e.box@linux.intel.com> > > --- > > drivers/pci/controller/vmd.c | 2 +- > > drivers/pci/pcie/aspm.c | 9 ++++++--- > > include/linux/pci.h | 5 +++-- > > 3 files changed, 10 insertions(+), 6 deletions(-) > > > > diff --git a/drivers/pci/controller/vmd.c b/drivers/pci/controller/vmd.c > > index 990630ec57c6..45aa35744eae 100644 > > --- a/drivers/pci/controller/vmd.c > > +++ b/drivers/pci/controller/vmd.c > > @@ -737,7 +737,7 @@ static int vmd_pm_enable_quirk(struct pci_dev *pdev, void *userdata) > > if (!(features & VMD_FEAT_BIOS_PM_QUIRK)) > > return 0; > > > > - pci_enable_link_state(pdev, PCIE_LINK_STATE_ALL); > > + pci_enable_link_state(pdev, PCIE_LINK_STATE_ALL, false); > > > > pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_LTR); > > if (!pos) > > diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c > > index 66d7514ca111..5b5a600bb864 100644 > > --- a/drivers/pci/pcie/aspm.c > > +++ b/drivers/pci/pcie/aspm.c > > @@ -1147,8 +1147,9 @@ EXPORT_SYMBOL(pci_disable_link_state); > > * > > * @pdev: PCI device > > * @state: Mask of ASPM link states to enable > > + * @sem: Boolean to acquire/release pci_bus_sem > > */ > > -int pci_enable_link_state(struct pci_dev *pdev, int state) > > +int pci_enable_link_state(struct pci_dev *pdev, int state, bool sem) > > { > > struct pcie_link_state *link = pcie_aspm_get_link(pdev); > > > > @@ -1165,7 +1166,8 @@ int pci_enable_link_state(struct pci_dev *pdev, int state) > > return -EPERM; > > } > > > > - down_read(&pci_bus_sem); > > + if (sem) > > + down_read(&pci_bus_sem); > > mutex_lock(&aspm_lock); > > link->aspm_default = 0; > > if (state & PCIE_LINK_STATE_L0S) > > @@ -1186,7 +1188,8 @@ int pci_enable_link_state(struct pci_dev *pdev, int state) > > link->clkpm_default = (state & PCIE_LINK_STATE_CLKPM) ? 1 : 0; > > pcie_set_clkpm(link, policy_to_clkpm_state(link)); > > mutex_unlock(&aspm_lock); > > - up_read(&pci_bus_sem); > > + if (sem) > > + up_read(&pci_bus_sem); > > > > return 0; > > } > > diff --git a/include/linux/pci.h b/include/linux/pci.h > > index fafd8020c6d7..a6f9f24b39fd 100644 > > --- a/include/linux/pci.h > > +++ b/include/linux/pci.h > > @@ -1707,7 +1707,7 @@ extern bool pcie_ports_native; > > #ifdef CONFIG_PCIEASPM > > int pci_disable_link_state(struct pci_dev *pdev, int state); > > int pci_disable_link_state_locked(struct pci_dev *pdev, int state); > > -int pci_enable_link_state(struct pci_dev *pdev, int state); > > +int pci_enable_link_state(struct pci_dev *pdev, int state, bool sem); > > void pcie_no_aspm(void); > > bool pcie_aspm_support_enabled(void); > > bool pcie_aspm_enabled(struct pci_dev *pdev); > > @@ -1716,7 +1716,8 @@ static inline int pci_disable_link_state(struct pci_dev *pdev, int state) > > { return 0; } > > static inline int pci_disable_link_state_locked(struct pci_dev *pdev, int state) > > { return 0; } > > -static inline int pci_enable_link_state(struct pci_dev *pdev, int state) > > +static inline int > > +pci_enable_link_state(struct pci_dev *pdev, int state, bool sem) > > { return 0; } > > static inline void pcie_no_aspm(void) { } > > static inline bool pcie_aspm_support_enabled(void) { return false; } > > -- > > 2.34.1 > >
Hi Bjorn, On Wed, 2023-03-22 at 15:57 -0500, Bjorn Helgaas wrote: > On Wed, Mar 22, 2023 at 03:45:01PM -0500, Bjorn Helgaas wrote: > > Hi David, > > > > On Tue, Mar 21, 2023 at 04:38:49PM -0700, David E. Box wrote: > > > The VMD driver calls pci_enabled_link_state as a callback from > > > pci_bus_walk. Both will acquire the pci_bus_sem lock leading to a lockdep > > > warning. Add an argument to pci_enable_link_state to set whether the lock > > > should be acquired. In the VMD driver, set the argument to false since the > > > lock will already be obtained by pci_bus_walk. > > > > > > Reported-by: Ville Syrjälä <ville.syrjala@linux.intel.com> > > > Fixes: de82f60f9c86 ("PCI/ASPM: Add pci_enable_link_state()") > > > > This means "if your kernel includes de82f60f9c86, you probably want to > > backport this fix to it." But that's not the case here. This patch > > is not fixing an issue with de82f60f9c86, so I don't think there's a > > reason to include a "Fixes" line. > > Oops, sorry, forgot to engage brain before hitting "send". > > I think the "Fixes" line should reference f492edb40b54 ("PCI: vmd: Add > quirk to configure PCIe ASPM and LTR") instead, since that's where the > locking problem started. > > > This patch is adding functionality that is only needed by some other > > patch, and it should be part of a series that also includes the patch > > that uses it to make sure they go together. Yeah this should have been two patches. > > And I see that the use *is* included in this patch. But I don't > really like this pattern: > > vmd_probe > vmd_enable_domain > vmd->bus = pci_create_root_bus(...); > pci_scan_child_bus(vmd->bus); > pci_walk_bus(vmd->bus, vmd_pm_enable_quirk, &features); > > because pci_walk_bus() makes locking complicated (as this issue shows) > and it doesn't work for hot-added devices (I don't know if that's an > issue for VMD, but the pattern gets copied to places where it *is*). > > Normally vmd_pm_enable_quirk() would be done by making it an actual > DECLARE_PCI_FIXUP_HEADER() or DECLARE_PCI_FIXUP_FINAL(), so it would > be called automatically by the PCI core when a new device is > enumerated. Would that work here? If it would, I don't think you'd > need to add the extra flag to pci_enable_link_state(). It should work. I'll test the change. David > > > > Link: https://lore.kernel.org/linux-pci/ZBjko%2FifunIwsK2v@intel.com/ > > > Signed-off-by: David E. Box <david.e.box@linux.intel.com> > > > --- > > > drivers/pci/controller/vmd.c | 2 +- > > > drivers/pci/pcie/aspm.c | 9 ++++++--- > > > include/linux/pci.h | 5 +++-- > > > 3 files changed, 10 insertions(+), 6 deletions(-) > > > > > > diff --git a/drivers/pci/controller/vmd.c b/drivers/pci/controller/vmd.c > > > index 990630ec57c6..45aa35744eae 100644 > > > --- a/drivers/pci/controller/vmd.c > > > +++ b/drivers/pci/controller/vmd.c > > > @@ -737,7 +737,7 @@ static int vmd_pm_enable_quirk(struct pci_dev *pdev, > > > void *userdata) > > > if (!(features & VMD_FEAT_BIOS_PM_QUIRK)) > > > return 0; > > > > > > - pci_enable_link_state(pdev, PCIE_LINK_STATE_ALL); > > > + pci_enable_link_state(pdev, PCIE_LINK_STATE_ALL, false); > > > > > > pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_LTR); > > > if (!pos) > > > diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c > > > index 66d7514ca111..5b5a600bb864 100644 > > > --- a/drivers/pci/pcie/aspm.c > > > +++ b/drivers/pci/pcie/aspm.c > > > @@ -1147,8 +1147,9 @@ EXPORT_SYMBOL(pci_disable_link_state); > > > * > > > * @pdev: PCI device > > > * @state: Mask of ASPM link states to enable > > > + * @sem: Boolean to acquire/release pci_bus_sem > > > */ > > > -int pci_enable_link_state(struct pci_dev *pdev, int state) > > > +int pci_enable_link_state(struct pci_dev *pdev, int state, bool sem) > > > { > > > struct pcie_link_state *link = pcie_aspm_get_link(pdev); > > > > > > @@ -1165,7 +1166,8 @@ int pci_enable_link_state(struct pci_dev *pdev, int > > > state) > > > return -EPERM; > > > } > > > > > > - down_read(&pci_bus_sem); > > > + if (sem) > > > + down_read(&pci_bus_sem); > > > mutex_lock(&aspm_lock); > > > link->aspm_default = 0; > > > if (state & PCIE_LINK_STATE_L0S) > > > @@ -1186,7 +1188,8 @@ int pci_enable_link_state(struct pci_dev *pdev, int > > > state) > > > link->clkpm_default = (state & PCIE_LINK_STATE_CLKPM) ? 1 : 0; > > > pcie_set_clkpm(link, policy_to_clkpm_state(link)); > > > mutex_unlock(&aspm_lock); > > > - up_read(&pci_bus_sem); > > > + if (sem) > > > + up_read(&pci_bus_sem); > > > > > > return 0; > > > } > > > diff --git a/include/linux/pci.h b/include/linux/pci.h > > > index fafd8020c6d7..a6f9f24b39fd 100644 > > > --- a/include/linux/pci.h > > > +++ b/include/linux/pci.h > > > @@ -1707,7 +1707,7 @@ extern bool pcie_ports_native; > > > #ifdef CONFIG_PCIEASPM > > > int pci_disable_link_state(struct pci_dev *pdev, int state); > > > int pci_disable_link_state_locked(struct pci_dev *pdev, int state); > > > -int pci_enable_link_state(struct pci_dev *pdev, int state); > > > +int pci_enable_link_state(struct pci_dev *pdev, int state, bool sem); > > > void pcie_no_aspm(void); > > > bool pcie_aspm_support_enabled(void); > > > bool pcie_aspm_enabled(struct pci_dev *pdev); > > > @@ -1716,7 +1716,8 @@ static inline int pci_disable_link_state(struct > > > pci_dev *pdev, int state) > > > { return 0; } > > > static inline int pci_disable_link_state_locked(struct pci_dev *pdev, int > > > state) > > > { return 0; } > > > -static inline int pci_enable_link_state(struct pci_dev *pdev, int state) > > > +static inline int > > > +pci_enable_link_state(struct pci_dev *pdev, int state, bool sem) > > > { return 0; } > > > static inline void pcie_no_aspm(void) { } > > > static inline bool pcie_aspm_support_enabled(void) { return false; } > > > -- > > > 2.34.1 > > >
diff --git a/drivers/pci/controller/vmd.c b/drivers/pci/controller/vmd.c index 990630ec57c6..45aa35744eae 100644 --- a/drivers/pci/controller/vmd.c +++ b/drivers/pci/controller/vmd.c @@ -737,7 +737,7 @@ static int vmd_pm_enable_quirk(struct pci_dev *pdev, void *userdata) if (!(features & VMD_FEAT_BIOS_PM_QUIRK)) return 0; - pci_enable_link_state(pdev, PCIE_LINK_STATE_ALL); + pci_enable_link_state(pdev, PCIE_LINK_STATE_ALL, false); pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_LTR); if (!pos) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 66d7514ca111..5b5a600bb864 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -1147,8 +1147,9 @@ EXPORT_SYMBOL(pci_disable_link_state); * * @pdev: PCI device * @state: Mask of ASPM link states to enable + * @sem: Boolean to acquire/release pci_bus_sem */ -int pci_enable_link_state(struct pci_dev *pdev, int state) +int pci_enable_link_state(struct pci_dev *pdev, int state, bool sem) { struct pcie_link_state *link = pcie_aspm_get_link(pdev); @@ -1165,7 +1166,8 @@ int pci_enable_link_state(struct pci_dev *pdev, int state) return -EPERM; } - down_read(&pci_bus_sem); + if (sem) + down_read(&pci_bus_sem); mutex_lock(&aspm_lock); link->aspm_default = 0; if (state & PCIE_LINK_STATE_L0S) @@ -1186,7 +1188,8 @@ int pci_enable_link_state(struct pci_dev *pdev, int state) link->clkpm_default = (state & PCIE_LINK_STATE_CLKPM) ? 1 : 0; pcie_set_clkpm(link, policy_to_clkpm_state(link)); mutex_unlock(&aspm_lock); - up_read(&pci_bus_sem); + if (sem) + up_read(&pci_bus_sem); return 0; } diff --git a/include/linux/pci.h b/include/linux/pci.h index fafd8020c6d7..a6f9f24b39fd 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -1707,7 +1707,7 @@ extern bool pcie_ports_native; #ifdef CONFIG_PCIEASPM int pci_disable_link_state(struct pci_dev *pdev, int state); int pci_disable_link_state_locked(struct pci_dev *pdev, int state); -int pci_enable_link_state(struct pci_dev *pdev, int state); +int pci_enable_link_state(struct pci_dev *pdev, int state, bool sem); void pcie_no_aspm(void); bool pcie_aspm_support_enabled(void); bool pcie_aspm_enabled(struct pci_dev *pdev); @@ -1716,7 +1716,8 @@ static inline int pci_disable_link_state(struct pci_dev *pdev, int state) { return 0; } static inline int pci_disable_link_state_locked(struct pci_dev *pdev, int state) { return 0; } -static inline int pci_enable_link_state(struct pci_dev *pdev, int state) +static inline int +pci_enable_link_state(struct pci_dev *pdev, int state, bool sem) { return 0; } static inline void pcie_no_aspm(void) { } static inline bool pcie_aspm_support_enabled(void) { return false; }