@@ -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 */
@@ -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 = {};
@@ -1314,9 +1314,19 @@ static bool vhost_shadow_vq_start_store_sections(struct vhost_dev *dev)
r = vhost_iova_tree_insert(&dev->iova_map, ®ion);
}
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;
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(-)