From: "Michael S. Tsirkin" <mst@redhat.com>
To: Ladi Prosek <lprosek@redhat.com>
Cc: qemu-devel@nongnu.org, liang.z.li@intel.com, pbonzini@redhat.com,
dgilbert@redhat.com
Subject: Re: [Qemu-devel] [PATCH v3] balloon: Fix failure of updating guest memory status
Date: Mon, 15 Aug 2016 16:39:30 +0300 [thread overview]
Message-ID: <20160815163239-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <1470396992-14564-1-git-send-email-lprosek@redhat.com>
On Fri, Aug 05, 2016 at 01:36:32PM +0200, Ladi Prosek wrote:
> The stats_vq_elem field keeps track of the state of the balloon stats
> virtqueue protocol but it wasn't preserved across migrations, resulting
> in losing guest memory status updates on the receiving VM.
>
> This commit adds a new VM state change handler which resets stats_vq_elem
> to NULL when the VM is stopped, eliminating the need for the field to be
> migrated. When the VM starts running again, the field is reinitialized by
> re-popping the element from the virtqueue.
>
> Signed-off-by: Ladi Prosek <lprosek@redhat.com>
> Suggested-by: Michael S. Tsirkin <mst@redhat.com>
Almost there. Except we should not touch rings
unless guest set DRIVER_OK in status register, and we should
not touch status vq at all unless VIRTIO_BALLOON_F_STATS_VQ
has been negotiated.
I'll post a patch to do this.
> ---
> hw/virtio/virtio-balloon.c | 23 +++++++++++++++++++++++
> include/hw/virtio/virtio-balloon.h | 1 +
> 2 files changed, 24 insertions(+)
>
> diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
> index 5af429a..65457e9 100644
> --- a/hw/virtio/virtio-balloon.c
> +++ b/hw/virtio/virtio-balloon.c
> @@ -423,6 +423,26 @@ static int virtio_balloon_load_device(VirtIODevice *vdev, QEMUFile *f,
> return 0;
> }
>
> +static void virtio_balloon_vmstate_cb(void *opaque, int running,
> + RunState state)
> +{
> + VirtIOBalloon *s = opaque;
> +
> + if (!running) {
> + /* put the stats element back if the VM is not running */
> + if (s->stats_vq_elem != NULL) {
> + virtqueue_discard(s->svq, s->stats_vq_elem, s->stats_vq_offset);
> + g_free(s->stats_vq_elem);
> + s->stats_vq_elem = NULL;
> + }
> +
> + } else {
> + /* poll stats queue for the element we may have discarded
> + * when the VM was stopped */
> + virtio_balloon_receive_stats(VIRTIO_DEVICE(s), s->svq);
> + }
> +}
> +
> static void virtio_balloon_device_realize(DeviceState *dev, Error **errp)
> {
> VirtIODevice *vdev = VIRTIO_DEVICE(dev);
> @@ -446,6 +466,8 @@ static void virtio_balloon_device_realize(DeviceState *dev, Error **errp)
> s->svq = virtio_add_queue(vdev, 128, virtio_balloon_receive_stats);
>
> reset_stats(s);
> +
> + s->change = qemu_add_vm_change_state_handler(virtio_balloon_vmstate_cb, s);
> }
>
> static void virtio_balloon_device_unrealize(DeviceState *dev, Error **errp)
> @@ -453,6 +475,7 @@ static void virtio_balloon_device_unrealize(DeviceState *dev, Error **errp)
> VirtIODevice *vdev = VIRTIO_DEVICE(dev);
> VirtIOBalloon *s = VIRTIO_BALLOON(dev);
>
> + qemu_del_vm_change_state_handler(s->change);
> balloon_stats_destroy_timer(s);
> qemu_remove_balloon_handler(s);
> virtio_cleanup(vdev);
> diff --git a/include/hw/virtio/virtio-balloon.h b/include/hw/virtio/virtio-balloon.h
> index 1ea13bd..d72ff7f 100644
> --- a/include/hw/virtio/virtio-balloon.h
> +++ b/include/hw/virtio/virtio-balloon.h
> @@ -43,6 +43,7 @@ typedef struct VirtIOBalloon {
> int64_t stats_last_update;
> int64_t stats_poll_interval;
> uint32_t host_features;
> + VMChangeStateEntry *change;
> } VirtIOBalloon;
>
> #endif
> --
> 2.5.5
next prev parent reply other threads:[~2016-08-15 13:39 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-05 11:36 [Qemu-devel] [PATCH v3] balloon: Fix failure of updating guest memory status Ladi Prosek
2016-08-15 12:09 ` Stefan Hajnoczi
2016-08-15 12:35 ` Ladi Prosek
2016-08-15 12:50 ` Stefan Hajnoczi
2016-08-15 12:56 ` Ladi Prosek
2016-08-15 13:39 ` Michael S. Tsirkin [this message]
2016-08-15 23:08 ` Michael S. Tsirkin
2016-08-22 2:00 ` Michael S. Tsirkin
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=20160815163239-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=dgilbert@redhat.com \
--cc=liang.z.li@intel.com \
--cc=lprosek@redhat.com \
--cc=pbonzini@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.