Skip to contentSkip to conversation

vhost: clean up device reset

PATCH Superseded Stefan Hajnoczi 6 participants 11 messages Sep 27, 2023 – Oct 3, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover vhost: clean up device reset

Stateful vhost devices may need to free resources or clear device state upon device reset. The vhost-user protocol has a VHOST_USER_RESET_DEVICE message for this and vDPA has SET_STATUS 0, but only QEMU's vhost-user-scsi device actually implements this today.

This patch series performs device reset across all device types. When virtio_reset() is called, the associated vhost_dev's ->vhost_reset_device() is called. vhost-user-scsi's one-off implementation is obsoleted and removed.

This patch affects behavior as follows:
- vhost-kernel: no change in behavior. No ioctl calls are made.
- vhost-user: back-ends that negotiate VHOST_USER_PROTOCOL_F_RESET_DEVICE now receive a VHOST_USER_DEVICE_RESET message upon device reset. Otherwise there is no change in behavior. DPDK, SPDK, libvhost-user, and the vhost-user-backend crate do not negotiate VHOST_USER_PROTOCOL_F_RESET_DEVICE automatically.
- vhost-vdpa: an extra SET_STATUS 0 call is made during device reset.

I have tested this series with vhost-net (kernel), vhost-user-blk, and vhost-user-fs (both Rust and legacy C).

Stefan Hajnoczi (3):
vhost-user: do not send RESET_OWNER on device reset
vhost-backend: remove vhost_kernel_reset_device()
virtio: call ->vhost_reset_device() during reset

 include/hw/virtio/vhost.h |  3 +++
 hw/scsi/vhost-user-scsi.c | 20 --------------------
 hw/virtio/vhost-backend.c |  6 ------
 hw/virtio/vhost-user.c    | 13 +++++++++----
 hw/virtio/vhost.c         |  9 +++++++++
 hw/virtio/virtio.c        |  4 ++++
 6 files changed, 25 insertions(+), 30 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/3 vhost-user: do not send RESET_OWNER on device reset

The VHOST_USER_RESET_OWNER message is deprecated in the spec:

This is no longer used. Used to be sent to request disabling all rings, but some back-ends interpreted it to also discard connection state (this interpretation would lead to bugs). It is recommended that back-ends either ignore this message, or use it to disable all rings.

The only caller of vhost_user_reset_device() is vhost_user_scsi_reset(). It checks that F_RESET_DEVICE was negotiated before calling it:

  static void vhost_user_scsi_reset(VirtIODevice *vdev)
  {
      VHostSCSICommon *vsc = VHOST_SCSI_COMMON(vdev);
      struct vhost_dev *dev = &vsc->dev;
      /*
       * Historically, reset was not implemented so only reset devices
       * that are expecting it.
       */
      if (!virtio_has_feature(dev->protocol_features,
                              VHOST_USER_PROTOCOL_F_RESET_DEVICE)) {
          return;
      }

      if (dev->vhost_ops->vhost_reset_device) {
          dev->vhost_ops->vhost_reset_device(dev);
      }

}

Therefore VHOST_USER_RESET_OWNER is actually never sent by vhost_user_reset_device(). Remove the dead code. This effectively moves the vhost-user protocol specific code from vhost-user-scsi.c into vhost-user.c where it belongs.

---
 hw/scsi/vhost-user-scsi.c |  9 ---------
 hw/virtio/vhost-user.c    | 13 +++++++++----
 2 files changed, 9 insertions(+), 13 deletions(-)
hw/scsi/vhost-user-scsi.c +0 -9
index ee99b19e7a..8582b2e8ab 100644
@@ -71,15 +71,6 @@ static void vhost_user_scsi_reset(VirtIODevice *vdev)
     VHostSCSICommon *vsc = VHOST_SCSI_COMMON(vdev);
     struct vhost_dev *dev = &vsc->dev;
 
-    /*
-     * Historically, reset was not implemented so only reset devices
-     * that are expecting it.
-     */
-    if (!virtio_has_feature(dev->protocol_features,
-                            VHOST_USER_PROTOCOL_F_RESET_DEVICE)) {
-        return;
-    }
-
     if (dev->vhost_ops->vhost_reset_device) {
         dev->vhost_ops->vhost_reset_device(dev);
     }
