Skip to contentSkip to conversation

vdpa: fix vhost-vdpa suspended state not be shared

PATCH In review Wafer Xie 2 participants 2 messages Nov 19, 2025 – Feb 5

lore
Share & tools
lore

Wafer Xie

author
#0 lore raw

PATCH v4 1/1 vdpa: fix vhost-vdpa suspended state not be shared

When stopping a vhost-vdpa device, only the first queue pair is marked as suspended, while the remaining queues are not updated to the suspended state.
As a result, when stopping a multi-queue vhost-vdpa device,
the following error message will be printed.

qemu-system-x86_64:vhost VQ 2 ring restore failed: -1: Operation not permitted (1)

qemu-system-x86_64:vhost VQ 3 ring restore failed: -1: Operation not permitted (1)

So move v->suspended to v->shared, and then all the vhost_vdpa devices cannot have different suspended states.

Fixes 0bb302a9960a ("vdpa: add vhost_vdpa_suspend")

--
Changes in v4:
-Add Acked-by

Changes in v3:
-Update comments and add Acked-by

Changes in v2:
-Move v->suspended to v->shared
--

---
 hw/virtio/vhost-vdpa.c         | 6 +++---
 include/hw/virtio/vhost-vdpa.h | 8 ++++++--
 2 files changed, 9 insertions(+), 5 deletions(-)
hw/virtio/vhost-vdpa.c +3 -3
index 7061b6e1a3..2f8f11df86 100644
@@ -905,7 +905,7 @@ static int vhost_vdpa_reset_device(struct vhost_dev *dev)
 
     memory_listener_unregister(&v->shared->listener);
     v->shared->listener_registered = false;
-    v->suspended = false;
+    v->shared->suspended = false;
     return 0;
 }
 
@@ -1354,7 +1354,7 @@ static void vhost_vdpa_suspend(struct vhost_dev *dev)
         if (unlikely(r)) {
             error_report("Cannot suspend: %s(%d)", g_strerror(errno), errno);
         } else {
-            v->suspended = true;
+            v->shared->suspended = true;
             return;
         }
     }
@@ -1481,7 +1481,7 @@ static int vhost_vdpa_get_vring_base(struct vhost_dev *dev,
         return 0;
     }
 
-    if (!v->suspended) {
+    if (!v->shared->suspended) {
         /*
          * Cannot trust in value returned by device, let vhost recover used
          * idx from guest.
include/hw/virtio/vhost-vdpa.h +6 -2
index 449bf5c840..80ff670e23 100644
@@ -76,6 +76,12 @@ typedef struct vhost_vdpa_shared {
 
     /* SVQ switching is in progress, or already completed? */
     SVQTransitionState svq_switching;
+
+    /*
+     * Device suspended successfully.
+     * The vhost_vdpa devices cannot have different suspended states.
+     */
+    bool suspended;
 } VhostVDPAShared;
 
 typedef struct vhost_vdpa {
@@ -83,8 +89,6 @@ typedef struct vhost_vdpa {
     uint32_t address_space_id;
     uint64_t acked_features;
     bool shadow_vqs_enabled;
-    /* Device suspended successfully */
-    bool suspended;
     VhostVDPAShared *shared;
     GPtrArray *shadow_vqs;
     const VhostShadowVirtqueueOps *shadow_vq_ops;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 5 lines · Wafer Xie

When stopping a vhost-vdpa device, only the first queue pair is marked as suspended, while the remaining queues are not updated to the suspended state.
As a result, when stopping a multi-queue vhost-vdpa device,
the following error message will be printed.

Quoted 8 lines

qemu-system-x86_64:vhost VQ 2 ring restore failed: -1: Operation not permitted (1)

qemu-system-x86_64:vhost VQ 3 ring restore failed: -1: Operation not permitted (1)

So move v->suspended to v->shared, and then all the vhost_vdpa devices cannot have different suspended states.

Fixes 0bb302a9960a ("vdpa: add vhost_vdpa_suspend")

Is it a qemu-stable material? To me it feels like it is.

(for 10.0.x, it needed small context fix due to missing v10.0.0-1280-g494c50dcc099 "vdpa: move memory listener register to vhost_vdpa_init")

Please let me know if it isn't.

Thanks,

/mjt