* [PATCH] PCI: Add missing bridge lock in pci_slot_lock()
@ 2025-05-29 14:59 Moshe Shemesh
2025-07-09 13:03 ` Moshe Shemesh
0 siblings, 1 reply; 2+ messages in thread
From: Moshe Shemesh @ 2025-05-29 14:59 UTC (permalink / raw)
To: Bjorn Helgaas, Dan Williams, Dave Jiang, Keith Busch, linux-pci
Cc: 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].
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@nvidia.com>
---
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;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] PCI: Add missing bridge lock in pci_slot_lock()
2025-05-29 14:59 [PATCH] PCI: Add missing bridge lock in pci_slot_lock() Moshe Shemesh
@ 2025-07-09 13:03 ` Moshe Shemesh
0 siblings, 0 replies; 2+ messages in thread
From: Moshe Shemesh @ 2025-07-09 13:03 UTC (permalink / raw)
To: Bjorn Helgaas, Dan Williams, Dave Jiang, Keith Busch, linux-pci
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@nvidia.com>
> ---
> 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;
> }
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-07-09 13:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-29 14:59 [PATCH] PCI: Add missing bridge lock in pci_slot_lock() Moshe Shemesh
2025-07-09 13:03 ` Moshe Shemesh
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).