From: Bjorn Helgaas <helgaas@kernel.org>
To: Yicong Yang <yangyicong@hisilicon.com>
Cc: bhelgaas@google.com, linux-pci@vger.kernel.org,
linuxarm@huawei.com,
Mika Westerberg <mika.westerberg@linux.intel.com>,
"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
Peter Wu <peter@lekensteyn.nl>
Subject: Re: [PATCH] PCI: Make sure the bus bridge powered on when scanning bus
Date: Thu, 17 Sep 2020 16:07:37 -0500 [thread overview]
Message-ID: <20200917210737.GA1732082@bjorn-Precision-5520> (raw)
In-Reply-To: <1596022223-4765-1-git-send-email-yangyicong@hisilicon.com>
[+cc Mika, Rafael, Peter]
On Wed, Jul 29, 2020 at 07:30:23PM +0800, Yicong Yang wrote:
> When the bus bridge is runtime suspended, we'll fail to rescan
> the devices through sysfs as we cannot access the configuration
> space correctly when the bridge is in D3hot.
> It can be reproduced like:
>
> $ echo 1 > /sys/bus/pci/devices/0000:80:00.0/0000:81:00.1/remove
> $ echo 1 > /sys/bus/pci/devices/0000:80:00.0/pci_bus/0000:81/rescan
>
> 0000:80:00.0 is root port and is runtime suspended and we cannot
> get 0000:81:00.1 after rescan.
>
> Make bridge powered on when scanning the child bus, by adding
> pm_runtime_get_sync()/pm_runtime_put() in pci_scan_child_bus_extend().
>
> Signed-off-by: Yicong Yang <yangyicong@hisilicon.com>
> ---
> drivers/pci/probe.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index 2f66988..5bb502b 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -2795,6 +2795,14 @@ static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus,
>
> dev_dbg(&bus->dev, "scanning bus\n");
>
> + /*
> + * Make sure the bus bridge is powered on, otherwise we may not be
> + * able to scan the devices as we may fail to access the configuration
> + * space of subordinates.
> + */
> + if (bus->self)
> + pm_runtime_get_sync(&bus->self->dev);
I think if we do this, we should be able to remove the call from
pci_scan_bridge() added by d963f6512e15 ("PCI: Power on bridges before
scanning new devices"), right?
The reason we need it here is because there are two paths to
pci_scan_child_bus_extend() and only one of them calls
pm_runtime_get_sync():
pci_scan_bridge_extend
pm_runtime_get_sync
pci_scan_child_bus_extend
pci_scan_child_bus
pci_scan_child_bus_extend
If we move the pm_runtime_get_sync() from pci_scan_bridge_extend() to
pci_scan_child_bus_extend(), both paths should be safe.
> /* Go find them, Rover! */
> for (devfn = 0; devfn < 256; devfn += 8) {
> nr_devs = pci_scan_slot(bus, devfn);
> @@ -2907,6 +2915,9 @@ static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus,
> }
> }
>
> + if (bus->self)
> + pm_runtime_put(&bus->self->dev);
I would probably do this:
struct pci_dev *bridge = bus->self;
if (bridge)
pm_runtime_get_sync(&bridge->dev);
...
if (bridge)
pm_runtime_put(&bridge->dev);
> /*
> * We've scanned the bus and so we know all about what's on
> * the other side of any bridges that may be on this bus plus
> --
> 2.8.1
>
next prev parent reply other threads:[~2020-09-17 21:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-29 11:30 [PATCH] PCI: Make sure the bus bridge powered on when scanning bus Yicong Yang
2020-08-21 9:54 ` Yicong Yang
2020-09-17 21:07 ` Bjorn Helgaas [this message]
2020-09-18 9:31 ` Yicong Yang
2020-09-18 16:17 ` Bjorn Helgaas
2020-09-19 10:22 ` Yicong Yang
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=20200917210737.GA1732082@bjorn-Precision-5520 \
--to=helgaas@kernel.org \
--cc=bhelgaas@google.com \
--cc=linux-pci@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=mika.westerberg@linux.intel.com \
--cc=peter@lekensteyn.nl \
--cc=rafael.j.wysocki@intel.com \
--cc=yangyicong@hisilicon.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;
as well as URLs for NNTP newsgroup(s).