hw/virtio/vhost-user.c +9 -4
index 8dcf049d42..7bed9ad7d5 100644
@@ -1492,12 +1492,17 @@ static int vhost_user_reset_device(struct vhost_dev *dev)
 {
     VhostUserMsg msg = {
         .hdr.flags = VHOST_USER_VERSION,
+        .hdr.request = VHOST_USER_RESET_DEVICE,
     };
 
-    msg.hdr.request = virtio_has_feature(dev->protocol_features,
-                                         VHOST_USER_PROTOCOL_F_RESET_DEVICE)
-        ? VHOST_USER_RESET_DEVICE
-        : VHOST_USER_RESET_OWNER;
+    /*
+     * Historically, reset was not implemented so only reset devices
+     * that are expecting it.
+     */
+    if (!virtio_has_feature(dev->protocol_features,
+                            VHOST_USER_PROTOCOL_F_RESET_DEVICE)) {
+        return -ENOSYS;
+    }
 
     return vhost_user_write(dev, &msg, NULL, 0);
 }
Signature · 1 line
2.41.0
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] vhost-user: do not send RESET_OWNER on device reset

Quoted 32 lines · Stefan Hajnoczi

The VHOST_USER_RESET_OWNER message is deprecated in the spec:

This is no longer used. Used to be sent to request disabling all rings, but some back-ends interpreted it to also discard connection state (this interpretation would lead to bugs). It is recommended that back-ends either ignore this message, or use it to disable all rings.

The only caller of vhost_user_reset_device() is vhost_user_scsi_reset(). It checks that F_RESET_DEVICE was negotiated before calling it:

static void vhost_user_scsi_reset(VirtIODevice *vdev)

 {
     VHostSCSICommon *vsc = VHOST_SCSI_COMMON(vdev);
     struct vhost_dev *dev = &vsc->dev;

     /*
      * Historically, reset was not implemented so only reset devices
      * that are expecting it.
      */
     if (!virtio_has_feature(dev->protocol_features,
                             VHOST_USER_PROTOCOL_F_RESET_DEVICE)) {
         return;
     }

     if (dev->vhost_ops->vhost_reset_device) {
         dev->vhost_ops->vhost_reset_device(dev);
     }
Quoted 6 lines

}

Therefore VHOST_USER_RESET_OWNER is actually never sent by vhost_user_reset_device(). Remove the dead code. This effectively moves the vhost-user protocol specific code from vhost-user-scsi.c into vhost-user.c where it belongs.

Quoted 55 lines

---
hw/scsi/vhost-user-scsi.c | 9 ---------
hw/virtio/vhost-user.c | 13 +++++++++----

2 files changed, 9 insertions(+), 13 deletions(-)
hw/scsi/vhost-user-scsi.c +0 -9
index ee99b19e7a..8582b2e8ab 100644
@@ -71,15 +71,6 @@ static void vhost_user_scsi_reset(VirtIODevice *vdev)
    VHostSCSICommon *vsc = VHOST_SCSI_COMMON(vdev);
    struct vhost_dev *dev = &vsc->dev;
 
-    /*
-     * Historically, reset was not implemented so only reset devices
-     * that are expecting it.
-     */
-    if (!virtio_has_feature(dev->protocol_features,
-                            VHOST_USER_PROTOCOL_F_RESET_DEVICE)) {
-        return;
-    }
-
    if (dev->vhost_ops->vhost_reset_device) {
        dev->vhost_ops->vhost_reset_device(dev);
    }
hw/virtio/vhost-user.c +9 -4
index 8dcf049d42..7bed9ad7d5 100644
@@ -1492,12 +1492,17 @@ static int vhost_user_reset_device(struct vhost_dev *dev)
 {
    VhostUserMsg msg = {
        .hdr.flags = VHOST_USER_VERSION,
+        .hdr.request = VHOST_USER_RESET_DEVICE,
    };
 
-    msg.hdr.request = virtio_has_feature(dev->protocol_features,
-                                         VHOST_USER_PROTOCOL_F_RESET_DEVICE)
-        ? VHOST_USER_RESET_DEVICE
-        : VHOST_USER_RESET_OWNER;
+    /*
+     * Historically, reset was not implemented so only reset devices
+     * that are expecting it.
+     */
+    if (!virtio_has_feature(dev->protocol_features,
+                            VHOST_USER_PROTOCOL_F_RESET_DEVICE)) {
+        return -ENOSYS;
+    }
 
    return vhost_user_write(dev, &msg, NULL, 0);
 }
