2021-07-29 14:51:40

by Rafael J. Wysocki

[permalink] [raw]
Subject: [PATCH v1 1/2] PCI: PM: Add special case handling for PCIe device wakeup

From: Rafael J. Wysocki <[email protected]>

It is inconsistent to return PCI_D0 from pci_target_state() instead
of the original target state if 'wakeup' is true and the device
cannot signal PME from D0.

This only happens when the device cannot signal PME from the original
target state and any shallower power states (including D0) and that
case is effectively equivalent to the one in which PME signaling is
not supported at all. Since the original target state is returned in
the latter case, make the function do that in the former one too.

Link: https://lore.kernel.org/linux-pm/3149540.aeNJFYEL58@kreacher/
Fixes: 666ff6f83e1d ("PCI/PM: Avoid using device_may_wakeup() for runtime PM")
Reported-by: Mika Westerberg <[email protected]>
Reported-by: Utkarsh H Patel <[email protected]>
Reported-by: Koba Ko <[email protected]>
Signed-off-by: Rafael J. Wysocki <[email protected]>
---
drivers/pci/pci.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)

Index: linux-pm/drivers/pci/pci.c
===================================================================
--- linux-pm.orig/drivers/pci/pci.c
+++ linux-pm/drivers/pci/pci.c
@@ -2595,16 +2595,20 @@ static pci_power_t pci_target_state(stru
if (dev->current_state == PCI_D3cold)
target_state = PCI_D3cold;

- if (wakeup) {
+ if (wakeup && dev->pme_support) {
+ pci_power_t state = target_state;
+
/*
* Find the deepest state from which the device can generate
* PME#.
*/
- if (dev->pme_support) {
- while (target_state
- && !(dev->pme_support & (1 << target_state)))
- target_state--;
- }
+ while (state && !(dev->pme_support & (1 << state)))
+ state--;
+
+ if (state)
+ return state;
+ else if (dev->pme_support & 1)
+ return PCI_D0;
}

return target_state;





2021-07-29 15:11:04

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v1 1/2] PCI: PM: Add special case handling for PCIe device wakeup

On Thu, Jul 29, 2021 at 4:49 PM Rafael J. Wysocki <[email protected]> wrote:
>
> From: Rafael J. Wysocki <[email protected]>
>
> It is inconsistent to return PCI_D0 from pci_target_state() instead
> of the original target state if 'wakeup' is true and the device
> cannot signal PME from D0.
>
> This only happens when the device cannot signal PME from the original
> target state and any shallower power states (including D0) and that
> case is effectively equivalent to the one in which PME signaling is
> not supported at all. Since the original target state is returned in
> the latter case, make the function do that in the former one too.
>
> Link: https://lore.kernel.org/linux-pm/3149540.aeNJFYEL58@kreacher/
> Fixes: 666ff6f83e1d ("PCI/PM: Avoid using device_may_wakeup() for runtime PM")
> Reported-by: Mika Westerberg <[email protected]>
> Reported-by: Utkarsh H Patel <[email protected]>
> Reported-by: Koba Ko <[email protected]>
> Signed-off-by: Rafael J. Wysocki <[email protected]>

The subject of this patch should be different, let me resend it.

2021-07-29 15:56:27

by Rafael J. Wysocki

[permalink] [raw]
Subject: [PATCH v1.1 1/2] PCI: PM: Avoid forcing PCI_D0 for wakeup reasons inconsistently

From: Rafael J. Wysocki <[email protected]>

It is inconsistent to return PCI_D0 from pci_target_state() instead
of the original target state if 'wakeup' is true and the device
cannot signal PME from D0.

This only happens when the device cannot signal PME from the original
target state and any shallower power states (including D0) and that
case is effectively equivalent to the one in which PME singaling is
not supported at all. Since the original target state is returned in
the latter case, make the function do that in the former one too.

Link: https://lore.kernel.org/linux-pm/3149540.aeNJFYEL58@kreacher/
Fixes: 666ff6f83e1d ("PCI/PM: Avoid using device_may_wakeup() for runtime PM")
Reported-by: Mika Westerberg <[email protected]>
Reported-by: Utkarsh H Patel <[email protected]>
Reported-by: Koba Ko <[email protected]>
Signed-off-by: Rafael J. Wysocki <[email protected]>
---

v1 -> v1.1
* Resend under a suitable subject.

---
drivers/pci/pci.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)

Index: linux-pm/drivers/pci/pci.c
===================================================================
--- linux-pm.orig/drivers/pci/pci.c
+++ linux-pm/drivers/pci/pci.c
@@ -2595,16 +2595,20 @@ static pci_power_t pci_target_state(stru
if (dev->current_state == PCI_D3cold)
target_state = PCI_D3cold;

- if (wakeup) {
+ if (wakeup && dev->pme_support) {
+ pci_power_t state = target_state;
+
/*
* Find the deepest state from which the device can generate
* PME#.
*/
- if (dev->pme_support) {
- while (target_state
- && !(dev->pme_support & (1 << target_state)))
- target_state--;
- }
+ while (state && !(dev->pme_support & (1 << state)))
+ state--;
+
+ if (state)
+ return state;
+ else if (dev->pme_support & 1)
+ return PCI_D0;
}

return target_state;




2021-07-30 10:28:27

by Mika Westerberg

[permalink] [raw]
Subject: Re: [PATCH v1.1 1/2] PCI: PM: Avoid forcing PCI_D0 for wakeup reasons inconsistently

On Thu, Jul 29, 2021 at 05:54:28PM +0200, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <[email protected]>
>
> It is inconsistent to return PCI_D0 from pci_target_state() instead
> of the original target state if 'wakeup' is true and the device
> cannot signal PME from D0.
>
> This only happens when the device cannot signal PME from the original
> target state and any shallower power states (including D0) and that
> case is effectively equivalent to the one in which PME singaling is
> not supported at all. Since the original target state is returned in
> the latter case, make the function do that in the former one too.
>
> Link: https://lore.kernel.org/linux-pm/3149540.aeNJFYEL58@kreacher/
> Fixes: 666ff6f83e1d ("PCI/PM: Avoid using device_may_wakeup() for runtime PM")
> Reported-by: Mika Westerberg <[email protected]>

Reviewed-by: Mika Westerberg <[email protected]>
Tested-by: Mika Westerberg <[email protected]>