Skip to contentSkip to conversation

PCI: Protect pci_reassign_bridge_resources() against concurrent addition/removal

RFC/PATCH Applied Benjamin Herrenschmidt 2 participants 3 messages Jun 24, 2019 – Sep 23, 2019 PCI

lore
Share & tools
lore
#0 lore raw

pci_reassign_bridge_resources() can be called by pci_resize_resource() at runtime.

It will walk the PCI tree up and down, and isn't currently protected against any changes or hotplug operation.

---

drivers/pci/setup-bus.c +4 -0
@@ -2104,6 +2104,8 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
 	unsigned int i;
 	int ret;
 
+	down_read(&pci_bus_sem);
+
 	/* Walk to the root hub, releasing bridge BARs when possible */
 	next = bridge;
 	do {
@@ -2160,6 +2162,7 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
 	}
 
 	free_list(&saved);
+	up_read(&pci_bus_sem);
 	return 0;
 
 cleanup:
@@ -2188,6 +2191,7 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
 		pci_setup_bridge(bridge->subordinate);
 	}
 	free_list(&saved);
+	up_read(&pci_bus_sem);
 
 	return ret;
 }
#1 lore raw
Quoted 7 lines · Benjamin Herrenschmidt

pci_reassign_bridge_resources() can be called by pci_resize_resource() at runtime.

It will walk the PCI tree up and down, and isn't currently protected against any changes or hotplug operation.

Applied to pci/resource for v5.4, thanks!

Quoted 30 lines

---

drivers/pci/setup-bus.c +4 -0
@@ -2104,6 +2104,8 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
 	unsigned int i;
 	int ret;
 
+	down_read(&pci_bus_sem);
+
 	/* Walk to the root hub, releasing bridge BARs when possible */
 	next = bridge;
 	do {
@@ -2160,6 +2162,7 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
 	}
 
 	free_list(&saved);
+	up_read(&pci_bus_sem);
 	return 0;
 
 cleanup:
@@ -2188,6 +2191,7 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
 		pci_setup_bridge(bridge->subordinate);
 	}
 	free_list(&saved);
+	up_read(&pci_bus_sem);
 
 	return ret;
 }
#2 lore raw
Quoted 10 lines · Bjorn Helgaas
Quoted 7 lines · Benjamin Herrenschmidt

pci_reassign_bridge_resources() can be called by pci_resize_resource() at runtime.

It will walk the PCI tree up and down, and isn't currently protected against any changes or hotplug operation.

Applied to pci/resource for v5.4, thanks!

Dropped for now per Dan's bug report:
https://lore.kernel.org/r/20190904100303.GD7007@mwanda

Quoted 30 lines
Quoted 30 lines

---

drivers/pci/setup-bus.c +4 -0
@@ -2104,6 +2104,8 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
 	unsigned int i;
 	int ret;
 
+	down_read(&pci_bus_sem);
+
 	/* Walk to the root hub, releasing bridge BARs when possible */
 	next = bridge;
 	do {
@@ -2160,6 +2162,7 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
 	}
 
 	free_list(&saved);
+	up_read(&pci_bus_sem);
 	return 0;
 
 cleanup:
@@ -2188,6 +2191,7 @@ int pci_reassign_bridge_resources(struct pci_dev *bridge, unsigned long type)
 		pci_setup_bridge(bridge->subordinate);
 	}
 	free_list(&saved);
+	up_read(&pci_bus_sem);
 
 	return ret;
 }