PCI: Serialize bridge window sizing and resource assignment
Subsystems (18)
Ilpo Järvinen
maintainerv3 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(). A per host bridge 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.
v3:
- Move the new lock under pci_host_bridge
- Make pci_find_host_bridge() input const bus
- Reduce number of lockdep asserts as finding the lock is more costly now
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 (17):
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: Make pci_find_host_bridge() take a const bus
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/host-bridge.c | 8 +- drivers/pci/hotplug/acpiphp_glue.c | 8 +- drivers/pci/hotplug/octep_hp.c | 2 +- drivers/pci/pci.h | 6 +- drivers/pci/probe.c | 2 + drivers/pci/setup-bus.c | 108 ++++++++++++++++++++------ drivers/pcmcia/cardbus.c | 3 +- drivers/platform/x86/asus-wmi.c | 2 +- drivers/platform/x86/eeepc-laptop.c | 2 +- include/linux/pci.h | 16 +++- 20 files changed, 125 insertions(+), 65 deletions(-)
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.47.3
Ilpo Järvinen
maintainerPATCH v3 1/17 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
Ilpo Järvinen
maintainerPATCH v3 2/17 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
Ilpo Järvinen
maintainerPATCH v3 3/17 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
Ilpo Järvinen
maintainerPATCH v3 4/17 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
Ilpo Järvinen
maintainerPATCH v3 5/17 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
Ilpo Järvinen
maintainerPATCH v3 6/17 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
Ilpo Järvinen
maintainerPATCH v3 7/17 PCI: Make pci_find_host_bridge() take a const bus
In reply to Ilpo Järvinenpci_find_host_bridge() only reads the bus hierarchy to find the root bus. Make it and find_pci_root_bus() take a const struct pci_bus so it can be used where only a const bus is available.
--- drivers/pci/host-bridge.c | 8 ++++---- include/linux/pci.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/pci/host-bridge.c +4 -4
@@ -9,7 +9,7 @@#include "pci.h" -static struct pci_bus *find_pci_root_bus (struct pci_bus *bus) +static const struct pci_bus *find_pci_root_bus (const struct pci_bus *bus) {while (bus->parent) bus = bus->parent;
@@ -17,9 +17,9 @@ static struct pci_bus *find_pci_root_bus(struct pci_bus *bus)return bus; } -struct pci_host_bridge *pci_find_host_bridge (struct pci_bus *bus) +struct pci_host_bridge *pci_find_host_bridge (const struct pci_bus *bus) { -struct pci_bus *root_bus =find_pci_root_bus (bus); +const struct pci_bus *root_bus =find_pci_root_bus (bus);return to_pci_host_bridge (root_bus->bridge); }
@@ -27,7 +27,7 @@ EXPORT_SYMBOL_GPL(pci_find_host_bridge);struct device *pci_get_host_bridge_device (struct pci_dev *dev) { -struct pci_bus *root_bus =find_pci_root_bus (dev->bus); +const struct pci_bus *root_bus =find_pci_root_bus (dev->bus);struct device *bridge = root_bus->bridge;kobject_get (&bridge->kobj);
include/linux/pci.h +1 -1
@@ -700,7 +700,7 @@ struct pci_host_bridge *devm_pci_alloc_host_bridge(struct device *dev, size_t priv);void pci_free_host_bridge (struct pci_host_bridge *bridge);struct device *pci_get_host_bridge_device (struct pci_dev *dev); -struct pci_host_bridge *pci_find_host_bridge (struct pci_bus *bus); +struct pci_host_bridge *pci_find_host_bridge (const struct pci_bus *bus); void pci_set_host_bridge_release(struct pci_host_bridge *bridge, void (*release_fn)(struct pci_host_bridge *),
Signature · 1 line
2.47.3
Ilpo Järvinen
maintainerPATCH v3 8/17 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 res_setup_lock into struct pci_host_bridge and hold it across sizing and assignment in all entrypoints. Sizing and assignment only operate within the hierarchy of a single host bridge, so serializing them per host bridge is enough. Assert the lock is held in the internal functions the entrypoints call. 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/probe.c | 2 ++ drivers/pci/setup-bus.c | 20 ++++++++++++++++++++ include/linux/pci.h | 12 ++++++++++++ 3 files changed, 34 insertions(+)
drivers/pci/probe.c +2 -0
@@ -641,6 +641,7 @@ static void pci_release_host_bridge_dev(struct device *dev)if (bridge->domain_nr !=PCI_DOMAIN_NR_NOT_SET )pci_bus_release_emul_domain_nr (bridge->domain_nr); +mutex_destroy (&bridge->res_setup_lock);kfree (bridge); }
@@ -663,6 +664,7 @@ static void pci_init_host_bridge(struct pci_host_bridge *bridge)INIT_LIST_HEAD (&bridge->windows);INIT_LIST_HEAD (&bridge->dma_ranges);INIT_LIST_HEAD (&bridge->ports); +mutex_init (&bridge->res_setup_lock);/* * We assume we can manage these PCIe features. Some systems may
drivers/pci/setup-bus.c +20 -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,11 @@unsigned int pci_flags;EXPORT_SYMBOL_GPL (pci_flags); +static struct mutex *pci_res_setup_lock (const struct pci_bus *bus) +{ +return &pci_find_host_bridge (bus)->res_setup_lock; +} +struct pci_dev_resource {struct list_head list;struct resource *res;
@@ -1396,6 +1402,8 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head)struct pci_host_bridge *host;int hdr_type; +lockdep_assert_held (pci_res_setup_lock (bus)); +list_for_each_entry (dev, &bus->devices, bus_list) {struct pci_bus *b = dev->subordinate;if (!b)
@@ -1459,6 +1467,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 (bus));guard (rwsem_read)(&pci_bus_sem);__pci_bus_size_bridges (bus,NULL ); }
@@ -1544,6 +1553,8 @@ void __pci_bus_assign_resources(const struct pci_bus *bus,struct list_head *add_list, struct list_head *fail_head) { +lockdep_assert_held (pci_res_setup_lock (bus )); +__pci_bus_assign_resources_one (bus, add_list, fail_head);if (WARN_ON_ONCE (add_list && !list_empty (add_list)))
@@ -1552,6 +1563,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 (bus));guard (rwsem_read)(&pci_bus_sem);__pci_bus_assign_resources (bus,NULL ,NULL ); }
@@ -2194,6 +2206,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 (bus));guard (rwsem_read)(&pci_bus_sem);/* Don't realloc if asked to do so */
@@ -2272,6 +2285,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 (bridge->bus));guard (rwsem_read)(&pci_bus_sem);while (1 ) {
@@ -2330,6 +2344,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 (bus)); +while (!pci_is_root_bus (bus)) { bridge = bus->self; res =pbus_select_window (bus, res);
@@ -2401,6 +2417,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 (bus));lockdep_assert_held (&pci_bus_sem); b_win =pbus_select_window (bus, res);
@@ -2495,6 +2512,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 (pdev->bus));guard (rwsem_read)(&pci_bus_sem); return __pci_do_resource_release_and_resize(pdev, resno, size,
@@ -2516,6 +2534,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 (bus));guard (rwsem_read)(&pci_bus_sem);for_each_pci_bridge (dev, bus) { if (slot != PCI_SLOT_ALL_DEVICES &&
@@ -2536,6 +2555,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 (bus));guard (rwsem_read)(&pci_bus_sem);__pci_bus_size_bridges (bus,NULL );__pci_bus_assign_resources (bus,NULL ,NULL );
include/linux/pci.h +12 -0
@@ -31,6 +31,7 @@#include <linux/init.h> #include <linux/ioport.h> #include <linux/list.h> +#include <linux/mutex.h> #include <linux/compiler.h> #include <linux/errno.h> #include <linux/kobject.h>
@@ -646,6 +647,17 @@ struct pci_host_bridge {struct list_head windows;/* resource_entry */ struct list_head dma_ranges;/* dma ranges resource list */ struct list_head ports;/* Root Port list (pci_host_port) */ +/* +* Serializes bridge window sizing, resource fitting, and assignment +* below the host bridge. pci_rescan_remove_lock cannot be used for +* this because these operations also run under device_lock(), e.g., +* BAR resize from sysfs or probe, and VMD probe. +* +* Context: +* - Nests inside pci_rescan_remove_lock and device_lock(). +* - Nests outside pci_bus_sem. +*/ +struct mutex res_setup_lock;#ifdef CONFIG_PCI_IDE u16 nr_ide_streams;/* Max streams possibly active in @ide_stream_ida */ struct ida ide_stream_ida;
Signature · 1 line
2.47.3
Ilpo Järvinen
maintainerPATCH v3 9/17 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
@@ -1393,7 +1393,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,
@@ -1549,9 +1550,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) {lockdep_assert_held (pci_res_setup_lock (bus));
Signature · 1 line
2.47.3
Ilpo Järvinen
maintainerPATCH v3 10/17 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
Borislav Petkov
maintainerRe: [PATCH v3 10/17] EDAC/i82875p: Convert to pci_assign_unassigned_bus_resources()
Quoted 20 lines · Ilpo Järvinen
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]>--- drivers/edac/i82875p_edac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/edac/i82875p_edac.c +0
-0
drivers/edac/i82875p_edac.c static int i82875p_setup_overfl_dev(struct pci_dev *pdev, · line 296
Quoted 8 lines
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); }
You can drop this from your set:
e5c2a84fd615 ("EDAC/i82875p: Convert to pci_assign_unassigned_bus_resources()")
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteIlpo Järvinen
maintainerPATCH v3 11/17 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
Ilpo Järvinen
maintainerPATCH v3 12/17 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
Ilpo Järvinen
maintainerPATCH v3 13/17 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
Ilpo Järvinen
maintainerPATCH v3 14/17 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
Ilpo Järvinen
maintainerPATCH v3 15/17 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
Ilpo Järvinen
maintainerPATCH v3 16/17 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
Ilpo Järvinen
maintainerPATCH v3 17/17 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
@@ -1562,14 +1562,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 (bus)); -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
@@ -1578,7 +1578,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 reviewSashiko has reviewed this 17-patch series and found no issues.
Sashiko has reviewed this 17-patch series and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]