All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/4] PCI: Rework pci_scan_slot() and isolated PCI functions
@ 2022-04-12 14:30 Niklas Schnelle
  2022-04-12 14:30 ` [PATCH v2 1/4] PCI: Clean up pci_scan_slot() Niklas Schnelle
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Niklas Schnelle @ 2022-04-12 14:30 UTC (permalink / raw)
  To: Bjorn Helgaas, Jan Kiszka, Matthew Rosato, Pierre Morel
  Cc: linux-s390, linux-pci

Hi Bjorn, Hi Jan,

In an earlier version[0], I sought to apply the existing jailhouse special case
for isolated PCI functions to s390. As Bjorn noted in[1] there appears to be
some potential for cleaning things up and removing duplication though.

This series attempts to do this cleanup (Patches 1 and 2) followed by enabling
isolated PCI functions for s390 (Patches 3 and 4). If need be I can of course
split the cleanup off but for now I kept it as one as that's what I have
been testing.

Thanks,
Niklas

[0] https://lore.kernel.org/linux-pci/20220404095346.2324666-1-schnelle@linux.ibm.com/
[1] https://lore.kernel.org/linux-pci/20220408224514.GA353445@bhelgaas/

Niklas Schnelle (4):
  PCI: Clean up pci_scan_slot()
  PCI: Move jailhouse's isolated function handling to pci_scan_slot()
  PCI: Extend isolated function probing to s390
  s390/pci: allow zPCI zbus without a function zero

 arch/s390/pci/pci_bus.c    | 82 ++++++++++----------------------------
 drivers/pci/probe.c        | 60 ++++++++++------------------
 include/linux/hypervisor.h |  9 +++++
 3 files changed, 51 insertions(+), 100 deletions(-)

-- 
2.32.0


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2 1/4] PCI: Clean up pci_scan_slot()
  2022-04-12 14:30 [PATCH v2 0/4] PCI: Rework pci_scan_slot() and isolated PCI functions Niklas Schnelle
@ 2022-04-12 14:30 ` Niklas Schnelle
  2022-04-12 15:24   ` Niklas Schnelle
  2022-04-12 14:30 ` [PATCH v2 2/4] PCI: Move jailhouse's isolated function handling to pci_scan_slot() Niklas Schnelle
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: Niklas Schnelle @ 2022-04-12 14:30 UTC (permalink / raw)
  To: Bjorn Helgaas, Jan Kiszka, Matthew Rosato, Pierre Morel
  Cc: linux-s390, linux-pci

While determining the next PCI function is factored out of
pci_scan_slot() into next_fn() the former still handles the first
function as a special case duplicating the code from the scan loop and
splitting the condition that the first function exits from it being
multifunction which is tested in next_fn().

Furthermore the non ARI branch of next_fn() mixes the case that
multifunction devices may have non-contiguous function ranges and dev
may thus be NULL with the multifunction requirement. It also signals
that no further functions need to be scanned by returning 0 which is
a valid function number.

Improve upon this by moving all conditions for having to scan for more
functions into next_fn() and make them obvious and commented.

By changing next_fn() to return -ENODEV instead of 0 when there is no
next function we can then handle the initial function inside the loop
and deduplicate the shared handling.

No functional change is intended.

Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
---
 drivers/pci/probe.c | 41 +++++++++++++++++++----------------------
 1 file changed, 19 insertions(+), 22 deletions(-)

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 17a969942d37..389aa1f9cb2c 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -2579,33 +2579,35 @@ struct pci_dev *pci_scan_single_device(struct pci_bus *bus, int devfn)
 }
 EXPORT_SYMBOL(pci_scan_single_device);
 
-static unsigned int next_fn(struct pci_bus *bus, struct pci_dev *dev,
-			    unsigned int fn)
+static int next_fn(struct pci_bus *bus, struct pci_dev *dev, int fn)
 {
 	int pos;
 	u16 cap = 0;
 	unsigned int next_fn;
 
-	if (pci_ari_enabled(bus)) {
-		if (!dev)
-			return 0;
+	if (dev && pci_ari_enabled(bus)) {
 		pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI);
 		if (!pos)
-			return 0;
+			return -ENODEV;
 
 		pci_read_config_word(dev, pos + PCI_ARI_CAP, &cap);
 		next_fn = PCI_ARI_CAP_NFN(cap);
 		if (next_fn <= fn)
-			return 0;	/* protect against malformed list */
+			return -ENODEV;	/* protect against malformed list */
 
 		return next_fn;
 	}
 
-	/* dev may be NULL for non-contiguous multifunction devices */
-	if (!dev || dev->multifunction)
-		return (fn + 1) % 8;
-
-	return 0;
+	/* only multifunction devices may have more functions */
+	if (dev && !dev->multifunction)
+		return -ENODEV;
+	/*
+	 * A function 0 is required but multifunction devices may
+	 * be non-contiguous so dev can be NULL otherwise.
+	 */
+	if (!fn && !dev)
+		return -ENODEV;
+	return (fn <= 6) ? fn + 1 : -ENODEV;
 }
 
 static int only_one_child(struct pci_bus *bus)
@@ -2643,24 +2645,19 @@ static int only_one_child(struct pci_bus *bus)
  */
 int pci_scan_slot(struct pci_bus *bus, int devfn)
 {
-	unsigned int fn, nr = 0;
-	struct pci_dev *dev;
+	int fn, nr = 0;
+	struct pci_dev *dev = NULL;
 
 	if (only_one_child(bus) && (devfn > 0))
 		return 0; /* Already scanned the entire slot */
 
-	dev = pci_scan_single_device(bus, devfn);
-	if (!dev)
-		return 0;
-	if (!pci_dev_is_added(dev))
-		nr++;
-
-	for (fn = next_fn(bus, dev, 0); fn > 0; fn = next_fn(bus, dev, fn)) {
+	for (fn = 0; fn >= 0; fn = next_fn(bus, dev, fn)) {
 		dev = pci_scan_single_device(bus, devfn + fn);
 		if (dev) {
 			if (!pci_dev_is_added(dev))
 				nr++;
-			dev->multifunction = 1;
+			if (nr > 1)
+				dev->multifunction = 1;
 		}
 	}
 
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 2/4] PCI: Move jailhouse's isolated function handling to pci_scan_slot()
  2022-04-12 14:30 [PATCH v2 0/4] PCI: Rework pci_scan_slot() and isolated PCI functions Niklas Schnelle
  2022-04-12 14:30 ` [PATCH v2 1/4] PCI: Clean up pci_scan_slot() Niklas Schnelle
@ 2022-04-12 14:30 ` Niklas Schnelle
  2022-04-12 16:28   ` kernel test robot
  2022-04-12 19:43   ` kernel test robot
  2022-04-12 14:30 ` [PATCH v2 3/4] PCI: Extend isolated function probing to s390 Niklas Schnelle
  2022-04-12 14:30 ` [PATCH v2 4/4] s390/pci: allow zPCI zbus without a function zero Niklas Schnelle
  3 siblings, 2 replies; 11+ messages in thread
From: Niklas Schnelle @ 2022-04-12 14:30 UTC (permalink / raw)
  To: Bjorn Helgaas, Jan Kiszka, Matthew Rosato, Pierre Morel
  Cc: linux-s390, linux-pci

The special case of the jailhouse hypervisor passing through individual
PCI functions handles scanning for PCI functions even if function 0 does
not exist. Currently this is done with an extra loop duplicating the one
in pci_scan_slot(). By incorporating the check for jailhouse_paravirt()
into next_fn() we can instead do this as part of the normal
pci_scan_slot(). The only functional change is that we now call
pcie_aspm_init_link_state() for these functions but this already
happened if function 0 was passed through and should not be a problem.

Link: https://lore.kernel.org/linux-pci/20220408224514.GA353445@bhelgaas/
Suggested-by: Bjorn Helgaas <bhelgaas@google.com>
Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
---
 drivers/pci/probe.c | 25 ++++++-------------------
 1 file changed, 6 insertions(+), 19 deletions(-)

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 389aa1f9cb2c..8100e044dfc5 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -2602,10 +2602,11 @@ static int next_fn(struct pci_bus *bus, struct pci_dev *dev, int fn)
 	if (dev && !dev->multifunction)
 		return -ENODEV;
 	/*
-	 * A function 0 is required but multifunction devices may
-	 * be non-contiguous so dev can be NULL otherwise.
+	 * Usually a function 0 is required but the jailhouse hypervisor may
+	 * pass individual functions. For non-contiguous multifunction devices
+	 * some functions may also be missing.
 	 */
-	if (!fn && !dev)
+	if (!fn && !dev && !jailhouse_paravirt())
 		return -ENODEV;
 	return (fn <= 6) ? fn + 1 : -ENODEV;
 }
@@ -2855,30 +2856,16 @@ static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus,
 {
 	unsigned int used_buses, normal_bridges = 0, hotplug_bridges = 0;
 	unsigned int start = bus->busn_res.start;
-	unsigned int devfn, fn, cmax, max = start;
+	unsigned int devfn, cmax, max = start;
 	struct pci_dev *dev;
 	int nr_devs;
 
 	dev_dbg(&bus->dev, "scanning bus\n");
 
 	/* Go find them, Rover! */
-	for (devfn = 0; devfn < 256; devfn += 8) {
+	for (devfn = 0; devfn < 256; devfn += 8)
 		nr_devs = pci_scan_slot(bus, devfn);
 
-		/*
-		 * The Jailhouse hypervisor may pass individual functions of a
-		 * multi-function device to a guest without passing function 0.
-		 * Look for them as well.
-		 */
-		if (jailhouse_paravirt() && nr_devs == 0) {
-			for (fn = 1; fn < 8; fn++) {
-				dev = pci_scan_single_device(bus, devfn + fn);
-				if (dev)
-					dev->multifunction = 1;
-			}
-		}
-	}
-
 	/* Reserve buses for SR-IOV capability */
 	used_buses = pci_iov_bus_range(bus);
 	max += used_buses;
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 3/4] PCI: Extend isolated function probing to s390
  2022-04-12 14:30 [PATCH v2 0/4] PCI: Rework pci_scan_slot() and isolated PCI functions Niklas Schnelle
  2022-04-12 14:30 ` [PATCH v2 1/4] PCI: Clean up pci_scan_slot() Niklas Schnelle
  2022-04-12 14:30 ` [PATCH v2 2/4] PCI: Move jailhouse's isolated function handling to pci_scan_slot() Niklas Schnelle
@ 2022-04-12 14:30 ` Niklas Schnelle
  2022-04-12 14:30 ` [PATCH v2 4/4] s390/pci: allow zPCI zbus without a function zero Niklas Schnelle
  3 siblings, 0 replies; 11+ messages in thread
From: Niklas Schnelle @ 2022-04-12 14:30 UTC (permalink / raw)
  To: Bjorn Helgaas, Jan Kiszka, Matthew Rosato, Pierre Morel
  Cc: linux-s390, linux-pci

Like the jailhouse hypervisor s390's PCI architecture allows passing
isolated PCI functions to an OS instance. As of now this is was not
utilized even with multi-function support as the s390 PCI code makes
sure that only virtual PCI busses including a function with devfn 0 are
presented to the PCI subsystem. A subsequent change will remove this
restriction.

Allow probing such functions by replacing the existing check for
jailhouse_paravirt() with a new hypervisor_isolated_pci_functions()
helper.

Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
---
 drivers/pci/probe.c        | 8 ++++----
 include/linux/hypervisor.h | 9 +++++++++
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 8100e044dfc5..a57ea0ff1470 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -2602,11 +2602,11 @@ static int next_fn(struct pci_bus *bus, struct pci_dev *dev, int fn)
 	if (dev && !dev->multifunction)
 		return -ENODEV;
 	/*
-	 * Usually a function 0 is required but the jailhouse hypervisor may
-	 * pass individual functions. For non-contiguous multifunction devices
-	 * some functions may also be missing.
+	 * Usually a function 0 is required but some hypervisors may pass
+	 * individual functions. For non-contiguous multifunction devices some
+	 * functions may also be missing.
 	 */
-	if (!fn && !dev && !jailhouse_paravirt())
+	if (!fn && !dev && !hypervisor_isolated_pci_functions())
 		return -ENODEV;
 	return (fn <= 6) ? fn + 1 : -ENODEV;
 }
diff --git a/include/linux/hypervisor.h b/include/linux/hypervisor.h
index fc08b433c856..52abd459f9a3 100644
--- a/include/linux/hypervisor.h
+++ b/include/linux/hypervisor.h
@@ -32,4 +32,13 @@ static inline bool jailhouse_paravirt(void)
 
 #endif /* !CONFIG_X86 */
 
+static inline bool hypervisor_isolated_pci_functions(void)
+{
+	if (IS_ENABLED(CONFIG_S390))
+		return true;
+	else
+		return jailhouse_paravirt();
+}
+
+
 #endif /* __LINUX_HYPEVISOR_H */
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 4/4] s390/pci: allow zPCI zbus without a function zero
  2022-04-12 14:30 [PATCH v2 0/4] PCI: Rework pci_scan_slot() and isolated PCI functions Niklas Schnelle
                   ` (2 preceding siblings ...)
  2022-04-12 14:30 ` [PATCH v2 3/4] PCI: Extend isolated function probing to s390 Niklas Schnelle
@ 2022-04-12 14:30 ` Niklas Schnelle
  3 siblings, 0 replies; 11+ messages in thread
From: Niklas Schnelle @ 2022-04-12 14:30 UTC (permalink / raw)
  To: Bjorn Helgaas, Jan Kiszka, Matthew Rosato, Pierre Morel
  Cc: linux-s390, linux-pci

Currently the zPCI code block PCI bus creation and probing of a zPCI
zbus unless there is a PCI function with devfn 0. This is always the
case for the PCI functions with hidden RID but may keep PCI functions
from a multi-function PCI device with RID information invisible until
the function 0 becomes visible. Worse as a PCI bus is necessary to even
present a PCI hotplug slot even that remains invisible.

With the probing of these so called isolated PCI functions enabled for
s390 in common code this restriction is no longer necessary. On network
cards with multiple ports and a PF per port this also allows using each
port on its own while still providing the physical PCI topology
information in the devfn needed to associate VFs with their parent PF.

Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
---
 arch/s390/pci/pci_bus.c | 82 ++++++++++-------------------------------
 1 file changed, 20 insertions(+), 62 deletions(-)

diff --git a/arch/s390/pci/pci_bus.c b/arch/s390/pci/pci_bus.c
index 5d77acbd1c87..6a8da1b742ae 100644
--- a/arch/s390/pci/pci_bus.c
+++ b/arch/s390/pci/pci_bus.c
@@ -145,9 +145,6 @@ int zpci_bus_scan_bus(struct zpci_bus *zbus)
 	struct zpci_dev *zdev;
 	int devfn, rc, ret = 0;
 
-	if (!zbus->function[0])
-		return 0;
-
 	for (devfn = 0; devfn < ZPCI_FUNCTIONS_PER_BUS; devfn++) {
 		zdev = zbus->function[devfn];
 		if (zdev && zdev->state == ZPCI_FN_STATE_CONFIGURED) {
@@ -184,26 +181,26 @@ void zpci_bus_scan_busses(void)
 
 /* zpci_bus_create_pci_bus - Create the PCI bus associated with this zbus
  * @zbus: the zbus holding the zdevices
- * @f0: function 0 of the bus
+ * @fr: PCI root function that will determine the bus's domain, and bus speeed
  * @ops: the pci operations
  *
- * Function zero is taken as a parameter as this is used to determine the
- * domain, multifunction property and maximum bus speed of the entire bus.
+ * The PCI function @fr determines the domain (its UID), multifunction property
+ * and maximum bus speed of the entire bus.
  *
  * Return: 0 on success, an error code otherwise
  */
-static int zpci_bus_create_pci_bus(struct zpci_bus *zbus, struct zpci_dev *f0, struct pci_ops *ops)
+static int zpci_bus_create_pci_bus(struct zpci_bus *zbus, struct zpci_dev *fr, struct pci_ops *ops)
 {
 	struct pci_bus *bus;
 	int domain;
 
-	domain = zpci_alloc_domain((u16)f0->uid);
+	domain = zpci_alloc_domain((u16)fr->uid);
 	if (domain < 0)
 		return domain;
 
 	zbus->domain_nr = domain;
-	zbus->multifunction = f0->rid_available;
-	zbus->max_bus_speed = f0->max_bus_speed;
+	zbus->multifunction = fr->rid_available;
+	zbus->max_bus_speed = fr->max_bus_speed;
 
 	/*
 	 * Note that the zbus->resources are taken over and zbus->resources
@@ -303,47 +300,6 @@ void pcibios_bus_add_device(struct pci_dev *pdev)
 	}
 }
 
-/* zpci_bus_create_hotplug_slots - Add hotplug slot(s) for device added to bus
- * @zdev: the zPCI device that was newly added
- *
- * Add the hotplug slot(s) for the newly added PCI function. Normally this is
- * simply the slot for the function itself. If however we are adding the
- * function 0 on a zbus, it might be that we already registered functions on
- * that zbus but could not create their hotplug slots yet so add those now too.
- *
- * Return: 0 on success, an error code otherwise
- */
-static int zpci_bus_create_hotplug_slots(struct zpci_dev *zdev)
-{
-	struct zpci_bus *zbus = zdev->zbus;
-	int devfn, rc = 0;
-
-	rc = zpci_init_slot(zdev);
-	if (rc)
-		return rc;
-	zdev->has_hp_slot = 1;
-
-	if (zdev->devfn == 0 && zbus->multifunction) {
-		/* Now that function 0 is there we can finally create the
-		 * hotplug slots for those functions with devfn != 0 that have
-		 * been parked in zbus->function[] waiting for us to be able to
-		 * create the PCI bus.
-		 */
-		for  (devfn = 1; devfn < ZPCI_FUNCTIONS_PER_BUS; devfn++) {
-			zdev = zbus->function[devfn];
-			if (zdev && !zdev->has_hp_slot) {
-				rc = zpci_init_slot(zdev);
-				if (rc)
-					return rc;
-				zdev->has_hp_slot = 1;
-			}
-		}
-
-	}
-
-	return rc;
-}
-
 static int zpci_bus_add_device(struct zpci_bus *zbus, struct zpci_dev *zdev)
 {
 	int rc = -EINVAL;
@@ -352,21 +308,19 @@ static int zpci_bus_add_device(struct zpci_bus *zbus, struct zpci_dev *zdev)
 		pr_err("devfn %04x is already assigned\n", zdev->devfn);
 		return rc;
 	}
+
 	zdev->zbus = zbus;
 	zbus->function[zdev->devfn] = zdev;
 	zpci_nb_devices++;
 
-	if (zbus->bus) {
-		if (zbus->multifunction && !zdev->rid_available) {
-			WARN_ONCE(1, "rid_available not set for multifunction\n");
-			goto error;
-		}
-
-		zpci_bus_create_hotplug_slots(zdev);
-	} else {
-		/* Hotplug slot will be created once function 0 appears */
-		zbus->multifunction = 1;
+	if (zbus->multifunction && !zdev->rid_available) {
+		WARN_ONCE(1, "rid_available not set for multifunction\n");
+		goto error;
 	}
+	rc = zpci_init_slot(zdev);
+	if (rc)
+		goto error;
+	zdev->has_hp_slot = 1;
 
 	return 0;
 
@@ -400,7 +354,11 @@ int zpci_bus_device_register(struct zpci_dev *zdev, struct pci_ops *ops)
 			return -ENOMEM;
 	}
 
-	if (zdev->devfn == 0) {
+	if (!zbus->bus) {
+		/* The UID of the first PCI function registered with a zpci_bus
+		 * is used as the domain number for that bus. Currently there
+		 * is exactly one zpci_bus per domain.
+		 */
 		rc = zpci_bus_create_pci_bus(zbus, zdev, ops);
 		if (rc)
 			goto error;
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 1/4] PCI: Clean up pci_scan_slot()
  2022-04-12 14:30 ` [PATCH v2 1/4] PCI: Clean up pci_scan_slot() Niklas Schnelle
@ 2022-04-12 15:24   ` Niklas Schnelle
  0 siblings, 0 replies; 11+ messages in thread
From: Niklas Schnelle @ 2022-04-12 15:24 UTC (permalink / raw)
  To: Bjorn Helgaas, Jan Kiszka, Matthew Rosato, Pierre Morel
  Cc: linux-s390, linux-pci

On Tue, 2022-04-12 at 16:30 +0200, Niklas Schnelle wrote:
> While determining the next PCI function is factored out of
> pci_scan_slot() into next_fn() the former still handles the first
> function as a special case duplicating the code from the scan loop and
> splitting the condition that the first function exits from it being
> multifunction which is tested in next_fn().
> 
> Furthermore the non ARI branch of next_fn() mixes the case that
> multifunction devices may have non-contiguous function ranges and dev
> may thus be NULL with the multifunction requirement. It also signals
> that no further functions need to be scanned by returning 0 which is
> a valid function number.
> 
> Improve upon this by moving all conditions for having to scan for more
> functions into next_fn() and make them obvious and commented.
> 
> By changing next_fn() to return -ENODEV instead of 0 when there is no
> next function we can then handle the initial function inside the loop
> and deduplicate the shared handling.
> 
> No functional change is intended.
> 
> Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com>
> ---
>  drivers/pci/probe.c | 41 +++++++++++++++++++----------------------
>  1 file changed, 19 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index 17a969942d37..389aa1f9cb2c 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -2579,33 +2579,35 @@ struct pci_dev *pci_scan_single_device(struct pci_bus *bus, int devfn)
>  }
>  EXPORT_SYMBOL(pci_scan_single_device);
>  
> -static unsigned int next_fn(struct pci_bus *bus, struct pci_dev *dev,
> -			    unsigned int fn)
> +static int next_fn(struct pci_bus *bus, struct pci_dev *dev, int fn)
>  {
>  	int pos;
>  	u16 cap = 0;
>  	unsigned int next_fn;
>  
> -	if (pci_ari_enabled(bus)) {
> -		if (!dev)
> -			return 0;

This part here theoretically changes the behavior slightly. If the ARI
information is wrong/lands us in a "hole" we may look for more
functions via the non-ARI path. Not sure if that is relevant though as
in the worst case we might find functions that we otherwise wouldn't
have seen. Seems rather obsure to me but I might be wrong, we currently
don't see the ARI capability in Linux on IBM Z so I have less
experience with this. I did of course boot test on my x86_64
workstation.

> +	if (dev && pci_ari_enabled(bus)) {
>  		pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI);
>  		if (!pos)
> -			return 0;
> +			return -ENODEV;
>  
>  		pci_read_config_word(dev, pos + PCI_ARI_CAP, &cap);
>  		next_fn = PCI_ARI_CAP_NFN(cap);
>  		if (next_fn <= fn)
> -			return 0;	/* protect against malformed list */
> +			return -ENODEV;	/* protect against malformed list */
>  
>  		return next_fn;
>  	}
>  
> -	/* dev may be NULL for non-contiguous multifunction devices */
> -	if (!dev || dev->multifunction)
> -		return (fn + 1) % 8;
> -
> -	return 0;
> +	/* only multifunction devices may have more functions */
> +	if (dev && !dev->multifunction)
> +		return -ENODEV;
> +	/*
> +	 * A function 0 is required but multifunction devices may
> +	 * be non-contiguous so dev can be NULL otherwise.
> +	 */
> +	if (!fn && !dev)
> +		return -ENODEV;
> +	return (fn <= 6) ? fn + 1 : -ENODEV;
>  }
>  
> 
---8<---



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/4] PCI: Move jailhouse's isolated function handling to pci_scan_slot()
  2022-04-12 14:30 ` [PATCH v2 2/4] PCI: Move jailhouse's isolated function handling to pci_scan_slot() Niklas Schnelle
