diff mbox series

PCI: PM: Fix ordering of operations in pci_back_from_sleep()

Message ID 11844217.O9o76ZdvQC@kreacher (mailing list archive)
State Accepted
Commit 6f9f0eef0096caddc3fd92760f818970033f06ea
Delegated to: Bjorn Helgaas
Headers show
Series PCI: PM: Fix ordering of operations in pci_back_from_sleep() | expand

Commit Message

Rafael J. Wysocki Oct. 15, 2021, 4:45 p.m. UTC
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

The ordering of operations in pci_back_from_sleep() is incorrect,
because the device may be in D3cold when it runs and pci_enable_wake()
needs to access the device's configuration space which cannot be
done in D3cold.

Fix this by calling pci_set_power_state() to put the device into D0
before calling pci_enable_wake() for it.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/pci/pci.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Rafael J. Wysocki Oct. 20, 2021, 2:24 p.m. UTC | #1
On Fri, Oct 15, 2021 at 6:46 PM Rafael J. Wysocki <rjw@rjwysocki.net> wrote:
>
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> The ordering of operations in pci_back_from_sleep() is incorrect,
> because the device may be in D3cold when it runs and pci_enable_wake()
> needs to access the device's configuration space which cannot be
> done in D3cold.
>
> Fix this by calling pci_set_power_state() to put the device into D0
> before calling pci_enable_wake() for it.
>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

If there are no concerns about this one, I will queue it up for 5.16.

> ---
>  drivers/pci/pci.c |    7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
>
> Index: linux-pm/drivers/pci/pci.c
> ===================================================================
> --- linux-pm.orig/drivers/pci/pci.c
> +++ linux-pm/drivers/pci/pci.c
> @@ -2638,8 +2638,13 @@ EXPORT_SYMBOL(pci_prepare_to_sleep);
>   */
>  int pci_back_from_sleep(struct pci_dev *dev)
>  {
> +       int ret = pci_set_power_state(dev, PCI_D0);
> +
> +       if (ret)
> +               return ret;
> +
>         pci_enable_wake(dev, PCI_D0, false);
> -       return pci_set_power_state(dev, PCI_D0);
> +       return 0;
>  }
>  EXPORT_SYMBOL(pci_back_from_sleep);
>
>
>
>
Bjorn Helgaas Oct. 21, 2021, 1 a.m. UTC | #2
On Fri, Oct 15, 2021 at 06:45:59PM +0200, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> The ordering of operations in pci_back_from_sleep() is incorrect,
> because the device may be in D3cold when it runs and pci_enable_wake()
> needs to access the device's configuration space which cannot be
> done in D3cold.
> 
> Fix this by calling pci_set_power_state() to put the device into D0
> before calling pci_enable_wake() for it.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Acked-by: Bjorn Helgaas <bhelgaas@google.com>

Thanks!

> ---
>  drivers/pci/pci.c |    7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> Index: linux-pm/drivers/pci/pci.c
> ===================================================================
> --- linux-pm.orig/drivers/pci/pci.c
> +++ linux-pm/drivers/pci/pci.c
> @@ -2638,8 +2638,13 @@ EXPORT_SYMBOL(pci_prepare_to_sleep);
>   */
>  int pci_back_from_sleep(struct pci_dev *dev)
>  {
> +	int ret = pci_set_power_state(dev, PCI_D0);
> +
> +	if (ret)
> +		return ret;
> +
>  	pci_enable_wake(dev, PCI_D0, false);
> -	return pci_set_power_state(dev, PCI_D0);
> +	return 0;
>  }
>  EXPORT_SYMBOL(pci_back_from_sleep);
>  
> 
> 
>
diff mbox series

Patch

Index: linux-pm/drivers/pci/pci.c
===================================================================
--- linux-pm.orig/drivers/pci/pci.c
+++ linux-pm/drivers/pci/pci.c
@@ -2638,8 +2638,13 @@  EXPORT_SYMBOL(pci_prepare_to_sleep);
  */
 int pci_back_from_sleep(struct pci_dev *dev)
 {
+	int ret = pci_set_power_state(dev, PCI_D0);
+
+	if (ret)
+		return ret;
+
 	pci_enable_wake(dev, PCI_D0, false);
-	return pci_set_power_state(dev, PCI_D0);
+	return 0;
 }
 EXPORT_SYMBOL(pci_back_from_sleep);