Skip to content

Commit 41044d5

Browse files
awilliambjorn-helgaas
authored andcommitted
PCI: Fix active state requirement in PME polling
The commit noted in fixes added a bogus requirement that runtime PM managed devices need to be in the RPM_ACTIVE state for PME polling. In fact, only devices in low power states should be polled. However there's still a requirement that the device config space must be accessible, which has implications for both the current state of the polled device and the parent bridge, when present. It's not sufficient to assume the bridge remains in D0 and cases have been observed where the bridge passes the D0 test, but the PM state indicates RPM_SUSPENDING and config space of the polled device becomes inaccessible during pci_pme_wakeup(). Therefore, since the bridge is already effectively required to be in the RPM_ACTIVE state, formalize this in the code and elevate the PM usage count to maintain the state while polling the subordinate device. This resolves a regression reported in the bugzilla below where a Thunderbolt/USB4 hierarchy fails to scan for an attached NVMe endpoint downstream of a bridge in a D3hot power state. Link: https://lore.kernel.org/r/20240123185548.1040096-1-alex.williamson@redhat.com Fixes: d3fcd73 ("PCI: Fix runtime PM race with PME polling") Reported-by: Sanath S <sanath.s@amd.com> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218360 Signed-off-by: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Tested-by: Sanath S <sanath.s@amd.com> Reviewed-by: Rafael J. Wysocki <rafael@kernel.org> Cc: Lukas Wunner <lukas@wunner.de> Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
1 parent 6613476 commit 41044d5

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

drivers/pci/pci.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2496,29 +2496,36 @@ static void pci_pme_list_scan(struct work_struct *work)
24962496
if (pdev->pme_poll) {
24972497
struct pci_dev *bridge = pdev->bus->self;
24982498
struct device *dev = &pdev->dev;
2499-
int pm_status;
2499+
struct device *bdev = bridge ? &bridge->dev : NULL;
2500+
int bref = 0;
25002501

25012502
/*
2502-
* If bridge is in low power state, the
2503-
* configuration space of subordinate devices
2504-
* may be not accessible
2503+
* If we have a bridge, it should be in an active/D0
2504+
* state or the configuration space of subordinate
2505+
* devices may not be accessible or stable over the
2506+
* course of the call.
25052507
*/
2506-
if (bridge && bridge->current_state != PCI_D0)
2507-
continue;
2508+
if (bdev) {
2509+
bref = pm_runtime_get_if_active(bdev, true);
2510+
if (!bref)
2511+
continue;
2512+
2513+
if (bridge->current_state != PCI_D0)
2514+
goto put_bridge;
2515+
}
25082516

25092517
/*
2510-
* If the device is in a low power state it
2511-
* should not be polled either.
2518+
* The device itself should be suspended but config
2519+
* space must be accessible, therefore it cannot be in
2520+
* D3cold.
25122521
*/
2513-
pm_status = pm_runtime_get_if_active(dev, true);
2514-
if (!pm_status)
2515-
continue;
2516-
2517-
if (pdev->current_state != PCI_D3cold)
2522+
if (pm_runtime_suspended(dev) &&
2523+
pdev->current_state != PCI_D3cold)
25182524
pci_pme_wakeup(pdev, NULL);
25192525

2520-
if (pm_status > 0)
2521-
pm_runtime_put(dev);
2526+
put_bridge:
2527+
if (bref > 0)
2528+
pm_runtime_put(bdev);
25222529
} else {
25232530
list_del(&pme_dev->list);
25242531
kfree(pme_dev);

0 commit comments

Comments
 (0)