Hardware resets clear PCI TPH registers, but PCI core software TPH state may remain stale across VFIO device open/close cycles. Invoke pcie_disable_tph() at enable and disable boundaries: - In vfio_pci_core_enable(): reset TPH state before saving PCI state for a fresh user session - In vfio_pci_core_disable(): reset TPH state when releasing the device, to clear stale software TPH tracking state Signed-off-by: Chengwen Feng --- drivers/vfio/pci/vfio_pci_core.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index 049392831b35..8d3d532cd51a 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -606,6 +606,8 @@ int vfio_pci_core_enable(struct vfio_pci_core_device *vdev) goto out_disable_device; vdev->reset_works = !ret; + /* Reset TPH state for new user session */ + pcie_disable_tph(vdev->pdev); pci_save_state(pdev); vdev->pci_saved_state = pci_store_saved_state(pdev); if (!vdev->pci_saved_state) @@ -762,6 +764,9 @@ void vfio_pci_core_disable(struct vfio_pci_core_device *vdev) vfio_pci_zdev_close_device(vdev); + /* Reset TPH state on user session exit */ + pcie_disable_tph(vdev->pdev); + /* * If we have saved state, restore it. If we can reset the device, * even better. Resetting with current state seems better than -- 2.17.1