Signature · 1 line
2.41.0
#3 lore raw

PATCH 2/3 vhost-backend: remove vhost_kernel_reset_device()

In reply to Stefan Hajnoczi

vhost_kernel_reset_device() invokes RESET_OWNER, which disassociates the owner process from the device. The device is left non-operational since SET_OWNER is only called once during startup in vhost_dev_init().

vhost_kernel_reset_device() is never called so this latent bug never appears. Get rid of vhost_kernel_reset_device() for now. If someone needs it in the future they'll need to implement it correctly.

---
 hw/virtio/vhost-backend.c | 6 ------
 1 file changed, 6 deletions(-)
hw/virtio/vhost-backend.c +0 -6
index 8e581575c9..17f3fc6a08 100644
@@ -197,11 +197,6 @@ static int vhost_kernel_set_owner(struct vhost_dev *dev)
     return vhost_kernel_call(dev, VHOST_SET_OWNER, NULL);
 }
 
-static int vhost_kernel_reset_device(struct vhost_dev *dev)
-{
-    return vhost_kernel_call(dev, VHOST_RESET_OWNER, NULL);
-}
-
 static int vhost_kernel_get_vq_index(struct vhost_dev *dev, int idx)
 {
     assert(idx >= dev->vq_index && idx < dev->vq_index + dev->nvqs);
@@ -322,7 +317,6 @@ const VhostOps kernel_ops = {
         .vhost_get_features = vhost_kernel_get_features,
         .vhost_set_backend_cap = vhost_kernel_set_backend_cap,
         .vhost_set_owner = vhost_kernel_set_owner,
-        .vhost_reset_device = vhost_kernel_reset_device,
         .vhost_get_vq_index = vhost_kernel_get_vq_index,
         .vhost_vsock_set_guest_cid = vhost_kernel_vsock_set_guest_cid,
         .vhost_vsock_set_running = vhost_kernel_vsock_set_running,
Signature · 1 line
2.41.0
Reviewed-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] vhost-backend: remove vhost_kernel_reset_device()

Quoted 12 lines · Stefan Hajnoczi

vhost_kernel_reset_device() invokes RESET_OWNER, which disassociates the owner process from the device. The device is left non-operational since SET_OWNER is only called once during startup in vhost_dev_init().

vhost_kernel_reset_device() is never called so this latent bug never appears. Get rid of vhost_kernel_reset_device() for now. If someone needs it in the future they'll need to implement it correctly.

Quoted 32 lines

---
hw/virtio/vhost-backend.c | 6 ------

1 file changed, 6 deletions(-)
hw/virtio/vhost-backend.c +0 -6
index 8e581575c9..17f3fc6a08 100644
@@ -197,11 +197,6 @@ static int vhost_kernel_set_owner(struct vhost_dev *dev)
    return vhost_kernel_call(dev, VHOST_SET_OWNER, NULL);
 }
 
