Skip to content

Commit fb794a7

Browse files
ozbenhbjorn-helgaas
authored andcommitted
PCI: Protect pci_reassign_bridge_resources() against concurrent addition/removal
pci_reassign_bridge_resources() can be called by pci_resize_resource() at runtime, it walks the PCI tree up and down, and it isn't currently protected against any changes or hotplug operation. Hold the pci_bus_sem to protect it. Link: https://lore.kernel.org/r/7339fd73ccaf58552737ab10008333fd9f7723f2.camel@kernel.crashing.org Signed-off-by: Benjamin Herrenschmidt <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent 54ecb8f commit fb794a7

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/pci/setup-bus.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2066,6 +2066,8 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
20662066
unsigned int i;
20672067
int ret;
20682068

2069+
down_read(&pci_bus_sem);
2070+
20692071
/* Walk to the root hub, releasing bridge BARs when possible */
20702072
next = bridge;
20712073
do {
@@ -2100,8 +2102,10 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
21002102
next = bridge->bus ? bridge->bus->self : NULL;
21012103
} while (next);
21022104

2103-
if (list_empty(&saved))
2105+
if (list_empty(&saved)) {
2106+
up_read(&pci_bus_sem);
21042107
return -ENOENT;
2108+
}
21052109

21062110
__pci_bus_size_bridges(bridge->subordinate, &added);
21072111
__pci_bridge_assign_resources(bridge, &added, &failed);
@@ -2122,6 +2126,7 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
21222126
}
21232127

21242128
free_list(&saved);
2129+
up_read(&pci_bus_sem);
21252130
return 0;
21262131

21272132
cleanup:
@@ -2150,6 +2155,7 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
21502155
pci_setup_bridge(bridge->subordinate);
21512156
}
21522157
free_list(&saved);
2158+
up_read(&pci_bus_sem);
21532159

21542160
return ret;
21552161
}

0 commit comments

Comments
 (0)