PCI: Do not add hotplug reservation multiple times
PATCH 1/1 PCI: Do not add hotplug reservation multiple times
In nested topologies, hotplug reservations gets added multiple times into the bridge window higher up in the hierarchy. Adding reservation for intermediate level bridges does not seem very useful because the hotplug is going to add device at a leaf.
Accounting the hoptlug reservation multiple times results in larger than expected bridge window size that may lead to assignment failures as show in this log:
pci_bus 0000:0a: root bus resource [mem 0x10a00000-0x10c00fff window] pci 0000:0a:00.0: BAR 0 [mem 0x10c00000-0x10c00fff]
pci 0000:0a:00.0: bridge window [mem 0x10a00000-0x10bfffff] pci 0000:0b:00.0: bridge window [mem 0x10a00000-0x10bfffff] pci 0000:0c:02.0: bridge window [mem 0x10a00000-0x10bfffff]
pci 0000:0c:02.0: bridge window [mem 0x00100000-0x000fffff 64bit pref] to [bus 0d] add_size 200000 add_align 100000 pci 0000:0c:02.0: bridge window [mem 0x00100000-0x000fffff] to [bus 0d] add_size 200000 add_align 100000 pci 0000:0b:00.0: bridge window [mem 0x00100000-0x000fffff 64bit pref] to [bus 0c-0d] add_size 200000 add_align 100000 pci 0000:0b:00.0: bridge window [mem 0x00100000-0x000fffff] to [bus 0c-0d] add_size 200000 add_align 100000 pci 0000:0a:00.0: bridge window [mem 0x00100000-0x000fffff 64bit pref] to [bus 0b-0d] add_size 400000 add_align 100000 pci 0000:0a:00.0: bridge window [mem 0x00100000-0x000fffff] to [bus 0b-0d] add_size 400000 add_align 100000 pci 0000:0a:00.0: bridge window [mem size 0x00400000]: can't assign; no space
pci 0000:0a:00.0: bridge window [mem size 0x00400000]: failed to assign
pci 0000:0a:00.0: bridge window [mem size 0x00400000 64bit pref]: can't assign; no space
pci 0000:0a:00.0: bridge window [mem size 0x00400000 64bit pref]: failed to assign
The problem stems from calculate_memsize() that calculates size first and then adds childen size:
size = max(0, 2M) + 2M
Alter the logic to first account for the children size before applying the hotplug reservation to not add hotplug reservation multiple times on different levels of a nested topology. As a result, the size calculation becomes:
size = max(0 + 2M, 2M)
--- drivers/pci/setup-bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/setup-bus.c +1 -1
@@ -1021,7 +1021,7 @@ static resource_size_t calculate_memsize(resource_size_t size,resource_size_t children_add_size, resource_size_t align) { - size =max (size, min_size) + children_add_size; + size =max (size + children_add_size, min_size);return ALIGN (size, align); }
base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482
Signature · 1 line
2.47.3
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The patch fixes nested hotplug reservation accumulation for memory windows in calculate_memsize(), but misses the identical buggy logic in calculate_iosize(), leading to I/O space exhaustion. --
--- Patch [1]: [PATCH 1/1] PCI: Do not add hotplug reservation multiple times --- commit 3c4b4a62adcb92793a7c17214021e8b637be1016
Author: Ilpo Järvinen <[email protected]>
PCI: Do not add hotplug reservation multiple times
In nested topologies, hotplug reservations gets added multiple times into the bridge window higher up in the hierarchy. Adding reservation for intermediate level bridges does not seem very useful because the hotplug is going to add device at a leaf.
drivers/pci/setup-bus.c static resource_size_t calculate_memsize(resource_size_t size, · line 1026
Quoted 12 lines
drivers/pci/setup-bus.c +1
-1@@ -1021,7 +1021,7 @@ static resource_size_t calculate_memsize(resource_size_t size,resource_size_t children_add_size, resource_size_t align) { - size =max (size, min_size) + children_add_size; + size =max (size + children_add_size, min_size);return ALIGN (size, align); }
[Severity: High]
This isn't a bug introduced by this patch, but does calculate_iosize() need a similar fix to avoid I/O space exhaustion in nested topologies?
Just above calculate_memsize(), calculate_iosize() retains the identical logic for I/O windows:
drivers/pci/setup-bus.c:calculate_iosize() {
...
size = max(size, add_size) + children_add_size;
return ALIGN(max(size, old_size), align);
}When allocating I/O windows for nested hotplug bridges, pbus_size_io() passes both the accumulated children I/O sizes (children_add_size) and the hotplug reservation (add_size) to calculate_iosize().
Because the logic is exactly the same as the unpatched calculate_memsize(), this appears to still unconditionally add an extra 4KB (due to bridge window alignment) at each nested bridge level. Can this linearly inflate the required space and quickly exhaust the limited 64KB I/O address space on systems with deeply nested hotplug PCIe bridges (like Thunderbolt docks)?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 49 lines · On Mon, 20 Jul 2026, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The patch fixes nested hotplug reservation accumulation for memory windows incalculate_memsize(), but misses the identical buggy logic incalculate_iosize(), leading to I/O space exhaustion. ----- Patch [1]: [PATCH 1/1] PCI: Do not add hotplug reservation multiple times --- commit
3c4b4a62adcb92793a7c17214021e8b637be1016
Author: Ilpo Järvinen <[email protected]>PCI: Do not add hotplug reservation multiple times
In nested topologies, hotplug reservations gets added multiple times into the bridge window higher up in the hierarchy. Adding reservation for intermediate level bridges does not seem very useful because the hotplug is going to add device at a leaf.
drivers/pci/setup-bus.c static resource_size_t calculate_memsize(resource_size_t size, · line 1026
Quoted 12 lines
drivers/pci/setup-bus.c +1
-1@@ -1021,7 +1021,7 @@ static resource_size_t calculate_memsize(resource_size_t size,resource_size_t children_add_size, resource_size_t align) { - size =max (size, min_size) + children_add_size; + size =max (size + children_add_size, min_size);return ALIGN (size, align); }[Severity: High]
This isn't a bug introduced by this patch, but doescalculate_iosize()need a similar fix to avoid I/O space exhaustion in nested topologies?Just above
calculate_memsize(),calculate_iosize()retains the identical logic for I/O windows:drivers/pci/setup-bus.c:calculate_iosize() { ... size = max(size, add_size) + children_add_size; return ALIGN(max(size, old_size), align); }When allocating I/O windows for nested hotplug bridges,
pbus_size_io()passes both the accumulated children I/O sizes (children_add_size) and the hotplug reservation (add_size) tocalculate_iosize().
Quoted 5 lines
Because the logic is exactly the same as the unpatched
calculate_memsize(), this appears to still unconditionally add an extra 4KB (due to bridge window alignment) at each nested bridge level. Can this linearly inflate the required space and quickly exhaust the limited 64KB I/O address space on systems with deeply nested hotplug PCIe bridges (like Thunderbolt docks)?
For the record, I intentionally left the io side untouched.
If somebody feels I should make the same change there, I can of course add it there.
IMO io side would be better served with defaulting hotplug allocation to zero, big systems keep running out of io space because of gazillions empty reservations even when nesting is not in the picture.
Signature · 1 line
i.
Bjorn Helgaas
AppliedQuoted 33 lines · Ilpo Järvinen
In nested topologies, hotplug reservations gets added multiple times into the bridge window higher up in the hierarchy. Adding reservation for intermediate level bridges does not seem very useful because the hotplug is going to add device at a leaf.
Accounting the hoptlug reservation multiple times results in larger than expected bridge window size that may lead to assignment failures as show in this log:
pci_bus0000:0a: root bus resource [mem 0x10a00000-0x10c00fff window] pci 0000:0a:00.0: BAR 0 [mem 0x10c00000-0x10c00fff]pci 0000:0a:00.0: bridge window [mem 0x10a00000-0x10bfffff] pci 0000:0b:00.0: bridge window [mem 0x10a00000-0x10bfffff] pci 0000:0c:02.0: bridge window [mem 0x10a00000-0x10bfffff]pci 0000:0c:02.0: bridge window [mem 0x00100000-0x000fffff 64bit pref] to [bus 0d]
add_size200000add_align100000 pci 0000:0c:02.0: bridge window [mem 0x00100000-0x000fffff] to [bus 0d]add_size200000add_align100000 pci 0000:0b:00.0: bridge window [mem 0x00100000-0x000fffff 64bit pref] to [bus 0c-0d]add_size200000add_align100000 pci 0000:0b:00.0: bridge window [mem 0x00100000-0x000fffff] to [bus 0c-0d]add_size200000add_align100000 pci 0000:0a:00.0: bridge window [mem 0x00100000-0x000fffff 64bit pref] to [bus 0b-0d]add_size400000add_align100000 pci 0000:0a:00.0: bridge window [mem 0x00100000-0x000fffff] to [bus 0b-0d]add_size400000add_align100000 pci 0000:0a:00.0: bridge window [mem size0x00400000]: can't assign; no space
pci 0000:0a:00.0: bridge window [mem size0x00400000]: failed to assign
pci 0000:0a:00.0: bridge window [mem size0x0040000064bit pref]: can't assign; no space
pci 0000:0a:00.0: bridge window [mem size0x0040000064bit pref]: failed to assignThe problem stems from
calculate_memsize()that calculates size first and then adds childen size:size = max(0, 2M) + 2MAlter the logic to first account for the children size before applying the hotplug reservation to not add hotplug reservation multiple times on different levels of a nested topology. As a result, the size calculation becomes:
Quoted 5 lines
size = max(0 + 2M, 2M)Reported-by Eric Auger <[email protected]>Signed-off-by Ilpo Järvinen <[email protected]>
Applied to pci/resource for v7.3, thanks!
Quoted 22 lines
--- drivers/pci/setup-bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/pci/setup-bus.c +1
-1@@ -1021,7 +1021,7 @@ static resource_size_t calculate_memsize(resource_size_t size,resource_size_t children_add_size, resource_size_t align) { - size =max (size, min_size) + children_add_size; + size =max (size + children_add_size, min_size);return ALIGN (size, align); }base-commit:
dc59e4fea9d83f03bad6bddf3fa2e52491777482Signature · 1 line
2.47.3