Skip to contentSkip to conversation

vhost_vdpa: no need to fetch vring base when poweroff

PATCH Superseded Zhu Lingshan 2 participants 3 messages Jul 7, 2023 – Jul 10, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost_vdpa: no need to fetch vring base when poweroff

In the poweroff routine, no need to fetch last available index.

This commit also provides a better debug message in the vhost caller vhost_virtqueue_stop, because if vhost does not fetch the last avail idx successfully, maybe the device does not suspend, vhost will sync last avail idx to vring used idx as a work around, not a failure.

---
 hw/virtio/vhost-vdpa.c | 4 ++++
 hw/virtio/vhost.c      | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)
hw/virtio/vhost-vdpa.c +4 -0
index 3c575a9a6e..f62952e1c7 100644
@@ -26,6 +26,7 @@
 #include "cpu.h"
 #include "trace.h"
 #include "qapi/error.h"
+#include "sysemu/runstate.h"
 
 /*
  * Return one past the end of the end of section. Be careful with uint64_t
@@ -1391,6 +1392,9 @@ static int vhost_vdpa_get_vring_base(struct vhost_dev *dev,
     struct vhost_vdpa *v = dev->opaque;
     int ret;
 
+    if (runstate_check(RUN_STATE_SHUTDOWN))
+        return 0;
+
     if (v->shadow_vqs_enabled) {
         ring->num = virtio_queue_get_last_avail_idx(dev->vdev, ring->index);
         return 0;
hw/virtio/vhost.c +1 -1
index 82394331bf..84712743e0 100644
@@ -1262,7 +1262,7 @@ void vhost_virtqueue_stop(struct vhost_dev *dev,
 
     r = dev->vhost_ops->vhost_get_vring_base(dev, &state);
     if (r < 0) {
-        VHOST_OPS_DEBUG(r, "vhost VQ %u ring restore failed: %d", idx, r);
+        VHOST_OPS_DEBUG(r, "sync last avail idx to the used idx for vhost VQ %u", idx);
         /* Connection to the backend is broken, so let's sync internal
          * last avail idx to the device used idx.
          */
Signature · 1 line
2.39.3
#1 lore raw
Quoted 10 lines · Zhu Lingshan

In the poweroff routine, no need to fetch last available index.

This commit also provides a better debug message in the vhost caller vhost_virtqueue_stop, because if vhost does not fetch the last avail idx successfully, maybe the device does not suspend, vhost will sync last avail idx to vring used idx as a work around, not a failure.

CCing MST.

Quoted 18 lines
---
 hw/virtio/vhost-vdpa.c | 4 ++++
 hw/virtio/vhost.c      | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)
hw/virtio/vhost-vdpa.c +1 -0
index 3c575a9a6e..f62952e1c7 100644
@@ -26,6 +26,7 @@
 #include "cpu.h"
 #include "trace.h"
 #include "qapi/error.h"
+#include "sysemu/runstate.h"
 
 /*
  * Return one past the end of the end of section. Be careful with uint64_t

hw/virtio/vhost-vdpa.c static int vhost_vdpa_get_vring_base(struct vhost_dev *dev, · line 1397

Quoted 6 lines
hw/virtio/vhost-vdpa.c +3 -0
@@ -1391,6 +1392,9 @@ static int vhost_vdpa_get_vring_base(struct vhost_dev *dev,
     struct vhost_vdpa *v = dev->opaque;
     int ret;
 
+    if (runstate_check(RUN_STATE_SHUTDOWN))
+        return 0;
+

QEMU coding style mandates braces around the "if" body (CODING_STYLE.rst file).

Apart from that I think we should add a comment here. Something in the line of:

Some devices do not support the call properly, and we don't need to retrieve the indexes if we're not migrating. Skip it in this case.

hw/virtio/vhost.c void vhost_virtqueue_stop(struct vhost_dev *dev, · line 1265

Quoted 13 lines
hw/virtio/vhost-vdpa.c +0 -0
     if (v->shadow_vqs_enabled) {
         ring->num = virtio_queue_get_last_avail_idx(dev->vdev, ring->index);
         return 0;
hw/virtio/vhost.c +1 -1
index 82394331bf..84712743e0 100644
@@ -1262,7 +1262,7 @@ void vhost_virtqueue_stop(struct vhost_dev *dev,
 
     r = dev->vhost_ops->vhost_get_vring_base(dev, &state);
     if (r < 0) {
-        VHOST_OPS_DEBUG(r, "vhost VQ %u ring restore failed: %d", idx, r);
+        VHOST_OPS_DEBUG(r, "sync last avail idx to the used idx for vhost VQ %u", idx);

Guest's used idx? Also, maybe it is worth splitting this in a separated patch.

Apart from the nitpicking, I think the general line of the patch is the way to go :).

Thanks!

Quoted 6 lines
hw/virtio/vhost.c +0 -1
         /* Connection to the backend is broken, so let's sync internal
          * last avail idx to the device used idx.
          */
