All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: Keith Busch <kbusch@meta.com>
Cc: <linux-pci@vger.kernel.org>, <bhelgaas@google.com>,
	<lukas@wunner.de>, <mika.westerberg@linux.intel.com>,
	Keith Busch <kbusch@kernel.org>
Subject: Re: [PATCH RFC 4/8] pci: walk bus recursively
Date: Thu, 15 Aug 2024 15:33:52 +0100	[thread overview]
Message-ID: <20240815153352.0000364c@Huawei.com> (raw)
In-Reply-To: <20240722151936.1452299-5-kbusch@meta.com>

On Mon, 22 Jul 2024 08:19:32 -0700
Keith Busch <kbusch@meta.com> 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.
> 
> Signed-off-by: Keith Busch <kbusch@kernel.org>
Trivial naming question inline. Otherwise LGTM
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/pci/bus.c | 34 ++++++++++------------------------
>  1 file changed, 10 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
> index 7c07a141e8772..b7208e644c79f 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 *),
> +static int __pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *),
Keeping the parameter name of 'top' seems less than intuitive
now this is recursive as on the recursions it is no longer the top.
Maybe just call it bus?  That will make this diff really confusing however.

>  			   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;
>  }
>  
>  /**


  reply	other threads:[~2024-08-15 14:33 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-22 15:19 [PATCH RFC 0/8] pci: rescan/remove locking rework Keith Busch
2024-07-22 15:19 ` [PATCH RFC 1/8] pci: make pci_stop_dev concurrent safe Keith Busch
2024-08-15 14:17   ` Jonathan Cameron
2024-08-20 15:02     ` Keith Busch
2024-08-21 11:01       ` Jonathan Cameron
2024-07-22 15:19 ` [PATCH RFC 2/8] pci: make pci_destroy_dev " Keith Busch
2024-08-15 14:18   ` Jonathan Cameron
2024-07-22 15:19 ` [PATCH RFC 3/8] pci: move the walk bus lock to where its needed Keith Busch
2024-08-15 14:20   ` Jonathan Cameron
2024-07-22 15:19 ` [PATCH RFC 4/8] pci: walk bus recursively Keith Busch
2024-08-15 14:33   ` Jonathan Cameron [this message]
2024-07-22 15:19 ` [PATCH RFC 5/8] pci: unexport pci_walk_bus_locked Keith Busch
2024-08-15 14:36   ` Jonathan Cameron
2024-07-22 15:19 ` [PATCH RFC 6/8] pci: add helpers for stop and remove bus Keith Busch
2024-08-15 14:49   ` Jonathan Cameron
2024-07-22 15:19 ` [PATCH RFC 7/8] pci: reference count subordinate Keith Busch
2024-08-15 15:10   ` Jonathan Cameron
2024-07-22 15:19 ` [PATCH RFC 8/8] pci: use finer grain locking for bus protection Keith Busch
2024-08-15 15:21   ` Jonathan Cameron
2024-08-15 17:05     ` Keith Busch
2024-08-07 15:40 ` [PATCH RFC 0/8] pci: rescan/remove locking rework Keith Busch

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=20240815153352.0000364c@Huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=bhelgaas@google.com \
    --cc=kbusch@kernel.org \
    --cc=kbusch@meta.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=mika.westerberg@linux.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 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.