PCI: Fix runtime PM race with PME polling
Testing that a device is not currently in a low power state provides no guarantees that the device is not imminently transitioning to such a state. Increment the PM usage counter before accessing the device. Since we don't wish to wake the device for PME polling, do so only if the device is already active by using pm_runtime_get_if_active(). Link: https://lore.kernel.org/r/20230803171233.3810944-3-alex.williamson@redhat.com Signed-off-by: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
This commit is contained in:
parent
5cd903bce9
commit
d3fcd73603
1 changed files with 16 additions and 7 deletions
|
@ -2415,10 +2415,13 @@ static void pci_pme_list_scan(struct work_struct *work)
|
||||||
|
|
||||||
mutex_lock(&pci_pme_list_mutex);
|
mutex_lock(&pci_pme_list_mutex);
|
||||||
list_for_each_entry_safe(pme_dev, n, &pci_pme_list, list) {
|
list_for_each_entry_safe(pme_dev, n, &pci_pme_list, list) {
|
||||||
if (pme_dev->dev->pme_poll) {
|
struct pci_dev *pdev = pme_dev->dev;
|
||||||
struct pci_dev *bridge;
|
|
||||||
|
if (pdev->pme_poll) {
|
||||||
|
struct pci_dev *bridge = pdev->bus->self;
|
||||||
|
struct device *dev = &pdev->dev;
|
||||||
|
int pm_status;
|
||||||
|
|
||||||
bridge = pme_dev->dev->bus->self;
|
|
||||||
/*
|
/*
|
||||||
* If bridge is in low power state, the
|
* If bridge is in low power state, the
|
||||||
* configuration space of subordinate devices
|
* configuration space of subordinate devices
|
||||||
|
@ -2426,14 +2429,20 @@ static void pci_pme_list_scan(struct work_struct *work)
|
||||||
*/
|
*/
|
||||||
if (bridge && bridge->current_state != PCI_D0)
|
if (bridge && bridge->current_state != PCI_D0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the device is in D3cold it should not be
|
* If the device is in a low power state it
|
||||||
* polled either.
|
* should not be polled either.
|
||||||
*/
|
*/
|
||||||
if (pme_dev->dev->current_state == PCI_D3cold)
|
pm_status = pm_runtime_get_if_active(dev, true);
|
||||||
|
if (!pm_status)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
pci_pme_wakeup(pme_dev->dev, NULL);
|
if (pdev->current_state != PCI_D3cold)
|
||||||
|
pci_pme_wakeup(pdev, NULL);
|
||||||
|
|
||||||
|
if (pm_status > 0)
|
||||||
|
pm_runtime_put(dev);
|
||||||
} else {
|
} else {
|
||||||
list_del(&pme_dev->list);
|
list_del(&pme_dev->list);
|
||||||
kfree(pme_dev);
|
kfree(pme_dev);
|
||||||
|
|
Loading…
Add table
Reference in a new issue