Skip to contentSkip to conversation

vhost: fail device start if iotlb update fails

PATCH In review Prasad Pandit 3 participants 4 messages Nov 7, 2024 – Nov 11, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost: fail device start if iotlb update fails

From: Prasad Pandit <[email protected]>

While starting a vhost device, updating iotlb entries via 'vhost_device_iotlb_miss' may return an error.

qemu-kvm: vhost_device_iotlb_miss:

    700871,700871: Fail to update device iotlb

Fail device start when such an error occurs.

---
 hw/virtio/vhost.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

v1:
- Remove VHOST_OPS_DEBUG call.
- Call vhost_set_iotlb_callback and vhost_dev_start with 'false' argument.

v0:
- https://lore.kernel.org/qemu-devel/[email protected]/

hw/virtio/vhost.c +12 -1
index 76f9b2aaad..c40f48ac4d 100644
@@ -2095,11 +2095,22 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings)
          * vhost-kernel code requires for this.*/
         for (i = 0; i < hdev->nvqs; ++i) {
             struct vhost_virtqueue *vq = hdev->vqs + i;
-            vhost_device_iotlb_miss(hdev, vq->used_phys, true);
+            r = vhost_device_iotlb_miss(hdev, vq->used_phys, true);
+            if (r) {
+                goto fail_iotlb;
+            }
         }
     }
     vhost_start_config_intr(hdev);
     return 0;
+fail_iotlb:
+    if (vhost_dev_has_iommu(hdev) &&
+        hdev->vhost_ops->vhost_set_iotlb_callback) {
+        hdev->vhost_ops->vhost_set_iotlb_callback(hdev, false);
+    }
+    if (hdev->vhost_ops->vhost_dev_start) {
+        hdev->vhost_ops->vhost_dev_start(hdev, false);
+    }
 fail_start:
     if (vrings) {
         vhost_dev_set_vring_enable(hdev, false);

--
2.47.0

Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Prasad Pandit

From: Prasad Pandit <[email protected]>

While starting a vhost device, updating iotlb entries via 'vhost_device_iotlb_miss' may return an error.

qemu-kvm: vhost_device_iotlb_miss:
700871,700871: Fail to update device iotlb

Fail device start when such an error occurs.

Quoted 8 lines

---
hw/virtio/vhost.c | 13 ++++++++++++-

1 file changed, 12 insertions(+), 1 deletion(-)

v1:
- Remove VHOST_OPS_DEBUG call.
- Call vhost_set_iotlb_callback and vhost_dev_start with 'false' argument.

LGTM!

Quoted 35 lines

v0:
- https://lore.kernel.org/qemu-devel/[email protected]/

hw/virtio/vhost.c +12 -1
index 76f9b2aaad..c40f48ac4d 100644
@@ -2095,11 +2095,22 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings)
         * vhost-kernel code requires for this.*/
        for (i = 0; i < hdev->nvqs; ++i) {
            struct vhost_virtqueue *vq = hdev->vqs + i;
-            vhost_device_iotlb_miss(hdev, vq->used_phys, true);
+            r = vhost_device_iotlb_miss(hdev, vq->used_phys, true);
+            if (r) {
+                goto fail_iotlb;
+            }
        }
    }
    vhost_start_config_intr(hdev);
    return 0;
+fail_iotlb:
+    if (vhost_dev_has_iommu(hdev) &&
+        hdev->vhost_ops->vhost_set_iotlb_callback) {
+        hdev->vhost_ops->vhost_set_iotlb_callback(hdev, false);
+    }
+    if (hdev->vhost_ops->vhost_dev_start) {
+        hdev->vhost_ops->vhost_dev_start(hdev, false);
+    }

fail_start:

    if (vrings) {
        vhost_dev_set_vring_enable(hdev, false);

--
2.47.0

#2 lore raw
In reply to Prasad Pandit

Hi Prasad:

Quoted 8 lines · Prasad Pandit

From: Prasad Pandit <[email protected]>

While starting a vhost device, updating iotlb entries via 'vhost_device_iotlb_miss' may return an error.

qemu-kvm: vhost_device_iotlb_miss:

    700871,700871: Fail to update device iotlb

Actually, such updating is a workaround for vhost-net kernel to run.

I wonder what kind of issue would we get if we don't do this?

Thanks

Quoted 46 lines

Fail device start when such an error occurs.

---
 hw/virtio/vhost.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

v1:
- Remove VHOST_OPS_DEBUG call.
- Call vhost_set_iotlb_callback and vhost_dev_start with 'false' argument.

v0:
- https://lore.kernel.org/qemu-devel/[email protected]/

hw/virtio/vhost.c +12 -2
index 76f9b2aaad..c40f48ac4d 100644
@@ -2095,11 +2095,22 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev, bool vrings)
          * vhost-kernel code requires for this.*/
         for (i = 0; i < hdev->nvqs; ++i) {
             struct vhost_virtqueue *vq = hdev->vqs + i;
-            vhost_device_iotlb_miss(hdev, vq->used_phys, true);
+            r = vhost_device_iotlb_miss(hdev, vq->used_phys, true);
+            if (r) {
+                goto fail_iotlb;
+            }
         }
     }
     vhost_start_config_intr(hdev);
     return 0;
+fail_iotlb:
+    if (vhost_dev_has_iommu(hdev) &&
+        hdev->vhost_ops->vhost_set_iotlb_callback) {
+        hdev->vhost_ops->vhost_set_iotlb_callback(hdev, false);
+    }
+    if (hdev->vhost_ops->vhost_dev_start) {
+        hdev->vhost_ops->vhost_dev_start(hdev, false);
+    }
 fail_start:
     if (vrings) {
         vhost_dev_set_vring_enable(hdev, false);
--

2.47.0

#3 lore raw

Hello Jason,

Quoted 8 lines · Jason Wang
Quoted 5 lines

While starting a vhost device, updating iotlb entries via 'vhost_device_iotlb_miss' may return an error.

qemu-kvm: vhost_device_iotlb_miss:

    700871,700871: Fail to update device iotlb

Actually, such updating is a workaround for vhost-net kernel to run. I wonder what kind of issue would we get if we don't do this?

* During Postcopy migration, while starting the 'vhost-user' device, update of its iotlb entries would fail and the guest on the destination would hang, not finishing the migration. There might be other such scenarios.

Thank you.
---
- Prasad