Skip to contentSkip to conversation

PCI: Add missing bridge lock in pci_slot_lock()

PATCH In review Moshe Shemesh 1 participant 2 messages May 29, 2025 – Jul 9, 2025 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: Add missing bridge lock in pci_slot_lock()

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].

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()")
---
 drivers/pci/pci.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/pci/pci.c +6 -0
index e77d5b53c0ce..c31929482122 100644
@@ -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;
 }
 
Signature · 1 line
2.34.1
#1 lore raw
Quoted 4 lines · Moshe Shemesh

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.

Quoted 50 lines

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()")
---
  drivers/pci/pci.c | 6 ++++++
  1 file changed, 6 insertions(+)
drivers/pci/pci.c +6 -0
index e77d5b53c0ce..c31929482122 100644
@@ -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;
  }