thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
34b321
From 4d0430b1f847d672a39c76e6567bb5e88bc33c78 Mon Sep 17 00:00:00 2001
34b321
From: Stefan Hajnoczi <stefanha@redhat.com>
34b321
Date: Fri, 16 Sep 2016 08:38:18 +0200
34b321
Subject: [PATCH] virtio: recalculate vq->inuse after migration
34b321
34b321
RH-Author: Stefan Hajnoczi <stefanha@redhat.com>
34b321
Message-id: <1474015098-11019-2-git-send-email-stefanha@redhat.com>
34b321
Patchwork-id: 72372
34b321
O-Subject: [RHEL-7.3 qemu-kvm PATCH 1/1] virtio: recalculate vq->inuse after migration
34b321
Bugzilla: 1376542
34b321
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
34b321
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
34b321
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
34b321
34b321
The vq->inuse field is not migrated.  Many devices don't hold
34b321
VirtQueueElements across migration so it doesn't matter that vq->inuse
34b321
starts at 0 on the destination QEMU.
34b321
34b321
At least virtio-serial, virtio-blk, and virtio-balloon migrate while
34b321
holding VirtQueueElements.  For these devices we need to recalculate
34b321
vq->inuse upon load so the value is correct.
34b321
34b321
Cc: qemu-stable@nongnu.org
34b321
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
34b321
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
34b321
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
34b321
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
34b321
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
34b321
(cherry picked from commit bccdef6b1a204db0f41ffb6e24ce373e4d7890d4)
34b321
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
34b321
34b321
Conflicts:
34b321
34b321
  hw/virtio/virtio.c
34b321
34b321
  Downstream does not have the vq->used_idx field which was added
34b321
  upstream as a performance optimization reducing guest memory accesses.
34b321
  Replace vq->used_idx with vring_used_idx(&vdev->vq[i]).
34b321
34b321
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
34b321
---
34b321
 hw/virtio/virtio.c | 15 +++++++++++++++
34b321
 1 file changed, 15 insertions(+)
34b321
34b321
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
34b321
index e67337b..0df4ed3 100644
34b321
--- a/hw/virtio/virtio.c
34b321
+++ b/hw/virtio/virtio.c
34b321
@@ -932,6 +932,21 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
34b321
                              vdev->vq[i].last_avail_idx, nheads);
34b321
                 return -1;
34b321
             }
34b321
+
34b321
+            /*
34b321
+             * Some devices migrate VirtQueueElements that have been popped
34b321
+             * from the avail ring but not yet returned to the used ring.
34b321
+             */
34b321
+            vdev->vq[i].inuse = vdev->vq[i].last_avail_idx -
34b321
+                                vring_used_idx(&vdev->vq[i]);
34b321
+            if (vdev->vq[i].inuse > vdev->vq[i].vring.num) {
34b321
+                error_report("VQ %d size 0x%x < last_avail_idx 0x%x - "
34b321
+                             "used_idx 0x%x",
34b321
+                             i, vdev->vq[i].vring.num,
34b321
+                             vdev->vq[i].last_avail_idx,
34b321
+                             vring_used_idx(&vdev->vq[i]));
34b321
+                return -1;
34b321
+            }
34b321
         } else if (vdev->vq[i].last_avail_idx) {
34b321
             error_report("VQ %d address 0x0 "
34b321
                          "inconsistent with Host index 0x%x",
34b321
-- 
34b321
1.8.3.1
34b321