From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Keith Busch <kbusch@meta.com>
Cc: linux-pci@vger.kernel.org, bhelgaas@google.com,
Keith Busch <kbusch@kernel.org>,
Jonathan Cameron <Jonathan.Cameron@huawei.com>
Subject: Re: [PATCHv2 4/5] pci: walk bus recursively
Date: Wed, 9 Oct 2024 15:08:38 +0300 (EEST) [thread overview]
Message-ID: <9750491b-f198-a195-eb39-1365bad39b5f@linux.intel.com> (raw)
In-Reply-To: <20240827192826.710031-5-kbusch@meta.com>
[-- Attachment #1: Type: text/plain, Size: 2597 bytes --]
On Tue, 27 Aug 2024, Keith Busch wrote:
> From: Keith Busch <kbusch@kernel.org>
>
> The original implementation purposefully chose a non-recursive walk,
> presumably as a precaution on stack use. We do recursive bus walking in
> other places though. For example:
>
> pci_bus_resettable
> pci_stop_bus_device
> pci_remove_bus_device
> pci_bus_allocate_dev_resources
>
> So, recursive pci bus walking is well tested and safe, and the
> implementation is easier to follow. The motivation for changing it now
> is to make it easier to introduce finer grain locking in the future.
>
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Signed-off-by: Keith Busch <kbusch@kernel.org>
> ---
> drivers/pci/bus.c | 36 +++++++++++-------------------------
> 1 file changed, 11 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
> index 7c07a141e8772..8491e9c7f0586 100644
> --- a/drivers/pci/bus.c
> +++ b/drivers/pci/bus.c
> @@ -389,37 +389,23 @@ void pci_bus_add_devices(const struct pci_bus *bus)
> }
> EXPORT_SYMBOL(pci_bus_add_devices);
>
> -static void __pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *),
> - void *userdata)
> +static int __pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *),
I guess the reason why this parameter was called "top" is now gone so you
could just name it "bus"?
Other than that, the change looks okay,
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
--
i.
> + void *userdata)
> {
> struct pci_dev *dev;
> - struct pci_bus *bus;
> - struct list_head *next;
> - int retval;
> + int ret = 0;
>
> - bus = top;
> - next = top->devices.next;
> - for (;;) {
> - if (next == &bus->devices) {
> - /* end of this bus, go up or finish */
> - if (bus == top)
> + list_for_each_entry(dev, &top->devices, bus_list) {
> + ret = cb(dev, userdata);
> + if (ret)
> + break;
> + if (dev->subordinate) {
> + ret = __pci_walk_bus(dev->subordinate, cb, userdata);
> + if (ret)
> break;
> - next = bus->self->bus_list.next;
> - bus = bus->self->bus;
> - continue;
> }
> - dev = list_entry(next, struct pci_dev, bus_list);
> - if (dev->subordinate) {
> - /* this is a pci-pci bridge, do its devices next */
> - next = dev->subordinate->devices.next;
> - bus = dev->subordinate;
> - } else
> - next = dev->bus_list.next;
> -
> - retval = cb(dev, userdata);
> - if (retval)
> - break;
> }
> + return ret;
> }
>
> /**
>
next prev parent reply other threads:[~2024-10-09 12:08 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-27 19:28 [PATCHv2 0/5] pci cleanup/prep patches Keith Busch
2024-08-27 19:28 ` [PATCHv2 1/5] pci: make pci_stop_dev concurrent safe Keith Busch
2024-10-02 23:39 ` Davidlohr Bueso
2024-10-03 0:04 ` Keith Busch
2024-08-27 19:28 ` [PATCHv2 2/5] pci: make pci_destroy_dev " Keith Busch
2024-10-03 2:34 ` Davidlohr Bueso
2024-10-03 14:54 ` Keith Busch
2024-10-03 17:04 ` Davidlohr Bueso
2024-10-03 17:59 ` Keith Busch
2024-10-08 2:15 ` Davidlohr Bueso
2024-10-22 20:29 ` Keith Busch
2024-08-27 19:28 ` [PATCHv2 3/5] pci: move the walk bus lock to where its needed Keith Busch
2024-10-03 0:32 ` Davidlohr Bueso
2024-10-09 11:09 ` Ilpo Järvinen
2024-08-27 19:28 ` [PATCHv2 4/5] pci: walk bus recursively Keith Busch
2024-10-09 12:08 ` Ilpo Järvinen [this message]
2024-08-27 19:28 ` [PATCHv2 5/5] pci: unexport pci_walk_bus_locked Keith Busch
2024-10-03 0:35 ` Davidlohr Bueso
2024-10-09 12:20 ` Ilpo Järvinen
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=9750491b-f198-a195-eb39-1365bad39b5f@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=Jonathan.Cameron@huawei.com \
--cc=bhelgaas@google.com \
--cc=kbusch@kernel.org \
--cc=kbusch@meta.com \
--cc=linux-pci@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox