qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC v3 18/29] vhost: Use vhost_enable_custom_iommu to unmap everything


From: Eugenio Pérez
Subject: [RFC v3 18/29] vhost: Use vhost_enable_custom_iommu to unmap everything if available
Date: Wed, 19 May 2021 18:28:52 +0200

This call is the right way to unmap every IOTLB in devices with non
standard IOMMU (vdpa devices), since regular one would require an IOTLB
message they don't support.

Another possible solution would be to implement
.vhost_send_device_iotlb_msg vhost operation in vhost-vdpa, but it
could conflict with expected backend iommu operations.

Currently, this method does not work for vp_vdpa. For some reason, intel
IOMMU is not able to map anything when vdpa has unmapped everything.
However that is on kernel side, this commit code should be as intended
in the final version.

Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
 hw/virtio/vhost.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 5b5001a08a..c8fa9df9b3 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -1241,7 +1241,12 @@ static int vhost_sw_live_migration_stop(struct vhost_dev 
*dev)
 
     r = dev->vhost_ops->vhost_vring_pause(dev);
     assert(r == 0);
-    if (vhost_backend_invalidate_device_iotlb(dev, 0, -1ULL)) {
+    if (dev->vhost_ops->vhost_enable_custom_iommu) {
+        r = dev->vhost_ops->vhost_enable_custom_iommu(dev, false);
+    } else {
+        r = vhost_backend_invalidate_device_iotlb(dev, 0, -1ULL);
+    }
+    if (r) {
         error_report("Fail to invalidate device iotlb");
     }
 
@@ -1343,7 +1348,12 @@ static int vhost_sw_live_migration_start(struct 
vhost_dev *dev)
 
     r = dev->vhost_ops->vhost_vring_pause(dev);
     assert(r == 0);
-    if (vhost_backend_invalidate_device_iotlb(dev, 0, -1ULL)) {
+    if (dev->vhost_ops->vhost_enable_custom_iommu) {
+        r = dev->vhost_ops->vhost_enable_custom_iommu(dev, false);
+    } else {
+        r = vhost_backend_invalidate_device_iotlb(dev, 0, -1ULL);
+    }
+    if (r) {
         error_report("Fail to invalidate device iotlb");
     }
 
@@ -2100,8 +2110,6 @@ void qmp_x_vhost_enable_shadow_vq(const char *name, bool 
enable, Error **errp)
             err_cause = "Cannot pause device";
         } else if (hdev->vhost_ops->vhost_get_iova_range) {
             err_cause = "Device may not support all iova range";
-        } else if (hdev->vhost_ops->vhost_enable_custom_iommu) {
-            err_cause = "Device does not use regular IOMMU";
         } else if (!virtio_vdev_has_feature(hdev->vdev, VIRTIO_F_VERSION_1)) {
             err_cause = "Legacy VirtIO device";
         }
-- 
2.27.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]