PCI/PM: Skip the suspend_noirq config save if runtime-suspended
Subsystems (2)
PATCH 1/1 PCI/PM: Skip the suspend_noirq config save if runtime-suspended
pci_pm_suspend_noirq() saves config space unconditionally when the driver of the device has no PM callbacks, which includes unbound devices. If such a device is runtime-suspended, the bridge above it may be in a low-power state with the link down. Depending on the platform, the config reads then either hang the CPU or return all ones, which overwrite the snapshot taken at runtime suspend and are written back to the device on resume.
Skip the save if the device is runtime-suspended, as pci_pm_freeze() does, since pci_pm_runtime_suspend() has already saved the config space. Use pm_runtime_status_suspended(), because runtime PM is disabled by the noirq phase and pm_runtime_suspended() would always be false.
---
Found on a Lenovo Yoga 83KF (Arrow Lake-H). A driverless O2 Micro SD reader at 57:00.0 with power/control=auto lets its root port 00:1c.0 runtime-suspend to D3hot. The port then swallows the ECAM reads in pci_save_state(), and the forward-progress watchdog raises a fatal machine check at the ECAM load in pci_mmcfg_read().
The same port returns all ones for CF8/CFC reads. A local quirk hid the reader's extended config space so the save did only those reads, and it was tried once on each kernel. The unpatched kernel still died, and the patched one resumed with no "restore config" writes for the reader.
!pci_dev->state_saved would only work for one cycle per boot, because pci_restore_state() clears it and pci_pm_runtime_suspend() does not run again for a device left in RPM_SUSPENDED.
Stable starts at v6.19 because the fix relies on a2f1e22390ac2 ("PCI/ERR:
Ensure error recoverability at all times"). Older trees still return early from pci_restore_state() when state_saved is false, so a backport there also needs "pci_dev->state_saved = true;" on the skip path.
Tested on 7.2.5 with the root port in D3hot, three suspend/resume cycles in one boot. The unpatched kernel dies on the first. W=1 and sparse clean.
drivers/pci/pci-driver.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/pci/pci-driver.c +9 -1
@@ -915,7 +915,15 @@ static int pci_pm_suspend_noirq(struct device *dev)return pci_legacy_suspend_late (dev);if (!pm) { -pci_save_state (pci_dev); +/* +* The bridge above a runtime-suspended device may be in a +* low-power state with the link down, which makes the device's +* config space inaccessible. pci_pm_runtime_suspend() has +* saved it already. +*/ +if (!pm_runtime_status_suspended (dev)) +pci_save_state (pci_dev); + goto set_unknown; }
Signature · 1 line
2.55.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines
pci_pm_suspend_noirq()saves config space unconditionally when the driver of the device has no PM callbacks, which includes unbound devices. If such a device is runtime-suspended, the bridge above it may be in a low-power state with the link down. Depending on the platform, the config reads then either hang the CPU or return all ones, which overwrite the snapshot taken at runtime suspend and are written back to the device on resume.
Quoted 8 lines
Skip the save if the device is runtime-suspended, as
pci_pm_freeze()does, sincepci_pm_runtime_suspend()has already saved the config space. Usepm_runtime_status_suspended(), because runtime PM is disabled by the noirq phase andpm_runtime_suspended()would always be false.Fixes 931ff68a5a53 ("PCI PM: Restore config spaces of all devices during early resume")Cc [email protected] # v6.19+Signed-off-by Navon John Lukose <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 16 lines · Navon John Lukose
pci_pm_suspend_noirq()saves config space unconditionally when the driver of the device has no PM callbacks, which includes unbound devices. If such a device is runtime-suspended, the bridge above it may be in a low-power state with the link down. Depending on the platform, the config reads then either hang the CPU or return all ones, which overwrite the snapshot taken at runtime suspend and are written back to the device on resume.Skip the save if the device is runtime-suspended, as
pci_pm_freeze()does, sincepci_pm_runtime_suspend()has already saved the config space. Usepm_runtime_status_suspended(), because runtime PM is disabled by the noirq phase andpm_runtime_suspended()would always be false.Fixes 931ff68a5a53 ("PCI PM: Restore config spaces of all devices during early resume")Cc [email protected] # v6.19+Signed-off-by Navon John Lukose <[email protected]>
Quoted 6 lines
---
Found on a Lenovo Yoga 83KF (Arrow Lake-H). A driverless O2 Micro SD reader at 57:00.0 with power/control=auto lets its root port 00:1c.0 runtime-suspend to D3hot. The port then swallows the ECAM reads inpci_save_state(), and the forward-progress watchdog raises a fatal machine check at the ECAM load inpci_mmcfg_read().
Hm, pci_pm_suspend_noirq() should bail out earlier because of the dev_pm_skip_suspend() check. That check resolves to:
dev_pm_smart_suspend(dev) && pm_runtime_status_suspended(dev)
The code comment in device_prepare_smart_suspend() explains that smart_suspend is true for devices without PM callbacks. But only if the parent has smart suspend enabled as well. I guess that's the sticking point? That the port above the card reader doesn't have smart suspend enabled?
Thanks,
Lukas
Quoted 10 lines · Lukas Wunner
Hm,
pci_pm_suspend_noirq()should bail out earlier because of thedev_pm_skip_suspend()check. That check resolves to:dev_pm_smart_suspend(dev) && pm_runtime_status_suspended(dev)The code comment in
device_prepare_smart_suspend()explains thatsmart_suspendis true for devices without PM callbacks. But only if the parent has smart suspend enabled as well. I guess that's the sticking point? That the port above the card reader doesn't have smart suspend enabled?
It is that check, but it fails on the card reader itself, before the parent is looked at. no_pm_callbacks is only set when the bus has no PM ops either, and pci_bus_type always has pci_dev_pm_ops, so no PCI device ever counts as having no callbacks. With no driver to set DPM_FLAG_SMART_SUSPEND, the reader never gets smart_suspend.
pcieport does set the flag for the port, and on this machine the port stays in D3hot through suspend.
Thanks,
Navon
Hi Bjorn,
Gentle ping. The patch still applies to pci/pm on top of Mario's pci_pm_suspend_noirq_common() split, since the !pm branch it touches is unchanged there.
Thanks,
Navon
[+cc Francisco, tangentially related to your series at
https://lore.kernel.org/linux-pci/[email protected]/t/#u]
Quoted 7 lines · Navon John Lukose
pci_pm_suspend_noirq()saves config space unconditionally when the driver of the device has no PM callbacks, which includes unbound devices. If such a device is runtime-suspended, the bridge above it may be in a low-power state with the link down. Depending on the platform, the config reads then either hang the CPU or return all ones, which overwrite the snapshot taken at runtime suspend and are written back to the device on resume.
Right, bridges in non-D0 states don't forward requests downstream, so they end with Unsupported Request (PCIe r7.0, sec 5.3.1) or master abort (PCI PM r1.2, sec 6). It's up to the host bridge to choose how to report those.
Quoted 2 lines
Skip the save if the device is runtime-suspended, as
pci_pm_freeze()does, sincepci_pm_runtime_suspend()has already saved the config space.
pci_pm_freeze() doesn't call pci_save_state() itself, so I guess it's the combination of pci_pm_freeze() and pci_pm_freeze_noirq(), where if not runtime-suspended, pci_pm_freeze() clears dev->state_saved so pci_pm_freeze_noirq() will call pci_save_state()?
Quoted 6 lines
Use
pm_runtime_status_suspended(), because runtime PM is disabled by the noirq phase andpm_runtime_suspended()would always be false.Fixes 931ff68a5a53 ("PCI PM: Restore config spaces of all devices during early resume")Cc [email protected] # v6.19+Signed-off-by Navon John Lukose <[email protected]>
Seems ok to me, but would be good to get Rafael's ack.
Quoted 52 lines
---
Found on a Lenovo Yoga 83KF (Arrow Lake-H). A driverless O2 Micro SD reader at 57:00.0 with power/control=auto lets its root port 00:1c.0 runtime-suspend to D3hot. The port then swallows the ECAM reads inpci_save_state(), and the forward-progress watchdog raises a fatal machine check at the ECAM load inpci_mmcfg_read().The same port returns all ones for CF8/CFC reads. A local quirk hid the reader's extended config space so the save did only those reads, and it was tried once on each kernel. The unpatched kernel still died, and the patched one resumed with no "restore config" writes for the reader.
!pci_dev->state_saved would only work for one cycle per boot, because
pci_restore_state()clears it andpci_pm_runtime_suspend()does not run again for a device left inRPM_SUSPENDED.Stable starts at v6.19 because the fix relies on
a2f1e22390ac2("PCI/ERR:
Ensure error recoverability at all times"). Older trees still return early frompci_restore_state()whenstate_savedis false, so a backport there also needs "pci_dev->state_saved= true;" on the skip path.Tested on 7.2.5 with the root port in D3hot, three suspend/resume cycles in one boot. The unpatched kernel dies on the first. W=1 and sparse clean.
drivers/pci/pci-driver.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)drivers/pci/pci-driver.c +9
-1@@ -915,7 +915,15 @@ static int pci_pm_suspend_noirq(struct device *dev)return pci_legacy_suspend_late (dev);if (!pm) { -pci_save_state (pci_dev); +/* +* The bridge above a runtime-suspended device may be in a +* low-power state with the link down, which makes the device's +* config space inaccessible. pci_pm_runtime_suspend() has +* saved it already. +*/ +if (!pm_runtime_status_suspended (dev)) +pci_save_state (pci_dev); + goto set_unknown; }Signature · 1 line
2.55.0
Quoted 4 lines · Bjorn Helgaas
pci_pm_freeze()doesn't callpci_save_state()itself, so I guess it's the combination ofpci_pm_freeze()andpci_pm_freeze_noirq(), where if not runtime-suspended,pci_pm_freeze()clearsdev->state_savedsopci_pm_freeze_noirq()will callpci_save_state()?
Yes, that's what I meant.
Thanks,
Navon