Skip to contentSkip to conversation

PCI: fix recusive device locking

PATCH Superseded Keith Busch 3 participants 3 messages Jun 28, 2024 – Jun 30, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: fix recusive device locking

From: Keith Busch <[email protected]>

If one of the bus' devices has subordinates, the recursive call locks itself, so no need to lock the device before the recusion or it will surely deadlock.

Fixes dbc5b5c0d268f87 ("PCI: Add missing bridge lock to pci_bus_lock()"
Cc Dan Williams <[email protected]>
---
 drivers/pci/pci.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/pci/pci.c +4 -2
index 46beaf1815fab..d9f357812b3c5 100644
@@ -5487,9 +5487,10 @@ static void pci_bus_lock(struct pci_bus *bus)
 
 	pci_dev_lock(bus->self);
 	list_for_each_entry(dev, &bus->devices, bus_list) {
-		pci_dev_lock(dev);
 		if (dev->subordinate)
 			pci_bus_lock(dev->subordinate);
+		else
+			pci_dev_lock(dev);
 	}
 }
 
@@ -5501,7 +5502,8 @@ static void pci_bus_unlock(struct pci_bus *bus)
 	list_for_each_entry(dev, &bus->devices, bus_list) {
 		if (dev->subordinate)
 			pci_bus_unlock(dev->subordinate);
-		pci_dev_unlock(dev);
+		else
+			pci_dev_unlock(dev);
 	}
 	pci_dev_unlock(bus->self);
 }
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw

[ add linux-pci ]

Quoted 9 lines · Keith Busch

From: Keith Busch <[email protected]>

If one of the bus' devices has subordinates, the recursive call locks itself, so no need to lock the device before the recusion or it will surely deadlock.

Fixes dbc5b5c0d268f87 ("PCI: Add missing bridge lock to pci_bus_lock()"
Cc Dan Williams <[email protected]>

Looks good, thanks for the fixup Keith!

#2 lore raw
In reply to Keith Busch
Quoted 2 lines

If one of the bus' devices has subordinates, the recursive call locks itself, so no need to lock the device before the recusion or it will

…

recursion?

Would you like to avoid another typo also in the summary phrase?

Regards,
Markus