From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: linux-pci@vger.kernel.org, "Bjorn Helgaas" <bhelgaas@google.com>,
"Lorenzo Pieralisi" <lorenzo.pieralisi@arm.com>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Wilczyński" <kw@linux.com>,
linux-kernel@vger.kernel.org
Cc: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Subject: [PATCH 04/13] PCI: Hold pci_bus_sem across sizing and assignment entrypoints
Date: Mon, 16 Nov 2026 17:23:49 +0200 [thread overview]
Message-ID: <20261116152403.2672-5-ilpo.jarvinen@linux.intel.com> (raw)
In-Reply-To: <20261116152403.2672-1-ilpo.jarvinen@linux.intel.com>
Bridge window sizing and resource assignment algorithm walks
bus->devices and insert resources of the found devices into the resource
tree in many places. In addition, its internal datastructures hold
references to devices and resource 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>
---
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 f95f217f94e6..5b2d870ca13d 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1457,6 +1457,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);
@@ -1549,6 +1550,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);
@@ -1837,7 +1839,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;
@@ -2190,6 +2192,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)) {
@@ -2258,14 +2262,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);
@@ -2292,6 +2297,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)
@@ -2424,7 +2436,7 @@ int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size
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)) {
@@ -2483,18 +2495,18 @@ void pci_assign_unassigned_bus_resources(struct pci_bus *bus)
/* 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 (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);
}
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
next prev parent reply other threads:[~2026-11-16 15:24 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 15:23 [PATCH 00/13] PCI: Serialize bridge window sizing and resource assignment Ilpo Järvinen
2026-11-16 15:23 ` [PATCH 01/13] PCI: Add pci_bus_size_and_assign_resources() Ilpo Järvinen
2026-11-16 15:23 ` [PATCH 02/13] alpha/PCI: Convert to pci_bus_size_and_assign_resources() Ilpo Järvinen
2026-11-16 15:23 ` [PATCH 03/13] PCI: Use guard(&pci_bus_sem) in pci_do_resource_release_and_resize() Ilpo Järvinen
2026-11-16 15:23 ` Ilpo Järvinen [this message]
2026-11-16 15:23 ` [PATCH 05/13] PCI: Serialize bridge window sizing and resource assignment Ilpo Järvinen
2026-11-16 15:23 ` [PATCH 06/13] i82875p_edac: Convert to pci_assign_unassigned_bus_resources() Ilpo Järvinen
2026-11-16 15:40 ` Borislav Petkov
2026-11-16 15:23 ` [PATCH 07/13] platform/x86: asus-wmi: " Ilpo Järvinen
2026-11-16 15:23 ` [PATCH 08/13] platform/x86: eeepc-laptop: " Ilpo Järvinen
2026-11-16 15:23 ` [PATCH 09/13] parisc/PCI: " Ilpo Järvinen
2026-11-16 15:23 ` [PATCH 10/13] PCI: hotplug: octep: " Ilpo Järvinen
2026-11-16 15:23 ` [PATCH 11/13] PCI: ftpci100: " Ilpo Järvinen
2026-11-16 15:23 ` [PATCH 12/13] PCI: hv: " Ilpo Järvinen
2026-11-16 15:23 ` [PATCH 13/13] PCI: Remove pci_bus_assign_resources() Ilpo Järvinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261116152403.2672-5-ilpo.jarvinen@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=bhelgaas@google.com \
--cc=kw@linux.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lorenzo.pieralisi@arm.com \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®