qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] vhost-user-scsi: add message for device reset
@ 2018-03-19 15:13 David Vrabel
  2018-03-19 15:13 ` [Qemu-devel] [PATCH 1/2] vhost-user: add VHOST_USER_RESET_DEVICE to reset devices David Vrabel
  2018-03-19 15:13 ` [Qemu-devel] [PATCH 2/2] vhost-user-scsi: reset the device if supported David Vrabel
  0 siblings, 2 replies; 3+ messages in thread
From: David Vrabel @ 2018-03-19 15:13 UTC (permalink / raw)
  To: qemu-devel

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Qemu-devel] [PATCH 1/2] vhost-user: add VHOST_USER_RESET_DEVICE to reset devices
  2018-03-19 15:13 [Qemu-devel] [PATCH 0/2] vhost-user-scsi: add message for device reset David Vrabel
@ 2018-03-19 15:13 ` David Vrabel
  2018-03-19 15:13 ` [Qemu-devel] [PATCH 2/2] vhost-user-scsi: reset the device if supported David Vrabel
  1 sibling, 0 replies; 3+ messages in thread
From: David Vrabel @ 2018-03-19 15:13 UTC (permalink / raw)
  To: qemu-devel; +Cc: David Vrabel

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.

Signed-off-by: David Vrabel <david.vrabel@nutanix.com>
---
 docs/interop/vhost-user.txt | 16 ++++++++++++++++
 hw/virtio/vhost-user.c      |  8 +++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/docs/interop/vhost-user.txt b/docs/interop/vhost-user.txt
index cb3a7595aa..c5faa9fff8 100644
--- a/docs/interop/vhost-user.txt
+++ b/docs/interop/vhost-user.txt
@@ -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
 -------------------
 
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 41ff5cff41..67207bfe8a 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -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;
     }
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [Qemu-devel] [PATCH 2/2] vhost-user-scsi: reset the device if supported
  2018-03-19 15:13 [Qemu-devel] [PATCH 0/2] vhost-user-scsi: add message for device reset David Vrabel
  2018-03-19 15:13 ` [Qemu-devel] [PATCH 1/2] vhost-user: add VHOST_USER_RESET_DEVICE to reset devices David Vrabel
@ 2018-03-19 15:13 ` David Vrabel
  1 sibling, 0 replies; 3+ messages in thread
From: David Vrabel @ 2018-03-19 15:13 UTC (permalink / raw)
  To: qemu-devel; +Cc: 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.

Signed-off-by: David Vrabel <david.vrabel@nutanix.com>
---
 hw/scsi/vhost-user-scsi.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c
index 9389ed48e0..15e2dabebb 100644
--- a/hw/scsi/vhost-user-scsi.c
+++ b/hw/scsi/vhost-user-scsi.c
@@ -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;
 }
 
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-03-19 15:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-19 15:13 [Qemu-devel] [PATCH 0/2] vhost-user-scsi: add message for device reset David Vrabel
2018-03-19 15:13 ` [Qemu-devel] [PATCH 1/2] vhost-user: add VHOST_USER_RESET_DEVICE to reset devices David Vrabel
2018-03-19 15:13 ` [Qemu-devel] [PATCH 2/2] vhost-user-scsi: reset the device if supported David Vrabel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).