Skip to contentSkip to conversation

vdpa: stop all svq on device deletion

PATCH In review Eugenio Pérez 3 participants 4 messages Feb 9, 2023 – Feb 24, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vdpa: stop all svq on device deletion

Not stopping them leave the device in a bad state when virtio-net fronted device is unplugged with device_del monitor command.

This is not triggable in regular poweroff or qemu forces shutdown because cleanup is called right after vhost_vdpa_dev_start(false). But devices hot unplug does not call vdpa device cleanups. This lead to all the vhost_vdpa devices without stop the SVQ but the last.

Fix it and clean the code, making it symmetric with vhost_vdpa_svqs_start.

Fixes dff4426fa656 ("vhost: Add Shadow VirtQueue kick forwarding capabilities")
---
 hw/virtio/vhost-vdpa.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)
hw/virtio/vhost-vdpa.c +2 -15
index 542e003101..df3a1e92ac 100644
@@ -689,26 +689,11 @@ static int vhost_vdpa_get_device_id(struct vhost_dev *dev,
     return ret;
 }
 
-static void vhost_vdpa_reset_svq(struct vhost_vdpa *v)
-{
-    if (!v->shadow_vqs_enabled) {
-        return;
-    }
-
-    for (unsigned i = 0; i < v->shadow_vqs->len; ++i) {
-        VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, i);
-        vhost_svq_stop(svq);
-    }
-}
-
 static int vhost_vdpa_reset_device(struct vhost_dev *dev)
 {
-    struct vhost_vdpa *v = dev->opaque;
     int ret;
     uint8_t status = 0;
 
-    vhost_vdpa_reset_svq(v);
-
     ret = vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &status);
     trace_vhost_vdpa_reset_device(dev, status);
     return ret;
@@ -1100,6 +1085,8 @@ static void vhost_vdpa_svqs_stop(struct vhost_dev *dev)
 
     for (unsigned i = 0; i < v->shadow_vqs->len; ++i) {
         VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, i);
+
+        vhost_svq_stop(svq);
         vhost_vdpa_svq_unmap_rings(dev, svq);
 
         event_notifier_cleanup(&svq->hdev_kick);
Signature · 1 line
2.31.1
Tested-by on v1 1/1
#1 lore raw
Quoted 50 lines · Eugenio Pérez

Not stopping them leave the device in a bad state when virtio-net fronted device is unplugged with device_del monitor command.

This is not triggable in regular poweroff or qemu forces shutdown because cleanup is called right after vhost_vdpa_dev_start(false). But devices hot unplug does not call vdpa device cleanups. This lead to all the vhost_vdpa devices without stop the SVQ but the last.

Fix it and clean the code, making it symmetric with vhost_vdpa_svqs_start.

Fixes dff4426fa656 ("vhost: Add Shadow VirtQueue kick forwarding capabilities")
---
  hw/virtio/vhost-vdpa.c | 17 ++---------------
  1 file changed, 2 insertions(+), 15 deletions(-)
hw/virtio/vhost-vdpa.c +0 -15
index 542e003101..df3a1e92ac 100644
@@ -689,26 +689,11 @@ static int vhost_vdpa_get_device_id(struct vhost_dev *dev,
      return ret;
  }
 
-static void vhost_vdpa_reset_svq(struct vhost_vdpa *v)
-{
-    if (!v->shadow_vqs_enabled) {
-        return;
-    }
-
-    for (unsigned i = 0; i < v->shadow_vqs->len; ++i) {
-        VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, i);
-        vhost_svq_stop(svq);
-    }
-}
-
  static int vhost_vdpa_reset_device(struct vhost_dev *dev)
  {
-    struct vhost_vdpa *v = dev->opaque;
      int ret;
      uint8_t status = 0;
 
-    vhost_vdpa_reset_svq(v);
-
      ret = vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &status);
      trace_vhost_vdpa_reset_device(dev, status);
      return ret;

hw/virtio/vhost-vdpa.c static void vhost_vdpa_svqs_stop(struct vhost_dev *dev) · line 1092

Quoted 8 lines
hw/virtio/vhost-vdpa.c +2 -0
@@ -1100,6 +1085,8 @@ static void vhost_vdpa_svqs_stop(struct vhost_dev *dev)
 
      for (unsigned i = 0; i < v->shadow_vqs->len; ++i) {
          VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, i);
+
+        vhost_svq_stop(svq);
          vhost_vdpa_svq_unmap_rings(dev, svq);
 
          event_notifier_cleanup(&svq->hdev_kick);
#2 lore raw
In reply to Eugenio Pérez

