* [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
* Re: [PATCH] PCI: lock upstream bridge in pci_try_reset_function()
2026-08-17 14:19 [PATCH] PCI: lock upstream bridge in pci_try_reset_function() Runyu Xiao
@ 2026-08-17 14:28 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-08-17 14:28 UTC (permalink / raw)
To: Runyu Xiao; +Cc: linux-pci
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Eagerly trylocking the shared upstream bridge introduces spurious -EAGAIN failures for concurrent resets of sibling devices (e.g., Virtual Functions).
--
--- Patch [1]: [PATCH] PCI: lock upstream bridge in pci_try_reset_function() ---
commit 26cda84dc0be3f7ffec20ace1e3feba4ee2b0184
Author: Runyu Xiao <runyu.xiao@seu.edu.cn>
PCI: lock upstream bridge in pci_try_reset_function()
This commit updates pci_try_reset_function() to trylock the upstream bridge
before locking the target device. This ensures bridge configuration access
is serialized during a secondary-bus reset fallback.
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 77b17b13ee615..c18aed839a866 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -5282,20 +5282,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;
[Severity: High]
Does eagerly trylocking the shared upstream bridge introduce spurious -EAGAIN
failures for concurrent resets of sibling devices?
When concurrent threads open sibling Virtual Functions (which share the same
physical function and thus the same upstream bridge) via
vfio_pci_core_enable(), both threads invoke pci_try_reset_function().
The first thread successfully acquires pci_dev_trylock(bridge). The second
thread fails the trylock and immediately returns -EAGAIN.
VFIO treats -EAGAIN as a fatal error during initialization, which can cause VM
startups or userspace applications opening multiple passed-through VFs
concurrently to fail spuriously.
Before this patch, VF resets (typically using Function Level Reset) executed
in parallel since they only locked the target device, not the shared bridge.
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260817141918.1339057-1-runyu.xiao@seu.edu.cn?part=1
^ permalink raw reply [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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox