linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] PCI/PM: Do not generate wakeup event when runtime resuming bus
@ 2020-11-25  9:07 Mika Westerberg
  2020-11-25  9:07 ` [PATCH v2 2/2] PCI: Rename pci_wakeup_bus() to pci_resume_bus() Mika Westerberg
  2020-12-04 23:18 ` [PATCH v2 1/2] PCI/PM: Do not generate wakeup event when runtime resuming bus Bjorn Helgaas
  0 siblings, 2 replies; 3+ messages in thread
From: Mika Westerberg @ 2020-11-25  9:07 UTC (permalink / raw)
  To: Bjorn Helgaas, Rafael J. Wysocki
  Cc: Lukas Wunner, David Airlie, Daniel Vetter, Utkarsh Patel,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	Mika Westerberg, linux-pci

When a PCI bridge is runtime resumed from D3cold the underlying bus is
walked and the attached devices are runtime resumed as well. However, in
addition to that we also generate a wakeup event for these devices even
though this actually is not a real wakeup event coming from the
hardware.

Normally this does not cause problems but when combined with
/sys/power/wakeup_count like using the steps below:

  # count=$(cat /sys/power/wakeup_count)
  # echo $count > /sys/power/wakeup_count
  # echo mem > /sys/power/state

The system suspend cycle might fail at this point if a PCI bridge that
was runtime suspended (D3cold) was runtime resumed for any reason. The
runtime resume calls pci_wakeup_bus() and that generates wakeup event
increasing wakeup_count.

Since this is not a real wakeup event we can prevent the above from
happening by removing the call to pci_wakeup_event() in
pci_wakeup_bus().

Reported-by: Utkarsh Patel <utkarsh.h.patel@intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
Previous version can be found here:

  https://www.spinics.net/lists/linux-pci/msg101083.html

Changes from the previous version:

  - Split the patch in two. The second patch only does the rename.
  - Tried to improve the commit message a bit
  - Added Rafael's reviewed-by tag

 drivers/pci/pci.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index e578d34095e9..6f7b33998fbe 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1181,7 +1181,6 @@ EXPORT_SYMBOL_GPL(pci_platform_power_transition);
  */
 static int pci_wakeup(struct pci_dev *pci_dev, void *ign)
 {
-	pci_wakeup_event(pci_dev);
 	pm_request_resume(&pci_dev->dev);
 	return 0;
 }
-- 
2.29.2


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

* [PATCH v2 2/2] PCI: Rename pci_wakeup_bus() to pci_resume_bus()
  2020-11-25  9:07 [PATCH v2 1/2] PCI/PM: Do not generate wakeup event when runtime resuming bus Mika Westerberg
@ 2020-11-25  9:07 ` Mika Westerberg
  2020-12-04 23:18 ` [PATCH v2 1/2] PCI/PM: Do not generate wakeup event when runtime resuming bus Bjorn Helgaas
  1 sibling, 0 replies; 3+ messages in thread
From: Mika Westerberg @ 2020-11-25  9:07 UTC (permalink / raw)
  To: Bjorn Helgaas, Rafael J. Wysocki
  Cc: Lukas Wunner, David Airlie, Daniel Vetter, Utkarsh Patel,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	Mika Westerberg, linux-pci

The previous commit changed the pci_wakeup_bus() to not to signal wakeup
event anymore so rename the function to better match what it does.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
This is new patch as suggested by Bjorn. This one only does the rename. I
added Rafael's tag here too as there are no other changes than the split.
Let me know if it's not OK.

 drivers/gpu/vga/vga_switcheroo.c |  2 +-
 drivers/pci/pci.c                | 15 +++++----------
 include/linux/pci.h              |  2 +-
 3 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
index 087304b1a5d7..8843b078ad4e 100644
--- a/drivers/gpu/vga/vga_switcheroo.c
+++ b/drivers/gpu/vga/vga_switcheroo.c
@@ -1039,7 +1039,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
 	mutex_lock(&vgasr_mutex);
 	vga_switcheroo_power_switch(pdev, VGA_SWITCHEROO_ON);
 	mutex_unlock(&vgasr_mutex);
-	pci_wakeup_bus(pdev->bus);
+	pci_resume_bus(pdev->bus);
 	ret = dev->bus->pm->runtime_resume(dev);
 	if (ret)
 		return ret;
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 6f7b33998fbe..0102cc973783 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1174,25 +1174,20 @@ int pci_platform_power_transition(struct pci_dev *dev, pci_power_t state)
 }
 EXPORT_SYMBOL_GPL(pci_platform_power_transition);
 
-/**
- * pci_wakeup - Wake up a PCI device
- * @pci_dev: Device to handle.
- * @ign: ignored parameter
- */
-static int pci_wakeup(struct pci_dev *pci_dev, void *ign)
+static int pci_resume_one(struct pci_dev *pci_dev, void *ign)
 {
 	pm_request_resume(&pci_dev->dev);
 	return 0;
 }
 
 /**
- * pci_wakeup_bus - Walk given bus and wake up devices on it
+ * pci_resume_bus - Walk given bus and runtime resume devices on it
  * @bus: Top bus of the subtree to walk.
  */
