PCI: Allow BAR movement during hotplug
Subsystems (5)
v6 cover PCI: Allow BAR movement during hotplug
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(-)
Signature · 1 line
2.23.0
PATCH v6 1/30 PCI: Fix race condition in pci_enable/disable_device()
This is a yet another approach to fix an old [1-2] concurrency issue, when:
- two or more devices are being hot-added into a bridge which was initially empty;
- a bridge with two or more devices is being hot-added;
- during boot, if BIOS/bootloader/firmware doesn't pre-enable bridges.
The problem is that a bridge is reported as enabled before the MEM/IO bits are actually written to the PCI_COMMAND register, so another driver thread starts memory requests through the not-yet-enabled bridge:
CPU0 CPU1
pci_enable_device_mem() pci_enable_device_mem()
pci_enable_bridge() pci_enable_bridge()
pci_is_enabled()
return false;
atomic_inc_return(enable_cnt)
Start actual enabling the bridge
... pci_is_enabled()
... return true;
... Start memory requests <-- FAIL
...
Set the PCI_COMMAND_MEMORY bit <-- Must wait for this
Protect the pci_enable/disable_device() and pci_enable_bridge(), which is similar to the previous solution from commit 40f11adc7cd9 ("PCI: Avoid race while enabling upstream bridges"), but adding a per-device mutexes and preventing the dev->enable_cnt from from incrementing early.
[1] https://lore.kernel.org/linux-pci/[email protected]/T/#u
[RFC PATCH v3] pci: Concurrency issue during pci enable bridge
[2] https://lore.kernel.org/linux-pci/[email protected]/T/#u
[RFC PATCH] nvme: avoid race-conditions when enabling devices
--- drivers/pci/pci.c | 26 ++++++++++++++++++++++---- drivers/pci/probe.c | 1 + include/linux/pci.h | 1 + 3 files changed, 24 insertions(+), 4 deletions(-)
drivers/pci/pci.c +22 -4
@@ -1643,6 +1643,8 @@ static void pci_enable_bridge(struct pci_dev *dev)struct pci_dev *bridge;int retval; +mutex_lock (&dev->enable_mutex); + bridge =pci_upstream_bridge (dev);if (bridge)pci_enable_bridge (bridge);
@@ -1650,6 +1652,7 @@ static void pci_enable_bridge(struct pci_dev *dev)if (pci_is_enabled (dev)) {if (!dev->is_busmaster)pci_set_master (dev); +mutex_unlock (&dev->enable_mutex);return ; }
@@ -1658,11 +1661,14 @@ static void pci_enable_bridge(struct pci_dev *dev)pci_err (dev,"Error enabling bridge (%d), continuing\n" , retval);pci_set_master (dev); +mutex_unlock (&dev->enable_mutex); }static int pci_enable_device_flags (struct pci_dev *dev,unsigned long flags) {struct pci_dev *bridge; +/* Enable-locking of bridges is performed within the pci_enable_bridge() */ +bool need_lock = !dev->subordinate;int err;int i, bars =0 ;
@@ -1678,8 +1684,13 @@ static int pci_enable_device_flags(struct pci_dev *dev, unsigned long flags) dev->current_state = (pmcsr &PCI_PM_CTRL_STATE_MASK ); } -if (atomic_inc_return (&dev->enable_cnt) >1 ) +if (need_lock) +mutex_lock (&dev->enable_mutex); +if (pci_is_enabled (dev)) { +if (need_lock) +mutex_unlock (&dev->enable_mutex);return 0 ;/* already enabled */ + } bridge =pci_upstream_bridge (dev);if (bridge)
@@ -1694,8 +1705,10 @@ static int pci_enable_device_flags(struct pci_dev *dev, unsigned long flags) bars |= (1 << i); err =do_pci_enable_device (dev, bars); -if (err <0 ) -atomic_dec (&dev->enable_cnt); +if (err >=0 ) +atomic_inc (&dev->enable_cnt); +if (need_lock) +mutex_unlock (&dev->enable_mutex);return err; }
@@ -1939,15 +1952,20 @@ void pci_disable_device(struct pci_dev *dev)if (dr) dr->enabled =0 ; +mutex_lock (&dev->enable_mutex);dev_WARN_ONCE (&dev->dev,atomic_read (&dev->enable_cnt) <=0 ,"disabling already-disabled device" ); -if (atomic_dec_return (&dev->enable_cnt) !=0 ) +if (atomic_dec_return (&dev->enable_cnt) !=0 ) { +mutex_unlock (&dev->enable_mutex);return ; + }do_pci_disable_device (dev); dev->is_busmaster =0 ; + +mutex_unlock (&dev->enable_mutex); }EXPORT_SYMBOL (pci_disable_device);
drivers/pci/probe.c +1 -0
@@ -2158,6 +2158,7 @@ struct pci_dev *pci_alloc_dev(struct pci_bus *bus)INIT_LIST_HEAD (&dev->bus_list); dev->dev.type = &pci_dev_type; dev->bus =pci_bus_get (bus); +mutex_init (&dev->enable_mutex);return dev; }
include/linux/pci.h +1 -0
@@ -425,6 +425,7 @@ struct pci_dev { unsigned int no_vf_scan:1; /* Don't scan for VFs after IOV enablement */pci_dev_flags_t dev_flags;atomic_t enable_cnt;/* pci_enable_device has been called */ +struct mutex enable_mutex;u32 saved_config_space[16 ];/* Config space saved at suspend time */ struct hlist_head saved_cap_space;
Signature · 1 line
2.23.0
Oxford Semiconductor Ltd OX16PCI954 - weird dmesg
pci_bus 0000:00: root bus resource [mem 0x50000000-0x5fffffff] pci_bus 0000:00: root bus resource [io 0x18800000-0x188fffff] pci_bus 0000:00: root bus resource [??? 0x00000000 flags 0x0] pci_bus 0000:00: No busn resource found for root bus, will use [bus 00-ff] pci 0000:00:00.0: [Firmware Bug]: reg 0x14: invalid BAR (can't size) pci 0000:00:00.0: [Firmware Bug]: reg 0x18: invalid BAR (can't size) pci 0000:00:04.0: BAR 0: assigned [mem 0x50000000-0x5000ffff] pci 0000:00:05.0: BAR 1: assigned [mem 0x50010000-0x50010fff] pci 0000:00:05.0: BAR 3: assigned [mem 0x50011000-0x50011fff] pci 0000:00:0a.0: BAR 1: assigned [mem 0x50012000-0x50012fff] pci 0000:00:0a.0: BAR 3: assigned [mem 0x50013000-0x50013fff] pci 0000:00:02.0: BAR 0: assigned [io 0x18800000-0x188000ff] pci 0000:00:02.0: BAR 1: assigned [mem 0x50014000-0x500140ff] pci 0000:00:03.0: BAR 0: assigned [io 0x18800400-0x188004ff] pci 0000:00:03.0: BAR 1: assigned [mem 0x50014100-0x500141ff]
pci 0000:00:05.0: BAR 0: assigned [io 0x18800800-0x1880081f] pci 0000:00:05.0: BAR 2: assigned [io 0x18800820-0x1880083f] pci 0000:00:0a.0: BAR 0: assigned [io 0x18800840-0x1880085f] pci 0000:00:0a.0: BAR 2: assigned [io 0x18800860-0x1880087f]
00:00.0 Non-VGA unclassified device: Integrated Device Technology, Inc. Device 0000
Subsystem: Device 0214:011d
Flags: bus master, 66MHz, medium devsel, latency 60, IRQ 140 Memory at <unassigned> (32-bit, prefetchable)
I/O ports at <ignored>
I/O ports at <ignored>
00:02.0 Ethernet controller: VIA Technologies, Inc. VT6105/VT6106S [Rhine-III] (rev 86)
Subsystem: AST Research Inc Device 086c
Flags: bus master, stepping, medium devsel, latency 64, IRQ 142 I/O ports at 18800000 [size=256]
Memory at 50014000 (32-bit, non-prefetchable) [size=256]
Capabilities: [40] Power Management version 2
Kernel driver in use: via-rhine
00:03.0 Ethernet controller: VIA Technologies, Inc. VT6105/VT6106S [Rhine-III] (rev 86)
Subsystem: AST Research Inc Device 086c
Flags: bus master, stepping, medium devsel, latency 64, IRQ 143 I/O ports at 18800400 [size=256]
Memory at 50014100 (32-bit, non-prefetchable) [size=256]
Capabilities: [40] Power Management version 2
Kernel driver in use: via-rhine
00:04.0 Network controller: Atheros Communications Inc. Device 0029 (rev 01)
Subsystem: Atheros Communications Inc. Device 2091
Flags: bus master, 66MHz, medium devsel, latency 168, IRQ 142 Memory at 50000000 (32-bit, non-prefetchable) [size=64K]
Capabilities: [44] Power Management version 2
Kernel driver in use: ath9k
00:05.0 Serial controller: Oxford Semiconductor Ltd OX16PCI954 (Quad 16950 UART) function 0 (Uart) (rev 01) (prog-if 06 [)
Subsystem: Oxford Semiconductor Ltd Device 0000
Flags: medium devsel, IRQ 143
I/O ports at 18800800 [size=32]
Memory at 50010000 (32-bit, non-prefetchable) [size=4K] I/O ports at 18800820 [size=32]
Memory at 50011000 (32-bit, non-prefetchable) [size=4K]
Capabilities: [40] Power Management version 2 Kernel driver in use: serial
00:05.1 Non-VGA unclassified device: Oxford Semiconductor Ltd OX16PCI954 (Quad 16950 UART) function 0 (Disabled) (rev 01)
Subsystem: Oxford Semiconductor Ltd Device 0000
Flags: medium devsel, IRQ 143
I/O ports at <unassigned> [disabled]
I/O ports at <unassigned> [disabled]
I/O ports at <unassigned> [disabled]
Capabilities: [40] Power Management version 2
00:0a.0 Serial controller: Oxford Semiconductor Ltd OX16PCI954 (Quad 16950 UART) function 0 (Uart) (rev 01) (prog-if 06 [)
Subsystem: Oxford Semiconductor Ltd Device 0000
Flags: medium devsel, IRQ 140
I/O ports at 18800840 [size=32]
Memory at 50012000 (32-bit, non-prefetchable) [size=4K] I/O ports at 18800860 [size=32]
Memory at 50013000 (32-bit, non-prefetchable) [size=4K]
Capabilities: [40] Power Management version 2 Kernel driver in use: serial
00:0a.1 Non-VGA unclassified device: Oxford Semiconductor Ltd OX16PCI954 (Quad 16950 UART) function 0 (Disabled) (rev 01)
Subsystem: Oxford Semiconductor Ltd Device 0000
Flags: medium devsel, IRQ 140
I/O ports at <unassigned> [disabled]
I/O ports at <unassigned> [disabled]
I/O ports at <unassigned> [disabled]
Capabilities: [40] Power Management version 2
hi guys
I have a couple of miniPCI Oxford Semiconductor Ltd OX16PCI954 cards installed, and the dmesg looks weird
espeially these linespci_bus 0000:00: root bus resource [mem 0x50000000-0x5fffffff] pci_bus 0000:00: root bus resource [io 0x18800000-0x188fffff] pci_bus 0000:00: root bus resource [??? 0x00000000 flags 0x0] pci_bus 0000:00: No busn resource found for root bus, will use [bus 00-ff] pci 0000:00:00.0: [Firmware Bug]: reg 0x14: invalid BAR (can't size) pci 0000:00:00.0: [Firmware Bug]: reg 0x18: invalid BAR (can't size)
besides, I am experimenting crashes happening in burn-in tests, and I do suspect it's something related to the newly added cards
any enlightenment?
Re: Oxford Semiconductor Ltd OX16PCI954 - weird dmesg
Quoted 99 lines · Carlo Pisani
pci_bus0000:00: root bus resource [mem 0x50000000-0x5fffffff]pci_bus0000:00: root bus resource [io 0x18800000-0x188fffff]pci_bus0000:00: root bus resource [???0x00000000flags0x0]pci_bus0000:00: No busn resource found for root bus, will use [bus 00-ff] pci 0000:00:00.0: [Firmware Bug]: reg0x14: invalid BAR (can't size) pci 0000:00:00.0: [Firmware Bug]: reg0x18: invalid BAR (can't size) pci 0000:00:04.0: BAR 0: assigned [mem 0x50000000-0x5000ffff] pci 0000:00:05.0: BAR 1: assigned [mem 0x50010000-0x50010fff] pci 0000:00:05.0: BAR 3: assigned [mem 0x50011000-0x50011fff] pci 0000:00:0a.0: BAR 1: assigned [mem 0x50012000-0x50012fff] pci 0000:00:0a.0: BAR 3: assigned [mem 0x50013000-0x50013fff] pci 0000:00:02.0: BAR 0: assigned [io 0x18800000-0x188000ff] pci 0000:00:02.0: BAR 1: assigned [mem 0x50014000-0x500140ff] pci 0000:00:03.0: BAR 0: assigned [io 0x18800400-0x188004ff] pci 0000:00:03.0: BAR 1: assigned [mem 0x50014100-0x500141ff]pci 0000:00:05.0: BAR 0: assigned [io 0x18800800-0x1880081f] pci 0000:00:05.0: BAR 2: assigned [io 0x18800820-0x1880083f] pci 0000:00:0a.0: BAR 0: assigned [io 0x18800840-0x1880085f] pci 0000:00:0a.0: BAR 2: assigned [io 0x18800860-0x1880087f]00:00.0 Non-VGA unclassified device: Integrated Device Technology, Inc. Device 0000
Subsystem: Device 0214:011d
Flags: bus master, 66MHz, medium devsel, latency 60, IRQ 140 Memory at <unassigned> (32-bit, prefetchable)
I/O ports at <ignored>
I/O ports at <ignored>00:02.0 Ethernet controller: VIA Technologies, Inc. VT6105/VT6106S [Rhine-III] (rev 86)
Subsystem: AST Research Inc Device 086c
Flags: bus master, stepping, medium devsel, latency 64, IRQ 142 I/O ports at 18800000 [size=256]
Memory at 50014000 (32-bit, non-prefetchable) [size=256]
Capabilities: [40] Power Management version 2
Kernel driver in use: via-rhine00:03.0 Ethernet controller: VIA Technologies, Inc. VT6105/VT6106S [Rhine-III] (rev 86)
Subsystem: AST Research Inc Device 086c
Flags: bus master, stepping, medium devsel, latency 64, IRQ 143 I/O ports at 18800400 [size=256]
Memory at 50014100 (32-bit, non-prefetchable) [size=256]
Capabilities: [40] Power Management version 2
Kernel driver in use: via-rhine00:04.0 Network controller: Atheros Communications Inc. Device 0029 (rev 01)
Subsystem: Atheros Communications Inc. Device 2091
Flags: bus master, 66MHz, medium devsel, latency 168, IRQ 142 Memory at 50000000 (32-bit, non-prefetchable) [size=64K]
Capabilities: [44] Power Management version 2
Kernel driver in use: ath9k00:05.0 Serial controller: Oxford Semiconductor Ltd OX16PCI954 (Quad 16950 UART) function 0 (Uart) (rev 01) (prog-if 06 [)
Subsystem: Oxford Semiconductor Ltd Device 0000
Flags: medium devsel, IRQ 143
I/O ports at 18800800 [size=32]
Memory at 50010000 (32-bit, non-prefetchable) [size=4K] I/O ports at 18800820 [size=32]
Memory at 50011000 (32-bit, non-prefetchable) [size=4K]
Capabilities: [40] Power Management version 2 Kernel driver in use: serial00:05.1 Non-VGA unclassified device: Oxford Semiconductor Ltd OX16PCI954 (Quad 16950 UART) function 0 (Disabled) (rev 01)
Subsystem: Oxford Semiconductor Ltd Device 0000
Flags: medium devsel, IRQ 143
I/O ports at <unassigned> [disabled]
I/O ports at <unassigned> [disabled]
I/O ports at <unassigned> [disabled]
Capabilities: [40] Power Management version 200:0a.0 Serial controller: Oxford Semiconductor Ltd OX16PCI954 (Quad 16950 UART) function 0 (Uart) (rev 01) (prog-if 06 [)
Subsystem: Oxford Semiconductor Ltd Device 0000
Flags: medium devsel, IRQ 140
I/O ports at 18800840 [size=32]
Memory at 50012000 (32-bit, non-prefetchable) [size=4K] I/O ports at 18800860 [size=32]
Memory at 50013000 (32-bit, non-prefetchable) [size=4K]
Capabilities: [40] Power Management version 2 Kernel driver in use: serial00:0a.1 Non-VGA unclassified device: Oxford Semiconductor Ltd OX16PCI954 (Quad 16950 UART) function 0 (Disabled) (rev 01)
Subsystem: Oxford Semiconductor Ltd Device 0000
Flags: medium devsel, IRQ 140
I/O ports at <unassigned> [disabled]
I/O ports at <unassigned> [disabled]
I/O ports at <unassigned> [disabled]
Capabilities: [40] Power Management version 2hi guys
I have a couple of miniPCI Oxford Semiconductor Ltd OX16PCI954 cards installed, and the dmesg looks weird
Quoted 5 lines
espeially these lines
pci_bus0000:00: root bus resource [mem 0x50000000-0x5fffffff]pci_bus0000:00: root bus resource [io 0x18800000-0x188fffff]pci_bus0000:00: root bus resource [???0x00000000flags0x0]pci_bus0000:00: No busn resource found for root bus, will use [bus 00-ff]
These resources are supplied to the PCI core, probably from DT. A complete dmesg log would show more.
Quoted 5 lines
pci 0000:00:00.0: [Firmware Bug]: reg
0x14: invalid BAR (can't size) pci 0000:00:00.0: [Firmware Bug]: reg0x18: invalid BAR (can't size)besides, I am experimenting crashes happening in burn-in tests, and I do suspect it's something related to the newly added cards
If you take the cards out do the lines you mention above change?
What sort of crashes do you see? I assume it doesn't crash without the cards?
It *looks* like the miniPCI cards should be these devices:
00:05.0 Serial controller: Oxford Semiconductor Ltd OX16PCI954 (Quad 16950 UART) function 0 (Uart) (rev 01) (prog-if 06 [) 00:0a.0 Serial controller: Oxford Semiconductor Ltd OX16PCI954 (Quad 16950 UART) function 0 (Uart) (rev 01) (prog-if 06 [)
which are unrelated to the 00:00.0 device with the broken BAR.
PATCH v6 2/30 PCI: Enable bridge's I/O and MEM access for hotplugged devices
In reply to Sergey MiroshnichenkoThe PCI_COMMAND_IO and PCI_COMMAND_MEMORY bits of the bridge must be updated not only when enabling the bridge for the first time, but also if a hotplugged device requests these types of resources.
Originally these bits were set by the pci_enable_device_flags() only, which exits early if the bridge is already pci_is_enabled(). So if the bridge was empty initially (an edge case), then hotplugged devices fail to IO/MEM.
--- drivers/pci/pci.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/pci/pci.c +8 -0
@@ -1650,6 +1650,14 @@ static void pci_enable_bridge(struct pci_dev *dev)pci_enable_bridge (bridge);if (pci_is_enabled (dev)) { +int i, bars =0 ; + +for (i =PCI_BRIDGE_RESOURCES ; i <DEVICE_COUNT_RESOURCE ; i++) { +if (dev->resource[i].flags & (IORESOURCE_MEM |IORESOURCE_IO )) + bars |= (1 << i); + } +do_pci_enable_device (dev, bars); +if (!dev->is_busmaster)pci_set_master (dev);mutex_unlock (&dev->enable_mutex);
Signature · 1 line
2.23.0
PATCH v6 3/30 PCI: hotplug: Add a flag for the movable BARs feature
In reply to Sergey MiroshnichenkoWhen hot-adding a device, the bridge may have windows not big enough (or fragmented too much) for newly requested BARs to fit in. And expanding these bridge windows may be impossible because blocked by "neighboring" BARs and bridge windows.
Still, it may be possible to allocate a memory region for new BARs with the following procedure:
1) notify all the drivers which support movable BARs to pause and release the BARs; the rest of the drivers are guaranteed that their devices will not get BARs moved;
2) release all the bridge windows and movable BARs;
3) try to recalculate new bridge windows that will fit all the BAR types:
- fixed;
- immovable;
- movable;
- newly requested by hot-added devices;
4) if the previous step fails, disable BARs for one of the hot-added devices and retry from step 3;
5) notify the drivers, so they remap BARs and resume.
If bridge calculation and BAR assignment fails with a hot-added devices, BARs of these devices will be disabled, falling back to the same amount and size of BARs as they were before the hotplug event. The kernel succeeded in assigning then, so the same algorithm will provide the same results again.
This makes the prior reservation of memory by BIOS/bootloader/firmware not required anymore for the PCI hotplug.
Drivers indicate their support of movable BARs by implementing the new .rescan_prepare() and .rescan_done() hooks in the struct pci_driver. All device's activity must be paused during a rescan, and iounmap()+ioremap() must be applied to every used BAR.
If a device is not bound to a driver, its BARs are considered movable.
For a higher probability of the successful BAR reassignment, all the BARs and bridge windows should be released before the rescan, not only those with higher addresses.
One example when it is needed, BAR(I) is moved to free a gap for the new BAR(II):
Before:
==================== parent bridge window ===============
---- hotplug bridge window ----
| BAR(I) | fixed BAR | fixed BAR | fixed BAR |
^
|
new BAR(II) After:
==================== parent bridge window ========================= ----------- hotplug bridge window -----------
| new BAR(II) | fixed BAR | fixed BAR | fixed BAR | BAR(I) |
Another example is a fragmented bridge window jammed between fixed BARs:
Before:
===================== parent bridge window ========================
---------- hotplug bridge window ----------
| fixed BAR | | BAR(I) | | BAR(II) | | BAR(III) | fixed BAR |
^
|
new BAR(IV) After:
==================== parent bridge window =========================
---------- hotplug bridge window ----------
| fixed BAR | BAR(I) | BAR(II) | BAR(III) | new BAR(IV) | fixed BAR |
This patch is a preparation for future patches with actual implementation, and for now it just does the following:
- declares the feature;
- defines the bool pci_can_move_bars and bool pci_dev_bar_movable(dev);
- invokes the .rescan_prepare() and .rescan_done() driver notifiers;
- disables the feature for the powerpc/pseries.
The feature is disabled by default until the final patch of the series. It can be overridden per-arch using the pci_can_move_bars=false flag or by the following command line option:
pci=no_movable_bars
--- .../admin-guide/kernel-parameters.txt | 1 + arch/powerpc/platforms/pseries/setup.c | 2 + drivers/pci/pci.c | 4 + drivers/pci/pci.h | 2 + drivers/pci/probe.c | 85 ++++++++++++++++++- include/linux/pci.h | 4 + 6 files changed, 96 insertions(+), 2 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +1 -0
@@ -3528,6 +3528,7 @@ may put more devices in an IOMMU group. force_floating [S390] Force usage of floating interrupts. nomio [S390] Do not use MIO instructions. + no_movable_bars Don't allow BARs to be moved during hotplug pcie_aspm= [PCIE] Forcibly enable or disable PCIe Active State Power Management.
arch/powerpc/platforms/pseries/setup.c +2 -0
@@ -920,6 +920,8 @@ static void __init pseries_init(void) {pr_debug (" -> pseries_init()\n" ); + pci_can_move_bars = false; +#ifdef CONFIG_HVC_CONSOLE if (firmware_has_feature (FW_FEATURE_LPAR ))hvc_vio_init_early ();
drivers/pci/pci.c +4 -0
@@ -78,6 +78,8 @@ static void pci_dev_d3_sleep(struct pci_dev *dev)int pci_domains_supported =1 ;#endif +bool pci_can_move_bars; +#define DEFAULT_CARDBUS_IO_SIZE (256)#define DEFAULT_CARDBUS_MEM_SIZE (64*1024*1024)/* pci=cbmemsize=nnM,cbiosize=nn can override this */
@@ -6331,6 +6333,8 @@ static int __init pci_setup(char *str)pci_add_flags (PCI_SCAN_ALL_PCIE_DEVS ); }else if (!strncmp (str,"disable_acs_redir=" ,18 )) { disable_acs_redir_param = str +18 ; + }else if (!strncmp (str,"no_movable_bars" ,15 )) { + pci_can_move_bars = false; }else {pr_err ("PCI: Unknown option `%s'\n" , str); }
drivers/pci/pci.h +2 -0
@@ -286,6 +286,8 @@ void pci_disable_bridge_window(struct pci_dev *dev);struct pci_bus *pci_bus_get (struct pci_bus *bus);void pci_bus_put (struct pci_bus *bus); +bool pci_dev_bar_movable (struct pci_dev *dev,struct resource *res); +/* PCIe link information */ #define PCIE_SPEED2STR (speed) \ ((speed) == PCIE_SPEED_16_0GT ? "16 GT/s" : \
drivers/pci/probe.c +83 -2
98 lines not on this page · raw message
include/linux/pci.h +4 -0
@@ -835,6 +835,8 @@ struct pci_driver {int (*resume)(struct pci_dev *dev);/* Device woken up */ void (*shutdown)(struct pci_dev *dev);int (*sriov_configure)(struct pci_dev *dev,int num_vfs);/* On PF */ +void (*rescan_prepare)(struct pci_dev *dev); +void (*rescan_done)(struct pci_dev *dev);const struct pci_error_handlers *err_handler;const struct attribute_group **groups;struct device_driver driver;
@@ -1395,6 +1397,8 @@ void pci_setup_bridge(struct pci_bus *bus);resource_size_t pcibios_window_alignment (struct pci_bus *bus,unsigned long type); +extern bool pci_can_move_bars; +#define PCI_VGA_STATE_CHANGE_BRIDGE (1 << 0)#define PCI_VGA_STATE_CHANGE_DECODES (1 << 1)
Signature · 1 line
2.23.0
kbuild test robot
build botRe: [PATCH v6 03/30] PCI: hotplug: Add a flag for the movable BARs feature
Thank you for the patch! Perhaps something to improve:
Hi Sergey,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on pci/next]
[cannot apply to v5.4-rc5 next-20191025]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Sergey-Miroshnichenko/PCI-Allow-BAR-movement-during-hotplug/20191028-002741 base: https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git next reproduce: make htmldocs
If you fix the issue, kindly add following tag
All warnings (new ones prefixed by >>):
Warning: The Sphinx 'sphinx_rtd_theme' HTML theme was not found. Make sure you have the theme installed to produce pretty HTML output. Falling back to the default theme.
WARNING: dot(1) not found, for better output quality install graphviz from http://www.graphviz.org
WARNING: convert(1) not found, for SVG to PDF conversion install ImageMagick (https://www.imagemagick.org)
>> include/linux/pci.h:845: warning: Function parameter or member 'rescan_prepare' not described in 'pci_driver' >> include/linux/pci.h:845: warning: Function parameter or member 'rescan_done' not described in 'pci_driver'
include/linux/regulator/machine.h:196: warning: Function parameter or member 'max_uV_step' not described in 'regulation_constraints' include/linux/regulator/driver.h:223: warning: Function parameter or member 'resume' not described in 'regulator_ops'
Error: Cannot open file drivers/dma-buf/reservation.c
Error: Cannot open file drivers/dma-buf/reservation.c
Error: Cannot open file drivers/dma-buf/reservation.c
Error: Cannot open file include/linux/reservation.h
Error: Cannot open file include/linux/reservation.h
include/linux/spi/spi.h:190: warning: Function parameter or member 'driver_override' not described in 'spi_device'
drivers/gpio/gpiolib-of.c:92: warning: Excess function parameter 'dev' description in 'of_gpio_need_valid_mask'
include/linux/i2c.h:337: warning: Function parameter or member 'init_irq' not described in 'i2c_client'
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c:335: warning: Excess function parameter 'dev' description in 'amdgpu_gem_prime_export' drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c:336: warning: Excess function parameter 'dev' description in 'amdgpu_gem_prime_export' drivers/gpu/drm/amd/amdgpu/amdgpu_mn.c:142: warning: Function parameter or member 'blockable' not described in 'amdgpu_mn_read_lock' drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c:347: warning: cannot understand function prototype: 'struct amdgpu_vm_pt_cursor '
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c:348: warning: cannot understand function prototype: 'struct amdgpu_vm_pt_cursor '
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c:494: warning: Function parameter or member 'start' not described in 'amdgpu_vm_pt_first_dfs' drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c:546: warning: Function parameter or member 'adev' not described in 'for_each_amdgpu_vm_pt_dfs_safe' drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c:546: warning: Function parameter or member 'vm' not described in 'for_each_amdgpu_vm_pt_dfs_safe' drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c:546: warning: Function parameter or member 'start' not described in 'for_each_amdgpu_vm_pt_dfs_safe' drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c:546: warning: Function parameter or member 'cursor' not described in 'for_each_amdgpu_vm_pt_dfs_safe' drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c:546: warning: Function parameter or member 'entry' not described in 'for_each_amdgpu_vm_pt_dfs_safe' drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c:823: warning: Function parameter or member 'level' not described in 'amdgpu_vm_bo_param' drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c:1285: warning: Function parameter or member 'params' not described in 'amdgpu_vm_update_flags' drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c:1285: warning: Function parameter or member 'bo' not described in 'amdgpu_vm_update_flags' drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c:1285: warning: Function parameter or member 'level' not described in 'amdgpu_vm_update_flags' drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c:1285: warning: Function parameter or member 'pe' not described in 'amdgpu_vm_update_flags' drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c:1285: warning: Function parameter or member 'addr' not described in 'amdgpu_vm_update_flags' drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c:1285: warning: Function parameter or member 'count' not described in 'amdgpu_vm_update_flags' drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c:1285: warning: Function parameter or member 'incr' not described in 'amdgpu_vm_update_flags' drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c:1285: warning: Function parameter or member 'flags' not described in 'amdgpu_vm_update_flags' drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c:2823: warning: Function parameter or member 'pasid' not described in 'amdgpu_vm_make_compute' drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c:378: warning: Excess function parameter 'entry' description in 'amdgpu_irq_dispatch' drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c:379: warning: Function parameter or member 'ih' not described in 'amdgpu_irq_dispatch' drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c:379: warning: Excess function parameter 'entry' description in 'amdgpu_irq_dispatch'
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c:1: warning: no structured comments found
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c:1: warning: no structured comments found
drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c:1: warning: 'pp_dpm_sclk pp_dpm_mclk pp_dpm_pcie' not found
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h:132: warning: Incorrect use of kernel-doc format: Documentation Makefile include scripts source @atomic_obj drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h:238: warning: Incorrect use of kernel-doc format: Documentation Makefile include scripts source gpu_info FW provided soc bounding box struct or 0 if not drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h:243: warning: Function parameter or member 'atomic_obj' not described in 'amdgpu_display_manager' drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h:243: warning: Function parameter or member 'backlight_link' not described in 'amdgpu_display_manager' drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h:243: warning: Function parameter or member 'backlight_caps' not described in 'amdgpu_display_manager' drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h:243: warning: Function parameter or member 'freesync_module' not described in 'amdgpu_display_manager' drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h:243: warning: Function parameter or member 'fw_dmcu' not described in 'amdgpu_display_manager' drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h:243: warning: Function parameter or member 'dmcu_fw_version' not described in 'amdgpu_display_manager' drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h:243: warning: Function parameter or member 'soc_bounding_box' not described in 'amdgpu_display_manager' drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c:1: warning: 'register_hpd_handlers' not found
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c:1: warning: 'dm_crtc_high_irq' not found
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c:1: warning: 'dm_pflip_high_irq' not found
mm/util.c:1: warning: 'get_user_pages_fast' not found
mm/slab.c:4215: warning: Function parameter or member 'objp' not described in '__ksize'
drivers/usb/typec/bus.c:1: warning: 'typec_altmode_unregister_driver' not found
drivers/usb/typec/bus.c:1: warning: 'typec_altmode_register_driver' not found
drivers/usb/typec/class.c:1: warning: 'typec_altmode_register_notifier' not found
drivers/usb/typec/class.c:1: warning: 'typec_altmode_unregister_notifier' not found
include/linux/w1.h:277: warning: Function parameter or member 'of_match_table' not described in 'w1_family'
fs/fs-writeback.c:913: warning: Excess function parameter 'nr_pages' description in 'cgroup_writeback_by_id'
fs/direct-io.c:258: warning: Excess function parameter 'offset' description in 'dio_complete'
fs/libfs.c:496: warning: Excess function parameter 'available' description in 'simple_write_end'
fs/posix_acl.c:647: warning: Function parameter or member 'inode' not described in 'posix_acl_update_mode'
fs/posix_acl.c:647: warning: Function parameter or member 'mode_p' not described in 'posix_acl_update_mode'
fs/posix_acl.c:647: warning: Function parameter or member 'acl' not described in 'posix_acl_update_mode'
kernel/dma/coherent.c:1: warning: no structured comments found
include/linux/input/sparse-keymap.h:43: warning: Function parameter or member 'sw' not described in 'key_entry'
lib/genalloc.c:1: warning: 'gen_pool_add_virt' not found
lib/genalloc.c:1: warning: 'gen_pool_alloc' not found
lib/genalloc.c:1: warning: 'gen_pool_free' not found
lib/genalloc.c:1: warning: 'gen_pool_alloc_algo' not found
include/linux/bitmap.h:341: warning: Function parameter or member 'nbits' not described in 'bitmap_or_equal'
include/linux/rculist.h:374: warning: Excess function parameter 'cond' description in 'list_for_each_entry_rcu'
include/linux/rculist.h:651: warning: Excess function parameter 'cond' description in 'hlist_for_each_entry_rcu'
include/linux/skbuff.h:888: warning: Function parameter or member 'dev_scratch' not described in 'sk_buff'
include/linux/skbuff.h:888: warning: Function parameter or member 'list' not described in 'sk_buff'
include/linux/skbuff.h:888: warning: Function parameter or member 'ip_defrag_offset' not described in 'sk_buff'
include/linux/skbuff.h:888: warning: Function parameter or member 'skb_mstamp_ns' not described in 'sk_buff'
include/linux/skbuff.h:888: warning: Function parameter or member '__cloned_offset' not described in 'sk_buff'
include/linux/skbuff.h:888: warning: Function parameter or member 'head_frag' not described in 'sk_buff'
include/linux/skbuff.h:888: warning: Function parameter or member '__pkt_type_offset' not described in 'sk_buff'
include/linux/skbuff.h:888: warning: Function parameter or member 'encapsulation' not described in 'sk_buff'
include/linux/skbuff.h:888: warning: Function parameter or member 'encap_hdr_csum' not described in 'sk_buff'
include/linux/skbuff.h:888: warning: Function parameter or member 'csum_valid' not described in 'sk_buff'
include/linux/skbuff.h:888: warning: Function parameter or member '__pkt_vlan_present_offset' not described in 'sk_buff'
include/linux/skbuff.h:888: warning: Function parameter or member 'vlan_present' not described in 'sk_buff'
include/linux/skbuff.h:888: warning: Function parameter or member 'csum_complete_sw' not described in 'sk_buff'
include/linux/skbuff.h:888: warning: Function parameter or member 'csum_level' not described in 'sk_buff'
include/linux/skbuff.h:888: warning: Function parameter or member 'inner_protocol_type' not described in 'sk_buff'
include/linux/skbuff.h:888: warning: Function parameter or member 'remcsum_offload' not described in 'sk_buff'
include/linux/skbuff.h:888: warning: Function parameter or member 'sender_cpu' not described in 'sk_buff'
include/linux/skbuff.h:888: warning: Function parameter or member 'reserved_tailroom' not described in 'sk_buff'
include/linux/skbuff.h:888: warning: Function parameter or member 'inner_ipproto' not described in 'sk_buff'
include/net/sock.h:233: warning: Function parameter or member 'skc_addrpair' not described in 'sock_common'
include/net/sock.h:233: warning: Function parameter or member 'skc_portpair' not described in 'sock_common'
include/net/sock.h:233: warning: Function parameter or member 'skc_ipv6only' not described in 'sock_common'
include/net/sock.h:233: warning: Function parameter or member 'skc_net_refcnt' not described in 'sock_common'
include/net/sock.h:233: warning: Function parameter or member 'skc_v6_daddr' not described in 'sock_common'
include/net/sock.h:233: warning: Function parameter or member 'skc_v6_rcv_saddr' not described in 'sock_common'
include/net/sock.h:233: warning: Function parameter or member 'skc_cookie' not described in 'sock_common'
include/net/sock.h:233: warning: Function parameter or member 'skc_listener' not described in 'sock_common'
include/net/sock.h:233: warning: Function parameter or member 'skc_tw_dr' not described in 'sock_common'
include/net/sock.h:233: warning: Function parameter or member 'skc_rcv_wnd' not described in 'sock_common'
vim +845 include/linux/pci.h
229b4e0728e0a6 Changbin Du 2019-05-14 783
229b4e0728e0a6 Changbin Du 2019-05-14 784 /**
229b4e0728e0a6 Changbin Du 2019-05-14 785 * struct pci_driver - PCI driver structure
229b4e0728e0a6 Changbin Du 2019-05-14 786 * @node: List of driver structures.
229b4e0728e0a6 Changbin Du 2019-05-14 787 * @name: Driver name.
229b4e0728e0a6 Changbin Du 2019-05-14 788 * @id_table: Pointer to table of device IDs the driver is
229b4e0728e0a6 Changbin Du 2019-05-14 789 * interested in. Most drivers should export this
229b4e0728e0a6 Changbin Du 2019-05-14 790 * table using MODULE_DEVICE_TABLE(pci,...).
229b4e0728e0a6 Changbin Du 2019-05-14 791 * @probe: This probing function gets called (during execution
229b4e0728e0a6 Changbin Du 2019-05-14 792 * of pci_register_driver() for already existing
229b4e0728e0a6 Changbin Du 2019-05-14 793 * devices or later if a new device gets inserted) for
229b4e0728e0a6 Changbin Du 2019-05-14 794 * all PCI devices which match the ID table and are not
229b4e0728e0a6 Changbin Du 2019-05-14 795 * "owned" by the other drivers yet. This function gets
229b4e0728e0a6 Changbin Du 2019-05-14 796 * passed a "struct pci_dev \*" for each device whose
229b4e0728e0a6 Changbin Du 2019-05-14 797 * entry in the ID table matches the device. The probe
229b4e0728e0a6 Changbin Du 2019-05-14 798 * function returns zero when the driver chooses to
229b4e0728e0a6 Changbin Du 2019-05-14 799 * take "ownership" of the device or an error code
229b4e0728e0a6 Changbin Du 2019-05-14 800 * (negative number) otherwise.
229b4e0728e0a6 Changbin Du 2019-05-14 801 * The probe function always gets called from process
229b4e0728e0a6 Changbin Du 2019-05-14 802 * context, so it can sleep.
229b4e0728e0a6 Changbin Du 2019-05-14 803 * @remove: The remove() function gets called whenever a device
229b4e0728e0a6 Changbin Du 2019-05-14 804 * being handled by this driver is removed (either during
229b4e0728e0a6 Changbin Du 2019-05-14 805 * deregistration of the driver or when it's manually
229b4e0728e0a6 Changbin Du 2019-05-14 806 * pulled out of a hot-pluggable slot).
229b4e0728e0a6 Changbin Du 2019-05-14 807 * The remove function always gets called from process
229b4e0728e0a6 Changbin Du 2019-05-14 808 * context, so it can sleep.
229b4e0728e0a6 Changbin Du 2019-05-14 809 * @suspend: Put device into low power state.
229b4e0728e0a6 Changbin Du 2019-05-14 810 * @suspend_late: Put device into low power state.
229b4e0728e0a6 Changbin Du 2019-05-14 811 * @resume_early: Wake device from low power state.
229b4e0728e0a6 Changbin Du 2019-05-14 812 * @resume: Wake device from low power state.
151f4e2bdc7a04 Mauro Carvalho Chehab 2019-06-13 813 * (Please see Documentation/power/pci.rst for descriptions
229b4e0728e0a6 Changbin Du 2019-05-14 814 * of PCI Power Management and the related functions.)
229b4e0728e0a6 Changbin Du 2019-05-14 815 * @shutdown: Hook into reboot_notifier_list (kernel/sys.c).
229b4e0728e0a6 Changbin Du 2019-05-14 816 * Intended to stop any idling DMA operations.
229b4e0728e0a6 Changbin Du 2019-05-14 817 * Useful for enabling wake-on-lan (NIC) or changing
229b4e0728e0a6 Changbin Du 2019-05-14 818 * the power state of a device before reboot.
229b4e0728e0a6 Changbin Du 2019-05-14 819 * e.g. drivers/net/e100.c.
229b4e0728e0a6 Changbin Du 2019-05-14 820 * @sriov_configure: Optional driver callback to allow configuration of
229b4e0728e0a6 Changbin Du 2019-05-14 821 * number of VFs to enable via sysfs "sriov_numvfs" file.
229b4e0728e0a6 Changbin Du 2019-05-14 822 * @err_handler: See Documentation/PCI/pci-error-recovery.rst
229b4e0728e0a6 Changbin Du 2019-05-14 823 * @groups: Sysfs attribute groups.
229b4e0728e0a6 Changbin Du 2019-05-14 824 * @driver: Driver model structure.
229b4e0728e0a6 Changbin Du 2019-05-14 825 * @dynids: List of dynamically added device IDs.
229b4e0728e0a6 Changbin Du 2019-05-14 826 */
^1da177e4c3f41 Linus Torvalds 2005-04-16 827 struct pci_driver {
^1da177e4c3f41 Linus Torvalds 2005-04-16 828 struct list_head node;
42b219322a97cc Stephen Hemminger 2010-09-02 829 const char *name;
0aa0f5d1084ca1 Bjorn Helgaas 2017-12-02 830 const struct pci_device_id *id_table; /* Must be non-NULL for probe to be called */
^1da177e4c3f41 Linus Torvalds 2005-04-16 831 int (*probe)(struct pci_dev *dev, const struct pci_device_id *id); /* New device inserted */
^1da177e4c3f41 Linus Torvalds 2005-04-16 832 void (*remove)(struct pci_dev *dev); /* Device removed (NULL if not a hot-plug capable driver) */
^1da177e4c3f41 Linus Torvalds 2005-04-16 833 int (*suspend)(struct pci_dev *dev, pm_message_t state); /* Device suspended */
cbd69dbbf1adfc Linus Torvalds 2006-06-24 834 int (*suspend_late)(struct pci_dev *dev, pm_message_t state);
cbd69dbbf1adfc Linus Torvalds 2006-06-24 835 int (*resume_early)(struct pci_dev *dev);
^1da177e4c3f41 Linus Torvalds 2005-04-16 836 int (*resume)(struct pci_dev *dev); /* Device woken up */
c8958177224622 Greg Kroah-Hartman 2005-04-08 837 void (*shutdown)(struct pci_dev *dev);
0aa0f5d1084ca1 Bjorn Helgaas 2017-12-02 838 int (*sriov_configure)(struct pci_dev *dev, int num_vfs); /* On PF */
c6685548ca6750 Sergey Miroshnichenko 2019-10-24 839 void (*rescan_prepare)(struct pci_dev *dev);
c6685548ca6750 Sergey Miroshnichenko 2019-10-24 840 void (*rescan_done)(struct pci_dev *dev);
494530284f1629 Stephen Hemminger 2012-09-07 841 const struct pci_error_handlers *err_handler;
92d50fc1602ece Greg Kroah-Hartman 2017-07-19 842 const struct attribute_group **groups;
^1da177e4c3f41 Linus Torvalds 2005-04-16 843 struct device_driver driver;
^1da177e4c3f41 Linus Torvalds 2005-04-16 844 struct pci_dynids dynids;^1da177e4c3f41 Linus Torvalds 2005-04-16 @845 };
^1da177e4c3f41 Linus Torvalds 2005-04-16 846
:::::: The code at line 845 was first introduced by commit :::::: 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 Linux-2.6.12-rc2
:::::: TO: Linus Torvalds <[email protected]> :::::: CC: Linus Torvalds <[email protected]>
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH v6 4/30 PCI: Define PCI-specific version of the release_child_resources()
In reply to Sergey MiroshnichenkoIf release the bridge resources with standard release_child_resources(), it drops the .start field of children's BARs to zero, but with the STARTALIGN flag remaining set, which makes the resource invalid for reassignment.
Some resources must preserve their offset and size: those marked with the PCI_FIXED and the immovable ones - which are bound by drivers without support of the movable BARs feature.
Add the pci_release_child_resources() to replace release_child_resources() in handling the described PCI-specific cases.
--- drivers/pci/setup-bus.c | 54 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-)
drivers/pci/setup-bus.c +53 -1
@@ -1482,6 +1482,54 @@ static void __pci_bridge_assign_resources(const struct pci_dev *bridge, (IORESOURCE_IO |IORESOURCE_MEM |IORESOURCE_PREFETCH |\IORESOURCE_MEM_64 ) +/* +* Similar to generic release_child_resources(), but aware of immovable BARs and +* PCI_FIXED and STARTALIGN flags + */ +static void pci_release_child_resources (struct pci_bus *bus,struct resource *r) +{ +struct pci_dev *dev; + +if (!bus || !r) +return ; + +if (r->flags &IORESOURCE_PCI_FIXED ) +return ; + + r->child =NULL ; + +list_for_each_entry (dev, &bus->devices, bus_list) { +int i; + +for (i =0 ; i <PCI_NUM_RESOURCES ; i++) { +struct resource *tmp = &dev->resource[i]; +resource_size_t size =resource_size (tmp); + +if (!tmp->flags || tmp->parent != r) +continue ; + + tmp->parent =NULL ; + tmp->sibling =NULL ; + +pci_release_child_resources (dev->subordinate, tmp); + + tmp->flags &= ~IORESOURCE_STARTALIGN ; + tmp->flags |=IORESOURCE_SIZEALIGN ; + +if (!pci_dev_bar_movable (dev, tmp)) { +pci_dbg (dev,"release immovable %pR (%s), keep its flags, base and size\n" , + tmp, tmp->name); +continue ; + } + +pci_dbg (dev,"release %pR (%s)\n" , tmp, tmp->name); + + tmp->start =0 ; + tmp->end = size -1 ; + } + } +} +static void pci_bridge_release_resources (struct pci_bus *bus,unsigned long type) {
@@ -1522,7 +1570,11 @@ static void pci_bridge_release_resources(struct pci_bus *bus,return ;/* If there are children, release them all */ -release_child_resources (r); +if (pci_can_move_bars) +pci_release_child_resources (bus, r); +else +release_child_resources (r); +if (!release_resource (r)) { type = old_flags = r->flags &PCI_RES_TYPE_MASK ; pci_info(dev, "resource %d %pR released\n",
Signature · 1 line
2.23.0
PATCH v6 5/30 PCI: hotplug: movable BARs: Fix reassigning the released bridge windows
In reply to Sergey MiroshnichenkoWhen a bridge window is temporarily released during the rescan, its old size is not relevant anymore - it will be recreated from pbus_size_*(), so it's start value should be zero.
If such window can't be reassigned, don't apply reset_resource(), so the next retry may succeed.
--- drivers/pci/setup-bus.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/pci/setup-bus.c +4 -3
@@ -295,7 +295,8 @@ static void assign_requested_resources_sorted(struct list_head *head,0 /* don't care */ , 0 /* don't care */); } -reset_resource (res); +if (!pci_can_move_bars) +reset_resource (res); } } }
@@ -1579,8 +1580,8 @@ static void pci_bridge_release_resources(struct pci_bus *bus, type = old_flags = r->flags &PCI_RES_TYPE_MASK ;pci_info (dev,"resource %d %pR released\n" ,PCI_BRIDGE_RESOURCES + idx, r); -/* Keep the old size */ - r->end =resource_size (r) -1 ; +/* Don't keep the old size if the bridge will be recalculated */ + r->end = pci_can_move_bars ?0 : (resource_size (r) -1 ); r->start =0 ; r->flags =0 ;
Signature · 1 line
2.23.0
PATCH v6 6/30 PCI: hotplug: movable BARs: Recalculate all bridge windows during rescan
In reply to Sergey MiroshnichenkoWhen the movable BARs feature is enabled and a rescan has been requested, release all the bridge windows and recalculate them from scratch, taking into account all kinds for BARs: fixed, immovable, movable, new.
This increases the chances to find a memory space to fit BARs for newly hotplugged devices, especially if no/not enough gaps were reserved by the BIOS/bootloader/firmware.
The last step of writing the recalculated windows to the bridges is done by the new pci_setup_bridges() function.
--- drivers/pci/pci.h | 1 + drivers/pci/probe.c | 22 ++++++++++++++++++++++ drivers/pci/setup-bus.c | 16 ++++++++++++++++ 3 files changed, 39 insertions(+)
drivers/pci/pci.h +1 -0
@@ -280,6 +280,7 @@ void __pci_bus_assign_resources(const struct pci_bus *bus,struct list_head *realloc_head, struct list_head *fail_head);bool pci_bus_clip_resource (struct pci_dev *dev,int idx); +void pci_bus_release_root_bridge_resources (struct pci_bus *bus);void pci_reassigndev_resource_alignment (struct pci_dev *dev);void pci_disable_bridge_window (struct pci_dev *dev);
drivers/pci/probe.c +22 -0
@@ -3200,6 +3200,25 @@ static void pci_bus_rescan_done(struct pci_bus *bus)pci_config_pm_runtime_put (bus->self); } +static void pci_setup_bridges (struct pci_bus *bus) +{ +struct pci_dev *dev; + +list_for_each_entry (dev, &bus->devices, bus_list) { +struct pci_bus *child; + +if (!pci_dev_is_added (dev)) +continue ; + + child = dev->subordinate; +if (child) +pci_setup_bridges (child); + } + +if (bus->self) +pci_setup_bridge (bus); +} +/** * pci_rescan_bus - Scan a PCI bus for devices * @bus: PCI bus to scan
@@ -3221,8 +3240,11 @@ unsigned int pci_rescan_bus(struct pci_bus *bus)pci_bus_rescan_prepare (root); max =pci_scan_child_bus (root); + +pci_bus_release_root_bridge_resources (root);pci_assign_unassigned_root_bus_resources (root); +pci_setup_bridges (root);pci_bus_rescan_done (root); }else { max =pci_scan_child_bus (bus);
drivers/pci/setup-bus.c +16 -0
@@ -1635,6 +1635,22 @@ static void pci_bus_release_bridge_resources(struct pci_bus *bus,pci_bridge_release_resources (bus, type); } +void pci_bus_release_root_bridge_resources (struct pci_bus *root_bus) +{ +int i; +struct resource *r; + +pci_bus_release_bridge_resources (root_bus,IORESOURCE_IO , whole_subtree); +pci_bus_release_bridge_resources (root_bus,IORESOURCE_MEM , whole_subtree); +pci_bus_release_bridge_resources (root_bus, +IORESOURCE_MEM_64 |IORESOURCE_PREFETCH , + whole_subtree); + +pci_bus_for_each_resource (root_bus, r, i) { +pci_release_child_resources (root_bus, r); + } +} +static void pci_bus_dump_res (struct pci_bus *bus) {struct resource *res;
Signature · 1 line
2.23.0
PATCH v6 7/30 PCI: hotplug: movable BARs: Don't disable the released bridge windows
In reply to Sergey MiroshnichenkoOn a hotplug event with enabled BAR movement, calculating the new bridge windows takes some time. During this procedure, the structures that represent these windows are released - marked for recalculation.
When new bridge windows are ready, they are written to the registers of every bridge via pci_setup_bridges().
Currently, bridge's registers are updated immediately after releasing a window to disable it. But if a driver doesn't yet support movable BARs, it doesn't stop MEM transactions during the hotplug, so disabled bridge windows will break them.
Let the bridge windows remain operating after releasing, as they will be updated to the new values in the end of a hotplug event.
--- drivers/pci/setup-bus.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pci/setup-bus.c +2 -1
@@ -1588,7 +1588,8 @@ static void pci_bridge_release_resources(struct pci_bus *bus,/* Avoiding touch the one without PREF */ if (type &IORESOURCE_PREFETCH ) type =IORESOURCE_PREFETCH ; -__pci_setup_bridge (bus, type); +if (!pci_can_move_bars) +__pci_setup_bridge (bus, type);/* For next child res under same bridge */ r->flags = old_flags; }
Signature · 1 line
2.23.0
PATCH v6 8/30 PCI: hotplug: movable BARs: Don't allow added devices to steal resources
In reply to Sergey MiroshnichenkoWhen movable BARs are enabled, the PCI subsystem at first releases all the bridge windows and then attempts to assign resources both to previously working devices and to the newly hotplugged ones, with the same priority.
If a hotplugged device gets its BARs first, this may lead to lack of space for already working devices, which is unacceptable. If that happens, mark one of the new devices with the newly introduced flag PCI_DEV_DISABLED_BARS (if it is not yet marked) and retry the BAR recalculation.
The worst case would be no BARs for hotplugged devices, while all the rest just continue working.
The algorithm is simple and it doesn't retry different subsets of hot-added devices in case of a failure, e.g. if there are no space to allocate BARs for both hotplugged devices A and B, but is enough for just A, the A will be marked with PCI_DEV_DISABLED_BARS first, then (after the next failure) - B. As a result, A will not get BARs while it could. This issue is only relevant when hotplugging two and more devices simultaneously.
Add a new res_mask bitmask to the struct pci_dev for storing the indices of assigned BARs.
--- drivers/pci/pci.h | 11 +++++ drivers/pci/probe.c | 102 ++++++++++++++++++++++++++++++++++++++-- drivers/pci/setup-bus.c | 15 ++++++ include/linux/pci.h | 1 + 4 files changed, 126 insertions(+), 3 deletions(-)
drivers/pci/pci.h +11 -0
@@ -403,6 +403,7 @@ static inline bool pci_dev_is_disconnected(const struct pci_dev *dev)/* pci_dev priv_flags */ #define PCI_DEV_ADDED 0 +#define PCI_DEV_DISABLED_BARS 1static inline void pci_dev_assign_added (struct pci_dev *dev,bool added) {
@@ -414,6 +415,16 @@ static inline bool pci_dev_is_added(const struct pci_dev *dev)return test_bit (PCI_DEV_ADDED , &dev->priv_flags); } +static inline void pci_dev_disable_bars (struct pci_dev *dev) +{ +assign_bit (PCI_DEV_DISABLED_BARS , &dev->priv_flags, true); +} + +static inline bool pci_dev_bars_enabled (const struct pci_dev *dev) +{ +return !test_bit (PCI_DEV_DISABLED_BARS , &dev->priv_flags); +} +#ifdef CONFIG_PCIEAER #include <linux/aer.h>
drivers/pci/probe.c +99 -3
135 lines not on this page · raw message
drivers/pci/setup-bus.c +15 -0
@@ -128,6 +128,9 @@ static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head) {int i; +if (!pci_dev_bars_enabled (dev)) +return ; +for (i =0 ; i <PCI_NUM_RESOURCES ; i++) {struct resource *r;struct pci_dev_resource *dev_res, *tmp;
@@ -177,6 +180,9 @@ static void __dev_sort_resources(struct pci_dev *dev, struct list_head *head) {u16 class = dev->class >>8 ; +if (!pci_dev_bars_enabled (dev)) +return ; +/* Don't touch classless devices or host bridges or IOAPICs */ if (class ==PCI_CLASS_NOT_DEFINED || class ==PCI_CLASS_BRIDGE_HOST )return ;
@@ -278,6 +284,9 @@ static void assign_requested_resources_sorted(struct list_head *head,int idx;list_for_each_entry (dev_res, head, list) { +if (!pci_dev_bars_enabled (dev_res->dev)) +continue ; + res = dev_res->res; idx = res - &dev_res->dev->resource[0 ]; if (resource_size(res) &&
@@ -995,6 +1004,9 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,list_for_each_entry (dev, &bus->devices, bus_list) {int i; +if (!pci_dev_bars_enabled (dev)) +continue ; +for (i =0 ; i <PCI_NUM_RESOURCES ; i++) {struct resource *r = &dev->resource[i];resource_size_t r_size;
@@ -1349,6 +1361,9 @@ void __pci_bus_assign_resources(const struct pci_bus *bus,pbus_assign_resources_sorted (bus, realloc_head, fail_head);list_for_each_entry (dev, &bus->devices, bus_list) { +if (!pci_dev_bars_enabled (dev)) +continue ; +pdev_assign_fixed_resources (dev); b = dev->subordinate;
include/linux/pci.h +1 -0
@@ -376,6 +376,7 @@ struct pci_dev {*/ unsigned int irq;struct resource resource[DEVICE_COUNT_RESOURCE ];/* I/O and memory regions + expansion ROMs */ +unsigned int res_mask;/* Bitmask of assigned resources */ bool match_driver;/* Skip attaching driver */
Signature · 1 line
2.23.0
PATCH v6 9/30 PCI: Include fixed and immovable BARs into the bus size calculating
In reply to Sergey MiroshnichenkoThe only difference between the fixed/immovable and movable BARs is a size and offset preservation after they are released (the corresponding struct resource* detached from a bridge window for a while during a bus rescan).
Include fixed/immovable BARs into result of pbus_size_mem() and prohibit assigning them to non-direct parents.
--- drivers/pci/setup-bus.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/pci/setup-bus.c +9 -1
@@ -1011,12 +1011,20 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,struct resource *r = &dev->resource[i];resource_size_t r_size; -if (r->parent || (r->flags &IORESOURCE_PCI_FIXED ) || +if (r->parent || ((r->flags & mask) != type && (r->flags & mask) != type2 && (r->flags & mask) != type3))continue ; r_size =resource_size (r); + +if (!pci_dev_bar_movable (dev, r)) { +if (pci_can_move_bars) + size += r_size; + +continue ; + } +#ifdef CONFIG_PCI_IOV /* Put SRIOV requested res to the optional list */ if (realloc_head && i >= PCI_IOV_RESOURCES &&
Signature · 1 line
2.23.0
PATCH v6 10/30 PCI: Prohibit assigning BARs and bridge windows to non-direct parents
In reply to Sergey MiroshnichenkoWhen movable BARs are enabled, the feature of resource relocating from commit 2bbc6942273b5 ("PCI : ability to relocate assigned pci-resources") is not used. Instead, inability to assign a resource is used as a signal to retry BAR assignment with other configuration of bridge windows.
--- drivers/pci/setup-bus.c | 2 ++ drivers/pci/setup-res.c | 12 ++++++++++++ 2 files changed, 14 insertions(+)
drivers/pci/setup-bus.c +2 -0
@@ -1355,6 +1355,8 @@ static void pdev_assign_fixed_resources(struct pci_dev *dev)while (b && !r->parent) {assign_fixed_resource_on_bus (b, r); b = b->parent; +if (!r->parent && pci_can_move_bars) +break ; } } }
drivers/pci/setup-res.c +12 -0
@@ -298,6 +298,18 @@ static int _pci_assign_resource(struct pci_dev *dev, int resno, bus = dev->bus;while ((ret =__pci_assign_resource (bus, dev, resno, size, min_align))) { +if (pci_can_move_bars) { +if (resno >=PCI_BRIDGE_RESOURCES && + resno <=PCI_BRIDGE_RESOURCE_END ) { +struct resource *res = dev->resource + resno; + + res->start =0 ; + res->end =0 ; + res->flags =0 ; + } +break ; + } +if (!bus->parent || !bus->self->transparent)break ; bus = bus->parent;
Signature · 1 line
2.23.0
PATCH v6 11/30 PCI: hotplug: movable BARs: Try to assign unassigned resources only once
In reply to Sergey MiroshnichenkoWith enabled BAR movement, BARs and bridge windows can only be assigned to their direct parents, so there can be only one variant of resource tree, thus every retry within the pci_assign_unassigned_root_bus_resources() will result in the same tree, and it is enough to try just once.
In case of failures the pci_reassign_root_bus_resources() disables BARs for one of the hotplugged devices and tries the assignment again.
--- drivers/pci/setup-bus.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/pci/setup-bus.c +7 -0
@@ -1819,6 +1819,13 @@ void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus)int pci_try_num =1 ;enum enable_type enable_local; +if (pci_can_move_bars) { +__pci_bus_size_bridges (bus,NULL ); +__pci_bus_assign_resources (bus,NULL ,NULL ); + + goto dump; + } +/* Don't realloc if asked to do so */ enable_local =pci_realloc_detect (bus, pci_realloc_enable);if (pci_realloc_enabled (enable_local)) {
Signature · 1 line
2.23.0
PATCH v6 12/30 PCI: hotplug: movable BARs: Calculate immovable parts of bridge windows
In reply to Sergey MiroshnichenkoWhen movable BARs are enabled, and if a bridge contains a device with fixed (IORESOURCE_PCI_FIXED) or immovable BARs, the corresponing windows can't be moved too far away from their original positions - they must still contain all the fixed/immovable BARs, like that:
1) Window position before a bus rescan:
| <-- root bridge window --> | | | | | <-- bridge window --> | | | | movable BARs | **fixed BAR** | |
2) Possible valid outcome after rescan and move:
| <-- root bridge window --> | | | | | <-- bridge window --> | | | | **fixed BAR** | Movable BARs | |
An immovable area of a bridge (separare for IO, MEM and MEM64 window types) is a range that covers all the fixed and immovable BARs of direct children, and all the fixed area of children bridges:
| <-- root bridge window --> | | | | | <-- bridge window level 1 --> | | | | ******** immovable area of this bridge window ******** | | | | | | | | **fixed BAR** | <-- bridge window level 2 --> | BARs | | | | | ***** fixed area of this bridge ***** | | | | | | | | | | | | ***fixed BAR*** | | ***fixed BAR*** | | |
To store these areas, the .immovable_range field has been added to struct pci_bus. It is filled recursively from leaves to the root before a rescan.
Also make pbus_size_io() and pbus_size_mem() return their usual result OR the size of an immovable range of according type, depending on which one is larger.
--- drivers/pci/pci.h | 14 +++++++ drivers/pci/probe.c | 88 +++++++++++++++++++++++++++++++++++++++++ drivers/pci/setup-bus.c | 17 ++++++++ include/linux/pci.h | 6 +++ 4 files changed, 125 insertions(+)
drivers/pci/pci.h +14 -0
@@ -401,6 +401,20 @@ static inline bool pci_dev_is_disconnected(const struct pci_dev *dev)return dev->error_state == pci_channel_io_perm_failure; } +static inline int pci_get_bridge_resource_idx (struct resource *r) +{ +int idx =1 ; + +if (r->flags &IORESOURCE_IO ) + idx =0 ; +else if (!(r->flags &IORESOURCE_PREFETCH )) + idx =1 ; +else if (r->flags &IORESOURCE_MEM_64 ) + idx =2 ; + +return idx; +} +/* pci_dev priv_flags */ #define PCI_DEV_ADDED 0#define PCI_DEV_DISABLED_BARS 1
drivers/pci/probe.c +88 -0
112 lines not on this page · raw message
drivers/pci/setup-bus.c +17 -0
@@ -882,9 +882,17 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size,resource_size_t children_add_size =0 ;resource_size_t min_align, align; +resource_size_t fixed_start = bus->immovable_range[0 ].start; +resource_size_t fixed_end = bus->immovable_range[0 ].end; +resource_size_t fixed_size = (fixed_start < fixed_end) ? + (fixed_end - fixed_start +1 ) :0 ; +if (!b_res)return ; +if (min_size < fixed_size) + min_size = fixed_size; + min_align =window_alignment (bus,IORESOURCE_IO );list_for_each_entry (dev, &bus->devices, bus_list) {int i;
@@ -993,6 +1001,15 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask,resource_size_t children_add_size =0 ;resource_size_t children_add_align =0 ;resource_size_t add_align =0 ; +bool is_mem64 = (mask &IORESOURCE_MEM_64 ); + +resource_size_t fixed_start = bus->immovable_range[is_mem64 ?2 :1 ].start; +resource_size_t fixed_end = bus->immovable_range[is_mem64 ?2 :1 ].end; +resource_size_t fixed_size = (fixed_start < fixed_end) ? + (fixed_end - fixed_start +1 ) :0 ; + +if (min_size < fixed_size) + min_size = fixed_size;if (!b_res)return -ENOSPC ;
include/linux/pci.h +6 -0
@@ -581,6 +581,12 @@ struct pci_bus {struct list_head resources;/* Address space routed to this bus */ struct resource busn_res;/* Bus numbers routed to this bus */ +/* +* If there are fixed or immovable resources in the bridge window, this range +* contains the lowest start address and highest end address of them. +*/ +struct resource immovable_range[PCI_BRIDGE_RESOURCE_NUM ]; +struct pci_ops *ops;/* Configuration access functions */ struct msi_controller *msi;/* MSI controller */ void *sysdata;/* Hook for sys-specific extension */
Signature · 1 line
2.23.0
PATCH v6 13/30 PCI: hotplug: movable BARs: Compute limits for relocated bridge windows
In reply to Sergey MiroshnichenkoWith enabled movable BARs, bridge windows are recalculated during each pci rescan. Some of the BARs below the bridge may be fixed/immovable: these areas are represented by the .immovable_range field in struct pci_bus.
If a bridge window size is equal to its immovable range, it can only be assigned to the start of this range. But if a bridge window size is larger, and this difference in size is denoted as "delta", the window can start from (immovable_range.start - delta) to (immovable_range.start), and it can end from (immovable_range.end) to (immovable_range.end + delta). This range (the new .realloc_range field in struct pci_bus) must then be compared with immovable ranges of neighbouring bridges to guarantee no intersections.
This patch only calculates valid ranges for reallocated bridges during pci rescan, and the next one will make use of these values during allocation.
--- drivers/pci/setup-bus.c | 67 +++++++++++++++++++++++++++++++++++++++++ include/linux/pci.h | 6 ++++ 2 files changed, 73 insertions(+)
drivers/pci/setup-bus.c +67 -0
@@ -1819,6 +1819,72 @@ static enum enable_type pci_realloc_detect(struct pci_bus *bus, }#endif +/* +* Calculate the address margins where the bridge windows may be allocated to fit all +* the fixed and immovable BARs beneath. +*/ +static void pci_bus_update_realloc_range (struct pci_bus *bus) +{ +struct pci_dev *dev; +struct pci_bus *parent = bus->parent; +int idx; + +list_for_each_entry (dev, &bus->devices, bus_list) +if (dev->subordinate) +pci_bus_update_realloc_range (dev->subordinate); + +if (!parent || !bus->self) +return ; + +for (idx =0 ; idx <PCI_BRIDGE_RESOURCE_NUM ; ++idx) { +struct resource *immovable_range = &bus->immovable_range[idx]; +resource_size_t window_size =resource_size (bus->resource[idx]); +resource_size_t realloc_start, realloc_end; + + bus->realloc_range[idx].start =0 ; + bus->realloc_range[idx].end =0 ; + +/* Check if there any immovable BARs under the bridge */ +if (immovable_range->start >= immovable_range->end) +continue ; + +/* The lowest possible address where the bridge window can start */ + realloc_start = immovable_range->end - window_size +1 ; +/* The highest possible address where the bridge window can end */ + realloc_end = immovable_range->start + window_size -1 ; + +if (realloc_start > immovable_range->start) + realloc_start = immovable_range->start; + +if (realloc_end < immovable_range->end) + realloc_end = immovable_range->end; + +/* +* Check that realloc range doesn't intersect with hard fixed ranges +* of neighboring bridges +*/ +list_for_each_entry (dev, &parent->devices, bus_list) { +struct pci_bus *neighbor = dev->subordinate; +struct resource *n_imm_range; + +if (!neighbor || neighbor == bus) +continue ; + + n_imm_range = &neighbor->immovable_range[idx]; + +if (n_imm_range->start >= n_imm_range->end) +continue ; + +if (n_imm_range->end < immovable_range->start && + n_imm_range->end > realloc_start) + realloc_start = n_imm_range->end; + } + + bus->realloc_range[idx].start = realloc_start; + bus->realloc_range[idx].end = realloc_end; + } +} +/* * First try will not touch PCI bridge res. * Second and later try will clear small leaf bridge res.
@@ -1838,6 +1904,7 @@ void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus)if (pci_can_move_bars) {__pci_bus_size_bridges (bus,NULL ); +pci_bus_update_realloc_range (bus);__pci_bus_assign_resources (bus,NULL ,NULL ); goto dump;
include/linux/pci.h +6 -0
@@ -587,6 +587,12 @@ struct pci_bus {*/ struct resource immovable_range[PCI_BRIDGE_RESOURCE_NUM ]; +/* +* Acceptable address range, where the bridge window may reside, considering its +* size, so it will cover all the fixed and immovable BARs below. +*/ +struct resource realloc_range[PCI_BRIDGE_RESOURCE_NUM ]; +struct pci_ops *ops;/* Configuration access functions */ struct msi_controller *msi;/* MSI controller */ void *sysdata;/* Hook for sys-specific extension */
Signature · 1 line
2.23.0
PATCH v6 14/30 PCI: Make sure bridge windows include their fixed BARs
In reply to Sergey MiroshnichenkoWhen the time comes to select a start address for the bridge window during the root bus rescan, it should be not just a lowest possible address: this window must cover all the underlying fixed and immovable BARs. The lowest address that satisfies this requirement is the .realloc_range field of struct pci_bus, which is calculated during the preparation to the rescan.
--- drivers/pci/bus.c | 2 +- drivers/pci/setup-res.c | 31 +++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-)
drivers/pci/bus.c +1 -1
@@ -192,7 +192,7 @@ static int pci_bus_alloc_from_region(struct pci_bus *bus, struct resource *res,* this is an already-configured bridge window, its start * overrides "min". */ -if (avail.start) +if (min_used < avail.start) min_used = avail.start; max = avail.end;
drivers/pci/setup-res.c +29 -2
@@ -248,9 +248,23 @@ static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev,struct resource *res = dev->resource + resno;resource_size_t min;int ret; +resource_size_t start = (resource_size_t)-1 ; +resource_size_t end =0 ; min = (res->flags &IORESOURCE_IO ) ?PCIBIOS_MIN_IO :PCIBIOS_MIN_MEM ; +if (dev->subordinate && resno >=PCI_BRIDGE_RESOURCES ) { +struct pci_bus *child_bus = dev->subordinate; +int b_resno = resno -PCI_BRIDGE_RESOURCES ; +struct resource *immovable_range = &child_bus->immovable_range[b_resno]; + +if (immovable_range->start < immovable_range->end) { + start = immovable_range->start; + end = immovable_range->end; + min = child_bus->realloc_range[b_resno].start; + } + } +/* * First, try exact prefetching match. Even if a 64-bit * prefetchable bridge window is below 4GB, we can't put a 32-bit
@@ -262,7 +276,7 @@ static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev,IORESOURCE_PREFETCH |IORESOURCE_MEM_64 , pcibios_align_resource, dev);if (ret ==0 ) -return 0 ; + goto check_fixed;/* * If the prefetchable window is only 32 bits wide, we can put
@@ -274,7 +288,7 @@ static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev,IORESOURCE_PREFETCH , pcibios_align_resource, dev);if (ret ==0 ) -return 0 ; + goto check_fixed; }/*
@@ -287,6 +301,19 @@ static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev, ret =pci_bus_alloc_resource (bus, res, size, align, min,0 , pcibios_align_resource, dev); +check_fixed: +if (ret ==0 && start < end) { +if (res->start > start || res->end < end) { +dev_err (&bus->dev,"fixed area 0x%llx-0x%llx for %s doesn't fit in the allocated %pR (0x%llx-0x%llx)" , + (unsigned long long )start, (unsigned long long )end, +dev_name (&dev->dev), + res, (unsigned long long )res->start, + (unsigned long long )res->end); +release_resource (res); +return -1 ; + } + } +return ret; }
Signature · 1 line
2.23.0
PATCH v6 15/30 PCI: Fix assigning the fixed prefetchable resources
In reply to Sergey MiroshnichenkoAllow matching IORESOURCE_PCI_FIXED prefetchable BARs to non-prefetchable windows, so they follow the same rules as immovable BARs.
--- drivers/pci/setup-bus.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/pci/setup-bus.c +9 -4
@@ -1339,15 +1339,20 @@ static void assign_fixed_resource_on_bus(struct pci_bus *b, struct resource *r) {int i;struct resource *parent_r; -unsigned long mask =IORESOURCE_IO |IORESOURCE_MEM | -IORESOURCE_PREFETCH ; +unsigned long mask =IORESOURCE_TYPE_BITS ;pci_bus_for_each_resource (b, parent_r, i) {if (!parent_r)continue ; -if ((r->flags & mask) == (parent_r->flags & mask) && -resource_contains (parent_r, r)) +if ((r->flags & mask) != (parent_r->flags & mask)) +continue ; + +if (parent_r->flags &IORESOURCE_PREFETCH && + !(r->flags &IORESOURCE_PREFETCH )) +continue ; + +if (resource_contains (parent_r, r))request_resource (parent_r, r); } }
Signature · 1 line
2.23.0
PATCH v6 16/30 PCI: hotplug: movable BARs: Assign fixed and immovable BARs before others
In reply to Sergey MiroshnichenkoReassign resources during rescan in two steps: first the fixed/immovable BARs and bridge windows that have fixed areas, so the movable ones will not steal these reserved areas; then the rest - so the movable BARs will divide the rest of the space.
With this change, pci_assign_resource() is now able to assign all types of BARs, so the pdev_assign_fixed_resources() became unused and thus removed.
--- drivers/pci/pci.h | 2 ++ drivers/pci/setup-bus.c | 78 ++++++++++++++++++++++++----------------- drivers/pci/setup-res.c | 7 ++-- 3 files changed, 53 insertions(+), 34 deletions(-)
drivers/pci/pci.h +2 -0
@@ -289,6 +289,8 @@ void pci_bus_put(struct pci_bus *bus);bool pci_dev_bar_movable (struct pci_dev *dev,struct resource *res); +int assign_fixed_resource_on_bus (struct pci_bus *b,struct resource *r); +/* PCIe link information */ #define PCIE_SPEED2STR (speed) \ ((speed) == PCIE_SPEED_16_0GT ? "16 GT/s" : \
drivers/pci/setup-bus.c +46 -32
121 lines not on this page · raw message
drivers/pci/setup-res.c +5 -2
@@ -351,8 +351,11 @@ int pci_assign_resource(struct pci_dev *dev, int resno)resource_size_t align, size;int ret; -if (res->flags &IORESOURCE_PCI_FIXED ) -return 0 ; +if (resno <PCI_BRIDGE_RESOURCES && + !pci_dev_bar_movable (dev, res) && + res->start) { +return assign_fixed_resource_on_bus (dev->bus, res); + } res->flags |=IORESOURCE_UNSET ; align =pci_resource_alignment (dev, res);
Signature · 1 line
2.23.0
PATCH v6 17/30 PCI: hotplug: movable BARs: Don't reserve IO/mem bus space
In reply to Sergey MiroshnichenkoA hotplugged bridge with many hotplug-capable ports may request reserving more IO space than the machine has. This could be overridden with the "hpiosize=" kernel argument though.
But when BARs are movable, there are no need to reserve space anymore:
new BARs are allocated not from reserved gaps, but via rearranging the existing BARs. Requesting a precise amount of space for bridge windows increases the chances of adding the new bridge successfully.
--- drivers/pci/setup-bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/setup-bus.c +1 -1
@@ -1285,7 +1285,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head)case PCI_HEADER_TYPE_BRIDGE :pci_bridge_check_ranges (bus); -if (bus->self->is_hotplug_bridge) { +if (bus->self->is_hotplug_bridge && !pci_can_move_bars) { additional_io_size = pci_hotplug_io_size; additional_mem_size = pci_hotplug_mem_size; }
Signature · 1 line
2.23.0
PATCH v6 18/30 PCI: hotplug: Configure MPS for hot-added bridges during bus rescan
In reply to Sergey MiroshnichenkoAssure that MPS settings are set up for bridges which are discovered during manually triggered rescan via sysfs. This sequence of bridge init (using pci_rescan_bus()) will be used for pciehp hot-add events when BARs are movable.
--- drivers/pci/probe.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/pci/probe.c +4 -1
@@ -3414,7 +3414,7 @@ static void pci_reassign_root_bus_resources(struct pci_bus *root)unsigned int pci_rescan_bus (struct pci_bus *bus) {unsigned int max; -struct pci_bus *root = bus; +struct pci_bus *root = bus, *child;while (!pci_is_root_bus (root)) root = root->parent;
@@ -3435,6 +3435,9 @@ unsigned int pci_rescan_bus(struct pci_bus *bus)pci_assign_unassigned_bus_resources (bus); } +list_for_each_entry (child, &root->children, node) +pcie_bus_configure_settings (child); +pci_bus_add_devices (bus);return max;
Signature · 1 line
2.23.0
PATCH v6 19/30 PCI: hotplug: movable BARs: Ignore the MEM BAR offsets from bootloader
In reply to Sergey MiroshnichenkoBAR allocation by BIOS/UEFI/bootloader/firmware may be non-optimal and it may even clash with the kernel's BAR assignment algorithm.
For example, if no space was reserved for SR-IOV BARs, and this bridge window is packed between immovable BARs (so it is unable to extend), and if this window can't be moved, the next PCI rescan will fail, as the kernel tries to find a space for all the BARs, including SR-IOV.
With this patch the kernel will use its own methods of BAR allocating when possible, increasing the chances of successful hotplug.
Also add a workaround for implicitly used video BARs on x86.
--- drivers/pci/probe.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/pci/probe.c +10 -0
@@ -305,6 +305,16 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, pos, (unsigned long long)region.start); } +if (pci_can_move_bars && + !(res->flags &IORESOURCE_IO ) && + (dev->class >>8 ) !=PCI_CLASS_DISPLAY_VGA ) { +pci_warn (dev,"ignore the current offset of BAR %llx-%llx\n" , + l64, l64 + sz64 -1 ); + res->start =0 ; + res->end = sz64 -1 ; + res->flags |=IORESOURCE_SIZEALIGN ; + } + goto out;
Signature · 1 line
2.23.0
PATCH v6 20/30 powerpc/pci: Fix crash with enabled movable BARs
In reply to Sergey MiroshnichenkoAdd a check for the UNSET resource flag to skip the released BARs
--- arch/powerpc/platforms/powernv/pci-ioda.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/powerpc/platforms/powernv/pci-ioda.c +2 -1
@@ -2976,7 +2976,8 @@ static void pnv_ioda_setup_pe_res(struct pnv_ioda_pe *pe,int index;int64_t rc; -if (!res || !res->flags || res->start > res->end) +if (!res || !res->flags || res->start > res->end || + (res->flags &IORESOURCE_UNSET ))return ;if (res->flags &IORESOURCE_IO ) {
Signature · 1 line
2.23.0
Re: [PATCH v6 20/30] powerpc/pci: Fix crash with enabled movable BARs
Quoted 1 line · Sergey Miroshnichenko
Add a check for the UNSET resource flag to skip the released BARs
Where/why does it crash exactly? It is not extremely clear from the code. Thanks,
Quoted 24 lines
CC Alexey Kardashevskiy <[email protected]>CC Oliver O'Halloran <[email protected]>CC Sam Bobroff <[email protected]>Signed-off-by Sergey Miroshnichenko <[email protected]>--- arch/powerpc/platforms/powernv/pci-ioda.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/powerpc/platforms/powernv/pci-ioda.c +2
-1@@ -2976,7 +2976,8 @@ static void pnv_ioda_setup_pe_res(struct pnv_ioda_pe *pe,int index;int64_t rc; -if (!res || !res->flags || res->start > res->end) +if (!res || !res->flags || res->start > res->end || + (res->flags &IORESOURCE_UNSET ))return ;if (res->flags &IORESOURCE_IO ) {
Signature · 1 line
Alexey
PATCH v6 21/30 powerpc/pci: Access PCI config space directly w/o pci_dn
In reply to Sergey MiroshnichenkoTo fetch an updated DT for the newly hotplugged device, OS must explicitly request it from the firmware via the pnv_php driver.
If pnv_php wasn't triggered/loaded, it is still possible to discover new devices if PCIe I/O will not stop in absence of the pci_dn structure.
--- arch/powerpc/kernel/rtas_pci.c | 97 +++++++++++++++++++--------- arch/powerpc/platforms/powernv/pci.c | 64 ++++++++++++------ 2 files changed, 109 insertions(+), 52 deletions(-)
arch/powerpc/kernel/rtas_pci.c +66 -31
@@ -42,10 +42,26 @@ static inline int config_access_valid(struct pci_dn *dn, int where)return 0 ; } -int rtas_read_config (struct pci_dn *pdn,int where,int size,u32 *val) +static int rtas_read_raw_config (unsigned long buid,int busno,unsigned int devfn, +int where,int size,u32 *val) {int returnval =-1 ; -unsigned long buid, addr; +unsigned long addr =rtas_config_addr (busno, devfn, where); +int ret; + +if (buid) { + ret =rtas_call (ibm_read_pci_config,4 ,2 , &returnval, + addr,BUID_HI (buid),BUID_LO (buid), size); + }else { + ret =rtas_call (read_pci_config,2 ,2 , &returnval, addr, size); + } + *val = returnval; + +return ret; +} + +int rtas_read_config (struct pci_dn *pdn,int where,int size,u32 *val) +{int ret;if (!pdn)
@@ -58,16 +74,8 @@ int rtas_read_config(struct pci_dn *pdn, int where, int size, u32 *val)return PCIBIOS_SET_FAILED ;#endif - addr =rtas_config_addr (pdn->busno, pdn->devfn, where); - buid = pdn->phb->buid; -if (buid) { - ret =rtas_call (ibm_read_pci_config,4 ,2 , &returnval, - addr,BUID_HI (buid),BUID_LO (buid), size); - }else { - ret =rtas_call (read_pci_config,2 ,2 , &returnval, addr, size); - } - *val = returnval; - + ret =rtas_read_raw_config (pdn->phb->buid, pdn->busno, pdn->devfn, + where, size, val);if (ret)return PCIBIOS_DEVICE_NOT_FOUND ;
@@ -85,18 +93,44 @@ static int rtas_pci_read_config(struct pci_bus *bus, pdn =pci_get_pdn_by_devfn (bus, devfn); -/* Validity of pdn is checked in here */ - ret =rtas_read_config (pdn, where, size, val); -if (*val ==EEH_IO_ERROR_VALUE (size) && -eeh_dev_check_failure (pdn_to_eeh_dev (pdn))) -return PCIBIOS_DEVICE_NOT_FOUND ; +if (pdn) { +/* Validity of pdn is checked in here */ + ret =rtas_read_config (pdn, where, size, val); + +if (*val ==EEH_IO_ERROR_VALUE (size) && +eeh_dev_check_failure (pdn_to_eeh_dev (pdn))) + ret =PCIBIOS_DEVICE_NOT_FOUND ; + }else { +struct pci_controller *phb =pci_bus_to_host (bus); + + ret =rtas_read_raw_config (phb->buid, bus->number, devfn, + where, size, val); + }return ret; } +static int rtas_write_raw_config (unsigned long buid,int busno,unsigned int devfn, +int where,int size,u32 val) +{ +unsigned long addr =rtas_config_addr (busno, devfn, where); +int ret; + +if (buid) { + ret =rtas_call (ibm_write_pci_config,5 ,1 ,NULL , addr, +BUID_HI (buid),BUID_LO (buid), size, (ulong )val); + }else { + ret =rtas_call (write_pci_config,3 ,1 ,NULL , addr, size, (ulong )val); + } + +if (ret) +return PCIBIOS_DEVICE_NOT_FOUND ; + +return PCIBIOS_SUCCESSFUL ; +} +int rtas_write_config (struct pci_dn *pdn,int where,int size,u32 val) { -unsigned long buid, addr;int ret;if (!pdn)
@@ -109,15 +143,8 @@ int rtas_write_config(struct pci_dn *pdn, int where, int size, u32 val)return PCIBIOS_SET_FAILED ;#endif - addr =rtas_config_addr (pdn->busno, pdn->devfn, where); - buid = pdn->phb->buid; -if (buid) { - ret =rtas_call (ibm_write_pci_config,5 ,1 ,NULL , addr, -BUID_HI (buid),BUID_LO (buid), size, (ulong ) val); - }else { - ret =rtas_call (write_pci_config,3 ,1 ,NULL , addr, size, (ulong )val); - } - + ret =rtas_write_raw_config (pdn->phb->buid, pdn->busno, pdn->devfn, + where, size, val);if (ret)return PCIBIOS_DEVICE_NOT_FOUND ;
@@ -128,12 +155,20 @@ static int rtas_pci_write_config(struct pci_bus *bus,unsigned int devfn, int where, int size, u32 val) { - struct pci_dn *pdn; + struct pci_dn *pdn = pci_get_pdn_by_devfn(bus, devfn); +int ret; - pdn =pci_get_pdn_by_devfn (bus, devfn); +if (pdn) { +/* Validity of pdn is checked in here. */ + ret =rtas_write_config (pdn, where, size, val); + }else { +struct pci_controller *phb =pci_bus_to_host (bus); -/* Validity of pdn is checked in here. */ -return rtas_write_config (pdn, where, size, val); + ret =rtas_write_raw_config (phb->buid, bus->number, devfn, + where, size, val); + } + +return ret; } static struct pci_ops rtas_pci_ops = {
arch/powerpc/platforms/powernv/pci.c +43 -21
131 lines not on this page · raw message
Signature · 1 line
2.23.0
PATCH v6 22/30 powerpc/pci: Create pci_dn on demand
In reply to Sergey MiroshnichenkoIf a struct pci_dn hasn't yet been created for the PCIe device (there was no DT node for it), allocate this structure and fill with info read from the device directly.
--- arch/powerpc/kernel/pci_dn.c | 88 ++++++++++++++++++++++++++++++------ 1 file changed, 74 insertions(+), 14 deletions(-)
arch/powerpc/kernel/pci_dn.c +74 -14
@@ -20,6 +20,9 @@#include <asm/firmware.h> #include <asm/eeh.h> +static struct pci_dn *pci_create_pdn_from_dev (struct pci_dev *pdev, +struct pci_dn *parent); +/* * The function is used to find the firmware data of one * specific PCI device, which is attached to the indicated
@@ -52,6 +55,9 @@ static struct pci_dn *pci_bus_to_pdn(struct pci_bus *bus) dn =pci_bus_to_OF_node (pbus); pdn = dn ?PCI_DN (dn) :NULL ; +if (!pdn && pbus->self) + pdn = pbus->self->dev.archdata.pci_data; +return pdn; }
@@ -61,10 +67,13 @@ struct pci_dn *pci_get_pdn_by_devfn(struct pci_bus *bus,struct device_node *dn =NULL ;struct pci_dn *parent, *pdn;struct pci_dev *pdev =NULL ; +bool pdev_found = false;/* Fast path: fetch from PCI device */ list_for_each_entry (pdev, &bus->devices, bus_list) {if (pdev->devfn == devfn) { + pdev_found = true; +if (pdev->dev.archdata.pci_data)return pdev->dev.archdata.pci_data;
@@ -73,6 +82,9 @@ struct pci_dn *pci_get_pdn_by_devfn(struct pci_bus *bus, } } +if (!pdev_found) + pdev =NULL ; +/* Fast path: fetch from device node */ pdn = dn ?PCI_DN (dn) :NULL ;if (pdn)
@@ -85,9 +97,12 @@ struct pci_dn *pci_get_pdn_by_devfn(struct pci_bus *bus,list_for_each_entry (pdn, &parent->child_list, list) {if (pdn->busno == bus->number && - pdn->devfn == devfn) -return pdn; - } + pdn->devfn == devfn) { +if (pdev) + pdev->dev.archdata.pci_data = pdn; +return pdn; + } + }return NULL ; }
@@ -117,17 +132,17 @@ struct pci_dn *pci_get_pdn(struct pci_dev *pdev)list_for_each_entry (pdn, &parent->child_list, list) {if (pdn->busno == pdev->bus->number && - pdn->devfn == pdev->devfn) + pdn->devfn == pdev->devfn) { + pdev->dev.archdata.pci_data = pdn;return pdn; + } } -return NULL ; +return pci_create_pdn_from_dev (pdev, parent); } -#ifdef CONFIG_PCI_IOV -static struct pci_dn *add_one_dev_pci_data (struct pci_dn *parent, -int vf_index, -int busno,int devfn) +static struct pci_dn *pci_alloc_pdn (struct pci_dn *parent, +int busno,int devfn) {struct pci_dn *pdn;
@@ -143,7 +158,6 @@ static struct pci_dn *add_one_dev_pci_data(struct pci_dn *parent, pdn->parent = parent; pdn->busno = busno; pdn->devfn = devfn; - pdn->vf_index = vf_index; pdn->pe_number =IODA_INVALID_PE ;INIT_LIST_HEAD (&pdn->child_list);INIT_LIST_HEAD (&pdn->list);
@@ -151,7 +165,51 @@ static struct pci_dn *add_one_dev_pci_data(struct pci_dn *parent,return pdn; } -#endif + +static struct pci_dn *pci_create_pdn_from_dev (struct pci_dev *pdev, +struct pci_dn *parent) +{ +struct pci_dn *pdn =NULL ; +u32 class_code; +u16 device_id; +u16 vendor_id; + +if (!parent) +return NULL ; + + pdn =pci_alloc_pdn (parent, pdev->bus->busn_res.start, pdev->devfn); +pci_info (pdev,"Create a new pdn for devfn %2x\n" , pdev->devfn /8 ); + +if (!pdn) { +pci_err (pdev,"%s: Failed to allocate pdn\n" , __func__); +return NULL ; + } + +#ifdef CONFIG_EEH +if (!eeh_dev_init (pdn)) { +kfree (pdn); +pci_err (pdev,"%s: Failed to allocate edev\n" , __func__); +return NULL ; + } +#endif /* CONFIG_EEH */ + +pci_bus_read_config_word (pdev->bus, pdev->devfn, +PCI_VENDOR_ID , &vendor_id); + pdn->vendor_id = vendor_id; + +pci_bus_read_config_word (pdev->bus, pdev->devfn, +PCI_DEVICE_ID , &device_id); + pdn->device_id = device_id; + +pci_bus_read_config_dword (pdev->bus, pdev->devfn, +PCI_CLASS_REVISION , &class_code); + class_code >>=8 ; + pdn->class_code = class_code; + + pdev->dev.archdata.pci_data = pdn; + +return pdn; +}struct pci_dn *add_dev_pci_data (struct pci_dev *pdev) {
@@ -176,15 +234,17 @@ struct pci_dn *add_dev_pci_data(struct pci_dev *pdev)for (i =0 ; i <pci_sriov_get_totalvfs (pdev); i++) {struct eeh_dev *edev__maybe_unused ; - pdn =add_one_dev_pci_data (parent, i, -pci_iov_virtfn_bus (pdev, i), -pci_iov_virtfn_devfn (pdev, i)); + pdn =pci_alloc_pdn (parent, +pci_iov_virtfn_bus (pdev, i), +pci_iov_virtfn_devfn (pdev, i));if (!pdn) {dev_warn (&pdev->dev,"%s: Cannot create firmware data for VF#%d\n" , __func__, i);return NULL ; } + pdn->vf_index = i; +#ifdef CONFIG_EEH /* Create the EEH device for the VF */ edev =eeh_dev_init (pdn);
Signature · 1 line
2.23.0
PATCH v6 23/30 powerpc/pci: hotplug: Add support for movable BARs
In reply to Sergey MiroshnichenkoAdd pcibios_root_bus_rescan_prepare()/_done() hooks for the powerpc, so it can reassign the PE numbers (which depend on BAR sizes and locations) and update the EEH address cache during a PCI rescan.
New PE numbers are assigned during pci_setup_bridges(root) after the rescan is done.
--- arch/powerpc/kernel/pci-hotplug.c | 43 +++++++++++++++++++++++++++++++ drivers/pci/probe.c | 10 +++++++ include/linux/pci.h | 3 +++ 3 files changed, 56 insertions(+)
arch/powerpc/kernel/pci-hotplug.c +43 -0
@@ -16,6 +16,7 @@#include <asm/ppc-pci.h> #include <asm/firmware.h> #include <asm/eeh.h> +#include <asm/iommu.h> static struct pci_bus *find_bus_among_children (struct pci_bus *bus,struct device_node *dn)
@@ -151,3 +152,45 @@ void pci_hp_add_devices(struct pci_bus *bus)pcibios_finish_adding_to_bus (bus); }EXPORT_SYMBOL_GPL (pci_hp_add_devices); + +static void pci_hp_bus_rescan_prepare (struct pci_bus *bus) +{ +struct pci_dev *dev; + +list_for_each_entry (dev, &bus->devices, bus_list) { +struct pci_bus *child = dev->subordinate; + +if (child) +pci_hp_bus_rescan_prepare (child); + +iommu_del_device (&dev->dev); + } + +list_for_each_entry (dev, &bus->devices, bus_list) { +pcibios_release_device (dev); + } +} + +static void pci_hp_bus_rescan_done (struct pci_bus *bus) +{ +struct pci_dev *dev; + +list_for_each_entry (dev, &bus->devices, bus_list) { +struct pci_bus *child = dev->subordinate; + +pcibios_bus_add_device (dev); + +if (child) +pci_hp_bus_rescan_done (child); + } +} + +void pcibios_root_bus_rescan_prepare (struct pci_bus *root) +{ +pci_hp_bus_rescan_prepare (root); +} + +void pcibios_root_bus_rescan_done (struct pci_bus *root) +{ +pci_hp_bus_rescan_done (root); +}
drivers/pci/probe.c +10 -0
@@ -3235,6 +3235,14 @@ static void pci_bus_rescan_done(struct pci_bus *bus)pci_config_pm_runtime_put (bus->self); } +void __weak pcibios_root_bus_rescan_prepare (struct pci_bus *root) +{ +} + +void __weak pcibios_root_bus_rescan_done (struct pci_bus *root) +{ +} +static void pci_setup_bridges (struct pci_bus *bus) {struct pci_dev *dev;
@@ -3430,6 +3438,7 @@ unsigned int pci_rescan_bus(struct pci_bus *bus) root = root->parent;if (pci_can_move_bars) { +pcibios_root_bus_rescan_prepare (root);pci_bus_rescan_prepare (root);pci_bus_update_immovable_range (root);pci_bus_release_root_bridge_resources (root);
@@ -3440,6 +3449,7 @@ unsigned int pci_rescan_bus(struct pci_bus *bus)pci_setup_bridges (root);pci_bus_rescan_done (root); +pcibios_root_bus_rescan_done (root); }else { max =pci_scan_child_bus (bus);pci_assign_unassigned_bus_resources (bus);
include/linux/pci.h +3 -0
@@ -1275,6 +1275,9 @@ unsigned int pci_rescan_bus(struct pci_bus *bus);void pci_lock_rescan_remove (void );void pci_unlock_rescan_remove (void ); +void pcibios_root_bus_rescan_prepare (struct pci_bus *root); +void pcibios_root_bus_rescan_done (struct pci_bus *root); +/* Vital Product Data routines */ ssize_t pci_read_vpd (struct pci_dev *dev,loff_t pos,size_t count,void *buf);ssize_t pci_write_vpd (struct pci_dev *dev,loff_t pos,size_t count,const void *buf);
Signature · 1 line
2.23.0
PATCH v6 24/30 powerpc/powernv/pci: Suppress an EEH error when reading an empty slot
In reply to Sergey MiroshnichenkoReading an empty slot returns all ones, which triggers a false EEH error event on PowerNV. A rescan is performed after all the PEs have been unmapped, so the reserved PE index is used for unfreezing.
--- arch/powerpc/platforms/powernv/pci.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
arch/powerpc/platforms/powernv/pci.c +10 -3
@@ -768,9 +768,16 @@ static int pnv_pci_read_config(struct pci_bus *bus, *val =0xFFFFFFFF ; pdn =pci_get_pdn_by_devfn (bus, devfn); -if (!pdn) -return pnv_pci_cfg_read_raw (phb->opal_id, bus->number, devfn, - where, size, val); +if (!pdn) { + ret =pnv_pci_cfg_read_raw (phb->opal_id, bus->number, devfn, + where, size, val); + +if (!ret && (*val ==EEH_IO_ERROR_VALUE (size)) && phb->unfreeze_pe) + phb->unfreeze_pe (phb, phb->ioda.reserved_pe_idx, +OPAL_EEH_ACTION_CLEAR_FREEZE_ALL ); + +return ret; + }if (!pnv_pci_cfg_check (pdn))return PCIBIOS_DEVICE_NOT_FOUND ;
Signature · 1 line
2.23.0
PATCH v6 25/30 PNP: Don't reserve BARs for PCI when enabled movable BARs
In reply to Sergey MiroshnichenkoWhen the Movable BARs feature is supported, the PCI subsystem is able to distribute existing BARs and allocate the new ones itself, without need to reserve gaps by BIOS.
--- drivers/pnp/system.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/pnp/system.c +4 -0
@@ -12,6 +12,7 @@#include <linux/device.h> #include <linux/init.h> #include <linux/slab.h> +#include <linux/pci.h> #include <linux/kernel.h> #include <linux/ioport.h>
@@ -58,6 +59,9 @@ static void reserve_resources_of_dev(struct pnp_dev *dev)struct resource *res;int i; +if (pci_can_move_bars) +return ; +for (i =0 ; (res =pnp_get_resource (dev,IORESOURCE_IO , i)); i++) {if (res->flags &IORESOURCE_DISABLED )continue ;
Signature · 1 line
2.23.0
kbuild test robot
build botRe: [PATCH v6 25/30] PNP: Don't reserve BARs for PCI when enabled movable BARs
Thank you for the patch! Yet something to improve:
Hi Sergey,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on pci/next]
[also build test ERROR on v5.4-rc4 next-20191025]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Sergey-Miroshnichenko/PCI-Allow-BAR-movement-during-hotplug/20191028-002741 base: https://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git next config: i386-alldefconfig (attached as .config) compiler: gcc-7 (Debian 7.4.0-14) 7.4.0 reproduce: # save the attached .config to linux build tree make ARCH=i386
If you fix the issue, kindly add following tag
All errors (new ones prefixed by >>):
drivers/pnp/system.c: In function 'reserve_resources_of_dev':
>> drivers/pnp/system.c:62:6: error: 'pci_can_move_bars' undeclared (first use in this function); did you mean 'pci_cap_saved_data'?
if (pci_can_move_bars)
^~~~~~~~~~~~~~~~~
pci_cap_saved_data drivers/pnp/system.c:62:6: note: each undeclared identifier is reported only once for each function it appears in
vim +62 drivers/pnp/system.c
56
57 static void reserve_resources_of_dev(struct pnp_dev *dev)
58 {
59 struct resource *res;
60 int i;
61
> 62 if (pci_can_move_bars)
63 return;
64
65 for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) {
66 if (res->flags & IORESOURCE_DISABLED)
67 continue;
68 if (res->start == 0)
69 continue; /* disabled */
70 if (res->start < 0x100)
71 /*
72 * Below 0x100 is only standard PC hardware
73 * (pics, kbd, timer, dma, ...)
74 * We should not get resource conflicts there,
75 * and the kernel reserves these anyway
76 * (see arch/i386/kernel/setup.c).
77 * So, do nothing
78 */
79 continue;
80 if (res->end < res->start)
81 continue; /* invalid */
82
83 reserve_range(dev, res, 1);
84 }
85
86 for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) {
87 if (res->flags & IORESOURCE_DISABLED)
88 continue;
89
90 reserve_range(dev, res, 0);
91 }
92 }
93 ---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
PATCH v6 26/30 PCI: hotplug: movable BARs: Enable the feature by default
In reply to Sergey MiroshnichenkoThis is the last patch in the series which implements the essentials of the Movable BARs feature, so it is turned by default now. Tested on:
- x86_64 with "pci=realloc,pcie_bus_peer2peer" command line argument;
- POWER8 PowerNV+PHB3 ppc64le with "pci=realloc,pcie_bus_peer2peer".
In case of problems it is still can be overridden by the following command line option:
pcie_movable_bars=off
--- drivers/pci/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/pci.c +1 -1
@@ -78,7 +78,7 @@ static void pci_dev_d3_sleep(struct pci_dev *dev)int pci_domains_supported =1 ;#endif -bool pci_can_move_bars; +bool pci_can_move_bars = true;#define DEFAULT_CARDBUS_IO_SIZE (256)#define DEFAULT_CARDBUS_MEM_SIZE (64*1024*1024)
Signature · 1 line
2.23.0
PATCH v6 27/30 nvme-pci: Handle movable BARs
In reply to Sergey MiroshnichenkoHotplugged devices can affect the existing ones by moving their BARs. The PCI subsystem will inform the NVME driver about this by invoking the .rescan_prepare() and .rescan_done() hooks, so the BARs can by re-mapped.
Tested under the "randrw" mode of the fio tool. Before the hotplugging:
% sudo cat /proc/iomem
...
3fe800000000-3fe8007fffff : PCI Bus 0020:0b
3fe800000000-3fe8007fffff : PCI Bus 0020:18
3fe800000000-3fe8000fffff : 0020:18:00.0
3fe800000000-3fe8000fffff : nvme
3fe800100000-3fe80017ffff : 0020:18:00.0...
, then another NVME drive was hot-added, so BARs of the 0020:18:00.0 are moved:
% sudo cat /proc/iomem
...
3fe800000000-3fe800ffffff : PCI Bus 0020:0b
3fe800000000-3fe8007fffff : PCI Bus 0020:10
3fe800000000-3fe800003fff : 0020:10:00.0
3fe800000000-3fe800003fff : nvme
3fe800010000-3fe80001ffff : 0020:10:00.0
3fe800800000-3fe800ffffff : PCI Bus 0020:18
3fe800800000-3fe8008fffff : 0020:18:00.0
3fe800800000-3fe8008fffff : nvme
3fe800900000-3fe80097ffff : 0020:18:00.0
...During the rescanning, both READ and WRITE speeds drop to zero for a while due to driver's pause, then restore.
Also tested with an NVME as a system drive.
--- drivers/nvme/host/pci.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
drivers/nvme/host/pci.c +20 -1
@@ -1650,7 +1650,7 @@ static int nvme_remap_bar(struct nvme_dev *dev, unsigned long size) {struct pci_dev *pdev =to_pci_dev (dev->dev); -if (size <= dev->bar_mapped_size) +if (dev->bar && size <= dev->bar_mapped_size)return 0 ;if (size >pci_resource_len (pdev,0 ))return -ENOMEM ;
@@ -3059,6 +3059,23 @@ static void nvme_error_resume(struct pci_dev *pdev)flush_work (&dev->ctrl.reset_work); } +static void nvme_rescan_prepare (struct pci_dev *pdev) +{ +struct nvme_dev *dev =pci_get_drvdata (pdev); + +nvme_dev_disable (dev, false); +nvme_dev_unmap (dev); + dev->bar =NULL ; +} + +static void nvme_rescan_done (struct pci_dev *pdev) +{ +struct nvme_dev *dev =pci_get_drvdata (pdev); + +nvme_dev_map (dev); +nvme_reset_ctrl_sync (&dev->ctrl); +} +static const struct pci_error_handlers nvme_err_handler = { .error_detected = nvme_error_detected, .slot_reset = nvme_slot_reset,
@@ -3135,6 +3152,8 @@ static struct pci_driver nvme_driver = {#endif .sriov_configure = pci_sriov_configure_simple, .err_handler = &nvme_err_handler, + .rescan_prepare = nvme_rescan_prepare, + .rescan_done = nvme_rescan_done, };static int __init nvme_init (void )
Signature · 1 line
2.23.0
PATCH v6 28/30 PCI/portdrv: Declare support of movable BARs
In reply to Sergey MiroshnichenkoSwitch's BARs are not used by the portdrv driver, but they are still considered as immovable until the .rescan_prepare() and .rescan_done() hooks are added. Add these hooks to increase chances to allocate new BARs.
--- drivers/pci/pcie/portdrv_pci.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/pci/pcie/portdrv_pci.c +11 -0
@@ -197,6 +197,14 @@ static const struct pci_error_handlers pcie_portdrv_err_handler = { .resume = pcie_portdrv_err_resume, }; +static void pcie_portdrv_rescan_prepare (struct pci_dev *pdev) +{ +} + +static void pcie_portdrv_rescan_done (struct pci_dev *pdev) +{ +} +static struct pci_driver pcie_portdriver = { .name ="pcieport" , .id_table = &port_pci_ids[0 ],
@@ -207,6 +215,9 @@ static struct pci_driver pcie_portdriver = { .err_handler = &pcie_portdrv_err_handler, + .rescan_prepare = pcie_portdrv_rescan_prepare, + .rescan_done = pcie_portdrv_rescan_done, + .driver.pm = PCIE_PORTDRV_PM_OPS, };
Signature · 1 line
2.23.0
PATCH v6 29/30 PCI: pciehp: movable BARs: Trigger a domain rescan on hp events
In reply to Sergey MiroshnichenkoWith movable BARs, adding a hotplugged device is not local to its bridge anymore, but it affects the whole domain: BARs, bridge windows and bus numbers can be substantially rearranged. So instead of trying to fit the new devices into preallocated reserved gaps, initiate a full domain rescan.
The pci_rescan_bus() covers all the operations of the replaced functions:
- assigning new bus numbers, as the pci_hp_add_bridge() does it;
- allocating BARs (pci_assign_unassigned_bridge_resources());
- cofiguring MPS settings (pcie_bus_configure_settings());
- binding devices to their drivers (pci_bus_add_devices()).
--- drivers/pci/hotplug/pciehp_pci.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/pci/hotplug/pciehp_pci.c +5 -0
@@ -58,6 +58,11 @@ int pciehp_configure_device(struct controller *ctrl) goto out; } +if (pci_can_move_bars) { +pci_rescan_bus (parent); + goto out; + } +for_each_pci_bridge (dev, parent)pci_hp_add_bridge (dev);
Signature · 1 line
2.23.0
PATCH v6 30/30 Revert "powerpc/powernv/pci: Work around races in PCI bridge enabling"
In reply to Sergey MiroshnichenkoThis reverts commit db2173198b9513f7add8009f225afa1f1c79bcc6.
The root cause of this bug is fixed by the following two commits:
1. "PCI: Fix race condition in pci_enable/disable_device()"
2. "PCI: Enable bridge's I/O and MEM access for hotplugged devices"
The x86 is also affected by this bug if a PCIe bridge has been hotplugged without pre-enabling by the BIOS.
--- arch/powerpc/platforms/powernv/pci-ioda.c | 37 ----------------------- 1 file changed, 37 deletions(-)
arch/powerpc/platforms/powernv/pci-ioda.c +0 -37
@@ -3119,49 +3119,12 @@ static void pnv_pci_ioda_create_dbgfs(void)#endif /* CONFIG_DEBUG_FS */ } -static void pnv_pci_enable_bridge (struct pci_bus *bus) -{ -struct pci_dev *dev = bus->self; -struct pci_bus *child; - -/* Empty bus ? bail */ -if (list_empty (&bus->devices)) -return ; - -/* -* If there's a bridge associated with that bus enable it. This works -* around races in the generic code if the enabling is done during -* parallel probing. This can be removed once those races have been -* fixed. -*/ -if (dev) { -int rc =pci_enable_device (dev); -if (rc) -pci_err (dev,"Error enabling bridge (%d)\n" , rc); -pci_set_master (dev); - } - -/* Perform the same to child busses */ -list_for_each_entry (child, &bus->children, node) -pnv_pci_enable_bridge (child); -} - -static void pnv_pci_enable_bridges (void ) -{ -struct pci_controller *hose; - -list_for_each_entry (hose, &hose_list, list_node) -pnv_pci_enable_bridge (hose->bus); -} -static void pnv_pci_ioda_fixup (void ) {pnv_pci_ioda_setup_PEs ();pnv_pci_ioda_setup_iommu_api ();pnv_pci_ioda_create_dbgfs (); -pnv_pci_enable_bridges (); -#ifdef CONFIG_EEH pnv_eeh_post_init ();#endif
Signature · 1 line
2.23.0