The commit 7e89efc6e9e4 ("Lock upstream bridge for pci_reset_function()") added locking of the upstream bridge to the reset function. To catch paths that are not properly locked, the commit 920f6468924f ("Warn on missing cfg_access_lock during secondary bus reset") added a warning if the PCI configuration space was not locked during a secondary bus reset request. When opening a PCI device for VFIO userspace access (vfio_pci_open_device), an attempt to reset the PCI device function is made. If the upstream bridge is not locked, the open request (esp. VFIO_GROUP_GET_DEVICE_FD) results in a warning: pcieport 0000:00:00.0: unlocked secondary bus reset via: pci_reset_bus_function+0x188/0x1b8 Add missing upstream bridge locking to pci_try_reset_function(). Fixes: 7e89efc6e9e4 ("PCI: Lock upstream bridge for pci_reset_function()") Signed-off-by: Anthony Pighin --- V1 -> V2: - Reworked commit log for clarity - Added a Fixes: tag drivers/pci/pci.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 13dbb405dc31..ff3f2df7e9c8 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -5196,19 +5196,34 @@ 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)) + /* + * If there's no upstream bridge, no locking is needed since there is + * no upstream bridge configuration to hold consistent. + */ + bridge = pci_upstream_bridge(dev); + if (bridge && !pci_dev_trylock(bridge)) return -EAGAIN; + if (!pci_dev_trylock(dev)) { + rc = -EAGAIN; + goto out_unlock_bridge; + } + pci_dev_save_and_disable(dev); rc = __pci_reset_function_locked(dev); pci_dev_restore(dev); pci_dev_unlock(dev); +out_unlock_bridge: + if (bridge) + pci_dev_unlock(bridge); + return rc; } EXPORT_SYMBOL_GPL(pci_try_reset_function); -- 2.43.0