Linux-NVME Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 0/1] PCI/ASPM: Remove locking
@ 2019-10-10 12:47 Bjorn Helgaas
  2019-10-10 12:47 ` [PATCH 1/1] PCI/ASPM: Remove pcie_aspm_enabled() unnecessary locking Bjorn Helgaas
  0 siblings, 1 reply; 5+ messages in thread
From: Bjorn Helgaas @ 2019-10-10 12:47 UTC (permalink / raw)
  To: linux-pci
  Cc: Sagi Grimberg, Mario Limonciello, linux-pm, Rafael J . Wysocki,
	linux-kernel, linux-nvme, Keith Busch, Kai-Heng Feng,
	Bjorn Helgaas, Rajat Jain, Christoph Hellwig, Heiner Kallweit

From: Bjorn Helgaas <bhelgaas@google.com>

In reference to this thread:
  https://lore.kernel.org/r/20191007223428.GA72605@google.com

This removes locking from pcie_aspm_enabled() because the reference count
held by the driver should provide all the locking we need.

Bjorn Helgaas (1):
  PCI/ASPM: Remove pcie_aspm_enabled() unnecessary locking

 drivers/pci/pcie/aspm.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

-- 
2.23.0.581.g78d2f28ef7-goog


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* [PATCH 1/1] PCI/ASPM: Remove pcie_aspm_enabled() unnecessary locking
  2019-10-10 12:47 [PATCH 0/1] PCI/ASPM: Remove locking Bjorn Helgaas
@ 2019-10-10 12:47 ` Bjorn Helgaas
  2019-10-10 14:01   ` Christoph Hellwig
  2019-10-10 16:28   ` Rafael J. Wysocki
  0 siblings, 2 replies; 5+ messages in thread
From: Bjorn Helgaas @ 2019-10-10 12:47 UTC (permalink / raw)
  To: linux-pci
  Cc: Sagi Grimberg, Mario Limonciello, linux-pm, Rafael J . Wysocki,
	linux-kernel, linux-nvme, Keith Busch, Kai-Heng Feng,
	Bjorn Helgaas, Rajat Jain, Christoph Hellwig, Heiner Kallweit

From: Bjorn Helgaas <bhelgaas@google.com>

The lifetime of the link_state structure (bridge->link_state) is not the
same as the lifetime of "bridge" itself.  The link_state is allocated by
pcie_aspm_init_link_state() after children of the bridge have been
enumerated, and it is deallocated by pcie_aspm_exit_link_state() after all
children of the bridge (but not the bridge itself) have been removed.

Previously pcie_aspm_enabled() acquired aspm_lock to ensure that
link_state was not deallocated while we're looking at it.  But the fact
that the caller of pcie_aspm_enabled() holds a reference to @pdev means
there's always at least one child of the bridge, which means link_state
can't be deallocated.

Remove the unnecessary locking in pcie_aspm_enabled().

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
---
 drivers/pci/pcie/aspm.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
index 652ef23bba35..f5c7138a34aa 100644
--- a/drivers/pci/pcie/aspm.c
+++ b/drivers/pci/pcie/aspm.c
@@ -1172,20 +1172,20 @@ module_param_call(policy, pcie_aspm_set_policy, pcie_aspm_get_policy,
 /**
  * pcie_aspm_enabled - Check if PCIe ASPM has been enabled for a device.
  * @pdev: Target device.
+ *
+ * Relies on the upstream bridge's link_state being valid.  The link_state
+ * is deallocated only when the last child of the bridge (i.e., @pdev or a
+ * sibling) is removed, and the caller should be holding a reference to
+ * @pdev, so this should be safe.
  */
 bool pcie_aspm_enabled(struct pci_dev *pdev)
 {
 	struct pci_dev *bridge = pci_upstream_bridge(pdev);
-	bool ret;
 
 	if (!bridge)
 		return false;
 
-	mutex_lock(&aspm_lock);
-	ret = bridge->link_state ? !!bridge->link_state->aspm_enabled : false;
-	mutex_unlock(&aspm_lock);
-
-	return ret;
+	return bridge->link_state ? !!bridge->link_state->aspm_enabled : false;
 }
 EXPORT_SYMBOL_GPL(pcie_aspm_enabled);
 
-- 
2.23.0.581.g78d2f28ef7-goog


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH 1/1] PCI/ASPM: Remove pcie_aspm_enabled() unnecessary locking
  2019-10-10 12:47 ` [PATCH 1/1] PCI/ASPM: Remove pcie_aspm_enabled() unnecessary locking Bjorn Helgaas
@ 2019-10-10 14:01   ` Christoph Hellwig
  2019-10-10 16:14     ` Bjorn Helgaas
  2019-10-10 16:28   ` Rafael J. Wysocki
  1 sibling, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2019-10-10 14:01 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Sagi Grimberg, Mario Limonciello, linux-pci, linux-pm,
	Rafael J . Wysocki, linux-kernel, linux-nvme, Keith Busch,
	Kai-Heng Feng, Bjorn Helgaas, Rajat Jain, Christoph Hellwig,
	Heiner Kallweit

On Thu, Oct 10, 2019 at 07:47:46AM -0500, Bjorn Helgaas wrote:
> +	return bridge->link_state ? !!bridge->link_state->aspm_enabled : false;

