Currently PCI hotplug works on top of resources, which are usually reserved not by the kernel, but by BIOS, bootloader, firmware, etc. These resources are gaps in the address space where BARs of new devices may fit, and extra bus number per port, so bridges can be hot-added. This series aim the former problem: it shows the kernel how to redistribute on the run, so the hotplug becomes predictable and cross-platform. A follow-up patchset will propose a solution for bus numbers. If the memory is arranged 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 ioremap() the new addresses of its BARs. 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=pcie_bus_peer2peer" - POWER8 PowerNV+OPAL+PHB3 ppc64le with "pci=pcie_bus_peer2peer". 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. Changes since v5: - Simplified the disable flag, now it is "pci=no_movable_buses"; - More deliberate marking the BARs as immovable; - Mark as immovable BARs which are used by unbound drivers; - Ignoring BAR assignment by non-kernel program components, so the kernel is able now to distribute BARs in optimal and predictable way; - Move here PowerNV-specific patches from the older "powerpc/powernv/pci: Make hotplug self-sufficient, independent of FW and DT" series; - Fix EEH cache rebuilding and PE allocation for PowerNV during rescan. 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 (30): 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 disable the released bridge windows 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 PCI: hotplug: Configure MPS for hot-added bridges during bus rescan PCI: hotplug: movable BARs: Ignore the MEM BAR offsets from bootloader powerpc/pci: Fix crash with enabled movable BARs powerpc/pci: Access PCI config space directly w/o pci_dn powerpc/pci: Create pci_dn on demand powerpc/pci: hotplug: Add support for movable BARs powerpc/powernv/pci: Suppress an EEH error when reading an empty slot PNP: Don't reserve BARs for PCI when enabled movable BARs 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 Revert "powerpc/powernv/pci: Work around races in PCI bridge enabling" .../admin-guide/kernel-parameters.txt | 1 + arch/powerpc/kernel/pci-hotplug.c | 43 +++ arch/powerpc/kernel/pci_dn.c | 88 ++++- arch/powerpc/kernel/rtas_pci.c | 97 ++++-- arch/powerpc/platforms/powernv/pci-ioda.c | 40 +-- arch/powerpc/platforms/powernv/pci.c | 73 ++-- arch/powerpc/platforms/pseries/setup.c | 2 + drivers/nvme/host/pci.c | 21 +- drivers/pci/bus.c | 2 +- drivers/pci/hotplug/pciehp_pci.c | 5 + drivers/pci/pci.c | 38 ++- drivers/pci/pci.h | 30 ++ drivers/pci/pcie/portdrv_pci.c | 11 + drivers/pci/probe.c | 315 +++++++++++++++++- drivers/pci/setup-bus.c | 277 +++++++++++++-- drivers/pci/setup-res.c | 50 ++- drivers/pnp/system.c | 4 + include/linux/pci.h | 21 ++ 18 files changed, 965 insertions(+), 153 deletions(-) -- 2.23.0