Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH v2 1/1] PCI: Fix lock symmetry in pci_slot_unlock()
@ 2025-05-05 11:54 Ilpo Järvinen
  2025-05-05 12:57 ` Lukas Wunner
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ilpo Järvinen @ 2025-05-05 11:54 UTC (permalink / raw)
  To: Lukas Wunner, Moshe Shemesh, Bjorn Helgaas, Dave Jiang,
	Dan Williams, Keith Busch, linux-pci, linux-kernel
  Cc: Ilpo Järvinen, stable

The commit a4e772898f8b ("PCI: Add missing bridge lock to
pci_bus_lock()") made the lock function to call depend on
dev->subordinate but left pci_slot_unlock() unmodified creating locking
asymmetry compared with pci_slot_lock().

Because of the asymmetric lock handling, the same bridge device is
unlocked twice. First pci_bus_unlock() unlocks bus->self and then
pci_slot_unlock() will unconditionally unlock the same bridge device.

Move pci_dev_unlock() inside an else branch to match the logic in
pci_slot_lock().

Fixes: a4e772898f8b ("PCI: Add missing bridge lock to pci_bus_lock()")
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Cc: <stable@vger.kernel.org>
---

v2:
- Improve changelog (Lukas)
- Added Cc stable

 drivers/pci/pci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 4d7c9f64ea24..26507aa906d7 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -5542,7 +5542,8 @@ static void pci_slot_unlock(struct pci_slot *slot)
 			continue;
 		if (dev->subordinate)
 			pci_bus_unlock(dev->subordinate);
-		pci_dev_unlock(dev);
+		else
+			pci_dev_unlock(dev);
 	}
 }
 

base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/1] PCI: Fix lock symmetry in pci_slot_unlock()
  2025-05-05 11:54 [PATCH v2 1/1] PCI: Fix lock symmetry in pci_slot_unlock() Ilpo Järvinen
@ 2025-05-05 12:57 ` Lukas Wunner
  2025-05-05 15:05 ` Dave Jiang
  2025-05-05 20:04 ` Bjorn Helgaas
  2 siblings, 0 replies; 4+ messages in thread
From: Lukas Wunner @ 2025-05-05 12:57 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: Moshe Shemesh, Bjorn Helgaas, Dave Jiang, Dan Williams,
	Keith Busch, linux-pci, linux-kernel

