From: Alex Williamson <alex.williamson@redhat.com>
To: linux-pci@vger.kernel.org
Cc: bhelgaas@google.com, linux-kernel@vger.kernel.org,
eric.auger@redhat.com, mika.westerberg@linux.intel.com,
lukas@wunner.de, rafael.j.wysocki@intel.com, Sanath.S@amd.com
Subject: Re: [PATCH v2 2/2] PCI: Fix runtime PM race with PME polling
Date: Thu, 18 Jan 2024 11:50:49 -0700 [thread overview]
Message-ID: <20240118115049.3b5efef0.alex.williamson@redhat.com> (raw)
In-Reply-To: <20230803171233.3810944-3-alex.williamson@redhat.com>
On Thu, 3 Aug 2023 11:12:33 -0600
Alex Williamson <alex.williamson@redhat.com> wrote:
> Testing that a device is not currently in a low power state provides no
> guarantees that the device is not immenently transitioning to such a state.
> We need to 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().
>
> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
> ---
> drivers/pci/pci.c | 23 ++++++++++++++++-------
> 1 file changed, 16 insertions(+), 7 deletions(-)
Hey folks,
Resurrecting this patch (currently commit d3fcd7360338) for discussion
as it's been identified as the source of a regression in:
https://bugzilla.kernel.org/show_bug.cgi?id=218360
Copying Mika, Lukas, and Rafael as it's related to:
000dd5316e1c ("PCI: Do not poll for PME if the device is in D3cold")
where we skip devices in D3cold when processing the PME list.
I think the issue in the above bz is that the downstream TB3/USB4 port
is in D3 (presumably D3hot) and I therefore infer the device is in state
RPM_SUSPENDED. This commit is attempting to make sure the device power
state is stable across the call such that it does not transition into
D3cold while we're accessing it.
To do that I used pm_runtime_get_if_active(), but in retrospect this
requires the device to be in RPM_ACTIVE so we end up skipping anything
suspended or transitioning.
As reported in the above bz, I tried replacing this with:
pm_runtime_get_noresume(dev);
pm_runtime_barrier(dev);
The theory here being that the barrier would wait for any transitioning
states such that as far as runtime power management is concerned, the
device power state is stable.
This causes live locks where the barrier never returns.
Instead I'm considering that since we're polling the PME list, maybe we
could just defer devices in transition states, for instance something
that looks like pm_runtime_get_if_active(), but would return zero if
the device was in RPM_SUSPENDING or RPM_RESUMING rather than requiring
RPM_ACTIVE.
I'm not an expert in PME or runtime power management though, so I'm
looking for advice. Thanks,
Alex
>
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 60230da957e0..bc266f290b2c 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -2415,10 +2415,13 @@ static void pci_pme_list_scan(struct work_struct *work)
>
> mutex_lock(&pci_pme_list_mutex);
> list_for_each_entry_safe(pme_dev, n, &pci_pme_list, list) {
> - if (pme_dev->dev->pme_poll) {
> - struct pci_dev *bridge;
> + struct pci_dev *pdev = pme_dev->dev;
> +
> + 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
> * 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)
> continue;
> +
> /*
> - * If the device is in D3cold it should not be
> - * polled either.
> + * If the device is in a low power state it
> + * 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;
>
> - 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 {
> list_del(&pme_dev->list);
> kfree(pme_dev);
next prev parent reply other threads:[~2024-01-18 18:50 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-03 17:12 [PATCH v2 0/2] PCI: Protect VPD and PME accesses from power management Alex Williamson
2023-08-03 17:12 ` [PATCH v2 1/2] PCI/VPD: Add runtime power management to sysfs interface Alex Williamson
2023-08-10 15:59 ` Bjorn Helgaas
2023-08-10 16:26 ` Alex Williamson
2023-08-11 19:25 ` Bjorn Helgaas
2023-08-11 19:56 ` Alex Williamson
2023-08-03 17:12 ` [PATCH v2 2/2] PCI: Fix runtime PM race with PME polling Alex Williamson
2024-01-18 18:50 ` Alex Williamson [this message]
2024-01-22 22:17 ` Lukas Wunner
2024-01-22 22:50 ` Alex Williamson
2024-01-23 4:46 ` Alex Williamson
2024-01-23 4:48 ` Sanath S
2024-01-23 10:45 ` Lukas Wunner
2024-01-23 15:55 ` Alex Williamson
2024-01-23 16:12 ` Lukas Wunner
2024-01-23 16:47 ` Alex Williamson
2023-08-10 18:29 ` [PATCH v2 0/2] PCI: Protect VPD and PME accesses from power management Bjorn Helgaas
2023-08-10 18:54 ` Alex Williamson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240118115049.3b5efef0.alex.williamson@redhat.com \
--to=alex.williamson@redhat.com \
--cc=Sanath.S@amd.com \
--cc=bhelgaas@google.com \
--cc=eric.auger@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=mika.westerberg@linux.intel.com \
--cc=rafael.j.wysocki@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®