-static int vhost_kernel_reset_device(struct vhost_dev *dev)
-{
-    return vhost_kernel_call(dev, VHOST_RESET_OWNER, NULL);
-}
-
 static int vhost_kernel_get_vq_index(struct vhost_dev *dev, int idx)
 {
    assert(idx >= dev->vq_index && idx < dev->vq_index + dev->nvqs);
@@ -322,7 +317,6 @@ const VhostOps kernel_ops = {
        .vhost_get_features = vhost_kernel_get_features,
        .vhost_set_backend_cap = vhost_kernel_set_backend_cap,
        .vhost_set_owner = vhost_kernel_set_owner,
-        .vhost_reset_device = vhost_kernel_reset_device,
        .vhost_get_vq_index = vhost_kernel_get_vq_index,
        .vhost_vsock_set_guest_cid = vhost_kernel_vsock_set_guest_cid,
        .vhost_vsock_set_running = vhost_kernel_vsock_set_running,
Signature · 1 line
2.41.0
#5 lore raw

PATCH 3/3 virtio: call ->vhost_reset_device() during reset

In reply to Stefan Hajnoczi

vhost-user-scsi has a VirtioDeviceClass->reset() function that calls ->vhost_reset_device(). The other vhost devices don't notify the vhost device upon reset.

Stateful vhost devices may need to handle device reset in order to free resources or prevent stale device state from interfering after reset.

Call ->vhost_device_reset() from virtio_reset() so that that vhost devices are notified of device reset.

This patch affects behavior as follows:
- vhost-kernel: No change in behavior since ->vhost_reset_device() is not implemented.
- vhost-user: back-ends that negotiate VHOST_USER_PROTOCOL_F_RESET_DEVICE now receive a VHOST_USER_DEVICE_RESET message upon device reset. Otherwise there is no change in behavior. DPDK, SPDK, libvhost-user, and the vhost-user-backend crate do not negotiate VHOST_USER_PROTOCOL_F_RESET_DEVICE automatically.
- vhost-vdpa: an extra SET_STATUS 0 call is made during device reset.

---
 include/hw/virtio/vhost.h |  3 +++
 hw/scsi/vhost-user-scsi.c | 11 -----------
 hw/virtio/vhost.c         |  9 +++++++++
 hw/virtio/virtio.c        |  4 ++++
 4 files changed, 16 insertions(+), 11 deletions(-)
include/hw/virtio/vhost.h +3 -0
index 6a173cb9fa..381fb51966 100644
@@ -338,4 +338,7 @@ int vhost_dev_set_inflight(struct vhost_dev *dev,
 int vhost_dev_get_inflight(struct vhost_dev *dev, uint16_t queue_size,
                            struct vhost_inflight *inflight);
 bool vhost_dev_has_iommu(struct vhost_dev *dev);
+
+int vhost_reset_device(struct vhost_dev *hdev);
+
 #endif
hw/scsi/vhost-user-scsi.c +0 -11
index 8582b2e8ab..6917a748bb 100644
@@ -66,16 +66,6 @@ static void vhost_user_scsi_set_status(VirtIODevice *vdev, uint8_t status)
     }
 }
 
-static void vhost_user_scsi_reset(VirtIODevice *vdev)
-{
-    VHostSCSICommon *vsc = VHOST_SCSI_COMMON(vdev);
-    struct vhost_dev *dev = &vsc->dev;
-
-    if (dev->vhost_ops->vhost_reset_device) {
-        dev->vhost_ops->vhost_reset_device(dev);
-    }
-}
-
 static void vhost_dummy_handle_output(VirtIODevice *vdev, VirtQueue *vq)
 {
 }
@@ -195,7 +185,6 @@ static void vhost_user_scsi_class_init(ObjectClass *klass, void *data)
     vdc->get_features = vhost_scsi_common_get_features;
     vdc->set_config = vhost_scsi_common_set_config;
     vdc->set_status = vhost_user_scsi_set_status;
-    vdc->reset = vhost_user_scsi_reset;
     fwc->get_dev_path = vhost_scsi_common_get_fw_dev_path;
 }
 
hw/virtio/vhost.c +9 -0
index e2f6ffb446..6003e50e83 100644
@@ -2087,3 +2087,12 @@ int vhost_net_set_backend(struct vhost_dev *hdev,
 
     return -ENOSYS;
 }
+
+int vhost_reset_device(struct vhost_dev *hdev)
+{
+    if (hdev->vhost_ops->vhost_reset_device) {
+        return hdev->vhost_ops->vhost_reset_device(hdev);
+    }
+
+    return -ENOSYS;
+}
hw/virtio/virtio.c +4 -0
index 4577f3f5b3..d863ffd5d6 100644
@@ -2121,6 +2121,10 @@ void virtio_reset(void *opaque)
         vdev->device_endian = virtio_default_endian();
     }
 
+    if (vdev->vhost_started) {
+        vhost_reset_device(k->get_vhost(vdev));
+    }
+
     if (k->reset) {
         k->reset(vdev);
     }
