On 5/29/2025 5:59 PM, Moshe Shemesh wrote:
Unlike pci_bus_lock(), which acquires the lock on the bus bridge before
locking devices and subordinate buses, pci_slot_lock() currently miss
locking the bridge. This may result in triggering warning on
pci_bridge_secondary_bus_reset() [1].
Hi all,
Kind reminder regarding this patch. I'd appreciate any feedback or
comments.
Fix it by adding bridge lock on pci_slot_lock() and pci_slot_trylock().
[1]
pcieport 0000:c1:05.0: unlocked secondary bus reset via: pciehp_reset_slot+0xa4/0x150
Fixes: a4e772898f8b ("PCI: Add missing bridge lock to pci_bus_lock()")
Signed-off-by: Moshe Shemesh <moshe@xxxxxxxxxx>
---
drivers/pci/pci.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index e77d5b53c0ce..c31929482122 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -5518,6 +5518,7 @@ static void pci_slot_lock(struct pci_slot *slot)
{
struct pci_dev *dev;
+ pci_dev_lock(slot->bus->self);
list_for_each_entry(dev, &slot->bus->devices, bus_list) {
if (!dev->slot || dev->slot != slot)
continue;
@@ -5540,6 +5541,7 @@ static void pci_slot_unlock(struct pci_slot *slot)
pci_bus_unlock(dev->subordinate);
pci_dev_unlock(dev);
}
+ pci_dev_unlock(slot->bus->self);
}
/* Return 1 on successful lock, 0 on contention */
@@ -5547,6 +5549,9 @@ static int pci_slot_trylock(struct pci_slot *slot)
{
struct pci_dev *dev;
+ if (!pci_dev_trylock(slot->bus->self))
+ return 0;
+
list_for_each_entry(dev, &slot->bus->devices, bus_list) {
if (!dev->slot || dev->slot != slot)
continue;
@@ -5570,6 +5575,7 @@ static int pci_slot_trylock(struct pci_slot *slot)
else
pci_dev_unlock(dev);
}
+ pci_dev_unlock(slot->bus->self);
return 0;
}