[PATCH rfcv1 09/23] vfio/iommufd_device: Add ioas_id in IOMMUFDDevice and pass to vIOMMU

Zhenzhong Duan posted 23 patches 10 months, 2 weeks ago
[PATCH rfcv1 09/23] vfio/iommufd_device: Add ioas_id in IOMMUFDDevice and pass to vIOMMU
Posted by Zhenzhong Duan 10 months, 2 weeks ago
Sometimes vIOMMU needs to re-attach device to ioas id of vfio,
i.e., when vIOMMU is disabled by guest.

This is a prerequisite patch for following one.

Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
 include/sysemu/iommufd_device.h | 3 ++-
 backends/iommufd_device.c       | 3 ++-
 hw/vfio/iommufd.c               | 2 +-
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/include/sysemu/iommufd_device.h b/include/sysemu/iommufd_device.h
index 799c1345fd..7aeec9b980 100644
--- a/include/sysemu/iommufd_device.h
+++ b/include/sysemu/iommufd_device.h
@@ -26,6 +26,7 @@ typedef struct IOMMUFDDeviceOps {
 struct IOMMUFDDevice {
     IOMMUFDBackend *iommufd;
     uint32_t dev_id;
+    uint32_t ioas_id;
     IOMMUFDDeviceOps *ops;
 };
 
@@ -36,5 +37,5 @@ int iommufd_device_get_info(IOMMUFDDevice *idev,
                             uint32_t len, void *data);
 void iommufd_device_init(void *_idev, size_t instance_size,
                          IOMMUFDBackend *iommufd, uint32_t dev_id,
-                         IOMMUFDDeviceOps *ops);
+                         uint32_t ioas_id, IOMMUFDDeviceOps *ops);
 #endif
diff --git a/backends/iommufd_device.c b/backends/iommufd_device.c
index 26f69252d2..f93a201453 100644
--- a/backends/iommufd_device.c
+++ b/backends/iommufd_device.c
@@ -52,7 +52,7 @@ int iommufd_device_get_info(IOMMUFDDevice *idev,
 
 void iommufd_device_init(void *_idev, size_t instance_size,
                          IOMMUFDBackend *iommufd, uint32_t dev_id,
-                         IOMMUFDDeviceOps *ops)
+                         uint32_t ioas_id, IOMMUFDDeviceOps *ops)
 {
     IOMMUFDDevice *idev = (IOMMUFDDevice *)_idev;
 
@@ -60,5 +60,6 @@ void iommufd_device_init(void *_idev, size_t instance_size,
 
     idev->iommufd = iommufd;
     idev->dev_id = dev_id;
+    idev->ioas_id = ioas_id;
     idev->ops = ops;
 }
diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index c8c669c59a..3aabe41043 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -432,7 +432,7 @@ found_container:
     QLIST_INSERT_HEAD(&vfio_device_list, vbasedev, global_next);
 
     iommufd_device_init(idev, sizeof(*idev), container->be, vbasedev->devid,
-                        &vfio_iommufd_device_ops);
+                        container->ioas_id, &vfio_iommufd_device_ops);
     trace_iommufd_cdev_device_info(vbasedev->name, devfd, vbasedev->num_irqs,
                                    vbasedev->num_regions, vbasedev->flags);
     return 0;
-- 
2.34.1