Signature · 1 line
2.41.0
Reviewed-by on v1 3/3
#6 lore raw

Re: [PATCH 3/3] virtio: call ->vhost_reset_device() during reset

Quoted 14 lines · Stefan Hajnoczi

vhost-user-scsi has a VirtioDeviceClass->reset() function that calls ->vhost_reset_device(). The other vhost devices don't notify the vhost device upon reset.

Stateful vhost devices may need to handle device reset in order to free resources or prevent stale device state from interfering after reset.

Call ->vhost_device_reset() from virtio_reset() so that that vhost devices are notified of device reset.

Quoted 10 lines

This patch affects behavior as follows:
- vhost-kernel: No change in behavior since ->vhost_reset_device() is not implemented.
- vhost-user: back-ends that negotiate VHOST_USER_PROTOCOL_F_RESET_DEVICE now receive a VHOST_USER_DEVICE_RESET message upon device reset. Otherwise there is no change in behavior. DPDK, SPDK, libvhost-user, and the vhost-user-backend crate do not negotiate VHOST_USER_PROTOCOL_F_RESET_DEVICE automatically.
- vhost-vdpa: an extra SET_STATUS 0 call is made during device reset.

Quoted 85 lines

---

include/hw/virtio/vhost.h |  3 +++
hw/scsi/vhost-user-scsi.c | 11 -----------
hw/virtio/vhost.c         |  9 +++++++++
hw/virtio/virtio.c        |  4 ++++
4 files changed, 16 insertions(+), 11 deletions(-)
include/hw/virtio/vhost.h +3 -0
index 6a173cb9fa..381fb51966 100644
@@ -338,4 +338,7 @@ int vhost_dev_set_inflight(struct vhost_dev *dev,
 int vhost_dev_get_inflight(struct vhost_dev *dev, uint16_t queue_size,
                           struct vhost_inflight *inflight);
 bool vhost_dev_has_iommu(struct vhost_dev *dev);
+
+int vhost_reset_device(struct vhost_dev *hdev);
+
 #endif
hw/scsi/vhost-user-scsi.c +0 -11
index 8582b2e8ab..6917a748bb 100644
@@ -66,16 +66,6 @@ static void vhost_user_scsi_set_status(VirtIODevice *vdev, uint8_t status)
    }
 }
 
-static void vhost_user_scsi_reset(VirtIODevice *vdev)
-{
-    VHostSCSICommon *vsc = VHOST_SCSI_COMMON(vdev);
-    struct vhost_dev *dev = &vsc->dev;
-
-    if (dev->vhost_ops->vhost_reset_device) {
-        dev->vhost_ops->vhost_reset_device(dev);
-    }
-}
-
 static void vhost_dummy_handle_output(VirtIODevice *vdev, VirtQueue *vq)
 {
 }
@@ -195,7 +185,6 @@ static void vhost_user_scsi_class_init(ObjectClass *klass, void *data)
    vdc->get_features = vhost_scsi_common_get_features;
    vdc->set_config = vhost_scsi_common_set_config;
    vdc->set_status = vhost_user_scsi_set_status;
-    vdc->reset = vhost_user_scsi_reset;
    fwc->get_dev_path = vhost_scsi_common_get_fw_dev_path;
 }
 
hw/virtio/vhost.c +9 -0
index e2f6ffb446..6003e50e83 100644
@@ -2087,3 +2087,12 @@ int vhost_net_set_backend(struct vhost_dev *hdev,
 
    return -ENOSYS;
 }
+
+int vhost_reset_device(struct vhost_dev *hdev)
+{
+    if (hdev->vhost_ops->vhost_reset_device) {
+        return hdev->vhost_ops->vhost_reset_device(hdev);
+    }
+
+    return -ENOSYS;
+}
hw/virtio/virtio.c +4 -0
index 4577f3f5b3..d863ffd5d6 100644
@@ -2121,6 +2121,10 @@ void virtio_reset(void *opaque)
        vdev->device_endian = virtio_default_endian();
    }
 
+    if (vdev->vhost_started) {
+        vhost_reset_device(k->get_vhost(vdev));
+    }
+
    if (k->reset) {
        k->reset(vdev);
    }
