Skip to content

Commit 962ae68

Browse files
Anthony Pighin (Nokia)awilliam
authored andcommitted
vfio/pci: Lock upstream bridge for vfio_pci_core_disable()
The commit 7e89efc ("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 920f646 ("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 a VFIO PCI device is released from userspace ownership, an attempt to reset the PCI device function may be made. If so, and the upstream bridge is not locked, the release request 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 vfio_pci_core_disable(). Fixes: 7e89efc ("PCI: Lock upstream bridge for pci_reset_function()") Signed-off-by: Anthony Pighin <anthony.pighin@nokia.com> Link: https://lore.kernel.org/r/BN0PR08MB695171D3AB759C65B6438B5D838DA@BN0PR08MB6951.namprd08.prod.outlook.com Signed-off-by: Alex Williamson <alex@shazbot.org>
1 parent fab06e9 commit 962ae68

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

drivers/vfio/pci/vfio_pci_core.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ EXPORT_SYMBOL_GPL(vfio_pci_core_enable);
588588

589589
void vfio_pci_core_disable(struct vfio_pci_core_device *vdev)
590590
{
591+
struct pci_dev *bridge;
591592
struct pci_dev *pdev = vdev->pdev;
592593
struct vfio_pci_dummy_resource *dummy_res, *tmp;
593594
struct vfio_pci_ioeventfd *ioeventfd, *ioeventfd_tmp;
@@ -694,12 +695,20 @@ void vfio_pci_core_disable(struct vfio_pci_core_device *vdev)
694695
* We can not use the "try" reset interface here, which will
695696
* overwrite the previously restored configuration information.
696697
*/
697-
if (vdev->reset_works && pci_dev_trylock(pdev)) {
698-
if (!__pci_reset_function_locked(pdev))
699-
vdev->needs_reset = false;
700-
pci_dev_unlock(pdev);
698+
if (vdev->reset_works) {
699+
bridge = pci_upstream_bridge(pdev);
700+
if (bridge && !pci_dev_trylock(bridge))
701+
goto out_restore_state;
702+
if (pci_dev_trylock(pdev)) {
703+
if (!__pci_reset_function_locked(pdev))
704+
vdev->needs_reset = false;
705+
pci_dev_unlock(pdev);
706+
}
707+
if (bridge)
708+
pci_dev_unlock(bridge);
701709
}
702710

711+
out_restore_state:
703712
pci_restore_state(pdev);
704713
out:
705714
pci_disable_device(pdev);

0 commit comments

Comments
 (0)