From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36675) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZN0Al-0008As-ME for qemu-devel@nongnu.org; Wed, 05 Aug 2015 11:00:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZN0Af-0007Ib-T6 for qemu-devel@nongnu.org; Wed, 05 Aug 2015 11:00:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39439) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZN0Af-0007IN-L7 for qemu-devel@nongnu.org; Wed, 05 Aug 2015 10:59:57 -0400 Date: Wed, 5 Aug 2015 17:59:54 +0300 From: "Michael S. Tsirkin" Message-ID: <1438786731-5199-2-git-send-email-mst@redhat.com> References: <1438786731-5199-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1438786731-5199-1-git-send-email-mst@redhat.com> Subject: [Qemu-devel] [PULL 1/1] virtio: fix 1.0 virtqueue migration List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Cornelia Huck , Peter Maydell , Jason Wang , "Dr. David Alan Gilbert" From: Jason Wang 1.0 does not requires physically-contiguous pages layout for a virtqueue. So we could not infer avail and used from desc. This means we need to migrate vring.avail and vring.used when host support virtio 1.0. This fixes malfunction of virtio 1.0 device after migration. Cc: Michael S. Tsirkin Cc: Cornelia Huck Cc: Dr. David Alan Gilbert Signed-off-by: Jason Wang Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/virtio.h | 6 +++++ hw/virtio/virtio.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 59f0763..cccae89 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -272,6 +272,12 @@ static inline bool virtio_has_feature(VirtIODevice *vdev, unsigned int fbit) return __virtio_has_feature(vdev->guest_features, fbit); } +static inline bool virtio_host_has_feature(VirtIODevice *vdev, + unsigned int fbit) +{ + return __virtio_has_feature(vdev->host_features, fbit); +} + static inline bool virtio_is_big_endian(VirtIODevice *vdev) { if (!virtio_has_feature(vdev, VIRTIO_F_VERSION_1)) { diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index ee4e07c..788b556 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1049,6 +1049,61 @@ static bool virtio_64bit_features_needed(void *opaque) return (vdev->host_features >> 32) != 0; } +static bool virtio_virtqueue_needed(void *opaque) +{ + VirtIODevice *vdev = opaque; + + return virtio_host_has_feature(vdev, VIRTIO_F_VERSION_1); +} + +static void put_virtqueue_state(QEMUFile *f, void *pv, size_t size) +{ + VirtIODevice *vdev = pv; + int i; + + for (i = 0; i < VIRTIO_QUEUE_MAX; i++) { + qemu_put_be64(f, vdev->vq[i].vring.avail); + qemu_put_be64(f, vdev->vq[i].vring.used); + } +} + +static int get_virtqueue_state(QEMUFile *f, void *pv, size_t size) +{ + VirtIODevice *vdev = pv; + int i; + + for (i = 0; i < VIRTIO_QUEUE_MAX; i++) { + vdev->vq[i].vring.avail = qemu_get_be64(f); + vdev->vq[i].vring.used = qemu_get_be64(f); + } + return 0; +} + +static VMStateInfo vmstate_info_virtqueue = { + .name = "virtqueue_state", + .get = get_virtqueue_state, + .put = put_virtqueue_state, +}; + +static const VMStateDescription vmstate_virtio_virtqueues = { + .name = "virtio/virtqueues", + .version_id = 1, + .minimum_version_id = 1, + .needed = &virtio_virtqueue_needed, + .fields = (VMStateField[]) { + { + .name = "virtqueues", + .version_id = 0, + .field_exists = NULL, + .size = 0, + .info = &vmstate_info_virtqueue, + .flags = VMS_SINGLE, + .offset = 0, + }, + VMSTATE_END_OF_LIST() + } +}; + static const VMStateDescription vmstate_virtio_device_endian = { .name = "virtio/device_endian", .version_id = 1, @@ -1082,6 +1137,7 @@ static const VMStateDescription vmstate_virtio = { .subsections = (const VMStateDescription*[]) { &vmstate_virtio_device_endian, &vmstate_virtio_64bit_features, + &vmstate_virtio_virtqueues, NULL } }; -- MST