Signature · 1 line
2.41.0
Acked-by on the v1 series
#7 lore raw
In reply to Stefan Hajnoczi
Quoted 20 lines · Stefan Hajnoczi

Stateful vhost devices may need to free resources or clear device state upon device reset. The vhost-user protocol has a VHOST_USER_RESET_DEVICE message for this and vDPA has SET_STATUS 0, but only QEMU's vhost-user-scsi device actually implements this today.

This patch series performs device reset across all device types. When virtio_reset() is called, the associated vhost_dev's ->vhost_reset_device() is called. vhost-user-scsi's one-off implementation is obsoleted and removed.

This patch affects behavior as follows:
- vhost-kernel: no change in behavior. No ioctl calls are made.
- vhost-user: back-ends that negotiate VHOST_USER_PROTOCOL_F_RESET_DEVICE now receive a VHOST_USER_DEVICE_RESET message upon device reset. Otherwise there is no change in behavior. DPDK, SPDK, libvhost-user, and the vhost-user-backend crate do not negotiate VHOST_USER_PROTOCOL_F_RESET_DEVICE automatically.
- vhost-vdpa: an extra SET_STATUS 0 call is made during device reset.

Quoted 3 lines

I have tested this series with vhost-net (kernel), vhost-user-blk, and vhost-user-fs (both Rust and legacy C).

Quoted 16 lines

Stefan Hajnoczi (3):
vhost-user: do not send RESET_OWNER on device reset
vhost-backend: remove vhost_kernel_reset_device()
virtio: call ->vhost_reset_device() during reset

 include/hw/virtio/vhost.h |  3 +++
 hw/scsi/vhost-user-scsi.c | 20 --------------------
 hw/virtio/vhost-backend.c |  6 ------
 hw/virtio/vhost-user.c    | 13 +++++++++----
 hw/virtio/vhost.c         |  9 +++++++++
 hw/virtio/virtio.c        |  4 ++++
 6 files changed, 25 insertions(+), 30 deletions(-)

--
2.41.0

Tested-by
#8 lore raw

QE tested a regression testing on this series with vhost-vdpa device, everything is working fine.

Quoted 46 lines · Eugenio Perez Martin
Quoted 20 lines · Stefan Hajnoczi

Stateful vhost devices may need to free resources or clear device state upon device reset. The vhost-user protocol has a VHOST_USER_RESET_DEVICE message for this and vDPA has SET_STATUS 0, but only QEMU's vhost-user-scsi device actually implements this today.

This patch series performs device reset across all device types. When virtio_reset() is called, the associated vhost_dev's ->vhost_reset_device() is called. vhost-user-scsi's one-off implementation is obsoleted and removed.

This patch affects behavior as follows:
- vhost-kernel: no change in behavior. No ioctl calls are made.
- vhost-user: back-ends that negotiate VHOST_USER_PROTOCOL_F_RESET_DEVICE now receive a VHOST_USER_DEVICE_RESET message upon device reset. Otherwise there is no change in behavior. DPDK, SPDK, libvhost-user, and the vhost-user-backend crate do not negotiate VHOST_USER_PROTOCOL_F_RESET_DEVICE automatically.
- vhost-vdpa: an extra SET_STATUS 0 call is made during device reset.

Quoted 3 lines

I have tested this series with vhost-net (kernel), vhost-user-blk, and vhost-user-fs (both Rust and legacy C).

Quoted 16 lines

Stefan Hajnoczi (3):
vhost-user: do not send RESET_OWNER on device reset
vhost-backend: remove vhost_kernel_reset_device()
virtio: call ->vhost_reset_device() during reset

 include/hw/virtio/vhost.h |  3 +++
 hw/scsi/vhost-user-scsi.c | 20 --------------------
 hw/virtio/vhost-backend.c |  6 ------
 hw/virtio/vhost-user.c    | 13 +++++++++----
 hw/virtio/vhost.c         |  9 +++++++++
 hw/virtio/virtio.c        |  4 ++++
 6 files changed, 25 insertions(+), 30 deletions(-)

--
2.41.0

