qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Anthony Liguori <aliguori@us.ibm.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	qemu-devel@nongnu.org, David Gibson <david@gibson.dropbear.id.au>
Subject: Re: [Qemu-devel] [PATCH 2/4] virtio: add wrapper for saving/restoring virtqueue elements
Date: Fri, 14 Dec 2012 12:46:52 +0100	[thread overview]
Message-ID: <50CB11AC.1070500@redhat.com> (raw)
In-Reply-To: <1355149790-8125-3-git-send-email-aliguori@us.ibm.com>

Il 10/12/2012 15:29, Anthony Liguori ha scritto:
> Putting raw structures on the wire is bad news.  Add a wrapper and use it.
> 
> Note that in virtio-serial-bus, we were mapping both the in and out vectors as
> writable.  This is a bug that is fixed by this change.  I checked the revision
> history, it has been there since the code was first added and does not appear
> to be intentional.
> 
> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
> ---
>  hw/virtio-blk.c        |  9 ++-------
>  hw/virtio-serial-bus.c | 10 ++--------
>  hw/virtio.c            | 13 +++++++++++++
>  hw/virtio.h            |  4 ++++
>  4 files changed, 21 insertions(+), 15 deletions(-)

virtio-scsi is missing; see virtio_scsi_load_request and
virtio_scsi_save_request.

Paolo

> diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
> index e25cc96..7ab174f 100644
> --- a/hw/virtio-blk.c
> +++ b/hw/virtio-blk.c
> @@ -555,7 +555,7 @@ static void virtio_blk_save(QEMUFile *f, void *opaque)
>      
>      while (req) {
>          qemu_put_sbyte(f, 1);
> -        qemu_put_buffer(f, (unsigned char*)&req->elem, sizeof(req->elem));
> +        virtio_put_virt_queue_element(f, &req->elem);
>          req = req->next;
>      }
>      qemu_put_sbyte(f, 0);
> @@ -576,14 +576,9 @@ static int virtio_blk_load(QEMUFile *f, void *opaque, int version_id)
>  
>      while (qemu_get_sbyte(f)) {
>          VirtIOBlockReq *req = virtio_blk_alloc_request(s);
> -        qemu_get_buffer(f, (unsigned char*)&req->elem, sizeof(req->elem));
> +        virtio_get_virt_queue_element(f, &req->elem);
>          req->next = s->rq;
>          s->rq = req;
> -
> -        virtqueue_map_sg(req->elem.in_sg, req->elem.in_addr,
> -            req->elem.in_num, 1);
> -        virtqueue_map_sg(req->elem.out_sg, req->elem.out_addr,
> -            req->elem.out_num, 0);
>      }
>  
>      return 0;
> diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
> index 155da58..aa1ded0 100644
> --- a/hw/virtio-serial-bus.c
> +++ b/hw/virtio-serial-bus.c
> @@ -629,8 +629,7 @@ static void virtio_serial_save(QEMUFile *f, void *opaque)
>              qemu_put_be32s(f, &port->iov_idx);
>              qemu_put_be64s(f, &port->iov_offset);
>  
> -            qemu_put_buffer(f, (unsigned char *)&port->elem,
> -                            sizeof(port->elem));
> +            virtio_put_virt_queue_element(f, &port->elem);
>          }
>      }
>  }
> @@ -731,12 +730,7 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)
>                  qemu_get_be32s(f, &port->iov_idx);
>                  qemu_get_be64s(f, &port->iov_offset);
>  
> -                qemu_get_buffer(f, (unsigned char *)&port->elem,
> -                                sizeof(port->elem));
> -                virtqueue_map_sg(port->elem.in_sg, port->elem.in_addr,
> -                                 port->elem.in_num, 1);
> -                virtqueue_map_sg(port->elem.out_sg, port->elem.out_addr,
> -                                 port->elem.out_num, 1);
> +                virtio_get_virt_queue_element(f, &port->elem);
>  
>                  /*
>                   *  Port was throttled on source machine.  Let's
> diff --git a/hw/virtio.c b/hw/virtio.c
> index f40a8c5..8eb8f69 100644
> --- a/hw/virtio.c
> +++ b/hw/virtio.c
> @@ -875,6 +875,19 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
>      return 0;
>  }
>  
> +void virtio_put_virt_queue_element(QEMUFile *f, const VirtQueueElement *elem)
> +{
> +    qemu_put_buffer(f, (unsigned char*)elem, sizeof(*elem));
> +}
> +
> +void virtio_get_virt_queue_element(QEMUFile *f, VirtQueueElement *elem)
> +{
> +    qemu_get_buffer(f, (unsigned char *)elem, sizeof(*elem));
> +
> +    virtqueue_map_sg(elem->in_sg, elem->in_addr, elem->in_num, 1);
> +    virtqueue_map_sg(elem->out_sg, elem->out_addr, elem->out_num, 0);
> +}
> +
>  void virtio_cleanup(VirtIODevice *vdev)
>  {
>      qemu_del_vm_change_state_handler(vdev->vmstate);
> diff --git a/hw/virtio.h b/hw/virtio.h
> index 7c17f7b..4af8239 100644
> --- a/hw/virtio.h
> +++ b/hw/virtio.h
> @@ -159,6 +159,10 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f);
>  
>  int virtio_load(VirtIODevice *vdev, QEMUFile *f);
>  
> +void virtio_put_virt_queue_element(QEMUFile *f, const VirtQueueElement *elem);
> +
> +void virtio_get_virt_queue_element(QEMUFile *f, VirtQueueElement *elem);
> +
>  void virtio_cleanup(VirtIODevice *vdev);
>  
>  void virtio_notify_config(VirtIODevice *vdev);
> 

  reply	other threads:[~2012-12-14 11:47 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-10 14:29 [Qemu-devel] [RFC 0/4] virtio: stabilize migration format Anthony Liguori
2012-12-10 14:29 ` [Qemu-devel] [PATCH 1/4] savevm: introduce little endian variants of savevm routines Anthony Liguori
2012-12-10 14:33   ` Peter Maydell
2012-12-10 15:24     ` Anthony Liguori
2012-12-10 14:29 ` [Qemu-devel] [PATCH 2/4] virtio: add wrapper for saving/restoring virtqueue elements Anthony Liguori
2012-12-14 11:46   ` Paolo Bonzini [this message]
2012-12-14 13:54     ` Anthony Liguori
2012-12-10 14:29 ` [Qemu-devel] [PATCH 3/4] virtio: modify savevm to have a stable wire format Anthony Liguori
2012-12-11  0:32   ` Rusty Russell
2012-12-11  0:54     ` Anthony Liguori
2012-12-14  0:57       ` Rusty Russell
2012-12-14 11:50         ` Paolo Bonzini
2012-12-14 13:59           ` Anthony Liguori
2012-12-10 14:29 ` [Qemu-devel] [PATCH 4/4] virtio: bump migration version number Anthony Liguori
2012-12-11  9:02 ` [Qemu-devel] [RFC 0/4] virtio: stabilize migration format Stefan Hajnoczi

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=50CB11AC.1070500@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rusty@rustcorp.com.au \
    /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).