All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PCI: lock upstream bridge in pci_try_reset_function()
@ 2026-08-17 14:19 Runyu Xiao
  2026-08-17 14:28 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Runyu Xiao @ 2026-08-17 14:19 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Alex Williamson, linux-pci, linux-kernel, stable, Runyu Xiao,
	Jianhao Xu

pci_try_reset_function() may fall back to a secondary-bus reset below
an upstream bridge. Unlike pci_reset_function(), it only trylocks the
target device, so bridge configuration access is left unlocked across
that reset path.

Mirror pci_reset_function() and trylock the upstream bridge before the
device. This keeps bridge config access serialized on the secondary-bus
reset fallback and avoids the unlocked secondary bus reset warning.

Fixes: 61cf16d8bd38 ("PCI: Add pci_try_reset_function(), pci_try_reset_slot(), pci_try_reset_bus()")
Cc: stable@vger.kernel.org
Signed-off-by: Runyu Xiao <runyu.xiao@seu.edu.cn>
---
 drivers/pci/pci.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index e128696d5b76..6da8ac8a2459 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -5342,20 +5342,33 @@ EXPORT_SYMBOL_GPL(pci_reset_function_locked);
  */
 int pci_try_reset_function(struct pci_dev *dev)
 {
+	struct pci_dev *bridge;
 	int rc;
 
 	if (!pci_reset_supported(dev))
 		return -ENOTTY;
 
-	if (!pci_dev_trylock(dev))
+	bridge = pci_upstream_bridge(dev);
+	if (bridge && !pci_dev_trylock(bridge))
 		return -EAGAIN;
 
+	if (!pci_dev_trylock(dev))
+		goto out_unlock_bridge;
+
 	pci_dev_save_and_disable(dev);
 	rc = __pci_reset_function_locked(dev);
 	pci_dev_restore(dev);
 	pci_dev_unlock(dev);
 
+	if (bridge)
+		pci_dev_unlock(bridge);
+
 	return rc;
+
+out_unlock_bridge:
+	if (bridge)
+		pci_dev_unlock(bridge);
+	return -EAGAIN;
 }
 EXPORT_SYMBOL_GPL(pci_try_reset_function);
 
-- 
2.34.1

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

end of thread, other threads:[~2026-08-17 14:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-17 14:19 [PATCH] PCI: lock upstream bridge in pci_try_reset_function() Runyu Xiao
2026-08-17 14:28 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.