@ 2022-04-12 16:28   ` kernel test robot
  2022-04-13  7:55       ` Niklas Schnelle
  2022-04-12 19:43   ` kernel test robot
  1 sibling, 1 reply; 11+ messages in thread
From: kernel test robot @ 2022-04-12 16:28 UTC (permalink / raw)
  To: Niklas Schnelle, Bjorn Helgaas, Jan Kiszka, Matthew Rosato, Pierre Morel
  Cc: kbuild-all, linux-s390, linux-pci

Hi Niklas,

I love your patch! Perhaps something to improve:

[auto build test WARNING on helgaas-pci/next]
[also build test WARNING on s390/features tip/x86/core v5.18-rc2 next-20220412]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Niklas-Schnelle/PCI-Rework-pci_scan_slot-and-isolated-PCI-functions/20220412-223307
base:   https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git next
config: alpha-defconfig (https://download.01.org/0day-ci/archive/20220413/202204130045.AeSigvk8-lkp@intel.com/config)
compiler: alpha-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/5cac6729750b7434ff5d6ae99469e9e54bc9fb6e
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Niklas-Schnelle/PCI-Rework-pci_scan_slot-and-isolated-PCI-functions/20220412-223307
        git checkout 5cac6729750b7434ff5d6ae99469e9e54bc9fb6e
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=alpha SHELL=/bin/bash drivers/pci/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/pci/probe.c: In function 'pci_scan_child_bus_extend':
>> drivers/pci/probe.c:2861:13: warning: variable 'nr_devs' set but not used [-Wunused-but-set-variable]
    2861 |         int nr_devs;
         |             ^~~~~~~


vim +/nr_devs +2861 drivers/pci/probe.c

bccf90d6e063d2 Palmer Dabbelt  2017-06-23  2841  
1c02ea81006548 Mika Westerberg 2017-10-13  2842  /**
1c02ea81006548 Mika Westerberg 2017-10-13  2843   * pci_scan_child_bus_extend() - Scan devices below a bus
1c02ea81006548 Mika Westerberg 2017-10-13  2844   * @bus: Bus to scan for devices
1c02ea81006548 Mika Westerberg 2017-10-13  2845   * @available_buses: Total number of buses available (%0 does not try to
1c02ea81006548 Mika Westerberg 2017-10-13  2846   *		     extend beyond the minimal)
1c02ea81006548 Mika Westerberg 2017-10-13  2847   *
1c02ea81006548 Mika Westerberg 2017-10-13  2848   * Scans devices below @bus including subordinate buses. Returns new
1c02ea81006548 Mika Westerberg 2017-10-13  2849   * subordinate number including all the found devices. Passing
1c02ea81006548 Mika Westerberg 2017-10-13  2850   * @available_buses causes the remaining bus space to be distributed
1c02ea81006548 Mika Westerberg 2017-10-13  2851   * equally between hotplug-capable bridges to allow future extension of the
1c02ea81006548 Mika Westerberg 2017-10-13  2852   * hierarchy.
1c02ea81006548 Mika Westerberg 2017-10-13  2853   */
1c02ea81006548 Mika Westerberg 2017-10-13  2854  static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus,
1c02ea81006548 Mika Westerberg 2017-10-13  2855  					      unsigned int available_buses)
1c02ea81006548 Mika Westerberg 2017-10-13  2856  {
1c02ea81006548 Mika Westerberg 2017-10-13  2857  	unsigned int used_buses, normal_bridges = 0, hotplug_bridges = 0;
1c02ea81006548 Mika Westerberg 2017-10-13  2858  	unsigned int start = bus->busn_res.start;
5cac6729750b74 Niklas Schnelle 2022-04-12  2859  	unsigned int devfn, cmax, max = start;
^1da177e4c3f41 Linus Torvalds  2005-04-16  2860  	struct pci_dev *dev;
690f4304104f37 Jan Kiszka      2018-03-07 @2861  	int nr_devs;
^1da177e4c3f41 Linus Torvalds  2005-04-16  2862  
0207c356ef0e2b Bjorn Helgaas   2009-11-04  2863  	dev_dbg(&bus->dev, "scanning bus\n");
^1da177e4c3f41 Linus Torvalds  2005-04-16  2864  
^1da177e4c3f41 Linus Torvalds  2005-04-16  2865  	/* Go find them, Rover! */
5cac6729750b74 Niklas Schnelle 2022-04-12  2866  	for (devfn = 0; devfn < 256; devfn += 8)
690f4304104f37 Jan Kiszka      2018-03-07  2867  		nr_devs = pci_scan_slot(bus, devfn);
690f4304104f37 Jan Kiszka      2018-03-07  2868  
3e466e2d3a04c7 Bjorn Helgaas   2017-11-30  2869  	/* Reserve buses for SR-IOV capability */
1c02ea81006548 Mika Westerberg 2017-10-13  2870  	used_buses = pci_iov_bus_range(bus);
1c02ea81006548 Mika Westerberg 2017-10-13  2871  	max += used_buses;
a28724b0fb909d Yu Zhao         2009-03-20  2872  
^1da177e4c3f41 Linus Torvalds  2005-04-16  2873  	/*
^1da177e4c3f41 Linus Torvalds  2005-04-16  2874  	 * After performing arch-dependent fixup of the bus, look behind
^1da177e4c3f41 Linus Torvalds  2005-04-16  2875  	 * all PCI-to-PCI bridges on this bus.
^1da177e4c3f41 Linus Torvalds  2005-04-16  2876  	 */
74710ded8e16fc Alex Chiang     2009-03-20  2877  	if (!bus->is_added) {
0207c356ef0e2b Bjorn Helgaas   2009-11-04  2878  		dev_dbg(&bus->dev, "fixups for bus\n");
^1da177e4c3f41 Linus Torvalds  2005-04-16  2879  		pcibios_fixup_bus(bus);
74710ded8e16fc Alex Chiang     2009-03-20  2880  		bus->is_added = 1;
74710ded8e16fc Alex Chiang     2009-03-20  2881  	}
74710ded8e16fc Alex Chiang     2009-03-20  2882  
1c02ea81006548 Mika Westerberg 2017-10-13  2883  	/*
1c02ea81006548 Mika Westerberg 2017-10-13  2884  	 * Calculate how many hotplug bridges and normal bridges there
1c02ea81006548 Mika Westerberg 2017-10-13  2885  	 * are on this bus. We will distribute the additional available
1c02ea81006548 Mika Westerberg 2017-10-13  2886  	 * buses between hotplug bridges.
1c02ea81006548 Mika Westerberg 2017-10-13  2887  	 */
1c02ea81006548 Mika Westerberg 2017-10-13  2888  	for_each_pci_bridge(dev, bus) {
1c02ea81006548 Mika Westerberg 2017-10-13  2889  		if (dev->is_hotplug_bridge)
1c02ea81006548 Mika Westerberg 2017-10-13  2890  			hotplug_bridges++;
1c02ea81006548 Mika Westerberg 2017-10-13  2891  		else
1c02ea81006548 Mika Westerberg 2017-10-13  2892  			normal_bridges++;
1c02ea81006548 Mika Westerberg 2017-10-13  2893  	}
1c02ea81006548 Mika Westerberg 2017-10-13  2894  
4147c2fd9b12ae Mika Westerberg 2017-10-13  2895  	/*
4147c2fd9b12ae Mika Westerberg 2017-10-13  2896  	 * Scan bridges that are already configured. We don't touch them
4147c2fd9b12ae Mika Westerberg 2017-10-13  2897  	 * unless they are misconfigured (which will be done in the second
4147c2fd9b12ae Mika Westerberg 2017-10-13  2898  	 * scan below).
4147c2fd9b12ae Mika Westerberg 2017-10-13  2899  	 */
1c02ea81006548 Mika Westerberg 2017-10-13  2900  	for_each_pci_bridge(dev, bus) {
1c02ea81006548 Mika Westerberg 2017-10-13  2901  		cmax = max;
1c02ea81006548 Mika Westerberg 2017-10-13  2902  		max = pci_scan_bridge_extend(bus, dev, max, 0, 0);
3374c545c27c53 Mika Westerberg 2018-05-28  2903  
3374c545c27c53 Mika Westerberg 2018-05-28  2904  		/*
3374c545c27c53 Mika Westerberg 2018-05-28  2905  		 * Reserve one bus for each bridge now to avoid extending
3374c545c27c53 Mika Westerberg 2018-05-28  2906  		 * hotplug bridges too much during the second scan below.
3374c545c27c53 Mika Westerberg 2018-05-28  2907  		 */
3374c545c27c53 Mika Westerberg 2018-05-28  2908  		used_buses++;
3374c545c27c53 Mika Westerberg 2018-05-28  2909  		if (cmax - max > 1)
3374c545c27c53 Mika Westerberg 2018-05-28  2910  			used_buses += cmax - max - 1;
1c02ea81006548 Mika Westerberg 2017-10-13  2911  	}
4147c2fd9b12ae Mika Westerberg 2017-10-13  2912  
4147c2fd9b12ae Mika Westerberg 2017-10-13  2913  	/* Scan bridges that need to be reconfigured */
1c02ea81006548 Mika Westerberg 2017-10-13  2914  	for_each_pci_bridge(dev, bus) {
1c02ea81006548 Mika Westerberg 2017-10-13  2915  		unsigned int buses = 0;
1c02ea81006548 Mika Westerberg 2017-10-13  2916  
1c02ea81006548 Mika Westerberg 2017-10-13  2917  		if (!hotplug_bridges && normal_bridges == 1) {
3e466e2d3a04c7 Bjorn Helgaas   2017-11-30  2918  
1c02ea81006548 Mika Westerberg 2017-10-13  2919  			/*
1c02ea81006548 Mika Westerberg 2017-10-13  2920  			 * There is only one bridge on the bus (upstream
1c02ea81006548 Mika Westerberg 2017-10-13  2921  			 * port) so it gets all available buses which it
1c02ea81006548 Mika Westerberg 2017-10-13  2922  			 * can then distribute to the possible hotplug
1c02ea81006548 Mika Westerberg 2017-10-13  2923  			 * bridges below.
1c02ea81006548 Mika Westerberg 2017-10-13  2924  			 */
1c02ea81006548 Mika Westerberg 2017-10-13  2925  			buses = available_buses;
1c02ea81006548 Mika Westerberg 2017-10-13  2926  		} else if (dev->is_hotplug_bridge) {
3e466e2d3a04c7 Bjorn Helgaas   2017-11-30  2927  
1c02ea81006548 Mika Westerberg 2017-10-13  2928  			/*
1c02ea81006548 Mika Westerberg 2017-10-13  2929  			 * Distribute the extra buses between hotplug
1c02ea81006548 Mika Westerberg 2017-10-13  2930  			 * bridges if any.
1c02ea81006548 Mika Westerberg 2017-10-13  2931  			 */
1c02ea81006548 Mika Westerberg 2017-10-13  2932  			buses = available_buses / hotplug_bridges;
3374c545c27c53 Mika Westerberg 2018-05-28  2933  			buses = min(buses, available_buses - used_buses + 1);
1c02ea81006548 Mika Westerberg 2017-10-13  2934  		}
1c02ea81006548 Mika Westerberg 2017-10-13  2935  
1c02ea81006548 Mika Westerberg 2017-10-13  2936  		cmax = max;
1c02ea81006548 Mika Westerberg 2017-10-13  2937  		max = pci_scan_bridge_extend(bus, dev, cmax, buses, 1);
3374c545c27c53 Mika Westerberg 2018-05-28  2938  		/* One bus is already accounted so don't add it again */
3374c545c27c53 Mika Westerberg 2018-05-28  2939  		if (max - cmax > 1)
3374c545c27c53 Mika Westerberg 2018-05-28  2940  			used_buses += max - cmax - 1;
1c02ea81006548 Mika Westerberg 2017-10-13  2941  	}
^1da177e4c3f41 Linus Torvalds  2005-04-16  2942  
e16b46605960bd Keith Busch     2016-07-21  2943  	/*
e16b46605960bd Keith Busch     2016-07-21  2944  	 * Make sure a hotplug bridge has at least the minimum requested
1c02ea81006548 Mika Westerberg 2017-10-13  2945  	 * number of buses but allow it to grow up to the maximum available
1c02ea81006548 Mika Westerberg 2017-10-13  2946  	 * bus number of there is room.
e16b46605960bd Keith Busch     2016-07-21  2947  	 */
1c02ea81006548 Mika Westerberg 2017-10-13  2948  	if (bus->self && bus->self->is_hotplug_bridge) {
1c02ea81006548 Mika Westerberg 2017-10-13  2949  		used_buses = max_t(unsigned int, available_buses,
1c02ea81006548 Mika Westerberg 2017-10-13  2950  				   pci_hotplug_bus_size - 1);
1c02ea81006548 Mika Westerberg 2017-10-13  2951  		if (max - start < used_buses) {
1c02ea81006548 Mika Westerberg 2017-10-13  2952  			max = start + used_buses;
a20c7f36bd3d20 Mika Westerberg 2017-10-13  2953  
a20c7f36bd3d20 Mika Westerberg 2017-10-13  2954  			/* Do not allocate more buses than we have room left */
a20c7f36bd3d20 Mika Westerberg 2017-10-13  2955  			if (max > bus->busn_res.end)
a20c7f36bd3d20 Mika Westerberg 2017-10-13  2956  				max = bus->busn_res.end;
1c02ea81006548 Mika Westerberg 2017-10-13  2957  
1c02ea81006548 Mika Westerberg 2017-10-13  2958  			dev_dbg(&bus->dev, "%pR extended by %#02x\n",
1c02ea81006548 Mika Westerberg 2017-10-13  2959  				&bus->busn_res, max - start);
1c02ea81006548 Mika Westerberg 2017-10-13  2960  		}
e16b46605960bd Keith Busch     2016-07-21  2961  	}
e16b46605960bd Keith Busch     2016-07-21  2962  
^1da177e4c3f41 Linus Torvalds  2005-04-16  2963  	/*
^1da177e4c3f41 Linus Torvalds  2005-04-16  2964  	 * We've scanned the bus and so we know all about what's on
^1da177e4c3f41 Linus Torvalds  2005-04-16  2965  	 * the other side of any bridges that may be on this bus plus
^1da177e4c3f41 Linus Torvalds  2005-04-16  2966  	 * any devices.
^1da177e4c3f41 Linus Torvalds  2005-04-16  2967  	 *
^1da177e4c3f41 Linus Torvalds  2005-04-16  2968  	 * Return how far we've got finding sub-buses.
^1da177e4c3f41 Linus Torvalds  2005-04-16  2969  	 */
0207c356ef0e2b Bjorn Helgaas   2009-11-04  2970  	dev_dbg(&bus->dev, "bus scan returning with max=%02x\n", max);
^1da177e4c3f41 Linus Torvalds  2005-04-16  2971  	return max;
^1da177e4c3f41 Linus Torvalds  2005-04-16  2972  }
1c02ea81006548 Mika Westerberg 2017-10-13  2973  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/4] PCI: Move jailhouse's isolated function handling to pci_scan_slot()
  2022-04-12 14:30 ` [PATCH v2 2/4] PCI: Move jailhouse's isolated function handling to pci_scan_slot() Niklas Schnelle
  2022-04-12 16:28   ` kernel test robot
@ 2022-04-12 19:43   ` kernel test robot
  1 sibling, 0 replies; 11+ messages in thread
