diff mbox series

[1/2] PCI: Avoid runtime resuming devices if system is shutting down

Message ID 20231213182656.6165-2-mario.limonciello@amd.com (mailing list archive)
State New
Delegated to: Bjorn Helgaas
Headers show
Series Improvements to system power consumption at S5 | expand

Commit Message

Mario Limonciello Dec. 13, 2023, 6:26 p.m. UTC
When the system is going to S5 resuming devices is unnecessary at
best and may cause problems for power consumption at S5 at worst.

Check the target `system_state` in the pci driver shutdown() callback
and skip the runtime resume step if the system is being powered off.

Cc: mpearson-lenovo@squebb.ca
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
 drivers/pci/pci-driver.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Rafael J. Wysocki Dec. 13, 2023, 6:31 p.m. UTC | #1
On Wed, Dec 13, 2023 at 7:27 PM Mario Limonciello
<mario.limonciello@amd.com> wrote:
>
> When the system is going to S5 resuming devices is unnecessary at
> best and may cause problems for power consumption at S5 at worst.
>
> Check the target `system_state` in the pci driver shutdown() callback
> and skip the runtime resume step if the system is being powered off.
>
> Cc: mpearson-lenovo@squebb.ca
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> ---
>  drivers/pci/pci-driver.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
> index 51ec9e7e784f..5a6f7a786952 100644
> --- a/drivers/pci/pci-driver.c
> +++ b/drivers/pci/pci-driver.c
> @@ -507,7 +507,9 @@ static void pci_device_shutdown(struct device *dev)
>         struct pci_dev *pci_dev = to_pci_dev(dev);
>         struct pci_driver *drv = pci_dev->driver;
>
> -       pm_runtime_resume(dev);
> +       /* If system will go to S5, don't wake up PCI devices for shutdown */
> +       if (system_state != SYSTEM_POWER_OFF)
> +               pm_runtime_resume(dev);

What's the guarantee that the driver's shutdown callback will not
access MMIO regions of a runtime-suspended device?

>         if (drv && drv->shutdown)
>                 drv->shutdown(pci_dev);
> --
Mario Limonciello Dec. 13, 2023, 6:33 p.m. UTC | #2
On 12/13/2023 12:31, Rafael J. Wysocki wrote:
> On Wed, Dec 13, 2023 at 7:27 PM Mario Limonciello
> <mario.limonciello@amd.com> wrote:
>>
>> When the system is going to S5 resuming devices is unnecessary at
>> best and may cause problems for power consumption at S5 at worst.
>>
>> Check the target `system_state` in the pci driver shutdown() callback
>> and skip the runtime resume step if the system is being powered off.
>>
>> Cc: mpearson-lenovo@squebb.ca
>> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
>> ---
>>   drivers/pci/pci-driver.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
>> index 51ec9e7e784f..5a6f7a786952 100644
>> --- a/drivers/pci/pci-driver.c
>> +++ b/drivers/pci/pci-driver.c
>> @@ -507,7 +507,9 @@ static void pci_device_shutdown(struct device *dev)
>>          struct pci_dev *pci_dev = to_pci_dev(dev);
>>          struct pci_driver *drv = pci_dev->driver;
>>
>> -       pm_runtime_resume(dev);
>> +       /* If system will go to S5, don't wake up PCI devices for shutdown */
>> +       if (system_state != SYSTEM_POWER_OFF)
>> +               pm_runtime_resume(dev);
> 
> What's the guarantee that the driver's shutdown callback will not
> access MMIO regions of a runtime-suspended device?

This is something that may need to be audited.

I have an expectation that drivers will runtime resume a device before 
they try to access it.

> 
>>          if (drv && drv->shutdown)
>>                  drv->shutdown(pci_dev);
>> --
Rafael J. Wysocki Dec. 13, 2023, 6:39 p.m. UTC | #3
On Wed, Dec 13, 2023 at 7:33 PM Mario Limonciello
<mario.limonciello@amd.com> wrote:
>
> On 12/13/2023 12:31, Rafael J. Wysocki wrote:
> > On Wed, Dec 13, 2023 at 7:27 PM Mario Limonciello
> > <mario.limonciello@amd.com> wrote:
> >>
> >> When the system is going to S5 resuming devices is unnecessary at
> >> best and may cause problems for power consumption at S5 at worst.
> >>
> >> Check the target `system_state` in the pci driver shutdown() callback
> >> and skip the runtime resume step if the system is being powered off.
> >>
> >> Cc: mpearson-lenovo@squebb.ca
> >> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> >> ---
> >>   drivers/pci/pci-driver.c | 4 +++-
> >>   1 file changed, 3 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
> >> index 51ec9e7e784f..5a6f7a786952 100644
> >> --- a/drivers/pci/pci-driver.c
> >> +++ b/drivers/pci/pci-driver.c
> >> @@ -507,7 +507,9 @@ static void pci_device_shutdown(struct device *dev)
> >>          struct pci_dev *pci_dev = to_pci_dev(dev);
> >>          struct pci_driver *drv = pci_dev->driver;
> >>
> >> -       pm_runtime_resume(dev);
> >> +       /* If system will go to S5, don't wake up PCI devices for shutdown */
> >> +       if (system_state != SYSTEM_POWER_OFF)
> >> +               pm_runtime_resume(dev);
> >
> > What's the guarantee that the driver's shutdown callback will not
> > access MMIO regions of a runtime-suspended device?
>
> This is something that may need to be audited.
>
> I have an expectation that drivers will runtime resume a device before
> they try to access it.

But they don't need to do it, because the core does it right now,
which is my point.
diff mbox series

Patch

diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 51ec9e7e784f..5a6f7a786952 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -507,7 +507,9 @@  static void pci_device_shutdown(struct device *dev)
 	struct pci_dev *pci_dev = to_pci_dev(dev);
 	struct pci_driver *drv = pci_dev->driver;
 
-	pm_runtime_resume(dev);
+	/* If system will go to S5, don't wake up PCI devices for shutdown */
+	if (system_state != SYSTEM_POWER_OFF)
+		pm_runtime_resume(dev);
 
 	if (drv && drv->shutdown)
 		drv->shutdown(pci_dev);