#9 lore raw
In reply to Stefan Hajnoczi
Quoted 19 lines · Stefan Hajnoczi

Stateful vhost devices may need to free resources or clear device state upon device reset. The vhost-user protocol has a VHOST_USER_RESET_DEVICE message for this and vDPA has SET_STATUS 0, but only QEMU's vhost-user-scsi device actually implements this today.

This patch series performs device reset across all device types. When virtio_reset() is called, the associated vhost_dev's ->vhost_reset_device() is called. vhost-user-scsi's one-off implementation is obsoleted and removed.

This patch affects behavior as follows:
- vhost-kernel: no change in behavior. No ioctl calls are made.
- vhost-user: back-ends that negotiate VHOST_USER_PROTOCOL_F_RESET_DEVICE now receive a VHOST_USER_DEVICE_RESET message upon device reset. Otherwise there is no change in behavior. DPDK, SPDK, libvhost-user, and the vhost-user-backend crate do not negotiate VHOST_USER_PROTOCOL_F_RESET_DEVICE automatically.
- vhost-vdpa: an extra SET_STATUS 0 call is made during device reset.

Quoted 7 lines

I have tested this series with vhost-net (kernel), vhost-user-blk, and vhost-user-fs (both Rust and legacy C).

Stefan Hajnoczi (3):
vhost-user: do not send RESET_OWNER on device reset
vhost-backend: remove vhost_kernel_reset_device()
virtio: call ->vhost_reset_device() during reset

Build failure:
https://gitlab.com/mstredhat/qemu/-/jobs/5215049540

Quoted 10 lines
 include/hw/virtio/vhost.h |  3 +++
 hw/scsi/vhost-user-scsi.c | 20 --------------------
 hw/virtio/vhost-backend.c |  6 ------
 hw/virtio/vhost-user.c    | 13 +++++++++----
 hw/virtio/vhost.c         |  9 +++++++++
 hw/virtio/virtio.c        |  4 ++++
 6 files changed, 25 insertions(+), 30 deletions(-)
Signature · 1 line
2.41.0
#10 lore raw
Quoted 24 lines · Michael S. Tsirkin
Quoted 22 lines · Stefan Hajnoczi

Stateful vhost devices may need to free resources or clear device state upon device reset. The vhost-user protocol has a VHOST_USER_RESET_DEVICE message for this and vDPA has SET_STATUS 0, but only QEMU's vhost-user-scsi device actually implements this today.

This patch series performs device reset across all device types. When virtio_reset() is called, the associated vhost_dev's ->vhost_reset_device() is called. vhost-user-scsi's one-off implementation is obsoleted and removed.

This patch affects behavior as follows:
- vhost-kernel: no change in behavior. No ioctl calls are made.
- vhost-user: back-ends that negotiate VHOST_USER_PROTOCOL_F_RESET_DEVICE now receive a VHOST_USER_DEVICE_RESET message upon device reset. Otherwise there is no change in behavior. DPDK, SPDK, libvhost-user, and the vhost-user-backend crate do not negotiate VHOST_USER_PROTOCOL_F_RESET_DEVICE automatically.
- vhost-vdpa: an extra SET_STATUS 0 call is made during device reset.

I have tested this series with vhost-net (kernel), vhost-user-blk, and vhost-user-fs (both Rust and legacy C).

Quoted 7 lines
Quoted 4 lines

Stefan Hajnoczi (3):
vhost-user: do not send RESET_OWNER on device reset
vhost-backend: remove vhost_kernel_reset_device()
virtio: call ->vhost_reset_device() during reset

Build failure:
https://gitlab.com/mstredhat/qemu/-/jobs/5215049540

Sorry about that, will fix.

Stefan

Quoted 12 lines
Quoted 10 lines
 include/hw/virtio/vhost.h |  3 +++
 hw/scsi/vhost-user-scsi.c | 20 --------------------
 hw/virtio/vhost-backend.c |  6 ------
 hw/virtio/vhost-user.c    | 13 +++++++++----
 hw/virtio/vhost.c         |  9 +++++++++
 hw/virtio/virtio.c        |  4 ++++
 6 files changed, 25 insertions(+), 30 deletions(-)

--
2.41.0