From: kernel test robot @ 2022-04-12 19:43 UTC (permalink / raw)
  To: Niklas Schnelle, Bjorn Helgaas, Jan Kiszka, Matthew Rosato, Pierre Morel
  Cc: llvm, kbuild-all, linux-s390, linux-pci

Hi Niklas,

I love your patch! Perhaps something to improve:

[auto build test WARNING on helgaas-pci/next]
[also build test WARNING on s390/features tip/x86/core v5.18-rc2 next-20220412]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Niklas-Schnelle/PCI-Rework-pci_scan_slot-and-isolated-PCI-functions/20220412-223307
base:   https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git next
config: i386-randconfig-a003-20220411 (https://download.01.org/0day-ci/archive/20220413/202204130326.eQ0YpxtC-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project fe2478d44e4f7f191c43fef629ac7a23d0251e72)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/5cac6729750b7434ff5d6ae99469e9e54bc9fb6e
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Niklas-Schnelle/PCI-Rework-pci_scan_slot-and-isolated-PCI-functions/20220412-223307
        git checkout 5cac6729750b7434ff5d6ae99469e9e54bc9fb6e
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/pci/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/pci/probe.c:2861:6: warning: variable 'nr_devs' set but not used [-Wunused-but-set-variable]
           int nr_devs;
               ^
   1 warning generated.


vim +/nr_devs +2861 drivers/pci/probe.c

bccf90d6e063d27 Palmer Dabbelt  2017-06-23  2841  
1c02ea81006548a Mika Westerberg 2017-10-13  2842  /**
1c02ea81006548a Mika Westerberg 2017-10-13  2843   * pci_scan_child_bus_extend() - Scan devices below a bus
1c02ea81006548a Mika Westerberg 2017-10-13  2844   * @bus: Bus to scan for devices
1c02ea81006548a Mika Westerberg 2017-10-13  2845   * @available_buses: Total number of buses available (%0 does not try to
1c02ea81006548a Mika Westerberg 2017-10-13  2846   *		     extend beyond the minimal)
1c02ea81006548a Mika Westerberg 2017-10-13  2847   *
1c02ea81006548a Mika Westerberg 2017-10-13  2848   * Scans devices below @bus including subordinate buses. Returns new
1c02ea81006548a Mika Westerberg 2017-10-13  2849   * subordinate number including all the found devices. Passing
1c02ea81006548a Mika Westerberg 2017-10-13  2850   * @available_buses causes the remaining bus space to be distributed
1c02ea81006548a Mika Westerberg 2017-10-13  2851   * equally between hotplug-capable bridges to allow future extension of the
1c02ea81006548a Mika Westerberg 2017-10-13  2852   * hierarchy.
1c02ea81006548a Mika Westerberg 2017-10-13  2853   */
1c02ea81006548a Mika Westerberg 2017-10-13  2854  static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus,
1c02ea81006548a Mika Westerberg 2017-10-13  2855  					      unsigned int available_buses)
1c02ea81006548a Mika Westerberg 2017-10-13  2856  {
1c02ea81006548a Mika Westerberg 2017-10-13  2857  	unsigned int used_buses, normal_bridges = 0, hotplug_bridges = 0;
1c02ea81006548a Mika Westerberg 2017-10-13  2858  	unsigned int start = bus->busn_res.start;
5cac6729750b743 Niklas Schnelle 2022-04-12  2859  	unsigned int devfn, cmax, max = start;
^1da177e4c3f415 Linus Torvalds  2005-04-16  2860  	struct pci_dev *dev;
690f4304104f37e Jan Kiszka      2018-03-07 @2861  	int nr_devs;
^1da177e4c3f415 Linus Torvalds  2005-04-16  2862  
0207c356ef0e2ba Bjorn Helgaas   2009-11-04  2863  	dev_dbg(&bus->dev, "scanning bus\n");
^1da177e4c3f415 Linus Torvalds  2005-04-16  2864  
^1da177e4c3f415 Linus Torvalds  2005-04-16  2865  	/* Go find them, Rover! */
5cac6729750b743 Niklas Schnelle 2022-04-12  2866  	for (devfn = 0; devfn < 256; devfn += 8)
690f4304104f37e Jan Kiszka      2018-03-07  2867  		nr_devs = pci_scan_slot(bus, devfn);
690f4304104f37e Jan Kiszka      2018-03-07  2868  
3e466e2d3a04c72 Bjorn Helgaas   2017-11-30  2869  	/* Reserve buses for SR-IOV capability */
1c02ea81006548a Mika Westerberg 2017-10-13  2870  	used_buses = pci_iov_bus_range(bus);
1c02ea81006548a Mika Westerberg 2017-10-13  2871  	max += used_buses;
a28724b0fb909d2 Yu Zhao         2009-03-20  2872  
^1da177e4c3f415 Linus Torvalds  2005-04-16  2873  	/*
^1da177e4c3f415 Linus Torvalds  2005-04-16  2874  	 * After performing arch-dependent fixup of the bus, look behind
^1da177e4c3f415 Linus Torvalds  2005-04-16  2875  	 * all PCI-to-PCI bridges on this bus.
^1da177e4c3f415 Linus Torvalds  2005-04-16  2876  	 */
74710ded8e16fc8 Alex Chiang     2009-03-20  2877  	if (!bus->is_added) {
0207c356ef0e2ba Bjorn Helgaas   2009-11-04  2878  		dev_dbg(&bus->dev, "fixups for bus\n");
^1da177e4c3f415 Linus Torvalds  2005-04-16  2879  		pcibios_fixup_bus(bus);
74710ded8e16fc8 Alex Chiang     2009-03-20  2880  		bus->is_added = 1;
74710ded8e16fc8 Alex Chiang     2009-03-20  2881  	}
74710ded8e16fc8 Alex Chiang     2009-03-20  2882  
1c02ea81006548a Mika Westerberg 2017-10-13  2883  	/*
1c02ea81006548a Mika Westerberg 2017-10-13  2884  	 * Calculate how many hotplug bridges and normal bridges there
1c02ea81006548a Mika Westerberg 2017-10-13  2885  	 * are on this bus. We will distribute the additional available
1c02ea81006548a Mika Westerberg 2017-10-13  2886  	 * buses between hotplug bridges.
1c02ea81006548a Mika Westerberg 2017-10-13  2887  	 */
1c02ea81006548a Mika Westerberg 2017-10-13  2888  	for_each_pci_bridge(dev, bus) {
1c02ea81006548a Mika Westerberg 2017-10-13  2889  		if (dev->is_hotplug_bridge)
1c02ea81006548a Mika Westerberg 2017-10-13  2890  			hotplug_bridges++;
1c02ea81006548a Mika Westerberg 2017-10-13  2891  		else
1c02ea81006548a Mika Westerberg 2017-10-13  2892  			normal_bridges++;
1c02ea81006548a Mika Westerberg 2017-10-13  2893  	}
1c02ea81006548a Mika Westerberg 2017-10-13  2894  
4147c2fd9b12ae1 Mika Westerberg 2017-10-13  2895  	/*
4147c2fd9b12ae1 Mika Westerberg 2017-10-13  2896  	 * Scan bridges that are already configured. We don't touch them
4147c2fd9b12ae1 Mika Westerberg 2017-10-13  2897  	 * unless they are misconfigured (which will be done in the second
4147c2fd9b12ae1 Mika Westerberg 2017-10-13  2898  	 * scan below).
4147c2fd9b12ae1 Mika Westerberg 2017-10-13  2899  	 */
1c02ea81006548a Mika Westerberg 2017-10-13  2900  	for_each_pci_bridge(dev, bus) {
1c02ea81006548a Mika Westerberg 2017-10-13  2901  		cmax = max;
1c02ea81006548a Mika Westerberg 2017-10-13  2902  		max = pci_scan_bridge_extend(bus, dev, max, 0, 0);
3374c545c27c535 Mika Westerberg 2018-05-28  2903  
3374c545c27c535 Mika Westerberg 2018-05-28  2904  		/*
3374c545c27c535 Mika Westerberg 2018-05-28  2905  		 * Reserve one bus for each bridge now to avoid extending
3374c545c27c535 Mika Westerberg 2018-05-28  2906  		 * hotplug bridges too much during the second scan below.
3374c545c27c535 Mika Westerberg 2018-05-28  2907  		 */
3374c545c27c535 Mika Westerberg 2018-05-28  2908  		used_buses++;
3374c545c27c535 Mika Westerberg 2018-05-28  2909  		if (cmax - max > 1)
3374c545c27c535 Mika Westerberg 2018-05-28  2910  			used_buses += cmax - max - 1;
1c02ea81006548a Mika Westerberg 2017-10-13  2911  	}
4147c2fd9b12ae1 Mika Westerberg 2017-10-13  2912  
4147c2fd9b12ae1 Mika Westerberg 2017-10-13  2913  	/* Scan bridges that need to be reconfigured */
1c02ea81006548a Mika Westerberg 2017-10-13  2914  	for_each_pci_bridge(dev, bus) {
1c02ea81006548a Mika Westerberg 2017-10-13  2915  		unsigned int buses = 0;
1c02ea81006548a Mika Westerberg 2017-10-13  2916  
1c02ea81006548a Mika Westerberg 2017-10-13  2917  		if (!hotplug_bridges && normal_bridges == 1) {
3e466e2d3a04c72 Bjorn Helgaas   2017-11-30  2918  
1c02ea81006548a Mika Westerberg 2017-10-13  2919  			/*
1c02ea81006548a Mika Westerberg 2017-10-13  2920  			 * There is only one bridge on the bus (upstream
1c02ea81006548a Mika Westerberg 2017-10-13  2921  			 * port) so it gets all available buses which it
1c02ea81006548a Mika Westerberg 2017-10-13  2922  			 * can then distribute to the possible hotplug
1c02ea81006548a Mika Westerberg 2017-10-13  2923  			 * bridges below.
1c02ea81006548a Mika Westerberg 2017-10-13  2924  			 */
1c02ea81006548a Mika Westerberg 2017-10-13  2925  			buses = available_buses;
1c02ea81006548a Mika Westerberg 2017-10-13  2926  		} else if (dev->is_hotplug_bridge) {
3e466e2d3a04c72 Bjorn Helgaas   2017-11-30  2927  
1c02ea81006548a Mika Westerberg 2017-10-13  2928  			/*
1c02ea81006548a Mika Westerberg 2017-10-13  2929  			 * Distribute the extra buses between hotplug
1c02ea81006548a Mika Westerberg 2017-10-13  2930  			 * bridges if any.
1c02ea81006548a Mika Westerberg 2017-10-13  2931  			 */
1c02ea81006548a Mika Westerberg 2017-10-13  2932  			buses = available_buses / hotplug_bridges;
3374c545c27c535 Mika Westerberg 2018-05-28  2933  			buses = min(buses, available_buses - used_buses + 1);
1c02ea81006548a Mika Westerberg 2017-10-13  2934  		}
1c02ea81006548a Mika Westerberg 2017-10-13  2935  
1c02ea81006548a Mika Westerberg 2017-10-13  2936  		cmax = max;
1c02ea81006548a Mika Westerberg 2017-10-13  2937  		max = pci_scan_bridge_extend(bus, dev, cmax, buses, 1);
3374c545c27c535 Mika Westerberg 2018-05-28  2938  		/* One bus is already accounted so don't add it again */
3374c545c27c535 Mika Westerberg 2018-05-28  2939  		if (max - cmax > 1)
3374c545c27c535 Mika Westerberg 2018-05-28  2940  			used_buses += max - cmax - 1;
1c02ea81006548a Mika Westerberg 2017-10-13  2941  	}
^1da177e4c3f415 Linus Torvalds  2005-04-16  2942  
e16b46605960bd0 Keith Busch     2016-07-21  2943  	/*
e16b46605960bd0 Keith Busch     2016-07-21  2944  	 * Make sure a hotplug bridge has at least the minimum requested
1c02ea81006548a Mika Westerberg 2017-10-13  2945  	 * number of buses but allow it to grow up to the maximum available
1c02ea81006548a Mika Westerberg 2017-10-13  2946  	 * bus number of there is room.
e16b46605960bd0 Keith Busch     2016-07-21  2947  	 */
1c02ea81006548a Mika Westerberg 2017-10-13  2948  	if (bus->self && bus->self->is_hotplug_bridge) {
1c02ea81006548a Mika Westerberg 2017-10-13  2949  		used_buses = max_t(unsigned int, available_buses,
1c02ea81006548a Mika Westerberg 2017-10-13  2950  				   pci_hotplug_bus_size - 1);
1c02ea81006548a Mika Westerberg 2017-10-13  2951  		if (max - start < used_buses) {
1c02ea81006548a Mika Westerberg 2017-10-13  2952  			max = start + used_buses;
a20c7f36bd3d20d Mika Westerberg 2017-10-13  2953  
a20c7f36bd3d20d Mika Westerberg 2017-10-13  2954  			/* Do not allocate more buses than we have room left */
a20c7f36bd3d20d Mika Westerberg 2017-10-13  2955  			if (max > bus->busn_res.end)
a20c7f36bd3d20d Mika Westerberg 2017-10-13  2956  				max = bus->busn_res.end;
1c02ea81006548a Mika Westerberg 2017-10-13  2957  
1c02ea81006548a Mika Westerberg 2017-10-13  2958  			dev_dbg(&bus->dev, "%pR extended by %#02x\n",
1c02ea81006548a Mika Westerberg 2017-10-13  2959  				&bus->busn_res, max - start);
1c02ea81006548a Mika Westerberg 2017-10-13  2960  		}
e16b46605960bd0 Keith Busch     2016-07-21  2961  	}
e16b46605960bd0 Keith Busch     2016-07-21  2962  
^1da177e4c3f415 Linus Torvalds  2005-04-16  2963  	/*
^1da177e4c3f415 Linus Torvalds  2005-04-16  2964  	 * We've scanned the bus and so we know all about what's on
^1da177e4c3f415 Linus Torvalds  2005-04-16  2965  	 * the other side of any bridges that may be on this bus plus
^1da177e4c3f415 Linus Torvalds  2005-04-16  2966  	 * any devices.
^1da177e4c3f415 Linus Torvalds  2005-04-16  2967  	 *
^1da177e4c3f415 Linus Torvalds  2005-04-16  2968  	 * Return how far we've got finding sub-buses.
^1da177e4c3f415 Linus Torvalds  2005-04-16  2969  	 */
0207c356ef0e2ba Bjorn Helgaas   2009-11-04  2970  	dev_dbg(&bus->dev, "bus scan returning with max=%02x\n", max);
^1da177e4c3f415 Linus Torvalds  2005-04-16  2971  	return max;
^1da177e4c3f415 Linus Torvalds  2005-04-16  2972  }
1c02ea81006548a Mika Westerberg 2017-10-13  2973  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/4] PCI: Move jailhouse's isolated function handling to pci_scan_slot()
  2022-04-12 16:28   ` kernel test robot
@ 2022-04-13  7:55       ` Niklas Schnelle
  0 siblings, 0 replies; 11+ messages in thread
