From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
Cornelia Huck <cornelia.huck@de.ibm.com>,
Fam Zheng <famz@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Subject: [Qemu-devel] [PATCH 1/2] virtio: recalculate vq->inuse after migration
Date: Mon, 15 Aug 2016 13:54:15 +0100 [thread overview]
Message-ID: <1471265656-11227-2-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1471265656-11227-1-git-send-email-stefanha@redhat.com>
The vq->inuse field is not migrated. Many devices don't hold
VirtQueueElements across migration so it doesn't matter that vq->inuse
starts at 0 on the destination QEMU.
At least virtio-serial, virtio-blk, and virtio-balloon migrate while
holding VirtQueueElements. For these devices we need to recalculate
vq->inuse upon load so the value is correct.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
hw/virtio/virtio.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 15ee3a7..6105c6e 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -1648,6 +1648,21 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
}
vdev->vq[i].used_idx = vring_used_idx(&vdev->vq[i]);
vdev->vq[i].shadow_avail_idx = vring_avail_idx(&vdev->vq[i]);
+
+ /*
+ * Some devices migrate VirtQueueElements that have been popped
+ * from the avail ring but not yet returned to the used ring.
+ */
+ vdev->vq[i].inuse = vdev->vq[i].last_avail_idx -
+ vdev->vq[i].used_idx;
+ if (vdev->vq[i].inuse > vdev->vq[i].vring.num) {
+ error_report("VQ %d size 0x%x < last_avail_idx 0x%x - "
+ "used_idx 0x%x",
+ i, vdev->vq[i].vring.num,
+ vdev->vq[i].last_avail_idx,
+ vdev->vq[i].used_idx);
+ return -1;
+ }
}
}
--
2.7.4
next prev parent reply other threads:[~2016-08-15 12:54 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-15 12:54 [Qemu-devel] [PATCH 0/2] virtio: fix VirtQueue->inuse field Stefan Hajnoczi
2016-08-15 12:54 ` Stefan Hajnoczi [this message]
2016-08-15 12:54 ` [Qemu-devel] [PATCH 2/2] virtio: decrement vq->inuse in virtqueue_discard() Stefan Hajnoczi
2016-08-17 13:58 ` [Qemu-devel] [PATCH 0/2] virtio: fix VirtQueue->inuse field Stefan Hajnoczi
2016-08-23 6:49 ` [Qemu-devel] [Qemu-stable] " Peter Lieven
2016-08-23 15:57 ` Stefan Hajnoczi
2016-08-22 14:00 ` [Qemu-devel] " Denis V. Lunev
2016-08-22 18:23 ` Denis V. Lunev
2016-08-30 19:54 ` Stefan Hajnoczi
2016-08-30 20:02 ` Denis V. Lunev
2016-08-31 9:25 ` Roman Kagan
2016-08-31 17:06 ` Denis V. Lunev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1471265656-11227-2-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=cornelia.huck@de.ibm.com \
--cc=famz@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).