PCI: Serialize bridge window sizing and resource assignment
Subsystems (18)
Ilpo Järvinen
maintainerv2 cover PCI: Serialize bridge window sizing and resource assignment
Hi all,
Bridge window sizing and resource assignment can be started from multiple entrypoints: rescan and hotplug under pci_rescan_remove_lock, and BAR resize from sysfs or driver probe under device_lock() only. As the entrypoints hold pci_bus_sem at most for read, nothing prevents two sizing and assignment passes from running concurrently on the same bridge windows and BARs.
Multiple issues due to these races could be reproduced some on a real host and more in QEMU with a synthetic PCI host bridge (not part of this series) by looping BAR resize against a rescan through sysfs. The failures include spurious BAR resize failures, a WARN in pci_dev_res_restore(), a NULL pointer dereference in __release_resource(), and a bridge window programmed over RAM. None of them occurred with this series applied.
The series adds pci_bus_size_and_assign_resources() and pci_assign_unassigned_slot_resources() so that PCI core can hold the locks across both phases. It converts the callers (alpha nautilus retains an extra sizing call to avoid complex refactoring). The entrypoints are made to consistently hold pci_bus_sem for read and use guard(). pci_res_setup_lock is added to serialize the sizing and assignment passes. Last, the series converts the remaining pci_bus_assign_resources() users and removes it.
Drivers that call pci_assign_resource() or pci_release_resource() directly are not covered by this series.
I've another series coming up which will add struct pci_setup_data that is to be held across the entire sizing and assignment algorithm, which is another reason why those actions have to be kept together going forward. The goal of that upcoming series is to size also assigned bridge windows properly and we need a place to keep the alignment because STARTALIGN is lost when a resource gets assigned.
v2:
- Expand BAR Resize lock coverage to include the parent window acquire (sashiko)
- Add pci_assign_unassigned_slot_resources()
- Refactor acpiphp, replaces sizing call in the loop with one pci_assign_unassigned_slot_resources() after the loop to not hold locks across scan
- Keep pci_res_setup_lock local to setup-bus.c (drops setup-cardbus.c assert that was of minor importance anyway)
- Minor language tweaks to changelogs
Ilpo Järvinen (16):
PCI: Add pci_bus_size_and_assign_resources() alpha/PCI: Convert to pci_bus_size_and_assign_resources()
PCI: Use guard() for pci_bus_sem in
pci_do_resource_release_and_resize()
PCI: Add pci_assign_unassigned_slot_resources()
PCI: acpiphp: Use pci_assign_unassigned_slot_resources()
PCI: Hold pci_bus_sem across sizing and assignment entrypoints
PCI: Serialize bridge window sizing and resource assignment
PCI: Make internal sizing and assignment functions static EDAC/i82875p: Convert to pci_assign_unassigned_bus_resources() platform/x86: asus-wmi: Convert to
pci_assign_unassigned_bus_resources()
platform/x86: eeepc-laptop: Convert to
pci_assign_unassigned_bus_resources()
parisc/PCI: Convert to pci_assign_unassigned_bus_resources()
PCI: octep_hp: Convert to pci_assign_unassigned_bus_resources()
PCI: ftpci100: Convert to pci_assign_unassigned_bus_resources()
PCI: hv: Convert to pci_assign_unassigned_bus_resources()
PCI: Remove pci_bus_assign_resources()
arch/alpha/kernel/sys_nautilus.c | 2 +- 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/edac/i82875p_edac.c | 2 +- drivers/parisc/dino.c | 2 +- drivers/parisc/lba_pci.c | 7 +- drivers/pci/controller/pci-ftpci100.c | 2 +- drivers/pci/controller/pci-hyperv.c | 2 +- drivers/pci/hotplug/acpiphp_glue.c | 8 +- drivers/pci/hotplug/octep_hp.c | 2 +- drivers/pci/pci.h | 6 +- drivers/pci/setup-bus.c | 128 +++++++++++++++++++++----- drivers/pcmcia/cardbus.c | 3 +- drivers/platform/x86/asus-wmi.c | 2 +- drivers/platform/x86/eeepc-laptop.c | 2 +- include/linux/pci.h | 2 +- 18 files changed, 126 insertions(+), 60 deletions(-)
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.47.3
Ilpo Järvinen
maintainerPATCH v2 1/16 PCI: Add pci_bus_size_and_assign_resources()
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.
--- 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(-)
arch/arm/kernel/bios32.c +2 -3
@@ -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);
arch/m68k/coldfire/pci.c +1 -2
@@ -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 ; }
arch/mips/pci/pci-legacy.c +2 -3
@@ -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); }
arch/sh/drivers/pci/pci.c +1 -2
@@ -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); }
drivers/parisc/lba_pci.c +2 -5
@@ -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" );
drivers/pci/hotplug/acpiphp_glue.c +1 -2
@@ -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); } } }
drivers/pci/setup-bus.c +7 -0
@@ -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);
drivers/pcmcia/cardbus.c +1 -2
@@ -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 */
include/linux/pci.h +1 -0
@@ -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 );
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v2 01/16] PCI: Add pci_bus_size_and_assign_resources()
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines
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 bypci_bus_assign_resources()and cannot hold the PCI core internal locks across the two calls.
Quoted 5 lines
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 <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Ilpo Järvinen
maintainerPATCH v2 2/16 alpha/PCI: Convert to pci_bus_size_and_assign_resources()
In reply to Ilpo JärvinenTo 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.
--- arch/alpha/kernel/sys_nautilus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/alpha/kernel/sys_nautilus.c +1 -1
@@ -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); }
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v2 02/16] alpha/PCI: Convert to pci_bus_size_and_assign_resources()
Sashiko has reviewed this patch and found no issues.
Quoted 21 lines
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()andpci_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__weakpcibios_*() 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()topci_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.
Quoted 1 line
Signed-off-by Ilpo Järvinen <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Ilpo Järvinen
maintainerPATCH v2 3/16 PCI: Use guard() for pci_bus_sem in pci_do_resource_release_and_resize()
In reply to Ilpo Järvinenpci_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.
--- drivers/pci/setup-bus.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
drivers/pci/setup-bus.c +16 -5
@@ -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 sizeunsigned 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 sizeif (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;
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v2 03/16] PCI: Use guard() for pci_bus_sem in pci_do_resource_release_and_resize()
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
pci_do_resource_release_and_resize()releasespci_bus_semon its common exit path, which it shares with freeing the saved resource list. Move the body into__pci_do_resource_release_and_resize()and takepci_bus_semwithguard()inpci_do_resource_release_and_resize()to make adding more locking simpler without mixing goto-based cleanup withguard().
pci_bus_semnow also covers selecting the bridge window.Signed-off-by Ilpo Järvinen <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Ilpo Järvinen
maintainerPATCH v2 4/16 PCI: Add pci_assign_unassigned_slot_resources()
In reply to Ilpo JärvinenBridge 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.
--- drivers/pci/pci.h | 1 + drivers/pci/setup-bus.c | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-)
drivers/pci/pci.h +1 -0
@@ -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 *),
drivers/pci/setup-bus.c +21 -2
@@ -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)
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v2 04/16] PCI: Add pci_assign_unassigned_slot_resources()
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines
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 implementpci_assign_unassigned_bus_resources()with it.Signed-off-by Ilpo Järvinen <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Ilpo Järvinen
maintainerPATCH v2 5/16 PCI: acpiphp: Use pci_assign_unassigned_slot_resources()
In reply to Ilpo Järvinenenable_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.
--- drivers/pci/hotplug/acpiphp_glue.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/pci/hotplug/acpiphp_glue.c +1 -4
@@ -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);
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v2 05/16] PCI: acpiphp: Use pci_assign_unassigned_slot_resources()
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
enable_slot()calls the internal sizing and assignment functions directly to size only the bridges in the slot. Usepci_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 <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Re: [PATCH v2 05/16] PCI: acpiphp: Use pci_assign_unassigned_slot_resources()
In reply to Ilpo JärvinenQuoted 5 lines · Ilpo Järvinen
enable_slot()calls the internal sizing and assignment functions directly to size only the bridges in the slot. Usepci_assign_unassigned_slot_resources()instead.
Quoted 7 lines
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 <[email protected]>
LGTM
Quoted 34 lines
--- drivers/pci/hotplug/acpiphp_glue.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)drivers/pci/hotplug/acpiphp_glue.c +1
-5@@ -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
Ilpo Järvinen
maintainerPATCH v2 6/16 PCI: Hold pci_bus_sem across sizing and assignment entrypoints
In reply to Ilpo JärvinenThe 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.
--- drivers/pci/setup-bus.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
drivers/pci/setup-bus.c +19 -7
@@ -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);
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v2 06/16] PCI: Hold pci_bus_sem across sizing and assignment entrypoints
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
The bridge window sizing and resource assignment algorithm walks
bus->devicesand 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, andpci_assign_unassigned_bus_resources()drops it before the assignment phase.
Quoted 7 lines
pci_rescan_remove_lockis not held by all callers and cannot be taken by callers running underdevice_lock().Protect the walks by holding
pci_bus_semfor read across the entire sizing and assignment operation right at the entrypoints.Signed-off-by Ilpo Järvinen <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Ilpo Järvinen
maintainerPATCH v2 7/16 PCI: Serialize bridge window sizing and resource assignment
In reply to Ilpo JärvinenBridge 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/0x1802) 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/0x603) 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: -284) 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]: assigned5) 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---
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(+)
drivers/pci/setup-bus.c +40 -0
@@ -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 );
Signature · 1 line
2.47.3
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 16 lines
Bridge window sizing and resource assignment are started from multiple
entrypoints: rescan and hotplug underpci_rescan_remove_lock, and BAR resize from sysfs or driver probe underdevice_lock()only. The entrypoints holdpci_bus_semonly 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_listsanity 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 [ ... ]
Quoted 5 lines
pci 10000:01:00.0: Failed to resize BAR 0: -22Fixes 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 <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Ilpo Järvinen
maintainerPATCH v2 8/16 PCI: Make internal sizing and assignment functions static
In reply to 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.
--- drivers/pci/pci.h | 5 ----- drivers/pci/setup-bus.c | 9 +++++---- 2 files changed, 5 insertions(+), 9 deletions(-)
drivers/pci/pci.h +0 -5
@@ -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,
drivers/pci/setup-bus.c +5 -4
@@ -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);
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v2 08/16] PCI: Make internal sizing and assignment functions static
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
__pci_bus_size_bridges()and__pci_bus_assign_resources()are no longer called outside ofsetup-bus.c. Make them static and remove their declarations frompci.h.Signed-off-by Ilpo Järvinen <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Ilpo Järvinen
maintainerPATCH v2 9/16 EDAC/i82875p: Convert to pci_assign_unassigned_bus_resources()
In reply to Ilpo JärvinenThe 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.
--- drivers/edac/i82875p_edac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/edac/i82875p_edac.c +1 -1
@@ -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); }
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v2 09/16] EDAC/i82875p: Convert to pci_assign_unassigned_bus_resources()
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
The
i82875p_edacdriver scans a single device and then attempts to assign its resources usingpci_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()topci_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 <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
Ilpo Järvinen
maintainerPATCH v2 10/16 platform/x86: asus-wmi: Convert to pci_assign_unassigned_bus_resources()
In reply to Ilpo JärvinenThe 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.
--- drivers/platform/x86/asus-wmi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/asus-wmi.c +1 -1
@@ -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 {
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v2 10/16] platform/x86: asus-wmi: Convert to pci_assign_unassigned_bus_resources()
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
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()topci_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 <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
Ilpo Järvinen
maintainerPATCH v2 11/16 platform/x86: eeepc-laptop: Convert to pci_assign_unassigned_bus_resources()
In reply to Ilpo JärvinenThe 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.
--- drivers/platform/x86/eeepc-laptop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/eeepc-laptop.c +1 -1
@@ -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 {
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v2 11/16] platform/x86: eeepc-laptop: Convert to pci_assign_unassigned_bus_resources()
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
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()topci_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 <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
Ilpo Järvinen
maintainerPATCH v2 12/16 parisc/PCI: Convert to pci_assign_unassigned_bus_resources()
In reply to Ilpo JärvinenThe 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.
--- drivers/parisc/dino.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/parisc/dino.c +1 -1
@@ -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 ; }
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v2 12/16] parisc/PCI: Convert to pci_assign_unassigned_bus_resources()
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
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()topci_assign_unassigned_bus_resources(). If no other bridges are involved, the extra sizing should be a no-op.Signed-off-by Ilpo Järvinen <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
Ilpo Järvinen
maintainerPATCH v2 13/16 PCI: octep_hp: Convert to pci_assign_unassigned_bus_resources()
In reply to Ilpo JärvinenThe 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.
--- drivers/pci/hotplug/octep_hp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/hotplug/octep_hp.c +1 -1
@@ -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",
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v2 13/16] PCI: octep_hp: Convert to pci_assign_unassigned_bus_resources()
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
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()topci_assign_unassigned_bus_resources(). If no other bridges are involved, the extra sizing should be a no-op.Signed-off-by Ilpo Järvinen <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
Ilpo Järvinen
maintainerPATCH v2 14/16 PCI: ftpci100: Convert to pci_assign_unassigned_bus_resources()
In reply to Ilpo JärvinenThe 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.
--- drivers/pci/controller/pci-ftpci100.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/pci-ftpci100.c +1 -1
@@ -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 ;
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v2 14/16] PCI: ftpci100: Convert to pci_assign_unassigned_bus_resources()
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
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()topci_assign_unassigned_bus_resources(). If no other bridges are involved, the extra sizing should be a no-op.Signed-off-by Ilpo Järvinen <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=14
Ilpo Järvinen
maintainerPATCH v2 15/16 PCI: hv: Convert to pci_assign_unassigned_bus_resources()
In reply to Ilpo JärvinenThe 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.
--- drivers/pci/controller/pci-hyperv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/pci-hyperv.c +1 -1
@@ -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 ();
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v2 15/16] PCI: hv: Convert to pci_assign_unassigned_bus_resources()
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines
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()topci_assign_unassigned_bus_resources(). If no other bridges are involved, the extra sizing should be a no-op.Tested-by Michael Kelley <[email protected]>Signed-off-by Ilpo Järvinen <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=15
Ilpo Järvinen
maintainerPATCH v2 16/16 PCI: Remove pci_bus_assign_resources()
In reply to Ilpo JärvinenThe 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.
--- drivers/pci/setup-bus.c | 8 -------- include/linux/pci.h | 1 - 2 files changed, 9 deletions(-)
drivers/pci/setup-bus.c +0 -8
@@ -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;
include/linux/pci.h +0 -1
@@ -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);
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH v2 16/16] PCI: Remove pci_bus_assign_resources()
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
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 <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=16