--

2.39.3

#2 lore raw
Quoted 38 lines · Eugenio Perez Martin
Quoted 9 lines · Zhu Lingshan

In the poweroff routine, no need to fetch last available index.

This commit also provides a better debug message in the vhost caller vhost_virtqueue_stop, because if vhost does not fetch the last avail idx successfully, maybe the device does not suspend, vhost will sync last avail idx to vring used idx as a work around, not a failure.

CCing MST.

Quoted 18 lines
---
  hw/virtio/vhost-vdpa.c | 4 ++++
  hw/virtio/vhost.c      | 2 +-
  2 files changed, 5 insertions(+), 1 deletion(-)
hw/virtio/vhost-vdpa.c +1 -0
index 3c575a9a6e..f62952e1c7 100644
@@ -26,6 +26,7 @@
  #include "cpu.h"
  #include "trace.h"
  #include "qapi/error.h"
+#include "sysemu/runstate.h"
 
  /*
   * Return one past the end of the end of section. Be careful with uint64_t

hw/virtio/vhost-vdpa.c static int vhost_vdpa_get_vring_base(struct vhost_dev *dev, · line 1397

Quoted 6 lines
hw/virtio/vhost-vdpa.c +3 -0
@@ -1391,6 +1392,9 @@ static int vhost_vdpa_get_vring_base(struct vhost_dev *dev,
      struct vhost_vdpa *v = dev->opaque;
      int ret;
 
+    if (runstate_check(RUN_STATE_SHUTDOWN))
+        return 0;
+

QEMU coding style mandates braces around the "if" body (CODING_STYLE.rst file).

Quoted 4 lines

Apart from that I think we should add a comment here. Something in the line of:

Some devices do not support the call properly, and we don't need to retrieve the indexes if we're not migrating. Skip it in this case.

V2 will include these changes, thanks!

Quoted 10 lines
Quoted 10 lines
hw/virtio/vhost-vdpa.c +0 -0
      if (v->shadow_vqs_enabled) {
          ring->num = virtio_queue_get_last_avail_idx(dev->vdev, ring->index);
          return 0;
hw/virtio/vhost.c +0 -0
index 82394331bf..84712743e0 100644
@@ -1262,7 +1262,7 @@ void vhost_virtqueue_stop(struct vhost_dev *dev,
 
Quoted 5 lines

hw/virtio/vhost.c void vhost_virtqueue_stop(struct vhost_dev *dev, · line 1265

Quoted 4 lines
hw/virtio/vhost.c +1 -1
      r = dev->vhost_ops->vhost_get_vring_base(dev, &state);
      if (r < 0) {
-        VHOST_OPS_DEBUG(r, "vhost VQ %u ring restore failed: %d", idx, r);
+        VHOST_OPS_DEBUG(r, "sync last avail idx to the used idx for vhost VQ %u", idx);

Guest's used idx? Also, maybe it is worth splitting this in a separated patch.

Yes, guest used idx is much clearer. I am not sure whether this worthy a separated patch, this is only a comment.

Quoted 3 lines

Apart from the nitpicking, I think the general line of the patch is the way to go :).

Thanks!

Quoted 9 lines

Thanks!

Quoted 6 lines
hw/virtio/vhost.c +0 -1
          /* Connection to the backend is broken, so let's sync internal
           * last avail idx to the device used idx.
           */
--

2.39.3