-void pci_wakeup_bus(struct pci_bus *bus)
+void pci_resume_bus(struct pci_bus *bus)
 {
 	if (bus)
-		pci_walk_bus(bus, pci_wakeup, NULL);
+		pci_walk_bus(bus, pci_resume_one, NULL);
 }
 
 static int pci_dev_wait(struct pci_dev *dev, char *reset_type, int timeout)
@@ -1255,7 +1250,7 @@ int pci_power_up(struct pci_dev *dev)
 		 * may be powered on into D0uninitialized state, resume them to
 		 * give them a chance to suspend again
 		 */
-		pci_wakeup_bus(dev->subordinate);
+		pci_resume_bus(dev->subordinate);
 	}
 
 	return pci_raw_set_power_state(dev, PCI_D0);
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 22207a79762c..9256ef2e4327 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1271,7 +1271,7 @@ bool pci_dev_run_wake(struct pci_dev *dev);
 void pci_d3cold_enable(struct pci_dev *dev);
 void pci_d3cold_disable(struct pci_dev *dev);
 bool pcie_relaxed_ordering_enabled(struct pci_dev *dev);
-void pci_wakeup_bus(struct pci_bus *bus);
+void pci_resume_bus(struct pci_bus *bus);
 void pci_bus_set_current_state(struct pci_bus *bus, pci_power_t state);
 
 /* For use by arch with custom probe code */
-- 
2.29.2


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

* Re: [PATCH v2 1/2] PCI/PM: Do not generate wakeup event when runtime resuming bus
  2020-11-25  9:07 [PATCH v2 1/2] PCI/PM: Do not generate wakeup event when runtime resuming bus Mika Westerberg
  2020-11-25  9:07 ` [PATCH v2 2/2] PCI: Rename pci_wakeup_bus() to pci_resume_bus() Mika Westerberg
@ 2020-12-04 23:18 ` Bjorn Helgaas
  1 sibling, 0 replies; 3+ messages in thread
From: Bjorn Helgaas @ 2020-12-04 23:18 UTC (permalink / raw)
  To: Mika Westerberg
  Cc: Bjorn Helgaas, Rafael J. Wysocki, Lukas Wunner, David Airlie,
	Daniel Vetter, Utkarsh Patel, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, linux-pci

On Wed, Nov 25, 2020 at 12:07:32PM +0300, Mika Westerberg wrote:
> When a PCI bridge is runtime resumed from D3cold the underlying bus is
> walked and the attached devices are runtime resumed as well. However, in
> addition to that we also generate a wakeup event for these devices even
> though this actually is not a real wakeup event coming from the
> hardware.
> 
> Normally this does not cause problems but when combined with
> /sys/power/wakeup_count like using the steps below:
> 
>   # count=$(cat /sys/power/wakeup_count)
>   # echo $count > /sys/power/wakeup_count
>   # echo mem > /sys/power/state
> 
> The system suspend cycle might fail at this point if a PCI bridge that
> was runtime suspended (D3cold) was runtime resumed for any reason. The
> runtime resume calls pci_wakeup_bus() and that generates wakeup event
> increasing wakeup_count.
> 
> Since this is not a real wakeup event we can prevent the above from
> happening by removing the call to pci_wakeup_event() in
> pci_wakeup_bus().
> 
> Reported-by: Utkarsh Patel <utkarsh.h.patel@intel.com>
> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

I reversed the order of these since I think it's more obvious that
pci_wakeup_event() doesn't fit in pci_resume_one() and applied both to
pci/pm for v5.11, thanks!

> ---
> Previous version can be found here:
> 
>   https://www.spinics.net/lists/linux-pci/msg101083.html
> 
> Changes from the previous version:
> 
>   - Split the patch in two. The second patch only does the rename.
>   - Tried to improve the commit message a bit
>   - Added Rafael's reviewed-by tag
> 
>  drivers/pci/pci.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index e578d34095e9..6f7b33998fbe 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -1181,7 +1181,6 @@ EXPORT_SYMBOL_GPL(pci_platform_power_transition);
>   */
>  static int pci_wakeup(struct pci_dev *pci_dev, void *ign)
>  {
> -	pci_wakeup_event(pci_dev);
>  	pm_request_resume(&pci_dev->dev);
>  	return 0;
>  }
> -- 
> 2.29.2
> 

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

end of thread, other threads:[~2020-12-04 23:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-25  9:07 [PATCH v2 1/2] PCI/PM: Do not generate wakeup event when runtime resuming bus Mika Westerberg
2020-11-25  9:07 ` [PATCH v2 2/2] PCI: Rename pci_wakeup_bus() to pci_resume_bus() Mika Westerberg
2020-12-04 23:18 ` [PATCH v2 1/2] PCI/PM: Do not generate wakeup event when runtime resuming bus Bjorn Helgaas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).