Skip to contentSkip to conversation

vhost-user-scsi: add message for device reset

PATCH New David Vrabel 1 participant 3 messages Mar 19, 2018

lore
Share & tools
lore
#0 lore raw

cover vhost-user-scsi: add message for device reset

When a virtio scsi device is reset by a guest, the reset is not passed on to the vhost-user backend. This reset may be necessary if a device driver is restarted or the device is handed off between (for example) SeaBIOS and the OS.

Iff the vhost-user-scsi backend reports that it supports a new "reset device" feature, QEMU will send a VHOST_USER_RESET_DEVICE message when the guest resets the virtio device.

Existing backends are unaffected.

David

#1 lore raw

PATCH 1/2 vhost-user: add VHOST_USER_RESET_DEVICE to reset devices

Add a VHOST_USER_RESET_DEVICE message which will reset the vhost user backend. Disabling all rings, and resetting all internal state, ready for the backend to be reinitialized.

A backend has to report it supports this features with the VHOST_USER_PROTOCOL_F_RESET_DEVICE protocol feature bit. If it does so, the new message is used instead of sending a RESET_OWNER which has had inconsistent implementations.

---
 docs/interop/vhost-user.txt | 16 ++++++++++++++++
 hw/virtio/vhost-user.c      |  8 +++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)
docs/interop/vhost-user.txt +16 -0
index cb3a7595aa..c5faa9fff8 100644
@@ -369,6 +369,7 @@ Protocol features
 #define VHOST_USER_PROTOCOL_F_SLAVE_REQ      5
 #define VHOST_USER_PROTOCOL_F_CROSS_ENDIAN   6
 #define VHOST_USER_PROTOCOL_F_CRYPTO_SESSION 7
+#define VHOST_USER_PROTOCOL_F_RESET_DEVICE   8
 
 Master message types
 --------------------
@@ -689,6 +690,21 @@ Master message types
      feature has been successfully negotiated.
      It's a required feature for crypto devices.
 
+ * VHOST_USER_RESET_DEVICE
+
+      Id: 28
+      Equivalent ioctl: N/A
+      Master payload: N/A
+      Slave payload: N/A
+
+      Ask the vhost user backend to disable all rings and reset all
+      internal device state to the initial state, ready to be
+      reinitialized. The backend retains ownership of the device
+      throughout the reset operation.
+
+      Only valid if the VHOST_USER_PROTOCOL_F_RESET_DEVICE protocol
+      feature is set by the backend.
+
 Slave message types
 -------------------
 
hw/virtio/vhost-user.c +7 -1
index 41ff5cff41..67207bfe8a 100644
@@ -41,6 +41,7 @@ enum VhostUserProtocolFeature {
     VHOST_USER_PROTOCOL_F_SLAVE_REQ = 5,
     VHOST_USER_PROTOCOL_F_CROSS_ENDIAN = 6,
     VHOST_USER_PROTOCOL_F_CRYPTO_SESSION = 7,
+    VHOST_USER_PROTOCOL_F_RESET_DEVICE = 8,
 
     VHOST_USER_PROTOCOL_F_MAX
 };
@@ -76,6 +77,7 @@ typedef enum VhostUserRequest {
     VHOST_USER_SET_CONFIG = 25,
     VHOST_USER_CREATE_CRYPTO_SESSION = 26,
     VHOST_USER_CLOSE_CRYPTO_SESSION = 27,
+    VHOST_USER_RESET_DEVICE = 28,
     VHOST_USER_MAX
 } VhostUserRequest;
 
@@ -641,10 +643,14 @@ static int vhost_user_set_owner(struct vhost_dev *dev)
 static int vhost_user_reset_device(struct vhost_dev *dev)
 {
     VhostUserMsg msg = {
-        .hdr.request = VHOST_USER_RESET_OWNER,
         .hdr.flags = VHOST_USER_VERSION,
     };
 
+    msg.hdr.request = virtio_has_feature(dev->protocol_features,
+                                         VHOST_USER_PROTOCOL_F_RESET_DEVICE)
+        ? VHOST_USER_RESET_DEVICE
+        : VHOST_USER_RESET_OWNER;
+
     if (vhost_user_write(dev, &msg, NULL, 0) < 0) {
         return -1;
     }
Signature · 1 line
2.11.0
#2 lore raw

PATCH 2/2 vhost-user-scsi: reset the device if supported

In reply to David Vrabel

If the vhost-user-scsi backend supports the VHOST_USER_F_RESET_DEVICE protocol feature, then the device can be reset when requested.

If this feature is not supported, do not try a reset as this will send a VHOST_USER_RESET_OWNER that the backend is not expecting, potentially putting into an inoperable state.

---
 hw/scsi/vhost-user-scsi.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
hw/scsi/vhost-user-scsi.c +24 -0
index 9389ed48e0..15e2dabebb 100644
@@ -37,6 +37,10 @@ static const int user_feature_bits[] = {
     VHOST_INVALID_FEATURE_BIT
 };
 
+enum VhostUserProtocolFeature {
+    VHOST_USER_PROTOCOL_F_RESET_DEVICE = 8,
+};
+
 static void vhost_user_scsi_set_status(VirtIODevice *vdev, uint8_t status)
 {
     VHostUserSCSI *s = (VHostUserSCSI *)vdev;
@@ -60,6 +64,25 @@ 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;
+
+    /*
+     * 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);
+    }
+}
+
 static void vhost_dummy_handle_output(VirtIODevice *vdev, VirtQueue *vq)
 {
 }
@@ -172,6 +195,7 @@ static void vhost_user_scsi_class_init(ObjectClass *klass, void *data)
     vdc->get_features = vhost_user_scsi_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;
 }
 
Signature · 1 line
2.11.0