PCI: fix recursive device locking
PATCH RESEND 1/1 PCI: fix recursive 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 recursion or it will surely deadlock.
---
Sending to the correct mailing list this time, and fixed up two typos in the commit message.
drivers/pci/pci.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/pci/pci.c +4 -2
@@ -5488,9 +5488,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); } }
@@ -5502,7 +5503,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
Quoted 13 lines · Keith Busch
drivers/pci/pci.c +2
-1@@ -5488,9 +5488,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); } }
drivers/pci/pci.c static void pci_bus_unlock(struct pci_bus *bus) · line 5510
Quoted 9 lines
drivers/pci/pci.c +2
-1@@ -5502,7 +5503,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); }
I realized pci_slot_lock() has the same problem. I wasn't able to test that path from not having a pcie topology with a subordinate on the slot device, but it follows the same pattern. Same thing with pci_bus_trylock() for that matter, so I will make a new version.
Quoted 13 lines · Keith Busch
Quoted 12 lines · Keith Busch
drivers/pci/pci.c +2
-1@@ -5488,9 +5488,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); } }
Quoted 15 lines
drivers/pci/pci.c static void pci_bus_unlock(struct pci_bus *bus) · line 5510
Quoted 10 lines
drivers/pci/pci.c +2
-1@@ -5502,7 +5503,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); }I realized
pci_slot_lock()has the same problem. I wasn't able to test that path from not having a pcie topology with a subordinate on the slot device, but it follows the same pattern. Same thing withpci_bus_trylock()for that matter, so I will make a new version.
I can take another look at that one as well, but feel free to carry my Reviewed-by tag on that one, and just trust that I'll scream if I notice something late.
Quoted 8 lines · Dan Williams
Quoted 4 lines
I realized
pci_slot_lock()has the same problem. I wasn't able to test that path from not having a pcie topology with a subordinate on the slot device, but it follows the same pattern. Same thing withpci_bus_trylock()for that matter, so I will make a new version.I can take another look at that one as well, but feel free to carry my Reviewed-by tag on that one, and just trust that I'll scream if I notice something late.
Disregard, I mistook this as comment about v2 rather than v1. v2 is good to go.