diff mbox series

[RFC,v3,26/29] vhost: Map in vdpa-dev

Message ID 20210519162903.1172366-27-eperezma@redhat.com (mailing list archive)
State New, archived
Headers show
Series vDPA software assisted live migration | expand

Commit Message

Eugenio Perez Martin May 19, 2021, 4:29 p.m. UTC
Use and export vhost-vpda functions directly. In the final version,
these methods needs to be exposed through VhostOps, or vhost-vdpa
backend needs to be adapted to work with vhost_send_device_iotlb_msg
in case its custom iommu is disabled.

Signed-off-by: Eugenio PĂ©rez <eperezma@redhat.com>
---
 include/hw/virtio/vhost-backend.h |  4 ++++
 hw/virtio/vhost-vdpa.c            |  2 +-
 hw/virtio/vhost.c                 | 18 ++++++++++++++++++
 3 files changed, 23 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-backend.h
index f8eed2ace5..9d88074e4d 100644
--- a/include/hw/virtio/vhost-backend.h
+++ b/include/hw/virtio/vhost-backend.h
@@ -203,4 +203,8 @@  int vhost_backend_handle_iotlb_msg(struct vhost_dev *dev,
 
 int vhost_user_gpu_set_socket(struct vhost_dev *dev, int fd);
 
+struct vhost_vdpa;
+int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size,
+                              void *vaddr, bool readonly);
+
 #endif /* VHOST_BACKEND_H */
diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
index 9e7a0ce5e0..c742e6944e 100644
--- a/hw/virtio/vhost-vdpa.c
+++ b/hw/virtio/vhost-vdpa.c
@@ -36,7 +36,7 @@  static bool vhost_vdpa_listener_skipped_section(MemoryRegionSection *section)
            section->offset_within_address_space & (1ULL << 63);
 }
 
-static int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size,
+int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size,
                               void *vaddr, bool readonly)
 {
     struct vhost_msg_v2 msg = {};
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 4339b899ea..286863ad42 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -1314,9 +1314,19 @@  static bool vhost_shadow_vq_start_store_sections(struct vhost_dev *dev)
             r = vhost_iova_tree_insert(&dev->iova_map, &region);
         }
         assert(r == VHOST_DMA_MAP_OK);
+        r = vhost_vdpa_dma_map(dev->opaque, region.iova, region_size,
+                               (void *)dev->mem->regions[idx].userspace_addr,
+                               false);
+        if (r != 0) {
+            goto fail;
+        }
     }
 
     return true;
+
+fail:
+    assert(0);
+    return false;
 }
 
 /*
@@ -1377,6 +1387,14 @@  static bool vhost_sw_live_migration_start_vq(struct vhost_dev *dev,
     }
 
     vhost_virtqueue_stop(dev, dev->vdev, &dev->vqs[idx], dev->vq_index + idx);
+    /* TODO: Why cannot make this read only? */
+    r = vhost_vdpa_dma_map(dev->opaque, addr.desc_user_addr, driver_region.size,
+                           (void *)driver_region.translated_addr, false);
+    assert(r == 0);
+    r = vhost_vdpa_dma_map(dev->opaque, addr.used_user_addr, device_region.size,
+                           (void *)device_region.translated_addr, false);
+    assert(r == 0);
+
     ok = vhost_shadow_vq_start(dev, idx, dev->shadow_vqs[idx]);
     if (unlikely(!ok)) {
         return false;