Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: bhelgaas@google.com, linux-pci@vger.kernel.org, lukas@wunner.de,
	mika.westerberg@linux.intel.com, sanath.s@amd.com
Subject: Re: [PATCH] PCI: Fix active state requirement in PME polling
Date: Tue, 23 Jan 2024 13:39:17 -0700	[thread overview]
Message-ID: <20240123133917.765743ed.alex.williamson@redhat.com> (raw)
In-Reply-To: <CAJZ5v0hLaka9od=_DB8L5nVJMPdu-9WKDgt5ro3jzE5b7MY-rQ@mail.gmail.com>

On Tue, 23 Jan 2024 20:59:50 +0100
"Rafael J. Wysocki" <rafael@kernel.org> wrote:

> On Tue, Jan 23, 2024 at 8:51 PM Alex Williamson
> <alex.williamson@redhat.com> wrote:
> >
> > On Tue, 23 Jan 2024 20:40:32 +0100
> > "Rafael J. Wysocki" <rafael@kernel.org> wrote:
> >  
> > > On Tue, Jan 23, 2024 at 7:56 PM Alex Williamson
> > > <alex.williamson@redhat.com> wrote:  
> > > >
> > > > 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.
> > > >
> > > > Cc: Lukas Wunner <lukas@wunner.de>
> > > > Cc: Mika Westerberg <mika.westerberg@linux.intel.com>
> > > > Cc: Rafael J. Wysocki <rafael@kernel.org>
> > > > Fixes: d3fcd7360338 ("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>
> > > > ---
> > > >  drivers/pci/pci.c | 37 ++++++++++++++++++++++---------------
> > > >  1 file changed, 22 insertions(+), 15 deletions(-)
> > > >
> > > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> > > > index bdbf8a94b4d0..764d7c977ef4 100644
> > > > --- a/drivers/pci/pci.c
> > > > +++ b/drivers/pci/pci.c
> > > > @@ -2433,29 +2433,36 @@ static void pci_pme_list_scan(struct work_struct *work)
> > > >                 if (pdev->pme_poll) {
> > > >                         struct pci_dev *bridge = pdev->bus->self;
> > > >                         struct device *dev = &pdev->dev;
> > > > -                       int pm_status;
> > > > +                       struct device *bdev = bridge ? &bridge->dev : NULL;
> > > > +                       int bref = 0;
> > > >
> > > >                         /*
> > > > -                        * If bridge is in low power state, the
> > > > -                        * configuration space of subordinate devices
> > > > -                        * may be not accessible
> > > > +                        * If we have a bridge, it should be in an active/D0
> > > > +                        * state or the configuration space of subordinate
> > > > +                        * devices may not be accessible or stable over the
> > > > +                        * course of the call.
> > > >                          */
> > > > -                       if (bridge && bridge->current_state != PCI_D0)
> > > > -                               continue;
> > > > +                       if (bdev) {
> > > > +                               bref = pm_runtime_get_if_active(bdev, true);
> > > > +                               if (!bref)  
> > >
> > > I would check bref <= 0 here.
> > >  
> > > > +                                       continue;
> > > > +
> > > > +                               if (bridge->current_state != PCI_D0)  
> > >
> > > Isn't the power state guaranteed to be PCI_D0 at this point?  If it
> > > isn't, then why?  
> >
> > Both of these seem necessary to support !CONFIG_PM, where bref would be
> > -EINVAL and provides no indication of the current_state.  Is that
> > incorrect?  Thanks,  
> 
> Well, CONFIG_PCIE_PME depends on CONFIG_PM, so I'm not sure how
> dev->pme_poll can be set without it.

I only see that drivers/pci/pci.c:pci_pm_init() sets pme_poll true and
I'm not spotting a dependency on either PCIE_PME or PM to get there.  I
see a few places where pme.c, governed by PCIE_PME, can set pme_poll
false though.

It's also not clear to me that we should skip scanning a device if
pm_runtime_get_if_active() returns -EINVAL for the bridge due to
power.disable_depth.  If runtime PM isn't enabled on the bridge,
shouldn't we be able to test current_state and assume it won't change?
Thanks,

Alex


  reply	other threads:[~2024-01-23 20:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-23 18:55 [PATCH] PCI: Fix active state requirement in PME polling Alex Williamson
2024-01-23 19:40 ` Rafael J. Wysocki
2024-01-23 19:50   ` Alex Williamson
2024-01-23 19:59     ` Rafael J. Wysocki
2024-01-23 20:39       ` Alex Williamson [this message]
2024-01-23 22:33         ` Rafael J. Wysocki
2024-01-24 14:21           ` Sanath S
2024-02-09 16:35 ` Bjorn Helgaas
2024-02-09 17:56   ` Alex Williamson
2024-02-09 19:03 ` Bjorn Helgaas

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=20240123133917.765743ed.alex.williamson@redhat.com \
    --to=alex.williamson@redhat.com \
    --cc=bhelgaas@google.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=mika.westerberg@linux.intel.com \
    --cc=rafael@kernel.org \
    --cc=sanath.s@amd.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