90 lines
2.9 KiB
Diff
90 lines
2.9 KiB
Diff
|
|
From dbbf6b33d9ce5f2785972f81919be143e81f866b Mon Sep 17 00:00:00 2001
|
||
|
|
From: Zhenzhong Duan <zhenzhong.duan@intel.com>
|
||
|
|
Date: Wed, 5 Jun 2024 16:30:40 +0800
|
||
|
|
Subject: [PATCH] vfio/pci: Pass HostIOMMUDevice to vIOMMU
|
||
|
|
|
||
|
|
With HostIOMMUDevice passed, vIOMMU can check compatibility with host
|
||
|
|
IOMMU, call into IOMMUFD specific methods, etc.
|
||
|
|
|
||
|
|
Originally-by: Yi Liu <yi.l.liu@intel.com>
|
||
|
|
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
|
||
|
|
Signed-off-by: Yi Sun <yi.y.sun@linux.intel.com>
|
||
|
|
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
|
||
|
|
Reviewed-by: Eric Auger <eric.auger@redhat.com>
|
||
|
|
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
|
||
|
|
---
|
||
|
|
hw/vfio/pci.c | 17 +++++++++++++----
|
||
|
|
1 file changed, 13 insertions(+), 4 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
|
||
|
|
index d84a9e73a6..675a608b9c 100644
|
||
|
|
--- a/hw/vfio/pci.c
|
||
|
|
+++ b/hw/vfio/pci.c
|
||
|
|
@@ -3107,6 +3107,11 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
|
||
|
|
|
||
|
|
vfio_bars_register(vdev);
|
||
|
|
|
||
|
|
+ if (!pci_device_set_iommu_device(pdev, vbasedev->hiod, errp)) {
|
||
|
|
+ error_prepend(errp, "Failed to set iommu_device: ");
|
||
|
|
+ goto out_teardown;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
ret = vfio_add_capabilities(vdev, errp);
|
||
|
|
if (ret) {
|
||
|
|
goto out_teardown;
|
||
|
|
@@ -3128,7 +3133,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
|
||
|
|
error_setg(errp,
|
||
|
|
"cannot support IGD OpRegion feature on hotplugged "
|
||
|
|
"device");
|
||
|
|
- goto out_teardown;
|
||
|
|
+ goto out_unset_idev;
|
||
|
|
}
|
||
|
|
|
||
|
|
ret = vfio_get_dev_region_info(vbasedev,
|
||
|
|
@@ -3137,13 +3142,13 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
|
||
|
|
if (ret) {
|
||
|
|
error_setg_errno(errp, -ret,
|
||
|
|
"does not support requested IGD OpRegion feature");
|
||
|
|
- goto out_teardown;
|
||
|
|
+ goto out_unset_idev;
|
||
|
|
}
|
||
|
|
|
||
|
|
ret = vfio_pci_igd_opregion_init(vdev, opregion, errp);
|
||
|
|
g_free(opregion);
|
||
|
|
if (ret) {
|
||
|
|
- goto out_teardown;
|
||
|
|
+ goto out_unset_idev;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
@@ -3229,6 +3234,8 @@ out_deregister:
|
||
|
|
if (vdev->intx.mmap_timer) {
|
||
|
|
timer_free(vdev->intx.mmap_timer);
|
||
|
|
}
|
||
|
|
+out_unset_idev:
|
||
|
|
+ pci_device_unset_iommu_device(pdev);
|
||
|
|
out_teardown:
|
||
|
|
vfio_teardown_msi(vdev);
|
||
|
|
vfio_bars_exit(vdev);
|
||
|
|
@@ -3257,6 +3264,7 @@ static void vfio_instance_finalize(Object *obj)
|
||
|
|
static void vfio_exitfn(PCIDevice *pdev)
|
||
|
|
{
|
||
|
|
VFIOPCIDevice *vdev = VFIO_PCI(pdev);
|
||
|
|
+ VFIODevice *vbasedev = &vdev->vbasedev;
|
||
|
|
|
||
|
|
vfio_unregister_req_notifier(vdev);
|
||
|
|
vfio_unregister_err_notifier(vdev);
|
||
|
|
@@ -3271,7 +3279,8 @@ static void vfio_exitfn(PCIDevice *pdev)
|
||
|
|
vfio_teardown_msi(vdev);
|
||
|
|
vfio_pci_disable_rp_atomics(vdev);
|
||
|
|
vfio_bars_exit(vdev);
|
||
|
|
- vfio_migration_exit(&vdev->vbasedev);
|
||
|
|
+ vfio_migration_exit(vbasedev);
|
||
|
|
+ pci_device_unset_iommu_device(pdev);
|
||
|
|
}
|
||
|
|
|
||
|
|
static void vfio_pci_reset(DeviceState *dev)
|
||
|
|
--
|
||
|
|
2.41.0.windows.1
|
||
|
|
|