From: Brian Norris <briannorris@chromium.org>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Bjorn Helgaas <bhelgaas@google.com>,
linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
Lukas Wunner <lukas@wunner.de>,
linux-pci@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] PCI/PM: Prevent runtime suspend before devices are fully initialized
Date: Fri, 17 Oct 2025 10:11:01 -0700 [thread overview]
Message-ID: <aPJ4pZFENCTx9yhy@google.com> (raw)
In-Reply-To: <CAJZ5v0iFa3_UFkA920Ogn0YAYLq4CjnAD_VjLsmxQxrfm5HEBw@mail.gmail.com>
Hi Rafael,
On Fri, Oct 17, 2025 at 11:45:14AM +0200, Rafael J. Wysocki wrote:
> On Fri, Oct 17, 2025 at 1:28 AM Brian Norris <briannorris@chromium.org> wrote:
> >
> > PCI devices are created via pci_scan_slot() and similar, and are
> > promptly configured for runtime PM (pci_pm_init()). They are initially
> > prevented from suspending by way of pm_runtime_forbid(); however, it's
> > expected that user space may override this via sysfs [1].
> >
> > Now, sometime after initial scan, a PCI device receives its BAR
> > configuration (pci_assign_unassigned_bus_resources(), etc.).
> >
> > If a PCI device is allowed to suspend between pci_scan_slot() and
> > pci_assign_unassigned_bus_resources(), then pci-driver.c will
> > save/restore incorrect BAR configuration for the device, and the device
> > may cease to function.
> >
> > This behavior races with user space, since user space may enable runtime
> > PM [1] as soon as it sees the device, which may be before BAR
> > configuration.
> >
> > Prevent suspending in this intermediate state by holding a runtime PM
> > reference until the device is fully initialized and ready for probe().
> >
> > [1] echo auto > /sys/bus/pci/devices/.../power/control
> >
> > Cc: <stable@vger.kernel.org>
> > Signed-off-by: Brian Norris <briannorris@chromium.org>
> > ---
> >
> > drivers/pci/bus.c | 7 +++++++
> > drivers/pci/pci.c | 6 ++++++
> > 2 files changed, 13 insertions(+)
> >
> > diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
> > index f26aec6ff588..227a8898acac 100644
> > --- a/drivers/pci/bus.c
> > +++ b/drivers/pci/bus.c
> > @@ -14,6 +14,7 @@
> > #include <linux/of.h>
> > #include <linux/of_platform.h>
> > #include <linux/platform_device.h>
> > +#include <linux/pm_runtime.h>
> > #include <linux/proc_fs.h>
> > #include <linux/slab.h>
> >
> > @@ -375,6 +376,12 @@ void pci_bus_add_device(struct pci_dev *dev)
> > put_device(&pdev->dev);
> > }
> >
> > + /*
> > + * Now that resources are assigned, drop the reference we grabbed in
> > + * pci_pm_init().
> > + */
> > + pm_runtime_put_noidle(&dev->dev);
> > +
> > if (!dn || of_device_is_available(dn))
> > pci_dev_allow_binding(dev);
> >
> > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> > index b14dd064006c..06a901214f2c 100644
> > --- a/drivers/pci/pci.c
> > +++ b/drivers/pci/pci.c
> > @@ -3226,6 +3226,12 @@ void pci_pm_init(struct pci_dev *dev)
> > pci_pm_power_up_and_verify_state(dev);
> > pm_runtime_forbid(&dev->dev);
> > pm_runtime_set_active(&dev->dev);
> > + /*
> > + * We cannot allow a device to suspend before its resources are
> > + * configured. Otherwise, we may allow saving/restoring unexpected BAR
> > + * configuration.
> > + */
> > + pm_runtime_get_noresume(&dev->dev);
> > pm_runtime_enable(&dev->dev);
>
> So runtime PM should not be enabled here, should it?
Hmm, I suppose not. Does that imply it would be a better solution to
simply defer pm_runtime_enable() to pci_bus_add_device() or some similar
point? I'll give that a shot, since that seems like a simpler and
cleaner solution.
Thanks,
Brian
> > }
> >
> > --
prev parent reply other threads:[~2025-10-17 17:11 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-16 22:53 [PATCH] PCI/PM: Prevent runtime suspend before devices are fully initialized Brian Norris
2025-10-17 8:32 ` Lukas Wunner
2025-10-17 11:49 ` Ilpo Järvinen
2025-10-17 17:43 ` Brian Norris
2025-10-17 19:20 ` Brian Norris
2025-10-20 15:56 ` Ilpo Järvinen
2025-10-20 18:52 ` Brian Norris
2025-10-21 11:27 ` Ilpo Järvinen
2025-10-21 12:53 ` Rafael J. Wysocki
2025-10-21 13:18 ` Ilpo Järvinen
2025-10-21 18:27 ` Brian Norris
2025-10-21 18:56 ` Rafael J. Wysocki
2025-10-21 18:13 ` Brian Norris
2025-10-22 13:38 ` Ilpo Järvinen
2025-10-17 9:45 ` Rafael J. Wysocki
2025-10-17 17:11 ` Brian Norris [this message]
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=aPJ4pZFENCTx9yhy@google.com \
--to=briannorris@chromium.org \
--cc=bhelgaas@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=rafael@kernel.org \
--cc=stable@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.