qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH for 2.4 V2] virtio: fix 1.0 virtqueue migration
@ 2015-08-05  9:50 Jason Wang
  2015-08-05 13:58 ` Michael S. Tsirkin
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Wang @ 2015-08-05  9:50 UTC (permalink / raw)
  To: mst, qemu-devel; +Cc: Cornelia Huck, Jason Wang, Dr. David Alan Gilbert

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 <mst@redhat.com>
Cc: Cornelia Huck <cornelia.huck@de.ibm.com>
Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
- Changes from V1: switch to use subsection to make debug easier
---
 hw/virtio/virtio.c         | 56 ++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/virtio/virtio.h |  6 +++++
 2 files changed, 62 insertions(+)

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
     }
 };
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)) {
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH for 2.4 V2] virtio: fix 1.0 virtqueue migration
  2015-08-05  9:50 [Qemu-devel] [PATCH for 2.4 V2] virtio: fix 1.0 virtqueue migration Jason Wang
@ 2015-08-05 13:58 ` Michael S. Tsirkin
  2015-08-05 14:43   ` Peter Maydell
  0 siblings, 1 reply; 3+ messages in thread
From: Michael S. Tsirkin @ 2015-08-05 13:58 UTC (permalink / raw)
  To: Jason Wang; +Cc: Cornelia Huck, qemu-devel, Dr. David Alan Gilbert

On Wed, Aug 05, 2015 at 05:50:07PM +0800, Jason Wang wrote:
> 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 <mst@redhat.com>
> Cc: Cornelia Huck <cornelia.huck@de.ibm.com>
> Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
> Signed-off-by: Jason Wang <jasowang@redhat.com>

Acked-by: Michael S. Tsirkin <mst@redhat.com>

> ---
> - Changes from V1: switch to use subsection to make debug easier
> ---
>  hw/virtio/virtio.c         | 56 ++++++++++++++++++++++++++++++++++++++++++++++
>  include/hw/virtio/virtio.h |  6 +++++
>  2 files changed, 62 insertions(+)
> 
> 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
>      }
>  };
> 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)) {
> -- 
> 2.1.4

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH for 2.4 V2] virtio: fix 1.0 virtqueue migration
  2015-08-05 13:58 ` Michael S. Tsirkin
@ 2015-08-05 14:43   ` Peter Maydell
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Maydell @ 2015-08-05 14:43 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: Cornelia Huck, Jason Wang, QEMU Developers,
	Dr. David Alan Gilbert

On 5 August 2015 at 14:58, Michael S. Tsirkin <mst@redhat.com> wrote:
> On Wed, Aug 05, 2015 at 05:50:07PM +0800, Jason Wang wrote:
>> 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 <mst@redhat.com>
>> Cc: Cornelia Huck <cornelia.huck@de.ibm.com>
>> Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
>> Signed-off-by: Jason Wang <jasowang@redhat.com>
>
> Acked-by: Michael S. Tsirkin <mst@redhat.com>

My current plan is to apply this to master, tag another
rc for 2.4, and then take no further patches for 2.4
unless they fix utterly critical bugs...

thanks
-- PMM

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-08-05 14:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-05  9:50 [Qemu-devel] [PATCH for 2.4 V2] virtio: fix 1.0 virtqueue migration Jason Wang
2015-08-05 13:58 ` Michael S. Tsirkin
2015-08-05 14:43   ` Peter Maydell

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).