Skip to contentSkip to conversation

virtio: add check for inconsistent VQ in virtio_save()

PATCH New Yi Wang 1 participant 1 message Oct 30, 2019

lore
Share & tools
lore

Yi Wang

author
#0 lore raw

PATCH 1/1 virtio: add check for inconsistent VQ in virtio_save()

From: Cheng Lin <[email protected]>

In a case, we have an not enabled VQ (virtio-net) which desc is NULL and get a last_avail_idx is not 0 from dpdk.

As a result, it is successed to create a snapshot, but failed to revert it. Because in virtio_load(), there is an inconsistent check for VQ. (call virtio_load() in revert, and virtio_save() in create.)

Correspondly, in virtio_save() should also do this check to find the error as early as possible.

---
 hw/virtio/virtio.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/virtio/virtio.c +6 -0
index 2e91dec..eadbf64 100644
@@ -2792,6 +2792,12 @@ int virtio_save(VirtIODevice *vdev, QEMUFile *f)
          * Save desc now, the rest of the ring addresses are saved in
          * subsections for VIRTIO-1 devices.
          */
+        if (!vdev->vq[i].vring.desc && vdev->vq[i].last_avail_idx) {
+            error_report("VQ %d address 0x0 "
+                         "inconsistent with Host index 0x%x",
+                         i, vdev->vq[i].last_avail_idx);
+            return -1;
+        }
         qemu_put_be64(f, vdev->vq[i].vring.desc);
         qemu_put_be16s(f, &vdev->vq[i].last_avail_idx);
         if (k->save_queue) {
Signature · 1 line
2.7.2.windows.1