kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Liang Li <liang.z.li@intel.com>
To: qemu-devel@nongnu.org
Cc: mst@redhat.com, pbonzini@redhat.com, quintela@redhat.com,
	amit.shah@redhat.com, kvm@vger.kernel.org, dgilbert@redhat.com,
	thuth@redhat.com, Liang Li <liang.z.li@intel.com>
Subject: [QEMU v2 6/9] balloon: migrate vq elem to destination
Date: Fri, 15 Jul 2016 10:47:26 +0800	[thread overview]
Message-ID: <1468550849-22172-7-git-send-email-liang.z.li@intel.com> (raw)
In-Reply-To: <1468550849-22172-1-git-send-email-liang.z.li@intel.com>

After live migration, 'guest-stats' can't get the expected memory
status in the guest. This issue is caused by commit 4eae2a657d.
The value of 's->stats_vq_elem' will be NULL after live migration,
and the check in the function 'balloon_stats_poll_cb()' will
prevent the 'virtio_notify()' from executing. So guest will not
update the memory status.

Commit 4eae2a657d is doing the right thing, but 's->stats_vq_elem'
should be treated as part of balloon device state and migrated to
destination if it's not NULL to make everything works well.

For the same reason, 's->misc_vq_elem' should be migrated to
destination too.
Michael has other idea to solve this issue, but he is busy at the
moment, this patch can be used for test before his patch is ready.

Signed-off-by: Liang Li <liang.z.li@intel.com>
---
 hw/virtio/virtio-balloon.c | 36 ++++++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index b0c09a7..f9bf26d 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -31,6 +31,7 @@
 #include "hw/virtio/virtio-access.h"
 
 #define BALLOON_PAGE_SIZE  (1 << VIRTIO_BALLOON_PFN_SHIFT)
+#define BALLOON_VERSION 2
 
 static void balloon_page(void *addr, int deflate)
 {
@@ -610,15 +611,33 @@ static void virtio_balloon_save(QEMUFile *f, void *opaque)
 static void virtio_balloon_save_device(VirtIODevice *vdev, QEMUFile *f)
 {
     VirtIOBalloon *s = VIRTIO_BALLOON(vdev);
+    uint16_t elem_num = 0;
 
     qemu_put_be32(f, s->num_pages);
     qemu_put_be32(f, s->actual);
+    if (s->stats_vq_elem != NULL) {
+        elem_num = 1;
+    }
+    qemu_put_be16(f, elem_num);
+    if (elem_num) {
+        qemu_put_virtqueue_element(f, s->stats_vq_elem);
+    }
+
+    elem_num = 0;
+    if (s->misc_vq_elem != NULL) {
+        elem_num = 1;
+    }
+    qemu_put_be16(f, elem_num);
+    if (elem_num) {
+        qemu_put_virtqueue_element(f, s->misc_vq_elem);
+    }
 }
 
 static int virtio_balloon_load(QEMUFile *f, void *opaque, int version_id)
 {
-    if (version_id != 1)
+    if (version_id < 1 || version_id > BALLOON_VERSION) {
         return -EINVAL;
+    }
 
     return virtio_load(VIRTIO_DEVICE(opaque), f, version_id);
 }
@@ -627,9 +646,22 @@ static int virtio_balloon_load_device(VirtIODevice *vdev, QEMUFile *f,
                                       int version_id)
 {
     VirtIOBalloon *s = VIRTIO_BALLOON(vdev);
+    uint16_t elem_num = 0;
 
     s->num_pages = qemu_get_be32(f);
     s->actual = qemu_get_be32(f);
+    if (version_id == BALLOON_VERSION) {
+        elem_num = qemu_get_be16(f);
+        if (elem_num == 1) {
+            s->stats_vq_elem =
+                    qemu_get_virtqueue_element(f, sizeof(VirtQueueElement));
+        }
+        elem_num = qemu_get_be16(f);
+        if (elem_num == 1) {
+            s->misc_vq_elem =
+                    qemu_get_virtqueue_element(f, sizeof(VirtQueueElement));
+        }
+    }
 
     if (balloon_stats_enabled(s)) {
         balloon_stats_change_timer(s, s->stats_poll_interval);
@@ -665,7 +697,7 @@ static void virtio_balloon_device_realize(DeviceState *dev, Error **errp)
     reset_stats(s);
     s->req_status = REQ_INIT;
 
-    register_savevm(dev, "virtio-balloon", -1, 1,
+    register_savevm(dev, "virtio-balloon", -1, BALLOON_VERSION,
                     virtio_balloon_save, virtio_balloon_load, s);
 }
 
-- 
1.9.1


  parent reply	other threads:[~2016-07-15  2:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-15  2:47 [QEMU v2 0/9] Fast (de)inflating & fast live migration Liang Li
2016-07-15  2:47 ` [QEMU v2 1/9] virtio-balloon: Remove needless precompiled directive Liang Li
2016-08-01 10:42   ` Dr. David Alan Gilbert
2016-08-01 23:48     ` Li, Liang Z
2016-07-15  2:47 ` [QEMU v2 2/9] virtio-balloon: update linux head file Liang Li
2016-07-15  2:47 ` [QEMU v2 3/9] virtio-balloon: speed up inflating & deflating process Liang Li
2016-07-15  2:47 ` [QEMU v2 4/9] virtio-balloon: update linux head file for new feature Liang Li
2016-07-15  2:47 ` [QEMU v2 5/9] balloon: get free page info from guest Liang Li
2016-07-15  2:47 ` Liang Li [this message]
2016-07-15  2:47 ` [QEMU v2 7/9] bitmap: Add a new bitmap_move function Liang Li
2016-08-01 11:25   ` Dr. David Alan Gilbert
2016-07-15  2:47 ` [QEMU v2 8/9] kvm: Add two new arch specific functions Liang Li
2016-07-15  2:47 ` [QEMU v2 9/9] migration: skip free pages during live migration Liang Li
2016-07-21  8:10 ` [QEMU v2 0/9] Fast (de)inflating & fast " Li, Liang Z

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=1468550849-22172-7-git-send-email-liang.z.li@intel.com \
    --to=liang.z.li@intel.com \
    --cc=amit.shah@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=thuth@redhat.com \
    /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).