[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 16/19] vfio/pci: Pass HostIOMMUDevice to vIOMMU
From: |
Zhenzhong Duan |
Subject: |
[PATCH v3 16/19] vfio/pci: Pass HostIOMMUDevice to vIOMMU |
Date: |
Mon, 29 Apr 2024 14:50:43 +0800 |
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>
---
hw/vfio/pci.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 64780d1b79..224501a86e 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -3111,11 +3111,17 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
vfio_bars_register(vdev);
- ret = vfio_add_capabilities(vdev, errp);
+ ret = pci_device_set_iommu_device(pdev, vbasedev->hiod, errp);
if (ret) {
+ error_prepend(errp, "Failed to set iommu_device: ");
goto out_teardown;
}
+ ret = vfio_add_capabilities(vdev, errp);
+ if (ret) {
+ goto out_unset_idev;
+ }
+
if (vdev->vga) {
vfio_vga_quirk_setup(vdev);
}
@@ -3132,7 +3138,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,
@@ -3141,13 +3147,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;
}
}
@@ -3233,6 +3239,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);
@@ -3261,6 +3269,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);
@@ -3275,7 +3284,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.34.1
- [PATCH v3 07/19] vfio/container: Implement HostIOMMUDeviceClass::realize() handler, (continued)
- [PATCH v3 07/19] vfio/container: Implement HostIOMMUDeviceClass::realize() handler, Zhenzhong Duan, 2024/04/29
- [PATCH v3 08/19] backends/iommufd: Introduce helper function iommufd_backend_get_device_info(), Zhenzhong Duan, 2024/04/29
- [PATCH v3 09/19] vfio/iommufd: Implement HostIOMMUDeviceClass::realize() handler, Zhenzhong Duan, 2024/04/29
- [PATCH v3 12/19] vfio: Introduce VFIOIOMMUClass::hiod_typename attribute, Zhenzhong Duan, 2024/04/29
- [PATCH v3 11/19] backends/iommufd: Implement HostIOMMUDeviceClass::check_cap() handler, Zhenzhong Duan, 2024/04/29
- [PATCH v3 10/19] vfio/container: Implement HostIOMMUDeviceClass::check_cap() handler, Zhenzhong Duan, 2024/04/29
- [PATCH v3 13/19] vfio: Create host IOMMU device instance, Zhenzhong Duan, 2024/04/29
- [PATCH v3 15/19] hw/pci: Introduce pci_device_[set|unset]_iommu_device(), Zhenzhong Duan, 2024/04/29
- [PATCH v3 14/19] hw/pci: Introduce helper function pci_device_get_iommu_bus_devfn(), Zhenzhong Duan, 2024/04/29
- [PATCH v3 17/19] intel_iommu: Extract out vtd_cap_init() to initialize cap/ecap, Zhenzhong Duan, 2024/04/29
- [PATCH v3 16/19] vfio/pci: Pass HostIOMMUDevice to vIOMMU,
Zhenzhong Duan <=
- [PATCH v3 18/19] intel_iommu: Implement [set|unset]_iommu_device() callbacks, Zhenzhong Duan, 2024/04/29
- [PATCH v3 19/19] intel_iommu: Check compatibility with host IOMMU capabilities, Zhenzhong Duan, 2024/04/29