Can we unobsfucated this while we're at it?

	if (!bridge->link_state)
		return false;
	return bridge->link_state->aspm_enabled;

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH 1/1] PCI/ASPM: Remove pcie_aspm_enabled() unnecessary locking
  2019-10-10 14:01   ` Christoph Hellwig
@ 2019-10-10 16:14     ` Bjorn Helgaas
  0 siblings, 0 replies; 5+ messages in thread
From: Bjorn Helgaas @ 2019-10-10 16:14 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Sagi Grimberg, Mario Limonciello, linux-pci, linux-pm,
	Rafael J . Wysocki, linux-kernel, linux-nvme, Keith Busch,
	Kai-Heng Feng, Rajat Jain, Heiner Kallweit

On Thu, Oct 10, 2019 at 04:01:21PM +0200, Christoph Hellwig wrote:
> On Thu, Oct 10, 2019 at 07:47:46AM -0500, Bjorn Helgaas wrote:
> > +	return bridge->link_state ? !!bridge->link_state->aspm_enabled : false;
> 
> Can we unobsfucated this while we're at it?
> 
> 	if (!bridge->link_state)
> 		return false;
> 	return bridge->link_state->aspm_enabled;

Yep, after some of the follow-up patches from Heiner, it looks like
this:

  bool pcie_aspm_enabled(struct pci_dev *pdev)
  {
	  struct pcie_link_state *link = pcie_aspm_get_link(pdev);

	  if (!link)
		  return false;

	  return link->aspm_enabled;
  }


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

* Re: [PATCH 1/1] PCI/ASPM: Remove pcie_aspm_enabled() unnecessary locking
  2019-10-10 12:47 ` [PATCH 1/1] PCI/ASPM: Remove pcie_aspm_enabled() unnecessary locking Bjorn Helgaas
  2019-10-10 14:01   ` Christoph Hellwig
@ 2019-10-10 16:28   ` Rafael J. Wysocki
  1 sibling, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2019-10-10 16:28 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Sagi Grimberg, Mario Limonciello, Linux PCI, Linux PM,
	Rafael J . Wysocki, Linux Kernel Mailing List, linux-nvme,
	Keith Busch, Kai-Heng Feng, Bjorn Helgaas, Rajat Jain,
	Christoph Hellwig, Heiner Kallweit

On Thu, Oct 10, 2019 at 2:48 PM Bjorn Helgaas <helgaas@kernel.org> wrote:
>
> From: Bjorn Helgaas <bhelgaas@google.com>
>
> The lifetime of the link_state structure (bridge->link_state) is not the
> same as the lifetime of "bridge" itself.  The link_state is allocated by
> pcie_aspm_init_link_state() after children of the bridge have been
> enumerated, and it is deallocated by pcie_aspm_exit_link_state() after all
> children of the bridge (but not the bridge itself) have been removed.
>
> Previously pcie_aspm_enabled() acquired aspm_lock to ensure that
> link_state was not deallocated while we're looking at it.  But the fact
> that the caller of pcie_aspm_enabled() holds a reference to @pdev means
> there's always at least one child of the bridge, which means link_state
> can't be deallocated.
>
> Remove the unnecessary locking in pcie_aspm_enabled().
>
> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>

Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

(also for the further changes you and Christoph have been discussing).

> ---
>  drivers/pci/pcie/aspm.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
> index 652ef23bba35..f5c7138a34aa 100644
> --- a/drivers/pci/pcie/aspm.c
> +++ b/drivers/pci/pcie/aspm.c
> @@ -1172,20 +1172,20 @@ module_param_call(policy, pcie_aspm_set_policy, pcie_aspm_get_policy,
>  /**
>   * pcie_aspm_enabled - Check if PCIe ASPM has been enabled for a device.
>   * @pdev: Target device.
> + *
> + * Relies on the upstream bridge's link_state being valid.  The link_state
> + * is deallocated only when the last child of the bridge (i.e., @pdev or a
> + * sibling) is removed, and the caller should be holding a reference to
> + * @pdev, so this should be safe.
>   */
>  bool pcie_aspm_enabled(struct pci_dev *pdev)
>  {
>         struct pci_dev *bridge = pci_upstream_bridge(pdev);
> -       bool ret;
>
>         if (!bridge)
>                 return false;
>
> -       mutex_lock(&aspm_lock);
> -       ret = bridge->link_state ? !!bridge->link_state->aspm_enabled : false;
> -       mutex_unlock(&aspm_lock);
> -
> -       return ret;
> +       return bridge->link_state ? !!bridge->link_state->aspm_enabled : false;
>  }
>  EXPORT_SYMBOL_GPL(pcie_aspm_enabled);
>
> --
> 2.23.0.581.g78d2f28ef7-goog
>

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-10 12:47 [PATCH 0/1] PCI/ASPM: Remove locking Bjorn Helgaas
2019-10-10 12:47 ` [PATCH 1/1] PCI/ASPM: Remove pcie_aspm_enabled() unnecessary locking Bjorn Helgaas
2019-10-10 14:01   ` Christoph Hellwig
2019-10-10 16:14     ` Bjorn Helgaas
2019-10-10 16:28   ` Rafael J. Wysocki

Linux-NVME Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-nvme/0 linux-nvme/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-nvme linux-nvme/ https://lore.kernel.org/linux-nvme \
		linux-nvme@lists.infradead.org
	public-inbox-index linux-nvme

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.infradead.lists.linux-nvme


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git