Hi,

this patch fixes a QEMU crash, could it be merged?

Thanks,
Laurent

Quoted 58 lines · Eugenio Pérez

Not stopping them leave the device in a bad state when virtio-net fronted device is unplugged with device_del monitor command.

This is not triggable in regular poweroff or qemu forces shutdown because cleanup is called right after vhost_vdpa_dev_start(false). But devices hot unplug does not call vdpa device cleanups. This lead to all the vhost_vdpa devices without stop the SVQ but the last.

Fix it and clean the code, making it symmetric with vhost_vdpa_svqs_start.

Fixes dff4426fa656 ("vhost: Add Shadow VirtQueue kick forwarding capabilities")
---
  hw/virtio/vhost-vdpa.c | 17 ++---------------
  1 file changed, 2 insertions(+), 15 deletions(-)
hw/virtio/vhost-vdpa.c +2 -15
index 542e003101..df3a1e92ac 100644
@@ -689,26 +689,11 @@ static int vhost_vdpa_get_device_id(struct vhost_dev *dev,
      return ret;
  }
 
-static void vhost_vdpa_reset_svq(struct vhost_vdpa *v)
-{
-    if (!v->shadow_vqs_enabled) {
-        return;
-    }
-
-    for (unsigned i = 0; i < v->shadow_vqs->len; ++i) {
-        VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, i);
-        vhost_svq_stop(svq);
-    }
-}
-
  static int vhost_vdpa_reset_device(struct vhost_dev *dev)
  {
-    struct vhost_vdpa *v = dev->opaque;
      int ret;
      uint8_t status = 0;
 
-    vhost_vdpa_reset_svq(v);
-
      ret = vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &status);
      trace_vhost_vdpa_reset_device(dev, status);
      return ret;
@@ -1100,6 +1085,8 @@ static void vhost_vdpa_svqs_stop(struct vhost_dev *dev)
 
      for (unsigned i = 0; i < v->shadow_vqs->len; ++i) {
          VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, i);
+
+        vhost_svq_stop(svq);
          vhost_vdpa_svq_unmap_rings(dev, svq);
 
          event_notifier_cleanup(&svq->hdev_kick);
Acked-by
#3 lore raw
Quoted 4 lines · Laurent Vivier

Hi,

this patch fixes a QEMU crash, could it be merged?

I think it should go with Michael's tree.

Thanks

Quoted 64 lines

Thanks,
Laurent

Quoted 58 lines · Eugenio Pérez

Not stopping them leave the device in a bad state when virtio-net fronted device is unplugged with device_del monitor command.

This is not triggable in regular poweroff or qemu forces shutdown because cleanup is called right after vhost_vdpa_dev_start(false). But devices hot unplug does not call vdpa device cleanups. This lead to all the vhost_vdpa devices without stop the SVQ but the last.

Fix it and clean the code, making it symmetric with vhost_vdpa_svqs_start.

Fixes dff4426fa656 ("vhost: Add Shadow VirtQueue kick forwarding capabilities")
---
  hw/virtio/vhost-vdpa.c | 17 ++---------------
  1 file changed, 2 insertions(+), 15 deletions(-)
hw/virtio/vhost-vdpa.c +2 -15
index 542e003101..df3a1e92ac 100644
@@ -689,26 +689,11 @@ static int vhost_vdpa_get_device_id(struct vhost_dev *dev,
      return ret;
  }
 
-static void vhost_vdpa_reset_svq(struct vhost_vdpa *v)
-{
-    if (!v->shadow_vqs_enabled) {
-        return;
-    }
-
-    for (unsigned i = 0; i < v->shadow_vqs->len; ++i) {
-        VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, i);
-        vhost_svq_stop(svq);
-    }
-}
-
  static int vhost_vdpa_reset_device(struct vhost_dev *dev)
  {
-    struct vhost_vdpa *v = dev->opaque;
      int ret;
      uint8_t status = 0;
 
-    vhost_vdpa_reset_svq(v);
-
      ret = vhost_vdpa_call(dev, VHOST_VDPA_SET_STATUS, &status);
      trace_vhost_vdpa_reset_device(dev, status);
      return ret;
@@ -1100,6 +1085,8 @@ static void vhost_vdpa_svqs_stop(struct vhost_dev *dev)
 
      for (unsigned i = 0; i < v->shadow_vqs->len; ++i) {
          VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, i);
+
+        vhost_svq_stop(svq);
          vhost_vdpa_svq_unmap_rings(dev, svq);
 
          event_notifier_cleanup(&svq->hdev_kick);