diff mbox series

[RFC,6/7] vhost-vdpa: init iommufd function in vhost_vdpa start

Message ID 20230503091337.2130631-7-lulu@redhat.com
State New
Headers show
Series vhost-vdpa: add support for iommufd | expand

Commit Message

Cindy Lu May 3, 2023, 9:13 a.m. UTC
Add support for iommufd, init the vdpa_iommufd in vdpa_start
in this step, driver will bind to the iommufd device
and attach the default ASID(asid 0) to iommufd

Signed-off-by: Cindy Lu <lulu@redhat.com>
---
 hw/virtio/vhost-vdpa.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
diff mbox series

Patch

diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
index 85240926b2..6c01e3b44f 100644
--- a/hw/virtio/vhost-vdpa.c
+++ b/hw/virtio/vhost-vdpa.c
@@ -1158,6 +1158,24 @@  static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)
     trace_vhost_vdpa_dev_start(dev, started);
 
     if (started) {
+        if ((v->enable_iommufd) && (vhost_vdpa_first_dev(dev))) {
+            struct vdpa_iommufd *vdpa_iommufd;
+
+            vdpa_backend_iommufd_ops_class_init(v);
+
+            if (dev->vdev->iommufd_ptr == NULL) {
+                vdpa_iommufd = g_malloc(sizeof(VDPAIOMMUFDState));
+
+                vdpa_iommufd->iommufd = g_malloc(sizeof(IOMMUFDBackend));
+                dev->vdev->iommufd_ptr = vdpa_iommufd;
+
+                qemu_mutex_init(&vdpa_iommufd->iommufd->lock);
+                iommufd_backend_connect(vdpa_iommufd->iommufd, NULL);
+
+                v->ops->attach_device(v, dev->vdev->dma_as, NULL);
+            }
+        }
+
         vhost_vdpa_host_notifiers_init(dev);
         ok = vhost_vdpa_svqs_start(dev);
         if (unlikely(!ok)) {