If the firmware or kernel has arranged memory for PCIe devices in a way that doesn't provide enough space for BARs of a new hotplugged device, the kernel can pause the drivers of the "obstructing" devices and move their BARs, so the new BARs can fit into the freed spaces. To rearrange the BARs and bridge windows these patches releases all of them after a rescan and re-assigns in the same way as during the initial PCIe topology scan at system boot. When a driver is un-paused by the kernel after the PCIe rescan, it should check if its BARs had moved, and ioremap() them. Drivers indicate their support of the feature by implementing the new hooks .rescan_prepare() and .rescan_done() in the struct pci_driver. If a driver doesn't yet support the feature, BARs of its devices will be considered as immovable (by checking the pci_dev_movable_bars_supported(dev)) and handled in the same way as resources with the IORESOURCE_PCI_FIXED flag. If a driver doesn't yet support the feature, its devices are guaranteed to have their BARs remaining untouched. Tested on: - x86_64 with "pci=realloc,assign-busses,use_crs,pcie_bus_peer2peer"; - POWER8 PowerNV+OPAL+PHB3 ppc64le with [1] applied and the following: "pci=realloc,pcie_bus_peer2peer"; - both platforms [with extra pacthes (yet to be submitted) for movable bus numbers]: manually initiated (via sysfs) rescan has found and turned on a hotplugged bridge. Not so many platforms and test cases were covered, so all who are interested are highly welcome to test on your setups - the more exotic the better! This patchset is a part of our work on adding support for hotplugging bridges full of other bridges, NVME drives, SAS HBAs and GPUs without special requirements such as Hot-Plug Controller, reservation of bus numbers or memory regions by firmware, etc. The next patchset to submit will implement the movable bus numbers. [1] https://lists.ozlabs.org/pipermail/linuxppc-dev/2019-August/195272.html [PATCH v6 0/5] powerpc/powernv/pci: Make hotplug self-sufficient, independent of FW and DT Changes since v4: - Feature is enabled by default (turned on by one of the latest patches); - Add pci_dev_movable_bars_supported(dev) instead of marking the immovable BARs with the IORESOURCE_PCI_FIXED flag; - Set up PCIe bridges during rescan via sysfs, so MPS settings are now configured not only during system boot or pcihp events; - Allow movement of switch's BARs if claimed by portdrv; - Update EEH address caches after rescan for powerpc; - Don't disable completely hot-added devices which can't have BARs being fit - just disable their BARs, so they are still visible in lspci etc; - Clearer names: fixed_range_hard -> immovable_range, fixed_range_soft -> realloc_range; - Drop the patch for pci_restore_config_space() - fixed by properly using the runtime PM. Changes since v3: - Rebased to the upstream, so the patches apply cleanly again. Changes since v2: - Fixed double-assignment of bridge windows; - Fixed assignment of fixed prefetched resources; - Fixed releasing of fixed resources; - Fixed a debug message; - Removed auto-enabling the movable BARs for x86 - let's rely on the "pcie_movable_bars=force" option for now; - Reordered the patches - bugfixes first. Changes since v1: - Add a "pcie_movable_bars={ off | force }" command line argument; - Handle the IORESOURCE_PCI_FIXED flag properly; - Don't move BARs of devices which don't support the feature; - Guarantee that new hotplugged devices will not steal memory from working devices by ignoring the failing new devices with the new PCI_DEV_IGNORE flag; - Add rescan_prepare()+rescan_done() to the struct pci_driver instead of using the reset_prepare()+reset_done() from struct pci_error_handlers; - Add a bugfix of a race condition; - Fixed hotplug in a non-pre-enabled (by BIOS/firmware) bridge; - Fix the compatibility of the feature with pm_runtime and D3-state; - Hotplug events from pciehp also can move BARs; - Add support of the feature to the NVME driver. Sergey Miroshnichenko (23): PCI: Fix race condition in pci_enable/disable_device() PCI: Enable bridge's I/O and MEM access for hotplugged devices PCI: hotplug: Add a flag for the movable BARs feature PCI: Define PCI-specific version of the release_child_resources() PCI: hotplug: movable BARs: Fix reassigning the released bridge windows PCI: hotplug: movable BARs: Recalculate all bridge windows during rescan PCI: hotplug: movable BARs: Don't allow added devices to steal resources PCI: Include fixed and immovable BARs into the bus size calculating PCI: Prohibit assigning BARs and bridge windows to non-direct parents PCI: hotplug: movable BARs: Try to assign unassigned resources only once PCI: hotplug: movable BARs: Calculate immovable parts of bridge windows PCI: hotplug: movable BARs: Compute limits for relocated bridge windows PCI: Make sure bridge windows include their fixed BARs PCI: Fix assigning the fixed prefetchable resources PCI: hotplug: movable BARs: Assign fixed and immovable BARs before others PCI: hotplug: movable BARs: Don't reserve IO/mem bus space powerpc/pci: Fix crash with enabled movable BARs powerpc/pci: Handle BAR movement PCI: hotplug: Configure MPS for hot-added bridges during bus rescan PCI: hotplug: movable BARs: Enable the feature by default nvme-pci: Handle movable BARs PCI/portdrv: Declare support of movable BARs PCI: pciehp: movable BARs: Trigger a domain rescan on hp events .../admin-guide/kernel-parameters.txt | 7 + arch/powerpc/kernel/pci-hotplug.c | 10 + arch/powerpc/platforms/powernv/pci-ioda.c | 3 +- drivers/nvme/host/pci.c | 21 +- drivers/pci/bus.c | 2 +- drivers/pci/hotplug/pciehp_pci.c | 5 + drivers/pci/pci.c | 58 +++- drivers/pci/pci.h | 30 ++ drivers/pci/pcie/portdrv_pci.c | 11 + drivers/pci/probe.c | 295 +++++++++++++++++- drivers/pci/setup-bus.c | 276 +++++++++++++--- drivers/pci/setup-res.c | 48 ++- include/linux/pci.h | 21 ++ 13 files changed, 739 insertions(+), 48 deletions(-) -- 2.21.0