On Mon, May 05, 2025 at 02:54:12PM +0300, Ilpo Järvinen wrote:
> The commit a4e772898f8b ("PCI: Add missing bridge lock to
> pci_bus_lock()") made the lock function to call depend on
> dev->subordinate but left pci_slot_unlock() unmodified creating locking
> asymmetry compared with pci_slot_lock().
> 
> Because of the asymmetric lock handling, the same bridge device is
> unlocked twice. First pci_bus_unlock() unlocks bus->self and then
> pci_slot_unlock() will unconditionally unlock the same bridge device.
> 
> Move pci_dev_unlock() inside an else branch to match the logic in
> pci_slot_lock().
> 
> Fixes: a4e772898f8b ("PCI: Add missing bridge lock to pci_bus_lock()")
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> Cc: <stable@vger.kernel.org>

Reviewed-by: Lukas Wunner <lukas@wunner.de>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/1] PCI: Fix lock symmetry in pci_slot_unlock()
  2025-05-05 11:54 [PATCH v2 1/1] PCI: Fix lock symmetry in pci_slot_unlock() Ilpo Järvinen
  2025-05-05 12:57 ` Lukas Wunner
@ 2025-05-05 15:05 ` Dave Jiang
  2025-05-05 20:04 ` Bjorn Helgaas
  2 siblings, 0 replies; 4+ messages in thread
From: Dave Jiang @ 2025-05-05 15:05 UTC (permalink / raw)
  To: Ilpo Järvinen, Lukas Wunner, Moshe Shemesh, Bjorn Helgaas,
	Dan Williams, Keith Busch, linux-pci, linux-kernel
  Cc: stable



On 5/5/25 4:54 AM, Ilpo Järvinen wrote:
> The commit a4e772898f8b ("PCI: Add missing bridge lock to
> pci_bus_lock()") made the lock function to call depend on
> dev->subordinate but left pci_slot_unlock() unmodified creating locking
> asymmetry compared with pci_slot_lock().
> 
> Because of the asymmetric lock handling, the same bridge device is
> unlocked twice. First pci_bus_unlock() unlocks bus->self and then
> pci_slot_unlock() will unconditionally unlock the same bridge device.
> 
> Move pci_dev_unlock() inside an else branch to match the logic in
> pci_slot_lock().
> 
> Fixes: a4e772898f8b ("PCI: Add missing bridge lock to pci_bus_lock()")
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> Cc: <stable@vger.kernel.org>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> ---
> 
> v2:
> - Improve changelog (Lukas)
> - Added Cc stable
> 
>  drivers/pci/pci.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 4d7c9f64ea24..26507aa906d7 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -5542,7 +5542,8 @@ static void pci_slot_unlock(struct pci_slot *slot)
>  			continue;
>  		if (dev->subordinate)
>  			pci_bus_unlock(dev->subordinate);
> -		pci_dev_unlock(dev);
> +		else
> +			pci_dev_unlock(dev);
>  	}
>  }
>  
> 
> base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/1] PCI: Fix lock symmetry in pci_slot_unlock()
  2025-05-05 11:54 [PATCH v2 1/1] PCI: Fix lock symmetry in pci_slot_unlock() Ilpo Järvinen
  2025-05-05 12:57 ` Lukas Wunner
  2025-05-05 15:05 ` Dave Jiang
@ 2025-05-05 20:04 ` Bjorn Helgaas
  2 siblings, 0 replies; 4+ messages in thread
From: Bjorn Helgaas @ 2025-05-05 20:04 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: Lukas Wunner, Moshe Shemesh, Bjorn Helgaas, Dave Jiang,
	Dan Williams, Keith Busch, linux-pci, linux-kernel, stable

On Mon, May 05, 2025 at 02:54:12PM +0300, Ilpo Järvinen wrote:
> The commit a4e772898f8b ("PCI: Add missing bridge lock to
> pci_bus_lock()") made the lock function to call depend on
> dev->subordinate but left pci_slot_unlock() unmodified creating locking
> asymmetry compared with pci_slot_lock().
> 
> Because of the asymmetric lock handling, the same bridge device is
> unlocked twice. First pci_bus_unlock() unlocks bus->self and then
> pci_slot_unlock() will unconditionally unlock the same bridge device.
> 
> Move pci_dev_unlock() inside an else branch to match the logic in
> pci_slot_lock().
> 
> Fixes: a4e772898f8b ("PCI: Add missing bridge lock to pci_bus_lock()")
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> Cc: <stable@vger.kernel.org>

Applied to pci/reset for v6.16, thanks!

> ---
> 
> v2:
> - Improve changelog (Lukas)
> - Added Cc stable
> 
>  drivers/pci/pci.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 4d7c9f64ea24..26507aa906d7 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -5542,7 +5542,8 @@ static void pci_slot_unlock(struct pci_slot *slot)
>  			continue;
>  		if (dev->subordinate)
>  			pci_bus_unlock(dev->subordinate);
> -		pci_dev_unlock(dev);
> +		else
> +			pci_dev_unlock(dev);
>  	}
>  }
>  
> 
> base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8
> -- 
> 2.39.5
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-05-05 20:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-05 11:54 [PATCH v2 1/1] PCI: Fix lock symmetry in pci_slot_unlock() Ilpo Järvinen
2025-05-05 12:57 ` Lukas Wunner
2025-05-05 15:05 ` Dave Jiang
2025-05-05 20:04 ` Bjorn Helgaas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox