* [PATCH v2 01/16] PCI: Add pci_bus_size_and_assign_resources()
2026-11-20 13:46 [PATCH v2 00/16] PCI: Serialize bridge window sizing and resource assignment Ilpo Järvinen
@ 2026-11-20 13:46 ` Ilpo Järvinen
2026-11-20 13:46 ` [PATCH v2 02/16] alpha/PCI: Convert to pci_bus_size_and_assign_resources() Ilpo Järvinen
` (14 subsequent siblings)
15 siblings, 0 replies; 18+ messages in thread
From: Ilpo Järvinen @ 2026-11-20 13:46 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi, Rob Herring,
Krzysztof Wilczyński, Rafael J. Wysocki (Intel),
Russell King, Greg Ungerer, Geert Uytterhoeven,
Thomas Bogendoerfer, Yoshinori Sato, Rich Felker,
John Paul Adrian Glaubitz, James E.J. Bottomley, Helge Deller,
Len Brown, Dominik Brodowski, linux-arm-kernel, linux-kernel,
linux-m68k, linux-mips, linux-sh, linux-parisc, linux-acpi
Cc: Ilpo Järvinen, stable
Bridge window sizing and resource assignment must not run concurrently
with another sizing and assignment pass or with device removal.
Preventing that requires holding locks across both phases. Many callers
outside of PCI core call pci_bus_size_bridges() immediately followed by
pci_bus_assign_resources() and cannot hold the PCI core internal locks
across the two calls.
Add pci_bus_size_and_assign_resources() into PCI core which combines
these two operations and convert the callers that call them back to
back.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Acked-by: Rafael J. Wysocki (Intel) <rafael@kernel.org>
Cc: stable@vger.kernel.org
---
arch/arm/kernel/bios32.c | 5 ++---
arch/m68k/coldfire/pci.c | 3 +--
arch/mips/pci/pci-legacy.c | 5 ++---
arch/sh/drivers/pci/pci.c | 3 +--
drivers/parisc/lba_pci.c | 7 ++-----
drivers/pci/hotplug/acpiphp_glue.c | 3 +--
drivers/pci/setup-bus.c | 7 +++++++
drivers/pcmcia/cardbus.c | 3 +--
include/linux/pci.h | 1 +
9 files changed, 18 insertions(+), 19 deletions(-)
diff --git a/arch/arm/kernel/bios32.c b/arch/arm/kernel/bios32.c
index ac0e890510da..555bfb091d30 100644
--- a/arch/arm/kernel/bios32.c
+++ b/arch/arm/kernel/bios32.c
@@ -510,15 +510,14 @@ void pci_common_init_dev(struct device *parent, struct hw_pci *hw)
/*
* We insert PCI resources into the iomem_resource and
* ioport_resource trees in either pci_bus_claim_resources()
- * or pci_bus_assign_resources().
+ * or pci_bus_size_and_assign_resources().
*/
if (pci_has_flag(PCI_PROBE_ONLY)) {
pci_bus_claim_resources(bus);
} else {
struct pci_bus *child;
- pci_bus_size_bridges(bus);
- pci_bus_assign_resources(bus);
+ pci_bus_size_and_assign_resources(bus);
list_for_each_entry(child, &bus->children, node)
pcie_bus_configure_settings(child);
diff --git a/arch/m68k/coldfire/pci.c b/arch/m68k/coldfire/pci.c
index 5afb207ccc51..dd21c77c43a6 100644
--- a/arch/m68k/coldfire/pci.c
+++ b/arch/m68k/coldfire/pci.c
@@ -250,8 +250,7 @@ static int __init mcf_pci_init(void)
rootbus->resource[0] = &mcf_pci_io;
rootbus->resource[1] = &mcf_pci_mem;
- pci_bus_size_bridges(rootbus);
- pci_bus_assign_resources(rootbus);
+ pci_bus_size_and_assign_resources(rootbus);
pci_bus_add_devices(rootbus);
return 0;
}
diff --git a/arch/mips/pci/pci-legacy.c b/arch/mips/pci/pci-legacy.c
index dae6dafdd6e0..ec0e42d9a895 100644
--- a/arch/mips/pci/pci-legacy.c
+++ b/arch/mips/pci/pci-legacy.c
@@ -129,15 +129,14 @@ static void pcibios_scanbus(struct pci_controller *hose)
/*
* We insert PCI resources into the iomem_resource and
* ioport_resource trees in either pci_bus_claim_resources()
- * or pci_bus_assign_resources().
+ * or pci_bus_size_and_assign_resources().
*/
if (pci_has_flag(PCI_PROBE_ONLY)) {
pci_bus_claim_resources(bus);
} else {
struct pci_bus *child;
- pci_bus_size_bridges(bus);
- pci_bus_assign_resources(bus);
+ pci_bus_size_and_assign_resources(bus);
list_for_each_entry(child, &bus->children, node)
pcie_bus_configure_settings(child);
}
diff --git a/arch/sh/drivers/pci/pci.c b/arch/sh/drivers/pci/pci.c
index 878a27a1acfb..c91ca8f4cb1c 100644
--- a/arch/sh/drivers/pci/pci.c
+++ b/arch/sh/drivers/pci/pci.c
@@ -81,8 +81,7 @@ static void pcibios_scanbus(struct pci_channel *hose)
need_domain_info = 1;
}
- pci_bus_size_bridges(hose->bus);
- pci_bus_assign_resources(hose->bus);
+ pci_bus_size_and_assign_resources(hose->bus);
pci_bus_add_devices(hose->bus);
}
diff --git a/drivers/parisc/lba_pci.c b/drivers/parisc/lba_pci.c
index 5197a3c93c70..39ab93ba458b 100644
--- a/drivers/parisc/lba_pci.c
+++ b/drivers/parisc/lba_pci.c
@@ -1639,11 +1639,8 @@ lba_driver_probe(struct parisc_device *dev)
if (is_pdc_pat()) {
/* assign resources to un-initialized devices */
- DBG_PAT("LBA pci_bus_size_bridges()\n");
- pci_bus_size_bridges(lba_bus);
-
- DBG_PAT("LBA pci_bus_assign_resources()\n");
- pci_bus_assign_resources(lba_bus);
+ DBG_PAT("LBA pci_bus_size_and_assign_resources()\n");
+ pci_bus_size_and_assign_resources(lba_bus);
#ifdef DEBUG_LBA_PAT
DBG_PAT("\nLBA PIOP resource tree\n");
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index 78e3effbb32d..632344f34cae 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -465,8 +465,7 @@ static void acpiphp_native_scan_bridge(struct pci_dev *bridge)
max = pci_scan_bridge(bus, dev, max, 1);
if (dev->subordinate) {
pcibios_resource_survey_bus(dev->subordinate);
- pci_bus_size_bridges(dev->subordinate);
- pci_bus_assign_resources(dev->subordinate);
+ pci_bus_size_and_assign_resources(dev->subordinate);
}
}
}
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index ed16ef7c26fa..29ec9ba59d92 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -2492,3 +2492,10 @@ void pci_assign_unassigned_bus_resources(struct pci_bus *bus)
__pci_bus_assign_resources(bus, &add_list, NULL);
}
EXPORT_SYMBOL_GPL(pci_assign_unassigned_bus_resources);
+
+void pci_bus_size_and_assign_resources(struct pci_bus *bus)
+{
+ pci_bus_size_bridges(bus);
+ __pci_bus_assign_resources(bus, NULL, NULL);
+}
+EXPORT_SYMBOL_GPL(pci_bus_size_and_assign_resources);
diff --git a/drivers/pcmcia/cardbus.c b/drivers/pcmcia/cardbus.c
index 5e5cf2c3e2c8..19df3f9228a7 100644
--- a/drivers/pcmcia/cardbus.c
+++ b/drivers/pcmcia/cardbus.c
@@ -81,8 +81,7 @@ int __ref cb_alloc(struct pcmcia_socket *s)
/*
* Size all resources below the CardBus controller.
*/
- pci_bus_size_bridges(bus);
- pci_bus_assign_resources(bus);
+ pci_bus_size_and_assign_resources(bus);
cardbus_config_irq_and_cls(bus, s->pci_irq);
/* socket specific tune function */
diff --git a/include/linux/pci.h b/include/linux/pci.h
index aa3765a20a96..d89aeb7c9ff7 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1569,6 +1569,7 @@ resource_size_t pcibios_retrieve_fw_addr(struct pci_dev *dev, int idx);
void pci_bus_assign_resources(const struct pci_bus *bus);
void pci_bus_claim_resources(struct pci_bus *bus);
void pci_bus_size_bridges(struct pci_bus *bus);
+void pci_bus_size_and_assign_resources(struct pci_bus *bus);
int pci_claim_resource(struct pci_dev *, int);
int pci_claim_bridge_resource(struct pci_dev *bridge, int i);
void pci_assign_unassigned_resources(void);
--
2.47.3
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v2 02/16] alpha/PCI: Convert to pci_bus_size_and_assign_resources()
2026-11-20 13:46 [PATCH v2 00/16] PCI: Serialize bridge window sizing and resource assignment Ilpo Järvinen
2026-11-20 13:46 ` [PATCH v2 01/16] PCI: Add pci_bus_size_and_assign_resources() Ilpo Järvinen
@ 2026-11-20 13:46 ` Ilpo Järvinen
2026-11-20 13:46 ` [PATCH v2 03/16] PCI: Use guard() for pci_bus_sem in pci_do_resource_release_and_resize() Ilpo Järvinen
` (13 subsequent siblings)
15 siblings, 0 replies; 18+ messages in thread
From: Ilpo Järvinen @ 2026-11-20 13:46 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi, Rob Herring,
Krzysztof Wilczyński, Rafael J. Wysocki (Intel),
Richard Henderson, Matt Turner, Magnus Lindholm, linux-alpha,
linux-kernel
Cc: Ilpo Järvinen, stable
To serialize bridge window sizing and resource assignment, PCI core
needs to hold locks across both phases. Alpha nautilus PCI code calls
pci_bus_size_bridges() and pci_bus_assign_resources() separately
because it needs to do special resource alignment and setup after the
window sizes have been calculated. At least the former would seem to
belong to some existing __weak pcibios_*() hook but the latter might
need yet another pcibios_*() hook just for this single use.
The nautilus code runs during init, so nothing is likely to race with
it. Converting it is mainly about consolidating the sizing and
assignment entrypoints of PCI core, which eventually allows removing
pci_bus_assign_resources().
Instead of trying to do a complex rework of the code, which is risky
without the ability to test on the hardware, simply convert
pci_bus_assign_resources() to pci_bus_size_and_assign_resources(). This
adds a small bit of extra work by performing the sizing step again. The
Irongate PCI memory window is a host bridge window and not a device
resource, so the resource assignment algorithm does not move or release
it, and sizing does not change it either once it has been registered.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Acked-by: Magnus Lindholm <linmag7@gmail.com>
Cc: stable@vger.kernel.org
---
arch/alpha/kernel/sys_nautilus.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/alpha/kernel/sys_nautilus.c b/arch/alpha/kernel/sys_nautilus.c
index 13b79960b4b9..23a74fd4a83f 100644
--- a/arch/alpha/kernel/sys_nautilus.c
+++ b/arch/alpha/kernel/sys_nautilus.c
@@ -263,7 +263,7 @@ nautilus_init_pci(void)
if ((IRONGATE0->dev_vendor >> 16) > 0x7006) /* Albacore? */
IRONGATE0->pci_mem = pci_mem;
- pci_bus_assign_resources(bus);
+ pci_bus_size_and_assign_resources(bus);
pci_bus_add_devices(bus);
}
--
2.47.3
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v2 03/16] PCI: Use guard() for pci_bus_sem in pci_do_resource_release_and_resize()
2026-11-20 13:46 [PATCH v2 00/16] PCI: Serialize bridge window sizing and resource assignment Ilpo Järvinen
2026-11-20 13:46 ` [PATCH v2 01/16] PCI: Add pci_bus_size_and_assign_resources() Ilpo Järvinen
2026-11-20 13:46 ` [PATCH v2 02/16] alpha/PCI: Convert to pci_bus_size_and_assign_resources() Ilpo Järvinen
@ 2026-11-20 13:46 ` Ilpo Järvinen
2026-11-20 13:46 ` [PATCH v2 04/16] PCI: Add pci_assign_unassigned_slot_resources() Ilpo Järvinen
` (12 subsequent siblings)
15 siblings, 0 replies; 18+ messages in thread
From: Ilpo Järvinen @ 2026-11-20 13:46 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi, Rob Herring,
Krzysztof Wilczyński, Rafael J. Wysocki (Intel),
linux-kernel
Cc: Ilpo Järvinen, stable
pci_do_resource_release_and_resize() releases pci_bus_sem on its common
exit path, which it shares with freeing the saved resource list. Move
the body into __pci_do_resource_release_and_resize() and take
pci_bus_sem with guard() in pci_do_resource_release_and_resize() to make
adding more locking simpler without mixing goto-based cleanup with
guard().
pci_bus_sem now also covers selecting the bridge window.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Cc: stable@vger.kernel.org
---
drivers/pci/setup-bus.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 29ec9ba59d92..10b9d3eb2864 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -26,6 +26,8 @@
#include <linux/ioport.h>
#include <linux/cache.h>
#include <linux/limits.h>
+#include <linux/lockdep.h>
+#include <linux/rwsem.h>
#include <linux/sizes.h>
#include <linux/slab.h>
#include <linux/acpi.h>
@@ -2374,8 +2376,9 @@ static int pbus_reassign_bridge_resources(struct pci_bus *bus, struct resource *
return 0;
}
-int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size,
- int exclude_bars)
+static int __pci_do_resource_release_and_resize(struct pci_dev *pdev,
+ int resno, int size,
+ int exclude_bars)
{
struct resource *res = pci_resource_n(pdev, resno);
struct pci_dev_resource *dev_res;
@@ -2386,6 +2389,8 @@ int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size
unsigned int i;
int old, ret;
+ lockdep_assert_held(&pci_bus_sem);
+
b_win = pbus_select_window(bus, res);
if (!b_win)
return -EINVAL;
@@ -2398,8 +2403,6 @@ int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size
if (ret)
return ret;
- down_read(&pci_bus_sem);
-
pci_dev_for_each_resource(pdev, r, i) {
if (i >= PCI_BRIDGE_RESOURCES)
break;
@@ -2435,7 +2438,6 @@ int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size
}
out:
- up_read(&pci_bus_sem);
pci_dev_res_free_list(&saved);
return ret;
@@ -2478,6 +2480,15 @@ int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size
goto out;
}
+int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size,
+ int exclude_bars)
+{
+ guard(rwsem_read)(&pci_bus_sem);
+
+ return __pci_do_resource_release_and_resize(pdev, resno, size,
+ exclude_bars);
+}
+
void pci_assign_unassigned_bus_resources(struct pci_bus *bus)
{
struct pci_dev *dev;
--
2.47.3
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v2 04/16] PCI: Add pci_assign_unassigned_slot_resources()
2026-11-20 13:46 [PATCH v2 00/16] PCI: Serialize bridge window sizing and resource assignment Ilpo Järvinen
` (2 preceding siblings ...)
2026-11-20 13:46 ` [PATCH v2 03/16] PCI: Use guard() for pci_bus_sem in pci_do_resource_release_and_resize() Ilpo Järvinen
@ 2026-11-20 13:46 ` Ilpo Järvinen
2026-11-20 13:47 ` [PATCH v2 05/16] PCI: acpiphp: Use pci_assign_unassigned_slot_resources() Ilpo Järvinen
` (11 subsequent siblings)
15 siblings, 0 replies; 18+ messages in thread
From: Ilpo Järvinen @ 2026-11-20 13:46 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi, Rob Herring,
Krzysztof Wilczyński, Rafael J. Wysocki (Intel),
linux-kernel
Cc: Ilpo Järvinen, stable
Bridge window sizing and resource assignment need locks that are held
across both phases. acpiphp open-codes
pci_assign_unassigned_bus_resources() with a slot filter by calling the
internal sizing and assignment functions directly, so it would have to
duplicate that locking.
Add pci_assign_unassigned_slot_resources() which sizes only the bridges
in the given slot, and implement pci_assign_unassigned_bus_resources()
with it.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Cc: stable@vger.kernel.org
---
drivers/pci/pci.h | 1 +
drivers/pci/setup-bus.c | 23 +++++++++++++++++++++--
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 77efa4c5c960..ce29d9ca0194 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -542,6 +542,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus,
void __pci_bus_assign_resources(const struct pci_bus *bus,
struct list_head *add_list,
struct list_head *fail_head);
+void pci_assign_unassigned_slot_resources(struct pci_bus *bus, u16 slot);
bool pci_bus_clip_resource(struct pci_dev *dev, int idx);
void pci_walk_bus_locked(struct pci_bus *top,
int (*cb)(struct pci_dev *, void *),
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 10b9d3eb2864..7d135ddd93b2 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -2489,19 +2489,38 @@ int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size
exclude_bars);
}
-void pci_assign_unassigned_bus_resources(struct pci_bus *bus)
+/**
+ * pci_assign_unassigned_slot_resources - Size and assign resources of a slot
+ * @bus: PCI bus
+ * @slot: Slot whose bridges to size, or %PCI_SLOT_ALL_DEVICES for all
+ * bridges on @bus
+ *
+ * Size the bridge windows of the bridges in @slot and assign unassigned
+ * resources on @bus.
+ */
+void pci_assign_unassigned_slot_resources(struct pci_bus *bus, u16 slot)
{
struct pci_dev *dev;
/* List of resources that want additional resources */
LIST_HEAD(add_list);
down_read(&pci_bus_sem);
- for_each_pci_bridge(dev, bus)
+ for_each_pci_bridge(dev, bus) {
+ if (slot != PCI_SLOT_ALL_DEVICES &&
+ PCI_SLOT(dev->devfn) != slot)
+ continue;
+
if (pci_has_subordinate(dev))
__pci_bus_size_bridges(dev->subordinate, &add_list);
+ }
up_read(&pci_bus_sem);
__pci_bus_assign_resources(bus, &add_list, NULL);
}
+
+void pci_assign_unassigned_bus_resources(struct pci_bus *bus)
+{
+ pci_assign_unassigned_slot_resources(bus, PCI_SLOT_ALL_DEVICES);
+}
EXPORT_SYMBOL_GPL(pci_assign_unassigned_bus_resources);
void pci_bus_size_and_assign_resources(struct pci_bus *bus)
--
2.47.3
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v2 05/16] PCI: acpiphp: Use pci_assign_unassigned_slot_resources()
2026-11-20 13:46 [PATCH v2 00/16] PCI: Serialize bridge window sizing and resource assignment Ilpo Järvinen
` (3 preceding siblings ...)
2026-11-20 13:46 ` [PATCH v2 04/16] PCI: Add pci_assign_unassigned_slot_resources() Ilpo Järvinen
@ 2026-11-20 13:47 ` Ilpo Järvinen
2026-11-20 14:33 ` Rafael J. Wysocki (Intel)
2026-11-20 13:47 ` [PATCH v2 06/16] PCI: Hold pci_bus_sem across sizing and assignment entrypoints Ilpo Järvinen
` (10 subsequent siblings)
15 siblings, 1 reply; 18+ messages in thread
From: Ilpo Järvinen @ 2026-11-20 13:47 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi, Rob Herring,
Krzysztof Wilczyński, Rafael J. Wysocki (Intel),
Len Brown, linux-acpi, linux-kernel
Cc: Ilpo Järvinen, stable
enable_slot() calls the internal sizing and assignment functions
directly to size only the bridges in the slot. Use
pci_assign_unassigned_slot_resources() instead.
Sizing now happens after scanning all bridges in the slot instead of
right after scanning each bridge. Sizing a bridge window only walks the
hierarchy below that bridge, so the order does not matter. Sizing now
also holds pci_bus_sem.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Cc: stable@vger.kernel.org
---
drivers/pci/hotplug/acpiphp_glue.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index 632344f34cae..fc95d5814ecb 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -497,7 +497,6 @@ static void enable_slot(struct acpiphp_slot *slot, bool bridge)
acpiphp_native_scan_bridge(dev);
}
} else {
- LIST_HEAD(add_list);
int max, pass;
acpiphp_rescan_slot(slot);
@@ -511,12 +510,10 @@ static void enable_slot(struct acpiphp_slot *slot, bool bridge)
if (pass && dev->subordinate) {
check_hotplug_bridge(slot, dev);
pcibios_resource_survey_bus(dev->subordinate);
- __pci_bus_size_bridges(dev->subordinate,
- &add_list);
}
}
}
- __pci_bus_assign_resources(bus, &add_list, NULL);
+ pci_assign_unassigned_slot_resources(bus, slot->device);
}
acpiphp_sanitize_bus(bus);
--
2.47.3
^ permalink raw reply [flat|nested] 18+ messages in thread* Re: [PATCH v2 05/16] PCI: acpiphp: Use pci_assign_unassigned_slot_resources()
2026-11-20 13:47 ` [PATCH v2 05/16] PCI: acpiphp: Use pci_assign_unassigned_slot_resources() Ilpo Järvinen
@ 2026-11-20 14:33 ` Rafael J. Wysocki (Intel)
0 siblings, 0 replies; 18+ messages in thread
From: Rafael J. Wysocki (Intel) @ 2026-11-20 14:33 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi, Rob Herring,
Krzysztof Wilczyński, Rafael J. Wysocki (Intel),
Len Brown, linux-acpi, linux-kernel, stable
On Fri, Nov 20, 2026 at 2:48 PM Ilpo Järvinen
<ilpo.jarvinen@linux.intel.com> wrote:
>
> enable_slot() calls the internal sizing and assignment functions
> directly to size only the bridges in the slot. Use
> pci_assign_unassigned_slot_resources() instead.
>
> Sizing now happens after scanning all bridges in the slot instead of
> right after scanning each bridge. Sizing a bridge window only walks the
> hierarchy below that bridge, so the order does not matter. Sizing now
> also holds pci_bus_sem.
>
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> Cc: stable@vger.kernel.org
LGTM
Acked-by: Rafael J. Wysocki (Intel) <rafael@kernel.org>
> ---
> drivers/pci/hotplug/acpiphp_glue.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
> index 632344f34cae..fc95d5814ecb 100644
> --- a/drivers/pci/hotplug/acpiphp_glue.c
> +++ b/drivers/pci/hotplug/acpiphp_glue.c
> @@ -497,7 +497,6 @@ static void enable_slot(struct acpiphp_slot *slot, bool bridge)
> acpiphp_native_scan_bridge(dev);
> }
> } else {
> - LIST_HEAD(add_list);
> int max, pass;
>
> acpiphp_rescan_slot(slot);
> @@ -511,12 +510,10 @@ static void enable_slot(struct acpiphp_slot *slot, bool bridge)
> if (pass && dev->subordinate) {
> check_hotplug_bridge(slot, dev);
> pcibios_resource_survey_bus(dev->subordinate);
> - __pci_bus_size_bridges(dev->subordinate,
> - &add_list);
> }
> }
> }
> - __pci_bus_assign_resources(bus, &add_list, NULL);
> + pci_assign_unassigned_slot_resources(bus, slot->device);
> }
>
> acpiphp_sanitize_bus(bus);
> --
> 2.47.3
>
>
^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH v2 06/16] PCI: Hold pci_bus_sem across sizing and assignment entrypoints
2026-11-20 13:46 [PATCH v2 00/16] PCI: Serialize bridge window sizing and resource assignment Ilpo Järvinen
` (4 preceding siblings ...)
2026-11-20 13:47 ` [PATCH v2 05/16] PCI: acpiphp: Use pci_assign_unassigned_slot_resources() Ilpo Järvinen
@ 2026-11-20 13:47 ` Ilpo Järvinen
2026-11-20 13:47 ` [PATCH v2 07/16] PCI: Serialize bridge window sizing and resource assignment Ilpo Järvinen
` (9 subsequent siblings)
15 siblings, 0 replies; 18+ messages in thread
From: Ilpo Järvinen @ 2026-11-20 13:47 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi, Rob Herring,
Krzysztof Wilczyński, Rafael J. Wysocki (Intel),
linux-kernel
Cc: Ilpo Järvinen, stable
The bridge window sizing and resource assignment algorithm walks
bus->devices and inserts resources of the found devices into the
resource tree in many places. In addition, its internal datastructures
hold references to devices and resources it encountered while walking.
Most entrypoints to the algorithm do not hold pci_bus_sem, and
pci_assign_unassigned_bus_resources() drops it before the assignment
phase.
pci_rescan_remove_lock is not held by all callers and cannot be taken
by callers running under device_lock().
Protect the walks by holding pci_bus_sem for read across the entire
sizing and assignment operation right at the entrypoints.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Cc: stable@vger.kernel.org
---
drivers/pci/setup-bus.c | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 7d135ddd93b2..966e0f243032 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1459,6 +1459,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head)
void pci_bus_size_bridges(struct pci_bus *bus)
{
+ guard(rwsem_read)(&pci_bus_sem);
__pci_bus_size_bridges(bus, NULL);
}
EXPORT_SYMBOL(pci_bus_size_bridges);
@@ -1551,6 +1552,7 @@ void __pci_bus_assign_resources(const struct pci_bus *bus,
void pci_bus_assign_resources(const struct pci_bus *bus)
{
+ guard(rwsem_read)(&pci_bus_sem);
__pci_bus_assign_resources(bus, NULL, NULL);
}
EXPORT_SYMBOL(pci_bus_assign_resources);
@@ -1839,7 +1841,7 @@ static enum enable_type pci_realloc_detect(struct pci_bus *bus,
if (host->preserve_config)
return auto_disabled;
- pci_walk_bus(bus, iov_resources_unassigned, &unassigned);
+ pci_walk_bus_locked(bus, iov_resources_unassigned, &unassigned);
if (unassigned)
return auto_enabled;
@@ -2192,6 +2194,8 @@ void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus)
int pci_try_num = 1;
enum enable_type enable_local;
+ guard(rwsem_read)(&pci_bus_sem);
+
/* Don't realloc if asked to do so */
enable_local = pci_realloc_detect(bus, pci_realloc_enable);
if (pci_realloc_enabled(enable_local)) {
@@ -2260,14 +2264,15 @@ void pci_assign_unassigned_resources(void)
}
}
-void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
+static void pci_bridge_size_and_assign_resources(struct pci_dev *bridge)
{
struct pci_bus *parent = bridge->subordinate;
/* List of resources that want additional resources */
LIST_HEAD(add_list);
int tried_times = 0;
LIST_HEAD(fail_head);
- int ret;
+
+ guard(rwsem_read)(&pci_bus_sem);
while (1) {
__pci_bus_size_bridges(parent, &add_list);
@@ -2294,6 +2299,13 @@ void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
pci_prepare_next_assign_round(&fail_head, tried_times,
whole_subtree);
}
+}
+
+void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
+{
+ int ret;
+
+ pci_bridge_size_and_assign_resources(bridge);
ret = pci_reenable_device(bridge);
if (ret)
@@ -2427,7 +2439,7 @@ static int __pci_do_resource_release_and_resize(struct pci_dev *pdev,
goto restore;
} else {
/* No bridge window to adjust; let the core reassign the bus. */
- pci_bus_assign_resources(bus);
+ __pci_bus_assign_resources(bus, NULL, NULL);
list_for_each_entry(dev_res, &saved, list) {
if (!resource_assigned(dev_res->res)) {
@@ -2504,7 +2516,7 @@ void pci_assign_unassigned_slot_resources(struct pci_bus *bus, u16 slot)
/* List of resources that want additional resources */
LIST_HEAD(add_list);
- down_read(&pci_bus_sem);
+ guard(rwsem_read)(&pci_bus_sem);
for_each_pci_bridge(dev, bus) {
if (slot != PCI_SLOT_ALL_DEVICES &&
PCI_SLOT(dev->devfn) != slot)
@@ -2513,7 +2525,6 @@ void pci_assign_unassigned_slot_resources(struct pci_bus *bus, u16 slot)
if (pci_has_subordinate(dev))
__pci_bus_size_bridges(dev->subordinate, &add_list);
}
- up_read(&pci_bus_sem);
__pci_bus_assign_resources(bus, &add_list, NULL);
}
@@ -2525,7 +2536,8 @@ EXPORT_SYMBOL_GPL(pci_assign_unassigned_bus_resources);
void pci_bus_size_and_assign_resources(struct pci_bus *bus)
{
- pci_bus_size_bridges(bus);
+ guard(rwsem_read)(&pci_bus_sem);
+ __pci_bus_size_bridges(bus, NULL);
__pci_bus_assign_resources(bus, NULL, NULL);
}
EXPORT_SYMBOL_GPL(pci_bus_size_and_assign_resources);
--
2.47.3
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v2 07/16] PCI: Serialize bridge window sizing and resource assignment
2026-11-20 13:46 [PATCH v2 00/16] PCI: Serialize bridge window sizing and resource assignment Ilpo Järvinen
` (5 preceding siblings ...)
2026-11-20 13:47 ` [PATCH v2 06/16] PCI: Hold pci_bus_sem across sizing and assignment entrypoints Ilpo Järvinen
@ 2026-11-20 13:47 ` Ilpo Järvinen
2026-11-20 13:47 ` [PATCH v2 08/16] PCI: Make internal sizing and assignment functions static Ilpo Järvinen
` (8 subsequent siblings)
15 siblings, 0 replies; 18+ messages in thread
From: Ilpo Järvinen @ 2026-11-20 13:47 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi, Rob Herring,
Krzysztof Wilczyński, Rafael J. Wysocki (Intel),
Christian König, Alex Williamson, linux-kernel
Cc: Ilpo Järvinen, stable
Bridge window sizing and resource assignment are started from multiple
entrypoints: rescan and hotplug under pci_rescan_remove_lock, and BAR
resize from sysfs or driver probe under device_lock() only. The
entrypoints hold pci_bus_sem only for read, so nothing prevents two
sizing and assignment passes from running concurrently on the same
bridge windows and BARs. E.g., a rescan may assign a BAR that a
concurrent BAR resize has released, or restore a resource the resize has
already assigned.
Looping BAR resize through sysfs against a rescan of the parent bus on a
system with a BMG GPU triggers the add_list sanity check. The rescan
sizes the Downstream Port's prefetchable window while the resize assigns
it, and the sizing values overwrite the assigned window. The resize then
programs these values into the Downstream Port, outside the root bus
resources and overlapping System RAM [mem 0x100000000-0x4075ffffff]. The
rescan skips assigning the window as it looks assigned, which leaves its
add_list entry unused:
pci_bus 0000:b7: root bus resource [mem 0xd6000000-0xddfbffff window]
pci_bus 0000:b7: root bus resource [mem 0x2e0000000000-0x2effffffffff window]
pcieport 0000:b9:01.0: bridge window [mem 0x800000000-0x1000ffffff 64bit pref] to [bus ba] add_size 4000000 add_align 800000000
pcieport 0000:b9:01.0: PCI bridge to [bus ba]
pcieport 0000:b9:01.0: bridge window [mem 0xdda00000-0xddbfffff]
pcieport 0000:b9:01.0: bridge window [mem 0x800000000-0x1000ffffff 64bit pref]
add_list && !list_empty(add_list)
WARNING: drivers/pci/setup-bus.c:1546 at pci_assign_unassigned_bus_resources+0x9e/0x130, CPU#58: srf8-resize-rac/2861
CPU: 58 UID: 0 PID: 2861 Comm: srf8-resize-rac Tainted: G S 7.4.0-rc1-g6628e7d4c6b2 #59 PREEMPT(full)
RIP: 0010:pci_assign_unassigned_bus_resources+0x9e/0x130
Call Trace:
pci_rescan_bus+0x20/0x40
dev_rescan_store+0x6e/0x90
Other trigger vectors are possible as well. Hotplug takes the same locks
as the sysfs rescan. BAR resize walks the bridge windows up to the Root
Port to make room for the resized BAR, and then sizes and assigns the
whole hierarchy below the Root Port. Thus, hotplug anywhere below the
same Root Port can race with the resize, e.g., when connecting a
Thunderbolt device. Instead of the sysfs resize, a driver can resize a
BAR during probe, e.g., after unbind and bind.
pci_rescan_remove_lock cannot be taken under device_lock() because the
device removal path takes them in the opposite order.
Add pci_res_setup_lock and hold it across sizing and assignment in all
entrypoints. Assert the lock is held in the functions that modify
resources deeper in the call chains. In
pci_do_resource_release_and_resize(), take the lock before selecting the
bridge window and setting the BAR size as both depend on or change
resource state.
The race was also reproduced in QEMU, which found more symptoms.
Looping BAR resize through sysfs against a rescan of the parent bus on
a guest with 512M of RAM, using a synthetic host bridge with a Root Port
and an Endpoint with a Resizable BAR, triggers the following failures:
1) Both the rescan and the resize release the Root Port's prefetchable
window. Both find it assigned, but the rescan releases it first, and
the resize then dereferences the NULL parent in __release_resource():
pcieport 10000:00:00.0: bridge window [mem 0x940000000-0x97fffffff 64bit pref]: releasing
pcieport 10000:00:00.0: bridge window [mem size 0x40000000 64bit pref]: releasing
BUG: kernel NULL pointer dereference, address: 0000000000000038
Oops: Oops: 0000 [#1] SMP
CPU: 0 UID: 0 PID: 49 Comm: init Not tainted 7.4.0-rc1-00001-g4aa3acaaeb08 #1 PREEMPTLAZY
RIP: 0010:__release_resource+0x8/0x70
Call Trace:
release_resource+0x22/0x40
pci_release_resource+0x54/0x90
pci_do_resource_release_and_resize+0x1f3/0x3d0
__resource_resize_store+0xf0/0x180
2) The rescan restores a resource that has already been assigned:
WARNING: drivers/pci/setup-bus.c:136 at pci_dev_res_restore+0x32/0x90, CPU#0: init/1
CPU: 0 UID: 0 PID: 1 Comm: init Not tainted 7.4.0-rc1-dirty #6 PREEMPTLAZY
RIP: 0010:pci_dev_res_restore+0x32/0x90
Call Trace:
__assign_resources_sorted+0x2db/0x570
__pci_bus_assign_resources_one+0x57/0x190
__pci_bus_assign_resources_one+0x12d/0x190
__pci_bus_assign_resources+0xd/0x30
pci_assign_unassigned_bus_resources+0x6f/0x80
pci_rescan_bus+0x1a/0x30
dev_rescan_store+0x46/0x60
3) The rescan assigns the BAR while the resize is assigning it, failing
the resize:
pci 10000:01:00.0: BAR 0 [mem 0x900000000-0x90fffffff 64bit pref]: releasing
pcieport 10000:00:00.0: bridge window [mem 0x900000000-0x90fffffff 64bit pref]: releasing
pci 10000:01:00.0: BAR 0 [mem size 0x40000000 64bit pref]: can't assign; no space
pcieport 10000:00:00.0: bridge window [mem 0x900000000-0x93fffffff 64bit pref]: assigned
pci 10000:01:00.0: BAR 0 [mem size 0x40000000 64bit pref]: failed to assign
pci 10000:01:00.0: BAR 0 [mem 0x900000000-0x93fffffff 64bit pref]: releasing
pci 10000:01:00.0: BAR 0 [mem 0x900000000-0x93fffffff 64bit pref]: assigned
pci 10000:01:00.0: BAR 0 [mem size 0x40000000 64bit pref]: resource restored
pci 10000:01:00.0: BAR 0 [mem 0x900000000-0x90fffffff 64bit pref]: old value restored
pci 10000:01:00.0: Failed to resize BAR 0: -28
4) While one pass is sorting a released bridge window for assignment,
the other pass assigns it, which clears IORESOURCE_STARTALIGN. The
window then has zero alignment:
pci 10000:01:00.0: BAR 0 [mem 0x900000000-0x93fffffff 64bit pref]: releasing
pcieport 10000:00:00.0: bridge window [mem 0x900000000-0x93fffffff 64bit pref]: releasing
pcieport 10000:00:00.0: bridge window [mem 0x900000000-0x90fffffff 64bit pref]: assigned
pcieport 10000:00:00.0: bridge window [mem 0x900000000-0x90fffffff 64bit pref]: alignment must not be zero
pci 10000:01:00.0: BAR 0 [mem 0x900000000-0x90fffffff 64bit pref]: assigned
5) BAR 0 loses its flags and the Root Port's prefetchable window gets
programmed over RAM, after which every BAR resize fails with -EINVAL:
pci 10000:01:00.0: BAR 0 [mem size 0x10000000 64bit pref]: can't assign; no space
resource: remaining [mem 0x000000001ffdf000-0x000000001fffffff] available
resource: avoiding allocation from e820 entry [mem 0x1ffdf000-0x1fffffff]
pci 10000:01:00.0: BAR 0 [mem size 0x10000000 64bit pref]: failed to assign
pci 10000:01:00.0: BAR 0 [mem size 0x10000000 64bit pref]: can't assign; no space
pci 10000:01:00.0: BAR 0 [mem size 0x10000000 64bit pref]: resetting resource
pci 10000:01:00.0: BAR 0 [??? 0x00000000 flags 0x0]: failed to assign
pci 10000:01:00.0: BAR 0 [??? 0x00000000 flags 0x0]: resetting resource
pcieport 10000:00:00.0: PCI bridge to [bus 01]
pcieport 10000:00:00.0: bridge window [mem 0x20000000-0x200fffff]
pcieport 10000:00:00.0: bridge window [mem 0x10000000-0x1fffffff 64bit pref]
pci 10000:01:00.0: Failed to resize BAR 0: -22
Fixes: 8bb705e3e79d ("PCI: Add pci_resize_resource() for resizing BARs")
Fixes: 91fa127794ac ("PCI: Expose PCIe Resizable BAR support via sysfs")
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Acked-by: Rafael J. Wysocki (Intel) <rafael@kernel.org>
Cc: stable@vger.kernel.org
---
Bjorn,
It's up to you if you want to keep all those qemu reproduced cases in the
changelog. You usually seem to prefer the log messages for easier googling
in case somebody happens to hit the issue so I added them all.
I couldn't get the rest to trigger on a real host but that could be due to
serial output that was too slow to keep up with the test loops which might
have affected timing.
drivers/pci/setup-bus.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 966e0f243032..f501fa63caab 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -27,6 +27,7 @@
#include <linux/cache.h>
#include <linux/limits.h>
#include <linux/lockdep.h>
+#include <linux/mutex.h>
#include <linux/rwsem.h>
#include <linux/sizes.h>
#include <linux/slab.h>
@@ -40,6 +41,17 @@
unsigned int pci_flags;
EXPORT_SYMBOL_GPL(pci_flags);
+/*
+ * Serializes bridge window sizing, resource fitting, and assignment.
+ * pci_rescan_remove_lock cannot be used for this because BAR resize and
+ * some drivers run these operations under device_lock() during probe.
+ *
+ * Context:
+ * - Nests inside pci_rescan_remove_lock and device_lock().
+ * - Nests outside pci_bus_sem.
+ */
+static DEFINE_MUTEX(pci_res_setup_lock);
+
struct pci_dev_resource {
struct list_head list;
struct resource *res;
@@ -135,6 +147,8 @@ static void pci_dev_res_restore(struct pci_dev_resource *dev_res)
int idx = pci_resource_num(dev, res);
const char *res_name = pci_resource_name(dev, idx);
+ lockdep_assert_held(&pci_res_setup_lock);
+
if (WARN_ON_ONCE(resource_assigned(res)))
return;
@@ -613,6 +627,8 @@ static void __assign_resources_sorted(struct list_head *head,
unsigned long fail_type;
resource_size_t align;
+ lockdep_assert_held(&pci_res_setup_lock);
+
if (!realloc_head)
realloc_head = &dummy_head;
@@ -895,6 +911,8 @@ static void __pci_setup_bridge(struct pci_bus *bus, unsigned long type)
{
struct pci_dev *bridge = bus->self;
+ lockdep_assert_held(&pci_res_setup_lock);
+
pci_info(bridge, "PCI bridge to %pR\n", &bus->busn_res);
if (type & IORESOURCE_IO)
@@ -975,6 +993,8 @@ static void pci_bridge_check_ranges(struct pci_bus *bus)
struct pci_dev *bridge = bus->self;
struct resource *b_res;
+ lockdep_assert_held(&pci_res_setup_lock);
+
b_res = &bridge->resource[PCI_BRIDGE_MEM_WINDOW];
b_res->flags |= IORESOURCE_MEM;
@@ -1079,6 +1099,8 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t add_size,
resource_size_t children_add_size = 0;
resource_size_t min_align, align;
+ lockdep_assert_held(&pci_res_setup_lock);
+
if (!b_res)
return;
@@ -1288,6 +1310,8 @@ static void pbus_size_mem(struct pci_bus *bus, struct resource *b_res,
resource_size_t children_add_size = 0;
resource_size_t add_align = 0;
+ lockdep_assert_held(&pci_res_setup_lock);
+
if (!b_res)
return;
@@ -1459,6 +1483,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head)
void pci_bus_size_bridges(struct pci_bus *bus)
{
+ guard(mutex)(&pci_res_setup_lock);
guard(rwsem_read)(&pci_bus_sem);
__pci_bus_size_bridges(bus, NULL);
}
@@ -1488,6 +1513,8 @@ static void pdev_assign_fixed_resources(struct pci_dev *dev)
{
struct resource *r;
+ lockdep_assert_held(&pci_res_setup_lock);
+
pci_dev_for_each_resource(dev, r) {
struct pci_bus *b;
@@ -1552,6 +1579,7 @@ void __pci_bus_assign_resources(const struct pci_bus *bus,
void pci_bus_assign_resources(const struct pci_bus *bus)
{
+ guard(mutex)(&pci_res_setup_lock);
guard(rwsem_read)(&pci_bus_sem);
__pci_bus_assign_resources(bus, NULL, NULL);
}
@@ -1665,6 +1693,8 @@ static void pci_bridge_release_resources(struct pci_bus *bus,
struct pci_dev *dev = bus->self;
int idx, ret;
+ lockdep_assert_held(&pci_res_setup_lock);
+
if (!resource_assigned(b_win))
return;
@@ -1862,6 +1892,8 @@ static void adjust_bridge_window(struct pci_dev *bridge, struct resource *res,
resource_size_t add_size, size = resource_size(res);
struct pci_dev_resource *dev_res;
+ lockdep_assert_held(&pci_res_setup_lock);
+
if (resource_assigned(res))
return;
@@ -2194,6 +2226,7 @@ void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus)
int pci_try_num = 1;
enum enable_type enable_local;
+ guard(mutex)(&pci_res_setup_lock);
guard(rwsem_read)(&pci_bus_sem);
/* Don't realloc if asked to do so */
@@ -2272,6 +2305,7 @@ static void pci_bridge_size_and_assign_resources(struct pci_dev *bridge)
int tried_times = 0;
LIST_HEAD(fail_head);
+ guard(mutex)(&pci_res_setup_lock);
guard(rwsem_read)(&pci_bus_sem);
while (1) {
@@ -2330,6 +2364,8 @@ static int pbus_reassign_bridge_resources(struct pci_bus *bus, struct resource *
unsigned int i;
int ret = 0;
+ lockdep_assert_held(&pci_res_setup_lock);
+
while (!pci_is_root_bus(bus)) {
bridge = bus->self;
res = pbus_select_window(bus, res);
@@ -2401,6 +2437,7 @@ static int __pci_do_resource_release_and_resize(struct pci_dev *pdev,
unsigned int i;
int old, ret;
+ lockdep_assert_held(&pci_res_setup_lock);
lockdep_assert_held(&pci_bus_sem);
b_win = pbus_select_window(bus, res);
@@ -2495,6 +2532,7 @@ static int __pci_do_resource_release_and_resize(struct pci_dev *pdev,
int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size,
int exclude_bars)
{
+ guard(mutex)(&pci_res_setup_lock);
guard(rwsem_read)(&pci_bus_sem);
return __pci_do_resource_release_and_resize(pdev, resno, size,
@@ -2516,6 +2554,7 @@ void pci_assign_unassigned_slot_resources(struct pci_bus *bus, u16 slot)
/* List of resources that want additional resources */
LIST_HEAD(add_list);
+ guard(mutex)(&pci_res_setup_lock);
guard(rwsem_read)(&pci_bus_sem);
for_each_pci_bridge(dev, bus) {
if (slot != PCI_SLOT_ALL_DEVICES &&
@@ -2536,6 +2575,7 @@ EXPORT_SYMBOL_GPL(pci_assign_unassigned_bus_resources);
void pci_bus_size_and_assign_resources(struct pci_bus *bus)
{
+ guard(mutex)(&pci_res_setup_lock);
guard(rwsem_read)(&pci_bus_sem);
__pci_bus_size_bridges(bus, NULL);
__pci_bus_assign_resources(bus, NULL, NULL);
--
2.47.3
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v2 08/16] PCI: Make internal sizing and assignment functions static
2026-11-20 13:46 [PATCH v2 00/16] PCI: Serialize bridge window sizing and resource assignment Ilpo Järvinen
` (6 preceding siblings ...)
2026-11-20 13:47 ` [PATCH v2 07/16] PCI: Serialize bridge window sizing and resource assignment Ilpo Järvinen
@ 2026-11-20 13:47 ` Ilpo Järvinen
2026-11-20 13:47 ` [PATCH v2 09/16] EDAC/i82875p: Convert to pci_assign_unassigned_bus_resources() Ilpo Järvinen
` (7 subsequent siblings)
15 siblings, 0 replies; 18+ messages in thread
From: Ilpo Järvinen @ 2026-11-20 13:47 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi, Rob Herring,
Krzysztof Wilczyński, Rafael J. Wysocki (Intel),
linux-kernel
Cc: Ilpo Järvinen
__pci_bus_size_bridges() and __pci_bus_assign_resources() are no longer
called outside of setup-bus.c. Make them static and remove their
declarations from pci.h.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/pci/pci.h | 5 -----
drivers/pci/setup-bus.c | 9 +++++----
2 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index ce29d9ca0194..1dd1becd0312 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -537,11 +537,6 @@ void pci_configure_ari(struct pci_dev *dev);
int pci_dev_res_add_to_list(struct list_head *head, struct pci_dev *dev,
struct resource *res, resource_size_t add_size,
resource_size_t min_align);
-void __pci_bus_size_bridges(struct pci_bus *bus,
- struct list_head *realloc_head);
-void __pci_bus_assign_resources(const struct pci_bus *bus,
- struct list_head *add_list,
- struct list_head *fail_head);
void pci_assign_unassigned_slot_resources(struct pci_bus *bus, u16 slot);
bool pci_bus_clip_resource(struct pci_dev *dev, int idx);
void pci_walk_bus_locked(struct pci_bus *top,
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index f501fa63caab..c7459662b3d5 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1411,7 +1411,8 @@ static void pbus_size_mem(struct pci_bus *bus, struct resource *b_res,
}
}
-void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head)
+static void __pci_bus_size_bridges(struct pci_bus *bus,
+ struct list_head *realloc_head)
{
struct pci_dev *dev;
resource_size_t additional_io_size = 0, additional_mmio_size = 0,
@@ -1567,9 +1568,9 @@ static void __pci_bus_assign_resources_one(const struct pci_bus *bus,
}
}
-void __pci_bus_assign_resources(const struct pci_bus *bus,
- struct list_head *add_list,
- struct list_head *fail_head)
+static void __pci_bus_assign_resources(const struct pci_bus *bus,
+ struct list_head *add_list,
+ struct list_head *fail_head)
{
__pci_bus_assign_resources_one(bus, add_list, fail_head);
--
2.47.3
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v2 09/16] EDAC/i82875p: Convert to pci_assign_unassigned_bus_resources()
2026-11-20 13:46 [PATCH v2 00/16] PCI: Serialize bridge window sizing and resource assignment Ilpo Järvinen
` (7 preceding siblings ...)
2026-11-20 13:47 ` [PATCH v2 08/16] PCI: Make internal sizing and assignment functions static Ilpo Järvinen
@ 2026-11-20 13:47 ` Ilpo Järvinen
2026-11-20 13:47 ` [PATCH v2 10/16] platform/x86: asus-wmi: " Ilpo Järvinen
` (6 subsequent siblings)
15 siblings, 0 replies; 18+ messages in thread
From: Ilpo Järvinen @ 2026-11-20 13:47 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi, Rob Herring,
Krzysztof Wilczyński, Rafael J. Wysocki (Intel),
Borislav Petkov, Tony Luck, linux-edac, linux-kernel
Cc: Ilpo Järvinen
The i82875p_edac driver scans a single device and then attempts to
assign its resources using pci_bus_assign_resources(). That function
makes bridge window sizing disjoint from the assignment phase and is
going to be removed.
Convert pci_bus_assign_resources() to
pci_assign_unassigned_bus_resources() which is likely a no-op in this
case as it looks like bridges are not involved here.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/edac/i82875p_edac.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
index 869de8e372b3..59a92a209dea 100644
--- a/drivers/edac/i82875p_edac.c
+++ b/drivers/edac/i82875p_edac.c
@@ -290,7 +290,7 @@ static int i82875p_setup_overfl_dev(struct pci_dev *pdev,
if (dev == NULL)
return 1;
- pci_bus_assign_resources(dev->bus);
+ pci_assign_unassigned_bus_resources(dev->bus);
pci_bus_add_device(dev);
}
--
2.47.3
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v2 10/16] platform/x86: asus-wmi: Convert to pci_assign_unassigned_bus_resources()
2026-11-20 13:46 [PATCH v2 00/16] PCI: Serialize bridge window sizing and resource assignment Ilpo Järvinen
` (8 preceding siblings ...)
2026-11-20 13:47 ` [PATCH v2 09/16] EDAC/i82875p: Convert to pci_assign_unassigned_bus_resources() Ilpo Järvinen
@ 2026-11-20 13:47 ` Ilpo Järvinen
2026-11-20 13:47 ` [PATCH v2 11/16] platform/x86: eeepc-laptop: " Ilpo Järvinen
` (5 subsequent siblings)
15 siblings, 0 replies; 18+ messages in thread
From: Ilpo Järvinen @ 2026-11-20 13:47 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi, Rob Herring,
Krzysztof Wilczyński, Rafael J. Wysocki (Intel),
Corentin Chary, Luke D. Jones, Denis Benato, Hans de Goede,
Ilpo Järvinen, platform-driver-x86, linux-kernel
The asus-wmi driver scans a single device and then attempts to assign
its resources using pci_bus_assign_resources(). That function makes
bridge window sizing disjoint from the assignment phase and is going to
be removed.
Convert pci_bus_assign_resources() to
pci_assign_unassigned_bus_resources() which is likely a no-op in this
case as it looks like bridges are not involved here.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Denis Benato <denis.benato@linux.dev>
---
drivers/platform/x86/asus-wmi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
index b33ebdb21aa2..9eb783eb53c6 100644
--- a/drivers/platform/x86/asus-wmi.c
+++ b/drivers/platform/x86/asus-wmi.c
@@ -2325,7 +2325,7 @@ static void asus_rfkill_hotplug(struct asus_wmi *asus)
}
dev = pci_scan_single_device(bus, 0);
if (dev) {
- pci_bus_assign_resources(bus);
+ pci_assign_unassigned_bus_resources(bus);
pci_bus_add_device(dev);
}
} else {
--
2.47.3
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v2 11/16] platform/x86: eeepc-laptop: Convert to pci_assign_unassigned_bus_resources()
2026-11-20 13:46 [PATCH v2 00/16] PCI: Serialize bridge window sizing and resource assignment Ilpo Järvinen
` (9 preceding siblings ...)
2026-11-20 13:47 ` [PATCH v2 10/16] platform/x86: asus-wmi: " Ilpo Järvinen
@ 2026-11-20 13:47 ` Ilpo Järvinen
2026-11-20 13:47 ` [PATCH v2 12/16] parisc/PCI: " Ilpo Järvinen
` (4 subsequent siblings)
15 siblings, 0 replies; 18+ messages in thread
From: Ilpo Järvinen @ 2026-11-20 13:47 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi, Rob Herring,
Krzysztof Wilczyński, Rafael J. Wysocki (Intel),
Corentin Chary, Luke D. Jones, Denis Benato, Hans de Goede,
Ilpo Järvinen, platform-driver-x86, linux-kernel
The eeepc-laptop driver scans a single device and then attempts to
assign its resources using pci_bus_assign_resources(). That function
makes bridge window sizing disjoint from the assignment phase and is
going to be removed.
Convert pci_bus_assign_resources() to
pci_assign_unassigned_bus_resources() which is likely a no-op in this
case as it looks like bridges are not involved here.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Denis Benato <denis.benato@linux.dev>
---
drivers/platform/x86/eeepc-laptop.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c
index 8a640c25830a..7394221cbad1 100644
--- a/drivers/platform/x86/eeepc-laptop.c
+++ b/drivers/platform/x86/eeepc-laptop.c
@@ -609,7 +609,7 @@ static void eeepc_rfkill_hotplug(struct eeepc_laptop *eeepc, acpi_handle handle)
}
dev = pci_scan_single_device(bus, 0);
if (dev) {
- pci_bus_assign_resources(bus);
+ pci_assign_unassigned_bus_resources(bus);
pci_bus_add_device(dev);
}
} else {
--
2.47.3
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v2 12/16] parisc/PCI: Convert to pci_assign_unassigned_bus_resources()
2026-11-20 13:46 [PATCH v2 00/16] PCI: Serialize bridge window sizing and resource assignment Ilpo Järvinen
` (10 preceding siblings ...)
2026-11-20 13:47 ` [PATCH v2 11/16] platform/x86: eeepc-laptop: " Ilpo Järvinen
@ 2026-11-20 13:47 ` Ilpo Järvinen
2026-11-20 13:47 ` [PATCH v2 13/16] PCI: octep_hp: " Ilpo Järvinen
` (3 subsequent siblings)
15 siblings, 0 replies; 18+ messages in thread
From: Ilpo Järvinen @ 2026-11-20 13:47 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi, Rob Herring,
Krzysztof Wilczyński, Rafael J. Wysocki (Intel),
James E.J. Bottomley, Helge Deller, linux-parisc, linux-kernel
Cc: Ilpo Järvinen
The Dino PCI bus driver assigns resources using
pci_bus_assign_resources(). That function makes bridge window sizing
disjoint from the assignment phase and is going to be removed.
Convert pci_bus_assign_resources() to
pci_assign_unassigned_bus_resources(). If no other bridges are involved,
the extra sizing should be a no-op.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/parisc/dino.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/parisc/dino.c b/drivers/parisc/dino.c
index 286f4f75dba7..da75ba15faf4 100644
--- a/drivers/parisc/dino.c
+++ b/drivers/parisc/dino.c
@@ -1050,7 +1050,7 @@ static int __init dino_probe(struct parisc_device *dev)
* if it isn't, this global bus number count will fail
*/
dino_current_bus = max + 1;
- pci_bus_assign_resources(bus);
+ pci_assign_unassigned_bus_resources(bus);
pci_bus_add_devices(bus);
return 0;
}
--
2.47.3
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v2 13/16] PCI: octep_hp: Convert to pci_assign_unassigned_bus_resources()
2026-11-20 13:46 [PATCH v2 00/16] PCI: Serialize bridge window sizing and resource assignment Ilpo Järvinen
` (11 preceding siblings ...)
2026-11-20 13:47 ` [PATCH v2 12/16] parisc/PCI: " Ilpo Järvinen
@ 2026-11-20 13:47 ` Ilpo Järvinen
2026-11-20 13:47 ` [PATCH v2 14/16] PCI: ftpci100: " Ilpo Järvinen
` (2 subsequent siblings)
15 siblings, 0 replies; 18+ messages in thread
From: Ilpo Järvinen @ 2026-11-20 13:47 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi, Rob Herring,
Krzysztof Wilczyński, Rafael J. Wysocki (Intel),
Shijith Thotton, Vamsi Attunuru, linux-kernel
Cc: Ilpo Järvinen
The Octeon hotplug driver scans a single device and then attempts to
assign its resources using pci_bus_assign_resources(). That function
makes bridge window sizing disjoint from the assignment phase and is
going to be removed.
Convert pci_bus_assign_resources() to
pci_assign_unassigned_bus_resources(). If no other bridges are involved,
the extra sizing should be a no-op.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/pci/hotplug/octep_hp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/pci/hotplug/octep_hp.c b/drivers/pci/hotplug/octep_hp.c
index a0a7f9ccb8fa..e793fc3012fd 100644
--- a/drivers/pci/hotplug/octep_hp.c
+++ b/drivers/pci/hotplug/octep_hp.c
@@ -79,7 +79,7 @@ static void octep_hp_enable_pdev(struct octep_hp_controller *hp_ctrl,
/* Scan the device and add it to the bus */
hp_slot->hp_pdev = pci_scan_single_device(hp_ctrl->pdev->bus,
hp_slot->hp_devfn);
- pci_bus_assign_resources(hp_ctrl->pdev->bus);
+ pci_assign_unassigned_bus_resources(hp_ctrl->pdev->bus);
pci_bus_add_device(hp_slot->hp_pdev);
dev_dbg(&hp_slot->hp_pdev->dev, "Enabled slot %s\n",
--
2.47.3
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v2 14/16] PCI: ftpci100: Convert to pci_assign_unassigned_bus_resources()
2026-11-20 13:46 [PATCH v2 00/16] PCI: Serialize bridge window sizing and resource assignment Ilpo Järvinen
` (12 preceding siblings ...)
2026-11-20 13:47 ` [PATCH v2 13/16] PCI: octep_hp: " Ilpo Järvinen
@ 2026-11-20 13:47 ` Ilpo Järvinen
2026-11-20 13:47 ` [PATCH v2 15/16] PCI: hv: " Ilpo Järvinen
2026-11-20 13:47 ` [PATCH v2 16/16] PCI: Remove pci_bus_assign_resources() Ilpo Järvinen
15 siblings, 0 replies; 18+ messages in thread
From: Ilpo Järvinen @ 2026-11-20 13:47 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi, Rob Herring,
Krzysztof Wilczyński, Rafael J. Wysocki (Intel),
Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, linux-kernel
Cc: Ilpo Järvinen
The ftpci100 driver attempts to assign bus resources using
pci_bus_assign_resources(). That function makes bridge window sizing
disjoint from the assignment phase and is going to be removed.
Convert pci_bus_assign_resources() to
pci_assign_unassigned_bus_resources(). If no other bridges are involved,
the extra sizing should be a no-op.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/pci/controller/pci-ftpci100.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/pci/controller/pci-ftpci100.c b/drivers/pci/controller/pci-ftpci100.c
index 28e43831c0f1..96b3deb70f57 100644
--- a/drivers/pci/controller/pci-ftpci100.c
+++ b/drivers/pci/controller/pci-ftpci100.c
@@ -509,7 +509,7 @@ static int faraday_pci_probe(struct platform_device *pdev)
p->bus->max_bus_speed = max_bus_speed;
p->bus->cur_bus_speed = cur_bus_speed;
- pci_bus_assign_resources(p->bus);
+ pci_assign_unassigned_bus_resources(p->bus);
pci_bus_add_devices(p->bus);
return 0;
--
2.47.3
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v2 15/16] PCI: hv: Convert to pci_assign_unassigned_bus_resources()
2026-11-20 13:46 [PATCH v2 00/16] PCI: Serialize bridge window sizing and resource assignment Ilpo Järvinen
` (13 preceding siblings ...)
2026-11-20 13:47 ` [PATCH v2 14/16] PCI: ftpci100: " Ilpo Järvinen
@ 2026-11-20 13:47 ` Ilpo Järvinen
2026-11-20 13:47 ` [PATCH v2 16/16] PCI: Remove pci_bus_assign_resources() Ilpo Järvinen
15 siblings, 0 replies; 18+ messages in thread
From: Ilpo Järvinen @ 2026-11-20 13:47 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi, Rob Herring,
Krzysztof Wilczyński, Rafael J. Wysocki (Intel),
Haiyang Zhang, Wei Liu, Dexuan Cui, Lorenzo Pieralisi,
Krzysztof Wilczyński, Manivannan Sadhasivam, linux-hyperv,
linux-kernel
Cc: Ilpo Järvinen, Michael Kelley
The pci-hyperv driver scans the bus and assigns resources using
pci_bus_assign_resources(). That function makes bridge window sizing
disjoint from the assignment phase and is going to be removed.
Convert pci_bus_assign_resources() to
pci_assign_unassigned_bus_resources(). If no other bridges are involved,
the extra sizing should be a no-op.
Tested-by: Michael Kelley <mhklinux@outlook.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Michael Kelley <mhklinux@outlook.com>
---
drivers/pci/controller/pci-hyperv.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
index 824cf27e85e6..8eff3e9b325f 100644
--- a/drivers/pci/controller/pci-hyperv.c
+++ b/drivers/pci/controller/pci-hyperv.c
@@ -2549,7 +2549,7 @@ static int create_root_hv_pci_bus(struct hv_pcibus_device *hbus)
pci_lock_rescan_remove();
hv_pci_assign_numa_node(hbus);
- pci_bus_assign_resources(bridge->bus);
+ pci_assign_unassigned_bus_resources(bridge->bus);
hv_pci_assign_slots(hbus);
pci_bus_add_devices(bridge->bus);
pci_unlock_rescan_remove();
--
2.47.3
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH v2 16/16] PCI: Remove pci_bus_assign_resources()
2026-11-20 13:46 [PATCH v2 00/16] PCI: Serialize bridge window sizing and resource assignment Ilpo Järvinen
` (14 preceding siblings ...)
2026-11-20 13:47 ` [PATCH v2 15/16] PCI: hv: " Ilpo Järvinen
@ 2026-11-20 13:47 ` Ilpo Järvinen
15 siblings, 0 replies; 18+ messages in thread
From: Ilpo Järvinen @ 2026-11-20 13:47 UTC (permalink / raw)
To: linux-pci, Bjorn Helgaas, Lorenzo Pieralisi, Rob Herring,
Krzysztof Wilczyński, Rafael J. Wysocki (Intel),
linux-kernel
Cc: Ilpo Järvinen
The pci_bus_assign_resources() interface is problematic because it makes
bridge window sizing disjoint from the assignment phase.
pci_bus_assign_resources() is now unused so remove it.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
drivers/pci/setup-bus.c | 8 --------
include/linux/pci.h | 1 -
2 files changed, 9 deletions(-)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index c7459662b3d5..0385d61f1b2e 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1578,14 +1578,6 @@ static void __pci_bus_assign_resources(const struct pci_bus *bus,
pci_dev_res_free_list(add_list);
}
-void pci_bus_assign_resources(const struct pci_bus *bus)
-{
- guard(mutex)(&pci_res_setup_lock);
- guard(rwsem_read)(&pci_bus_sem);
- __pci_bus_assign_resources(bus, NULL, NULL);
-}
-EXPORT_SYMBOL(pci_bus_assign_resources);
-
static void pci_claim_device_resources(struct pci_dev *dev)
{
int i;
diff --git a/include/linux/pci.h b/include/linux/pci.h
index d89aeb7c9ff7..7d71ad6d89af 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1566,7 +1566,6 @@ ssize_t pci_write_vpd_any(struct pci_dev *dev, loff_t pos, size_t count, const v
/* Helper functions for low-level code (drivers/pci/setup-[bus,res].c) */
resource_size_t pcibios_retrieve_fw_addr(struct pci_dev *dev, int idx);
-void pci_bus_assign_resources(const struct pci_bus *bus);
void pci_bus_claim_resources(struct pci_bus *bus);
void pci_bus_size_bridges(struct pci_bus *bus);
void pci_bus_size_and_assign_resources(struct pci_bus *bus);
--
2.47.3
^ permalink raw reply [flat|nested] 18+ messages in thread