[PATCH 02/15] PCI: Set new BAR Size only after releasing the BARs for BAR resize
From: Ilpo Järvinen
Date: Tue Dec 01 2026 - 10:59:36 EST
pci_do_resource_release_and_resize() sets the new BAR Size before it
saves and releases the BARs that share the bridge window with the BAR
being resized. The BAR Size decides which bits of the Base Address
Register are read-only, so the address in the resized BAR may lose its
low bits right away.
Saving the BARs needs memory allocations, which can fail. If that
happens before the resized BAR has been saved, the BAR resize rollback
restores the old BAR Size but cannot restore the address of the resized
BAR, which leaves the BAR and its resource out of sync.
Nothing requires setting the new BAR Size that early. Set it only after
all the BARs have been saved and released, right before the resource is
resized.
Fixes: 337b1b566db0 ("PCI: Fix restoring BARs on BAR resize rollback path")
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@xxxxxxxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
drivers/pci/setup-bus.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index b69041fbbd39..608ca7afbfb8 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -2394,10 +2394,6 @@ int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size
if (old < 0)
return old;
- ret = pci_rebar_set_size(pdev, resno, size);
- if (ret)
- return ret;
-
down_read(&pci_bus_sem);
pci_dev_for_each_resource(pdev, r, i) {
@@ -2416,6 +2412,10 @@ int pci_do_resource_release_and_resize(struct pci_dev *pdev, int resno, int size
pci_release_resource(pdev, i);
}
+ ret = pci_rebar_set_size(pdev, resno, size);
+ if (ret)
+ goto restore;
+
pci_resize_resource_set_size(pdev, resno, size);
if (bridge) {
--
2.47.3