From: Niklas Schnelle @ 2022-04-13  7:55 UTC (permalink / raw)
  To: kernel test robot, Bjorn Helgaas, Jan Kiszka, Matthew Rosato,
	Pierre Morel
  Cc: kbuild-all, linux-s390, linux-pci

On Wed, 2022-04-13 at 00:28 +0800, kernel test robot wrote:
> Hi Niklas,
> 
> I love your patch! Perhaps something to improve:
> 
> [auto build test WARNING on helgaas-pci/next]
> [also build test WARNING on s390/features tip/x86/core v5.18-rc2 next-20220412]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch]
> 
> url:    https://github.com/intel-lab-lkp/linux/commits/Niklas-Schnelle/PCI-Rework-pci_scan_slot-and-isolated-PCI-functions/20220412-223307
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git next
> config: alpha-defconfig (https://download.01.org/0day-ci/archive/20220413/202204130045.AeSigvk8-lkp@intel.com/config)
> compiler: alpha-linux-gcc (GCC) 11.2.0
> reproduce (this is a W=1 build):
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # https://github.com/intel-lab-lkp/linux/commit/5cac6729750b7434ff5d6ae99469e9e54bc9fb6e
>         git remote add linux-review https://github.com/intel-lab-lkp/linux
>         git fetch --no-tags linux-review Niklas-Schnelle/PCI-Rework-pci_scan_slot-and-isolated-PCI-functions/20220412-223307
>         git checkout 5cac6729750b7434ff5d6ae99469e9e54bc9fb6e
>         # save the config file to linux build tree
>         mkdir build_dir
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=alpha SHELL=/bin/bash drivers/pci/
> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
> 
> All warnings (new ones prefixed by >>):
> 
>    drivers/pci/probe.c: In function 'pci_scan_child_bus_extend':
> > > drivers/pci/probe.c:2861:13: warning: variable 'nr_devs' set but not used [-Wunused-but-set-variable]
>     2861 |         int nr_devs;
>          |             ^~~~~~~
> 
> 
> vim +/nr_devs +2861 drivers/pci/probe.c
> 
> bccf90d6e063d2 Palmer Dabbelt  2017-06-23  2841  
> 1c02ea81006548 Mika Westerberg 2017-10-13  2842  /**
> 1c02ea81006548 Mika Westerberg 2017-10-13  2843   * pci_scan_child_bus_extend() - Scan devices below a bus
> 1c02ea81006548 Mika Westerberg 2017-10-13  2844   * @bus: Bus to scan for devices
> 1c02ea81006548 Mika Westerberg 2017-10-13  2845   * @available_buses: Total number of buses available (%0 does not try to
> 1c02ea81006548 Mika Westerberg 2017-10-13  2846   *		     extend beyond the minimal)
> 1c02ea81006548 Mika Westerberg 2017-10-13  2847   *
> 1c02ea81006548 Mika Westerberg 2017-10-13  2848   * Scans devices below @bus including subordinate buses. Returns new
> 1c02ea81006548 Mika Westerberg 2017-10-13  2849   * subordinate number including all the found devices. Passing
> 1c02ea81006548 Mika Westerberg 2017-10-13  2850   * @available_buses causes the remaining bus space to be distributed
> 1c02ea81006548 Mika Westerberg 2017-10-13  2851   * equally between hotplug-capable bridges to allow future extension of the
> 1c02ea81006548 Mika Westerberg 2017-10-13  2852   * hierarchy.
> 1c02ea81006548 Mika Westerberg 2017-10-13  2853   */
> 1c02ea81006548 Mika Westerberg 2017-10-13  2854  static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus,
> 1c02ea81006548 Mika Westerberg 2017-10-13  2855  					      unsigned int available_buses)
> 1c02ea81006548 Mika Westerberg 2017-10-13  2856  {
> 1c02ea81006548 Mika Westerberg 2017-10-13  2857  	unsigned int used_buses, normal_bridges = 0, hotplug_bridges = 0;
> 1c02ea81006548 Mika Westerberg 2017-10-13  2858  	unsigned int start = bus->busn_res.start;
> 5cac6729750b74 Niklas Schnelle 2022-04-12  2859  	unsigned int devfn, cmax, max = start;
> ^1da177e4c3f41 Linus Torvalds  2005-04-16  2860  	struct pci_dev *dev;
> 690f4304104f37 Jan Kiszka      2018-03-07 @2861  	int nr_devs;
> ^1da177e4c3f41 Linus Torvalds  2005-04-16  2862  
> 0207c356ef0e2b Bjorn Helgaas   2009-11-04  2863  	dev_dbg(&bus->dev, "scanning bus\n");
> ^1da177e4c3f41 Linus Torvalds  2005-04-16  2864  
> ^1da177e4c3f41 Linus Torvalds  2005-04-16  2865  	/* Go find them, Rover! */
> 5cac6729750b74 Niklas Schnelle 2022-04-12  2866  	for (devfn = 0; devfn < 256; devfn += 8)
> 690f4304104f37 Jan Kiszka      2018-03-07  2867  		nr_devs = pci_scan_slot(bus, devfn);

The bot is right, the nr_devs can be removed as the patch removed the
only read access did so locally already.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/4] PCI: Move jailhouse's isolated function handling to pci_scan_slot()
@ 2022-04-13  7:55       ` Niklas Schnelle
  0 siblings, 0 replies; 11+ messages in thread
From: Niklas Schnelle @ 2022-04-13  7:55 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 4553 bytes --]

On Wed, 2022-04-13 at 00:28 +0800, kernel test robot wrote:
> Hi Niklas,
> 
> I love your patch! Perhaps something to improve:
> 
> [auto build test WARNING on helgaas-pci/next]
> [also build test WARNING on s390/features tip/x86/core v5.18-rc2 next-20220412]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch]
> 
> url:    https://github.com/intel-lab-lkp/linux/commits/Niklas-Schnelle/PCI-Rework-pci_scan_slot-and-isolated-PCI-functions/20220412-223307
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git next
> config: alpha-defconfig (https://download.01.org/0day-ci/archive/20220413/202204130045.AeSigvk8-lkp(a)intel.com/config)
> compiler: alpha-linux-gcc (GCC) 11.2.0
> reproduce (this is a W=1 build):
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # https://github.com/intel-lab-lkp/linux/commit/5cac6729750b7434ff5d6ae99469e9e54bc9fb6e
>         git remote add linux-review https://github.com/intel-lab-lkp/linux
>         git fetch --no-tags linux-review Niklas-Schnelle/PCI-Rework-pci_scan_slot-and-isolated-PCI-functions/20220412-223307
>         git checkout 5cac6729750b7434ff5d6ae99469e9e54bc9fb6e
>         # save the config file to linux build tree
>         mkdir build_dir
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=alpha SHELL=/bin/bash drivers/pci/
> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
> 
> All warnings (new ones prefixed by >>):
> 
>    drivers/pci/probe.c: In function 'pci_scan_child_bus_extend':
> > > drivers/pci/probe.c:2861:13: warning: variable 'nr_devs' set but not used [-Wunused-but-set-variable]
>     2861 |         int nr_devs;
>          |             ^~~~~~~
> 
> 
> vim +/nr_devs +2861 drivers/pci/probe.c
> 
> bccf90d6e063d2 Palmer Dabbelt  2017-06-23  2841  
> 1c02ea81006548 Mika Westerberg 2017-10-13  2842  /**
> 1c02ea81006548 Mika Westerberg 2017-10-13  2843   * pci_scan_child_bus_extend() - Scan devices below a bus
> 1c02ea81006548 Mika Westerberg 2017-10-13  2844   * @bus: Bus to scan for devices
> 1c02ea81006548 Mika Westerberg 2017-10-13  2845   * @available_buses: Total number of buses available (%0 does not try to
> 1c02ea81006548 Mika Westerberg 2017-10-13  2846   *		     extend beyond the minimal)
> 1c02ea81006548 Mika Westerberg 2017-10-13  2847   *
> 1c02ea81006548 Mika Westerberg 2017-10-13  2848   * Scans devices below @bus including subordinate buses. Returns new
> 1c02ea81006548 Mika Westerberg 2017-10-13  2849   * subordinate number including all the found devices. Passing
> 1c02ea81006548 Mika Westerberg 2017-10-13  2850   * @available_buses causes the remaining bus space to be distributed
> 1c02ea81006548 Mika Westerberg 2017-10-13  2851   * equally between hotplug-capable bridges to allow future extension of the
> 1c02ea81006548 Mika Westerberg 2017-10-13  2852   * hierarchy.
> 1c02ea81006548 Mika Westerberg 2017-10-13  2853   */
> 1c02ea81006548 Mika Westerberg 2017-10-13  2854  static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus,
> 1c02ea81006548 Mika Westerberg 2017-10-13  2855  					      unsigned int available_buses)
> 1c02ea81006548 Mika Westerberg 2017-10-13  2856  {
> 1c02ea81006548 Mika Westerberg 2017-10-13  2857  	unsigned int used_buses, normal_bridges = 0, hotplug_bridges = 0;
> 1c02ea81006548 Mika Westerberg 2017-10-13  2858  	unsigned int start = bus->busn_res.start;
> 5cac6729750b74 Niklas Schnelle 2022-04-12  2859  	unsigned int devfn, cmax, max = start;
> ^1da177e4c3f41 Linus Torvalds  2005-04-16  2860  	struct pci_dev *dev;
> 690f4304104f37 Jan Kiszka      2018-03-07 @2861  	int nr_devs;
> ^1da177e4c3f41 Linus Torvalds  2005-04-16  2862  
> 0207c356ef0e2b Bjorn Helgaas   2009-11-04  2863  	dev_dbg(&bus->dev, "scanning bus\n");
> ^1da177e4c3f41 Linus Torvalds  2005-04-16  2864  
> ^1da177e4c3f41 Linus Torvalds  2005-04-16  2865  	/* Go find them, Rover! */
> 5cac6729750b74 Niklas Schnelle 2022-04-12  2866  	for (devfn = 0; devfn < 256; devfn += 8)
> 690f4304104f37 Jan Kiszka      2018-03-07  2867  		nr_devs = pci_scan_slot(bus, devfn);

The bot is right, the nr_devs can be removed as the patch removed the
only read access did so locally already.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/4] PCI: Move jailhouse's isolated function handling to pci_scan_slot()
@ 2022-04-13 22:12 kernel test robot
  0 siblings, 0 replies; 11+ messages in thread
From: kernel test robot @ 2022-04-13 22:12 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 31912 bytes --]

CC: llvm(a)lists.linux.dev
CC: kbuild-all(a)lists.01.org
BCC: lkp(a)intel.com
In-Reply-To: <20220412143040.1882096-3-schnelle@linux.ibm.com>
References: <20220412143040.1882096-3-schnelle@linux.ibm.com>
TO: Niklas Schnelle <schnelle@linux.ibm.com>
TO: Bjorn Helgaas <helgaas@kernel.org>
TO: Jan Kiszka <jan.kiszka@siemens.com>
TO: Matthew Rosato <mjrosato@linux.ibm.com>
TO: Pierre Morel <pmorel@linux.ibm.com>
CC: linux-s390(a)vger.kernel.org
CC: linux-pci(a)vger.kernel.org

Hi Niklas,

I love your patch! Perhaps something to improve:

[auto build test WARNING on helgaas-pci/next]
[also build test WARNING on s390/features tip/x86/core v5.18-rc2 next-20220413]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/intel-lab-lkp/linux/commits/Niklas-Schnelle/PCI-Rework-pci_scan_slot-and-isolated-PCI-functions/20220412-223307
base:   https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git next
:::::: branch date: 32 hours ago
:::::: commit date: 32 hours ago
config: x86_64-randconfig-c007-20220411 (https://download.01.org/0day-ci/archive/20220414/202204140641.r3fD3EBW-lkp(a)intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project fe2478d44e4f7f191c43fef629ac7a23d0251e72)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/5cac6729750b7434ff5d6ae99469e9e54bc9fb6e
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Niklas-Schnelle/PCI-Rework-pci_scan_slot-and-isolated-PCI-functions/20220412-223307
        git checkout 5cac6729750b7434ff5d6ae99469e9e54bc9fb6e
        # save the config file to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 clang-analyzer 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


clang-analyzer warnings: (new ones prefixed by >>)
           if (primary & WM831X_TCHDATA_INT)
           ^
   drivers/mfd/wm831x-irq.c:478:2: note: Loop condition is true.  Entering loop body
           for (i = 0; i < ARRAY_SIZE(wm831x_irqs); i++) {
           ^
   drivers/mfd/wm831x-irq.c:481:7: note: Assuming the condition is false
                   if (!(primary & wm831x_irqs[i].primary))
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/mfd/wm831x-irq.c:481:3: note: Taking false branch
                   if (!(primary & wm831x_irqs[i].primary))
                   ^
   drivers/mfd/wm831x-irq.c:488:7: note: Assuming the condition is false
                   if (!read[offset]) {
                       ^~~~~~~~~~~~~
   drivers/mfd/wm831x-irq.c:488:3: note: Taking false branch
                   if (!read[offset]) {
                   ^
   drivers/mfd/wm831x-irq.c:510:7: note: Assuming the condition is false
                   if (*status & wm831x_irqs[i].mask)
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/mfd/wm831x-irq.c:510:3: note: Taking false branch
                   if (*status & wm831x_irqs[i].mask)
                   ^
   drivers/mfd/wm831x-irq.c:517:7: note: Assuming 'primary' is equal to WM831X_GP_INT
                   if (primary == WM831X_GP_INT &&
                       ^~~~~~~~~~~~~~~~~~~~~~~~
   drivers/mfd/wm831x-irq.c:517:7: note: Left side of '&&' is true
   drivers/mfd/wm831x-irq.c:518:7: note: Assuming the condition is false
                       wm831x->gpio_level_high[i - WM831X_IRQ_GPIO_1]) {
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/mfd/wm831x-irq.c:517:3: note: Taking false branch
                   if (primary == WM831X_GP_INT &&
                   ^
   drivers/mfd/wm831x-irq.c:528:7: note: 'primary' is equal to WM831X_GP_INT
                   if (primary == WM831X_GP_INT &&
                       ^~~~~~~
   drivers/mfd/wm831x-irq.c:528:7: note: Left side of '&&' is true
   drivers/mfd/wm831x-irq.c:529:7: note: Assuming the condition is true
                       wm831x->gpio_level_low[i - WM831X_IRQ_GPIO_1]) {
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/mfd/wm831x-irq.c:528:3: note: Taking true branch
                   if (primary == WM831X_GP_INT &&
                   ^
   drivers/mfd/wm831x-irq.c:531:21: note: The result of the left shift is undefined due to shifting by '4294967295', which is greater or equal to the width of type 'int'
                           while (!(ret & 1 << (i - WM831X_IRQ_GPIO_1))) {
                                            ^  ~~~~~~~~~~~~~~~~~~~~~~~
   Suppressed 41 warnings (41 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   47 warnings generated.
   block/partitions/cmdline.c:84:3: warning: Call to function 'strncpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'strncpy_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
                   strncpy(new_subpart->name, partdef, length);
                   ^~~~~~~
   block/partitions/cmdline.c:84:3: note: Call to function 'strncpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'strncpy_s' in case of C11
                   strncpy(new_subpart->name, partdef, length);
                   ^~~~~~~
   block/partitions/cmdline.c:143:2: warning: Call to function 'strncpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'strncpy_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
           strncpy(newparts->name, bdevdef, length);
           ^~~~~~~
   block/partitions/cmdline.c:143:2: note: Call to function 'strncpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'strncpy_s' in case of C11
           strncpy(newparts->name, bdevdef, length);
           ^~~~~~~
   block/partitions/cmdline.c:156:3: warning: Call to function 'strncpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'strncpy_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
                   strncpy(buf, bdevdef, length);
                   ^~~~~~~
   block/partitions/cmdline.c:156:3: note: Call to function 'strncpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'strncpy_s' in case of C11
                   strncpy(buf, bdevdef, length);
                   ^~~~~~~
   block/partitions/cmdline.c:270:2: warning: Call to function 'strncpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'strncpy_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
           strncpy(info->volname, subpart->name, label_min);
           ^~~~~~~
   block/partitions/cmdline.c:270:2: note: Call to function 'strncpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'strncpy_s' in case of C11
           strncpy(info->volname, subpart->name, label_min);
           ^~~~~~~
   block/partitions/cmdline.c:273:2: warning: Call to function 'snprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'snprintf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
           snprintf(tmp, sizeof(tmp), "(%s)", info->volname);
           ^~~~~~~~
   block/partitions/cmdline.c:273:2: note: Call to function 'snprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'snprintf_s' in case of C11
           snprintf(tmp, sizeof(tmp), "(%s)", info->volname);
           ^~~~~~~~
   Suppressed 42 warnings (42 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   33 warnings generated.
   Suppressed 33 warnings (33 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   33 warnings generated.
   Suppressed 33 warnings (33 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   37 warnings generated.
   drivers/pci/probe.c:1013:4: warning: Call to function 'snprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'snprintf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
                           snprintf(addr, sizeof(addr), fmt,
                           ^~~~~~~~
   drivers/pci/probe.c:1013:4: note: Call to function 'snprintf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'snprintf_s' in case of C11
                           snprintf(addr, sizeof(addr), fmt,
                           ^~~~~~~~
   drivers/pci/probe.c:1447:2: warning: Call to function 'sprintf' is insecure as it does not provide bounding of the memory buffer or security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
           sprintf(child->name,
           ^~~~~~~
   drivers/pci/probe.c:1447:2: note: Call to function 'sprintf' is insecure as it does not provide bounding of the memory buffer or security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sprintf_s' in case of C11
           sprintf(child->name,
           ^~~~~~~
>> drivers/pci/probe.c:2867:3: warning: Value stored to 'nr_devs' is never read [clang-analyzer-deadcode.DeadStores]
                   nr_devs = pci_scan_slot(bus, devfn);
                   ^         ~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/pci/probe.c:2867:3: note: Value stored to 'nr_devs' is never read
                   nr_devs = pci_scan_slot(bus, devfn);
                   ^         ~~~~~~~~~~~~~~~~~~~~~~~~~
   Suppressed 34 warnings (33 in non-user code, 1 with check filters).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   33 warnings generated.
   Suppressed 33 warnings (33 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   33 warnings generated.
   Suppressed 33 warnings (33 in non-user code).
   Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
   44 warnings generated.
   drivers/pci/pci.c:286:9: warning: Call to function 'sscanf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sscanf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
                   ret = sscanf(p, "/%x.%x%c", &slot, &func, &end);
                         ^~~~~~
   drivers/pci/pci.c:286:9: note: Call to function 'sscanf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sscanf_s' in case of C11
                   ret = sscanf(p, "/%x.%x%c", &slot, &func, &end);
                         ^~~~~~
   drivers/pci/pci.c:312:8: warning: Call to function 'sscanf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sscanf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
           ret = sscanf(wpath, "%x:%x:%x.%x%c", &seg, &bus, &slot,
                 ^~~~~~
   drivers/pci/pci.c:312:8: note: Call to function 'sscanf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sscanf_s' in case of C11
           ret = sscanf(wpath, "%x:%x:%x.%x%c", &seg, &bus, &slot,
                 ^~~~~~
   drivers/pci/pci.c:316:9: warning: Call to function 'sscanf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sscanf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
                   ret = sscanf(wpath, "%x:%x.%x%c", &bus, &slot, &func, &end);
                         ^~~~~~
   drivers/pci/pci.c:316:9: note: Call to function 'sscanf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sscanf_s' in case of C11
                   ret = sscanf(wpath, "%x:%x.%x%c", &bus, &slot, &func, &end);
                         ^~~~~~
   drivers/pci/pci.c:372:9: warning: Call to function 'sscanf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sscanf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
                   ret = sscanf(p, "%hx:%hx:%hx:%hx%n", &vendor, &device,
                         ^~~~~~
   drivers/pci/pci.c:372:9: note: Call to function 'sscanf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sscanf_s' in case of C11
                   ret = sscanf(p, "%hx:%hx:%hx:%hx%n", &vendor, &device,
                         ^~~~~~
   drivers/pci/pci.c:375:10: warning: Call to function 'sscanf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sscanf_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
                           ret = sscanf(p, "%hx:%hx%n", &vendor, &device, &count);
                                 ^~~~~~
   drivers/pci/pci.c:375:10: note: Call to function 'sscanf' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'sscanf_s' in case of C11
                           ret = sscanf(p, "%hx:%hx%n", &vendor, &device, &count);
                                 ^~~~~~
   drivers/pci/pci.c:1783:2: warning: Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
           memcpy(state->config_space, dev->saved_config_space,
           ^
   include/linux/fortify-string.h:369:26: note: expanded from macro 'memcpy'
   #define memcpy(p, q, s)  __fortify_memcpy_chk(p, q, s,                  \
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/fortify-string.h:362:2: note: expanded from macro '__fortify_memcpy_chk'
           __underlying_##op(p, q, __fortify_size);                        \
           ^~~~~~~~~~~~~~~~~
   note: expanded from here
   include/linux/fortify-string.h:45:29: note: expanded from macro '__underlying_memcpy'
   #define __underlying_memcpy     __builtin_memcpy
                                   ^~~~~~~~~~~~~~~~
   drivers/pci/pci.c:1783:2: note: Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11
           memcpy(state->config_space, dev->saved_config_space,
           ^
   include/linux/fortify-string.h:369:26: note: expanded from macro 'memcpy'
   #define memcpy(p, q, s)  __fortify_memcpy_chk(p, q, s,                  \
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/fortify-string.h:362:2: note: expanded from macro '__fortify_memcpy_chk'
           __underlying_##op(p, q, __fortify_size);                        \
           ^~~~~~~~~~~~~~~~~
   note: expanded from here
   include/linux/fortify-string.h:45:29: note: expanded from macro '__underlying_memcpy'
   #define __underlying_memcpy     __builtin_memcpy
                                   ^~~~~~~~~~~~~~~~
   drivers/pci/pci.c:1789:3: warning: Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
                   memcpy(cap, &tmp->cap, len);
                   ^
   include/linux/fortify-string.h:369:26: note: expanded from macro 'memcpy'
   #define memcpy(p, q, s)  __fortify_memcpy_chk(p, q, s,                  \
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/fortify-string.h:362:2: note: expanded from macro '__fortify_memcpy_chk'
           __underlying_##op(p, q, __fortify_size);                        \
           ^~~~~~~~~~~~~~~~~
   note: expanded from here
   include/linux/fortify-string.h:45:29: note: expanded from macro '__underlying_memcpy'
   #define __underlying_memcpy     __builtin_memcpy
                                   ^~~~~~~~~~~~~~~~
   drivers/pci/pci.c:1789:3: note: Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11
                   memcpy(cap, &tmp->cap, len);
                   ^
   include/linux/fortify-string.h:369:26: note: expanded from macro 'memcpy'
   #define memcpy(p, q, s)  __fortify_memcpy_chk(p, q, s,                  \
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/fortify-string.h:362:2: note: expanded from macro '__fortify_memcpy_chk'
           __underlying_##op(p, q, __fortify_size);                        \
           ^~~~~~~~~~~~~~~~~
   note: expanded from here
   include/linux/fortify-string.h:45:29: note: expanded from macro '__underlying_memcpy'
   #define __underlying_memcpy     __builtin_memcpy
                                   ^~~~~~~~~~~~~~~~
   drivers/pci/pci.c:1813:2: warning: Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling]
           memcpy(dev->saved_config_space, state->config_space,
           ^
   include/linux/fortify-string.h:369:26: note: expanded from macro 'memcpy'

vim +/nr_devs +2867 drivers/pci/probe.c

bccf90d6e063d27 Palmer Dabbelt  2017-06-23  2841  
1c02ea81006548a Mika Westerberg 2017-10-13  2842  /**
1c02ea81006548a Mika Westerberg 2017-10-13  2843   * pci_scan_child_bus_extend() - Scan devices below a bus
1c02ea81006548a Mika Westerberg 2017-10-13  2844   * @bus: Bus to scan for devices
1c02ea81006548a Mika Westerberg 2017-10-13  2845   * @available_buses: Total number of buses available (%0 does not try to
1c02ea81006548a Mika Westerberg 2017-10-13  2846   *		     extend beyond the minimal)
1c02ea81006548a Mika Westerberg 2017-10-13  2847   *
1c02ea81006548a Mika Westerberg 2017-10-13  2848   * Scans devices below @bus including subordinate buses. Returns new
1c02ea81006548a Mika Westerberg 2017-10-13  2849   * subordinate number including all the found devices. Passing
1c02ea81006548a Mika Westerberg 2017-10-13  2850   * @available_buses causes the remaining bus space to be distributed
1c02ea81006548a Mika Westerberg 2017-10-13  2851   * equally between hotplug-capable bridges to allow future extension of the
1c02ea81006548a Mika Westerberg 2017-10-13  2852   * hierarchy.
1c02ea81006548a Mika Westerberg 2017-10-13  2853   */
1c02ea81006548a Mika Westerberg 2017-10-13  2854  static unsigned int pci_scan_child_bus_extend(struct pci_bus *bus,
1c02ea81006548a Mika Westerberg 2017-10-13  2855  					      unsigned int available_buses)
1c02ea81006548a Mika Westerberg 2017-10-13  2856  {
1c02ea81006548a Mika Westerberg 2017-10-13  2857  	unsigned int used_buses, normal_bridges = 0, hotplug_bridges = 0;
1c02ea81006548a Mika Westerberg 2017-10-13  2858  	unsigned int start = bus->busn_res.start;
5cac6729750b743 Niklas Schnelle 2022-04-12  2859  	unsigned int devfn, cmax, max = start;
^1da177e4c3f415 Linus Torvalds  2005-04-16  2860  	struct pci_dev *dev;
690f4304104f37e Jan Kiszka      2018-03-07  2861  	int nr_devs;
^1da177e4c3f415 Linus Torvalds  2005-04-16  2862  
0207c356ef0e2ba Bjorn Helgaas   2009-11-04  2863  	dev_dbg(&bus->dev, "scanning bus\n");
^1da177e4c3f415 Linus Torvalds  2005-04-16  2864  
^1da177e4c3f415 Linus Torvalds  2005-04-16  2865  	/* Go find them, Rover! */
5cac6729750b743 Niklas Schnelle 2022-04-12  2866  	for (devfn = 0; devfn < 256; devfn += 8)
690f4304104f37e Jan Kiszka      2018-03-07 @2867  		nr_devs = pci_scan_slot(bus, devfn);
690f4304104f37e Jan Kiszka      2018-03-07  2868  
3e466e2d3a04c72 Bjorn Helgaas   2017-11-30  2869  	/* Reserve buses for SR-IOV capability */
1c02ea81006548a Mika Westerberg 2017-10-13  2870  	used_buses = pci_iov_bus_range(bus);
1c02ea81006548a Mika Westerberg 2017-10-13  2871  	max += used_buses;
a28724b0fb909d2 Yu Zhao         2009-03-20  2872  
^1da177e4c3f415 Linus Torvalds  2005-04-16  2873  	/*
^1da177e4c3f415 Linus Torvalds  2005-04-16  2874  	 * After performing arch-dependent fixup of the bus, look behind
^1da177e4c3f415 Linus Torvalds  2005-04-16  2875  	 * all PCI-to-PCI bridges on this bus.
^1da177e4c3f415 Linus Torvalds  2005-04-16  2876  	 */
74710ded8e16fc8 Alex Chiang     2009-03-20  2877  	if (!bus->is_added) {
0207c356ef0e2ba Bjorn Helgaas   2009-11-04  2878  		dev_dbg(&bus->dev, "fixups for bus\n");
^1da177e4c3f415 Linus Torvalds  2005-04-16  2879  		pcibios_fixup_bus(bus);
74710ded8e16fc8 Alex Chiang     2009-03-20  2880  		bus->is_added = 1;
74710ded8e16fc8 Alex Chiang     2009-03-20  2881  	}
74710ded8e16fc8 Alex Chiang     2009-03-20  2882  
1c02ea81006548a Mika Westerberg 2017-10-13  2883  	/*
1c02ea81006548a Mika Westerberg 2017-10-13  2884  	 * Calculate how many hotplug bridges and normal bridges there
1c02ea81006548a Mika Westerberg 2017-10-13  2885  	 * are on this bus. We will distribute the additional available
1c02ea81006548a Mika Westerberg 2017-10-13  2886  	 * buses between hotplug bridges.
1c02ea81006548a Mika Westerberg 2017-10-13  2887  	 */
1c02ea81006548a Mika Westerberg 2017-10-13  2888  	for_each_pci_bridge(dev, bus) {
1c02ea81006548a Mika Westerberg 2017-10-13  2889  		if (dev->is_hotplug_bridge)
1c02ea81006548a Mika Westerberg 2017-10-13  2890  			hotplug_bridges++;
1c02ea81006548a Mika Westerberg 2017-10-13  2891  		else
1c02ea81006548a Mika Westerberg 2017-10-13  2892  			normal_bridges++;
1c02ea81006548a Mika Westerberg 2017-10-13  2893  	}
1c02ea81006548a Mika Westerberg 2017-10-13  2894  
4147c2fd9b12ae1 Mika Westerberg 2017-10-13  2895  	/*
4147c2fd9b12ae1 Mika Westerberg 2017-10-13  2896  	 * Scan bridges that are already configured. We don't touch them
4147c2fd9b12ae1 Mika Westerberg 2017-10-13  2897  	 * unless they are misconfigured (which will be done in the second
4147c2fd9b12ae1 Mika Westerberg 2017-10-13  2898  	 * scan below).
4147c2fd9b12ae1 Mika Westerberg 2017-10-13  2899  	 */
1c02ea81006548a Mika Westerberg 2017-10-13  2900  	for_each_pci_bridge(dev, bus) {
1c02ea81006548a Mika Westerberg 2017-10-13  2901  		cmax = max;
1c02ea81006548a Mika Westerberg 2017-10-13  2902  		max = pci_scan_bridge_extend(bus, dev, max, 0, 0);
3374c545c27c535 Mika Westerberg 2018-05-28  2903  
3374c545c27c535 Mika Westerberg 2018-05-28  2904  		/*
3374c545c27c535 Mika Westerberg 2018-05-28  2905  		 * Reserve one bus for each bridge now to avoid extending
3374c545c27c535 Mika Westerberg 2018-05-28  2906  		 * hotplug bridges too much during the second scan below.
3374c545c27c535 Mika Westerberg 2018-05-28  2907  		 */
3374c545c27c535 Mika Westerberg 2018-05-28  2908  		used_buses++;
3374c545c27c535 Mika Westerberg 2018-05-28  2909  		if (cmax - max > 1)
3374c545c27c535 Mika Westerberg 2018-05-28  2910  			used_buses += cmax - max - 1;
1c02ea81006548a Mika Westerberg 2017-10-13  2911  	}
4147c2fd9b12ae1 Mika Westerberg 2017-10-13  2912  
4147c2fd9b12ae1 Mika Westerberg 2017-10-13  2913  	/* Scan bridges that need to be reconfigured */
1c02ea81006548a Mika Westerberg 2017-10-13  2914  	for_each_pci_bridge(dev, bus) {
1c02ea81006548a Mika Westerberg 2017-10-13  2915  		unsigned int buses = 0;
1c02ea81006548a Mika Westerberg 2017-10-13  2916  
1c02ea81006548a Mika Westerberg 2017-10-13  2917  		if (!hotplug_bridges && normal_bridges == 1) {
3e466e2d3a04c72 Bjorn Helgaas   2017-11-30  2918  
1c02ea81006548a Mika Westerberg 2017-10-13  2919  			/*
1c02ea81006548a Mika Westerberg 2017-10-13  2920  			 * There is only one bridge on the bus (upstream
1c02ea81006548a Mika Westerberg 2017-10-13  2921  			 * port) so it gets all available buses which it
1c02ea81006548a Mika Westerberg 2017-10-13  2922  			 * can then distribute to the possible hotplug
1c02ea81006548a Mika Westerberg 2017-10-13  2923  			 * bridges below.
1c02ea81006548a Mika Westerberg 2017-10-13  2924  			 */
1c02ea81006548a Mika Westerberg 2017-10-13  2925  			buses = available_buses;
1c02ea81006548a Mika Westerberg 2017-10-13  2926  		} else if (dev->is_hotplug_bridge) {
3e466e2d3a04c72 Bjorn Helgaas   2017-11-30  2927  
1c02ea81006548a Mika Westerberg 2017-10-13  2928  			/*
1c02ea81006548a Mika Westerberg 2017-10-13  2929  			 * Distribute the extra buses between hotplug
1c02ea81006548a Mika Westerberg 2017-10-13  2930  			 * bridges if any.
1c02ea81006548a Mika Westerberg 2017-10-13  2931  			 */
1c02ea81006548a Mika Westerberg 2017-10-13  2932  			buses = available_buses / hotplug_bridges;
3374c545c27c535 Mika Westerberg 2018-05-28  2933  			buses = min(buses, available_buses - used_buses + 1);
1c02ea81006548a Mika Westerberg 2017-10-13  2934  		}
1c02ea81006548a Mika Westerberg 2017-10-13  2935  
1c02ea81006548a Mika Westerberg 2017-10-13  2936  		cmax = max;
1c02ea81006548a Mika Westerberg 2017-10-13  2937  		max = pci_scan_bridge_extend(bus, dev, cmax, buses, 1);
3374c545c27c535 Mika Westerberg 2018-05-28  2938  		/* One bus is already accounted so don't add it again */
3374c545c27c535 Mika Westerberg 2018-05-28  2939  		if (max - cmax > 1)
3374c545c27c535 Mika Westerberg 2018-05-28  2940  			used_buses += max - cmax - 1;
1c02ea81006548a Mika Westerberg 2017-10-13  2941  	}
^1da177e4c3f415 Linus Torvalds  2005-04-16  2942  
e16b46605960bd0 Keith Busch     2016-07-21  2943  	/*
e16b46605960bd0 Keith Busch     2016-07-21  2944  	 * Make sure a hotplug bridge has at least the minimum requested
1c02ea81006548a Mika Westerberg 2017-10-13  2945  	 * number of buses but allow it to grow up to the maximum available
1c02ea81006548a Mika Westerberg 2017-10-13  2946  	 * bus number of there is room.
e16b46605960bd0 Keith Busch     2016-07-21  2947  	 */
1c02ea81006548a Mika Westerberg 2017-10-13  2948  	if (bus->self && bus->self->is_hotplug_bridge) {
1c02ea81006548a Mika Westerberg 2017-10-13  2949  		used_buses = max_t(unsigned int, available_buses,
1c02ea81006548a Mika Westerberg 2017-10-13  2950  				   pci_hotplug_bus_size - 1);
1c02ea81006548a Mika Westerberg 2017-10-13  2951  		if (max - start < used_buses) {
1c02ea81006548a Mika Westerberg 2017-10-13  2952  			max = start + used_buses;
a20c7f36bd3d20d Mika Westerberg 2017-10-13  2953  
a20c7f36bd3d20d Mika Westerberg 2017-10-13  2954  			/* Do not allocate more buses than we have room left */
a20c7f36bd3d20d Mika Westerberg 2017-10-13  2955  			if (max > bus->busn_res.end)
a20c7f36bd3d20d Mika Westerberg 2017-10-13  2956  				max = bus->busn_res.end;
1c02ea81006548a Mika Westerberg 2017-10-13  2957  
1c02ea81006548a Mika Westerberg 2017-10-13  2958  			dev_dbg(&bus->dev, "%pR extended by %#02x\n",
1c02ea81006548a Mika Westerberg 2017-10-13  2959  				&bus->busn_res, max - start);
1c02ea81006548a Mika Westerberg 2017-10-13  2960  		}
e16b46605960bd0 Keith Busch     2016-07-21  2961  	}
e16b46605960bd0 Keith Busch     2016-07-21  2962  
^1da177e4c3f415 Linus Torvalds  2005-04-16  2963  	/*
^1da177e4c3f415 Linus Torvalds  2005-04-16  2964  	 * We've scanned the bus and so we know all about what's on
^1da177e4c3f415 Linus Torvalds  2005-04-16  2965  	 * the other side of any bridges that may be on this bus plus
^1da177e4c3f415 Linus Torvalds  2005-04-16  2966  	 * any devices.
^1da177e4c3f415 Linus Torvalds  2005-04-16  2967  	 *
^1da177e4c3f415 Linus Torvalds  2005-04-16  2968  	 * Return how far we've got finding sub-buses.
^1da177e4c3f415 Linus Torvalds  2005-04-16  2969  	 */
0207c356ef0e2ba Bjorn Helgaas   2009-11-04  2970  	dev_dbg(&bus->dev, "bus scan returning with max=%02x\n", max);
^1da177e4c3f415 Linus Torvalds  2005-04-16  2971  	return max;
^1da177e4c3f415 Linus Torvalds  2005-04-16  2972  }
1c02ea81006548a Mika Westerberg 2017-10-13  2973  

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-04-13 22:12 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-12 14:30 [PATCH v2 0/4] PCI: Rework pci_scan_slot() and isolated PCI functions Niklas Schnelle
2022-04-12 14:30 ` [PATCH v2 1/4] PCI: Clean up pci_scan_slot() Niklas Schnelle
2022-04-12 15:24   ` Niklas Schnelle
2022-04-12 14:30 ` [PATCH v2 2/4] PCI: Move jailhouse's isolated function handling to pci_scan_slot() Niklas Schnelle
2022-04-12 16:28   ` kernel test robot
2022-04-13  7:55     ` Niklas Schnelle
2022-04-13  7:55       ` Niklas Schnelle
2022-04-12 19:43   ` kernel test robot
2022-04-12 14:30 ` [PATCH v2 3/4] PCI: Extend isolated function probing to s390 Niklas Schnelle
2022-04-12 14:30 ` [PATCH v2 4/4] s390/pci: allow zPCI zbus without a function zero Niklas Schnelle
2022-04-13 22:12 [PATCH v2 2/4] PCI: Move jailhouse's isolated function handling to pci_scan_slot() kernel test robot

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.