Skip to contentSkip to conversation

balloon: Fix failure of updating guest memory status

PATCH In review Liang Li 3 participants 13 messages Jul 6, 2016 – Aug 8, 2016

lore
Share & tools
lore

Liang Li

author
#0 lore raw

PATCH v2 1/1 balloon: Fix failure of updating guest memory status

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.

Cc Michael S. Tsirkin <[email protected]>
Cc Ladi Prosek <[email protected]>
Cc Paolo Bonzini <[email protected]>
---
 hw/virtio/virtio-balloon.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
hw/virtio/virtio-balloon.c +20 -2
index 557d3f9..64e80c6 100644
@@ -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)
 {
@@ -404,15 +405,24 @@ 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);
+    }
 }
 
 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);
 }
@@ -421,9 +431,17 @@ 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));
+        }
+    }
 
     if (balloon_stats_enabled(s)) {
         balloon_stats_change_timer(s, s->stats_poll_interval);
@@ -455,7 +473,7 @@ static void virtio_balloon_device_realize(DeviceState *dev, Error **errp)
 
     reset_stats(s);
 
-    register_savevm(dev, "virtio-balloon", -1, 1,
+    register_savevm(dev, "virtio-balloon", -1, BALLOON_VERSION,
                     virtio_balloon_save, virtio_balloon_load, s);
 }
 
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 11 lines · Liang Li

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.

Quoted 5 lines
Cc Michael S. Tsirkin <[email protected]>
Cc Ladi Prosek <[email protected]>
Cc Paolo Bonzini <[email protected]>

I agree there's an issue but we don't change versions anymore. Breaking migrations for everyone is also not nice.

How about queueing virtio_balloon_receive_stats
so it will get invoked when vm starts?

Quoted 71 lines
---
 hw/virtio/virtio-balloon.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
hw/virtio/virtio-balloon.c +20 -2
index 557d3f9..64e80c6 100644
@@ -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)
 {
@@ -404,15 +405,24 @@ 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);
+    }
 }
 
 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);
 }
@@ -421,9 +431,17 @@ 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));
+        }
+    }
 
     if (balloon_stats_enabled(s)) {
         balloon_stats_change_timer(s, s->stats_poll_interval);
@@ -455,7 +473,7 @@ static void virtio_balloon_device_realize(DeviceState *dev, Error **errp)
 
     reset_stats(s);
 
-    register_savevm(dev, "virtio-balloon", -1, 1,
+    register_savevm(dev, "virtio-balloon", -1, BALLOON_VERSION,
                     virtio_balloon_save, virtio_balloon_load, s);
 }
 
Signature · 1 line
1.8.3.1
#2 lore raw
Quoted 18 lines · Liang Li
Quoted 11 lines

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.

Quoted 5 lines
Cc Michael S. Tsirkin <[email protected]>
Cc Ladi Prosek <[email protected]>
Cc Paolo Bonzini <[email protected]>
Quoted 6 lines

I agree there's an issue but we don't change versions anymore. Breaking migrations for everyone is also not nice.

How about queueing virtio_balloon_receive_stats so it will get invoked when vm starts?

Could you give more explanation about how it works? I can't catch you.

Thanks!
Liang

#3 lore raw
Quoted 21 lines · Liang Z
Quoted 21 lines · Liang Li
Quoted 11 lines

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.

Quoted 5 lines
Cc Michael S. Tsirkin <[email protected]>
Cc Ladi Prosek <[email protected]>
Cc Paolo Bonzini <[email protected]>

I agree there's an issue but we don't change versions anymore. Breaking migrations for everyone is also not nice.

Quoted 8 lines
Quoted 3 lines

How about queueing virtio_balloon_receive_stats so it will get invoked when vm starts?

Could you give more explanation about how it works? I can't catch you.

Thanks!
Liang

virtqueue_discard before migration

virtio_balloon_receive_stats after migration

Signature · 1 line
MST
#4 lore raw
Quoted 24 lines
Quoted 24 lines
Quoted 23 lines
Quoted 11 lines

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.

Quoted 5 lines
Cc Michael S. Tsirkin <[email protected]>
Cc Ladi Prosek <[email protected]>
Cc Paolo Bonzini <[email protected]>

I agree there's an issue but we don't change versions anymore. Breaking migrations for everyone is also not nice.

How about queueing virtio_balloon_receive_stats so it will get invoked when vm starts?

Quoted 9 lines
Quoted 4 lines

Could you give more explanation about how it works? I can't catch you.

Thanks!
Liang

virtqueue_discard before migration

virtio_balloon_receive_stats after migration

Sorry, I still can't catch you. Maybe it's easier for you to submit a patch than writing a lot a words to make me understand your idea.

I just don't understand why not to use the version to make things easier, is that not the original intent of version id?
If we want to extend the device and more states are needed, the idea you suggest can be used as a common solution?

Thanks!
Liang

Quoted 2 lines

--
MST

#5 lore raw
Quoted 29 lines · Liang Z
Quoted 29 lines
Quoted 28 lines
Quoted 17 lines
Quoted 11 lines

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.

Quoted 5 lines
Cc Michael S. Tsirkin <[email protected]>
Cc Ladi Prosek <[email protected]>
Cc Paolo Bonzini <[email protected]>
Quoted 6 lines

I agree there's an issue but we don't change versions anymore. Breaking migrations for everyone is also not nice.

How about queueing virtio_balloon_receive_stats so it will get invoked when vm starts?

Could you give more explanation about how it works? I can't catch you.

Thanks!
Liang

Quoted 7 lines
Quoted 4 lines

virtqueue_discard before migration

virtio_balloon_receive_stats after migration

Sorry, I still can't catch you. Maybe it's easier for you to submit a patch than writing a lot a words to make me understand your idea.

I'm rather busy now. I might look into it towards end of the month.

Quoted 2 lines

I just don't understand why not to use the version to make things easier, is that not the original intent of version id?

This was the original idea but we stopped using version ids since they have many shortcomings.

Quoted 5 lines

If we want to extend the device and more states are needed, the idea you suggest can be used as a common solution?

Thanks!
Liang

The idea is to try to avoid adding more state. that's not always possible but in this case element was seen but not consumed yet, so it should be possible for destination to simply get it from the VQ again.

Quoted 2 lines
Quoted 2 lines

--
MST

#6 lore raw
Quoted 50 lines · Liang Z
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

After live migration, 'guest-stats' can't get the expected memory status in the guest. This issue is caused by commit

4eae2a657d.

Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 15 lines
Quoted 9 lines

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.

Quoted 5 lines
Cc Michael S. Tsirkin <[email protected]>
Cc Ladi Prosek <[email protected]>
Cc Paolo Bonzini <[email protected]>
Quoted 6 lines

I agree there's an issue but we don't change versions anymore. Breaking migrations for everyone is also not nice.

How about queueing virtio_balloon_receive_stats so it will get invoked when vm starts?

Could you give more explanation about how it works? I can't catch you.

Thanks!
Liang

Quoted 7 lines
Quoted 4 lines

virtqueue_discard before migration

virtio_balloon_receive_stats after migration

Sorry, I still can't catch you. Maybe it's easier for you to submit a patch than writing a lot a words to make me understand your idea.

I'm rather busy now. I might look into it towards end of the month.

Quoted 2 lines

I just don't understand why not to use the version to make things easier, is that not the original intent of version id?

This was the original idea but we stopped using version ids since they have many shortcomings.

Quoted 3 lines

If we want to extend the device and more states are needed, the idea you suggest can be used as a common solution?

Quoted 9 lines
Quoted 2 lines

Thanks!
Liang

The idea is to try to avoid adding more state. that's not always possible but in this case element was seen but not consumed yet, so it should be possible for destination to simply get it from the VQ again.

Quoted 2 lines
Quoted 2 lines

--
MST

Hi Michel,

Do you have time for this issue recently?

Thanks!
Liang

#7 lore raw
Quoted 60 lines · Liang Z
Quoted 50 lines · Liang Z
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

After live migration, 'guest-stats' can't get the expected memory status in the guest. This issue is caused by commit

4eae2a657d.

Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 15 lines
Quoted 9 lines

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.

Quoted 5 lines
Cc Michael S. Tsirkin <[email protected]>
Cc Ladi Prosek <[email protected]>
Cc Paolo Bonzini <[email protected]>
Quoted 6 lines

I agree there's an issue but we don't change versions anymore. Breaking migrations for everyone is also not nice.

How about queueing virtio_balloon_receive_stats so it will get invoked when vm starts?

Could you give more explanation about how it works? I can't catch you.

Thanks!
Liang

Quoted 7 lines
Quoted 4 lines

virtqueue_discard before migration

virtio_balloon_receive_stats after migration

Sorry, I still can't catch you. Maybe it's easier for you to submit a patch than writing a lot a words to make me understand your idea.

I'm rather busy now. I might look into it towards end of the month.

Quoted 2 lines

I just don't understand why not to use the version to make things easier, is that not the original intent of version id?

This was the original idea but we stopped using version ids since they have many shortcomings.

Quoted 3 lines

If we want to extend the device and more states are needed, the idea you suggest can be used as a common solution?

Quoted 9 lines
Quoted 2 lines

Thanks!
Liang

The idea is to try to avoid adding more state. that's not always possible but in this case element was seen but not consumed yet, so it should be possible for destination to simply get it from the VQ again.

Quoted 2 lines
Quoted 2 lines

--
MST

Quoted 6 lines

Hi Michel,

Do you have time for this issue recently?

Thanks!
Liang

Sorry, doesn't look like I will.
Idea is to make sure balloon_stats_poll_cb runs
on source. This will set stats_vq_elem to NULL.

Signature · 1 line
MST
#8 lore raw
Quoted 61 lines · Michael S. Tsirkin
Quoted 60 lines · Liang Z
Quoted 59 lines · Liang Z
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

After live migration, 'guest-stats' can't get the expected memory status in the guest. This issue is caused by commit

4eae2a657d.

Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 15 lines
Quoted 9 lines

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.

Quoted 5 lines
Cc Michael S. Tsirkin <[email protected]>
Cc Ladi Prosek <[email protected]>
Cc Paolo Bonzini <[email protected]>
Quoted 6 lines

I agree there's an issue but we don't change versions anymore. Breaking migrations for everyone is also not nice.

How about queueing virtio_balloon_receive_stats so it will get invoked when vm starts?

Could you give more explanation about how it works? I can't catch you.

Thanks!
Liang

Quoted 7 lines
Quoted 4 lines

virtqueue_discard before migration

virtio_balloon_receive_stats after migration

Sorry, I still can't catch you. Maybe it's easier for you to submit a patch than writing a lot a words to make me understand your idea.

I'm rather busy now. I might look into it towards end of the month.

Quoted 2 lines

I just don't understand why not to use the version to make things easier, is that not the original intent of version id?

This was the original idea but we stopped using version ids since they have many shortcomings.

Quoted 5 lines

If we want to extend the device and more states are needed, the idea you suggest can be used as a common solution?

Thanks!
Liang

The idea is to try to avoid adding more state. that's not always possible but in this case element was seen but not consumed yet, so it should be possible for destination to simply get it from the VQ again.

Quoted 2 lines
Quoted 2 lines

--
MST

Quoted 6 lines
Quoted 6 lines

Hi Michel,

Do you have time for this issue recently?

Thanks!
Liang

Hi Liang,

I should be able to look into it this week if you help me with testing.

Thanks,
Ladi

Quoted 7 lines

Sorry, doesn't look like I will.
Idea is to make sure balloon_stats_poll_cb runs
on source. This will set stats_vq_elem to NULL.

--
MST

#9 lore raw
Quoted 69 lines · Ladi Prosek
Quoted 61 lines · Michael S. Tsirkin
Quoted 60 lines · Liang Z
Quoted 59 lines · Liang Z
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

After live migration, 'guest-stats' can't get the expected memory status in the guest. This issue is caused by commit

4eae2a657d.

Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 15 lines
Quoted 9 lines

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.

Quoted 5 lines
Cc Michael S. Tsirkin <[email protected]>
Cc Ladi Prosek <[email protected]>
Cc Paolo Bonzini <[email protected]>
Quoted 6 lines

I agree there's an issue but we don't change versions anymore. Breaking migrations for everyone is also not nice.

How about queueing virtio_balloon_receive_stats so it will get invoked when vm starts?

Could you give more explanation about how it works? I can't catch you.

Thanks!
Liang

Quoted 7 lines
Quoted 4 lines

virtqueue_discard before migration

virtio_balloon_receive_stats after migration

Sorry, I still can't catch you. Maybe it's easier for you to submit a patch than writing a lot a words to make me understand your idea.

I'm rather busy now. I might look into it towards end of the month.

Quoted 2 lines

I just don't understand why not to use the version to make things easier, is that not the original intent of version id?

This was the original idea but we stopped using version ids since they have many shortcomings.

Quoted 5 lines

If we want to extend the device and more states are needed, the idea you suggest can be used as a common solution?

Thanks!
Liang

The idea is to try to avoid adding more state. that's not always possible but in this case element was seen but not consumed yet, so it should be possible for destination to simply get it from the VQ again.

Quoted 2 lines
Quoted 2 lines

--
MST

Quoted 6 lines
Quoted 6 lines

Hi Michel,

Do you have time for this issue recently?

Thanks!
Liang

Quoted 6 lines

Hi Liang,

I should be able to look into it this week if you help me with testing.

Thanks,
Ladi

Please try the attached patch. I have tested it with a simple 'migrate' to save the state and then '-incoming' to load it back.

One question for you: is it expected that stats_poll_interval is not preserved by save/load? I had to explicitly set guest-stats-polling-interval on the receiving VM to start getting stats again. It's also the reason why the new virtio_balloon_receive_stats call is not under if (balloon_stats_enabled(s)) because this condition always evaluates to false for me.

Thanks!
Ladi

Quoted 7 lines
Quoted 7 lines

Sorry, doesn't look like I will.
Idea is to make sure balloon_stats_poll_cb runs
on source. This will set stats_vq_elem to NULL.

--
MST

From f2f779e12f4aa4d3469d1b44e54484e66f82a2d7 Mon Sep 17 00:00:00 2001
From: Ladi Prosek <[email protected]>
Date: Thu, 4 Aug 2016 15:22:05 +0200
Subject: [PATCH] balloon: preserve stats virtqueue state across migrations

---
 hw/virtio/virtio-balloon.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
hw/virtio/virtio-balloon.c +17 -1
index 5af429a..1293be0 100644
@@ -396,6 +396,19 @@ static void virtio_balloon_to_target(void *opaque, ram_addr_t target)
     trace_virtio_balloon_to_target(target, dev->num_pages);
 }
 
+static void virtio_balloon_save(QEMUFile *f, void *opaque, size_t size)
+{
+    VirtIOBalloon *s = VIRTIO_BALLOON(opaque);
+
+    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;
+    }
+
+    virtio_save(VIRTIO_DEVICE(opaque), f);
+}
+
 static void virtio_balloon_save_device(VirtIODevice *vdev, QEMUFile *f)
 {
     VirtIOBalloon *s = VIRTIO_BALLOON(vdev);
@@ -417,6 +430,9 @@ static int virtio_balloon_load_device(VirtIODevice *vdev, QEMUFile *f,
     s->num_pages = qemu_get_be32(f);
     s->actual = qemu_get_be32(f);
 
+    /* poll the queue for the element we may have discarded on save */
+    virtio_balloon_receive_stats(VIRTIO_DEVICE(s), s->svq);
+
     if (balloon_stats_enabled(s)) {
         balloon_stats_change_timer(s, s->stats_poll_interval);
     }
@@ -481,7 +497,7 @@ static void virtio_balloon_instance_init(Object *obj)
                         NULL, s, NULL);
 }
 
-VMSTATE_VIRTIO_DEVICE(balloon, 1, virtio_balloon_load, virtio_vmstate_save);
+VMSTATE_VIRTIO_DEVICE(balloon, 1, virtio_balloon_load, virtio_balloon_save);
 
 static Property virtio_balloon_properties[] = {
     DEFINE_PROP_BIT("deflate-on-oom", VirtIOBalloon, host_features,
Signature · 1 line
2.5.5
#10 lore raw
Quoted 144 lines · Ladi Prosek
Quoted 69 lines · Ladi Prosek
Quoted 61 lines · Michael S. Tsirkin
Quoted 60 lines · Liang Z
Quoted 59 lines · Liang Z
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

After live migration, 'guest-stats' can't get the expected memory status in the guest. This issue is caused by commit

4eae2a657d.

Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 15 lines
Quoted 9 lines

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.

Quoted 5 lines
Cc Michael S. Tsirkin <[email protected]>
Cc Ladi Prosek <[email protected]>
Cc Paolo Bonzini <[email protected]>
Quoted 6 lines

I agree there's an issue but we don't change versions anymore. Breaking migrations for everyone is also not nice.

How about queueing virtio_balloon_receive_stats so it will get invoked when vm starts?

Could you give more explanation about how it works? I can't catch you.

Thanks!
Liang

Quoted 7 lines
Quoted 4 lines

virtqueue_discard before migration

virtio_balloon_receive_stats after migration

Sorry, I still can't catch you. Maybe it's easier for you to submit a patch than writing a lot a words to make me understand your idea.

I'm rather busy now. I might look into it towards end of the month.

Quoted 2 lines

I just don't understand why not to use the version to make things easier, is that not the original intent of version id?

This was the original idea but we stopped using version ids since they have many shortcomings.

Quoted 5 lines

If we want to extend the device and more states are needed, the idea you suggest can be used as a common solution?

Thanks!
Liang

The idea is to try to avoid adding more state. that's not always possible but in this case element was seen but not consumed yet, so it should be possible for destination to simply get it from the VQ again.

Quoted 2 lines
Quoted 2 lines

--
MST

Quoted 6 lines
Quoted 6 lines

Hi Michel,

Do you have time for this issue recently?

Thanks!
Liang

Quoted 6 lines

Hi Liang,

I should be able to look into it this week if you help me with testing.

Thanks,
Ladi

Please try the attached patch. I have tested it with a simple 'migrate' to save the state and then '-incoming' to load it back.

One question for you: is it expected that stats_poll_interval is not preserved by save/load? I had to explicitly set guest-stats-polling-interval on the receiving VM to start getting stats again. It's also the reason why the new virtio_balloon_receive_stats call is not under if (balloon_stats_enabled(s)) because this condition always evaluates to false for me.

Thanks!
Ladi

Quoted 7 lines
Quoted 7 lines

Sorry, doesn't look like I will.
Idea is to make sure balloon_stats_poll_cb runs
on source. This will set stats_vq_elem to NULL.

--
MST

From f2f779e12f4aa4d3469d1b44e54484e66f82a2d7 Mon Sep 17 00:00:00 2001
From: Ladi Prosek <[email protected]>
Date: Thu, 4 Aug 2016 15:22:05 +0200
Subject: [PATCH] balloon: preserve stats virtqueue state across migrations

---
 hw/virtio/virtio-balloon.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
hw/virtio/virtio-balloon.c +16 -0
index 5af429a..1293be0 100644
@@ -396,6 +396,19 @@ static void virtio_balloon_to_target(void *opaque, ram_addr_t target)
     trace_virtio_balloon_to_target(target, dev->num_pages);
 }
 
+static void virtio_balloon_save(QEMUFile *f, void *opaque, size_t size)
+{
+    VirtIOBalloon *s = VIRTIO_BALLOON(opaque);
+
+    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;
+    }
+
+    virtio_save(VIRTIO_DEVICE(opaque), f);
+}
+
 static void virtio_balloon_save_device(VirtIODevice *vdev, QEMUFile *f)
 {
     VirtIOBalloon *s = VIRTIO_BALLOON(vdev);
@@ -417,6 +430,9 @@ static int virtio_balloon_load_device(VirtIODevice *vdev, QEMUFile *f,
     s->num_pages = qemu_get_be32(f);
     s->actual = qemu_get_be32(f);
 
+    /* poll the queue for the element we may have discarded on save */
+    virtio_balloon_receive_stats(VIRTIO_DEVICE(s), s->svq);
+
     if (balloon_stats_enabled(s)) {
         balloon_stats_change_timer(s, s->stats_poll_interval);
     }

hw/virtio/virtio-balloon.c static void virtio_balloon_instance_init(Object *obj) · line 503

Quoted 8 lines
hw/virtio/virtio-balloon.c +1 -1
@@ -481,7 +497,7 @@ static void virtio_balloon_instance_init(Object *obj)
                         NULL, s, NULL);
 }
 
-VMSTATE_VIRTIO_DEVICE(balloon, 1, virtio_balloon_load, virtio_vmstate_save);
+VMSTATE_VIRTIO_DEVICE(balloon, 1, virtio_balloon_load, virtio_balloon_save);
 
 static Property virtio_balloon_properties[] = {
     DEFINE_PROP_BIT("deflate-on-oom", VirtIOBalloon, host_features,

So almost, but I think I'd be happier if instead of save/load we handled vm stop/run. Simply specify vmstate_change callback and check vm_running value.

This way we don't modify guest memory when vm is not running, and that is a useful invariant to keep (e.g. save+load+save will produce two identical images).

Quoted 3 lines
Signature · 1 line
2.5.5
#11 lore raw
Quoted 158 lines · Michael S. Tsirkin
Quoted 144 lines · Ladi Prosek
Quoted 69 lines · Ladi Prosek
Quoted 61 lines · Michael S. Tsirkin
Quoted 60 lines · Liang Z
Quoted 59 lines · Liang Z
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

After live migration, 'guest-stats' can't get the expected memory status in the guest. This issue is caused by commit

4eae2a657d.

Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 15 lines
Quoted 9 lines

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.

Quoted 5 lines
Cc Michael S. Tsirkin <[email protected]>
Cc Ladi Prosek <[email protected]>
Cc Paolo Bonzini <[email protected]>
Quoted 6 lines

I agree there's an issue but we don't change versions anymore. Breaking migrations for everyone is also not nice.

How about queueing virtio_balloon_receive_stats so it will get invoked when vm starts?

Could you give more explanation about how it works? I can't catch you.

Thanks!
Liang

Quoted 7 lines
Quoted 4 lines

virtqueue_discard before migration

virtio_balloon_receive_stats after migration

Sorry, I still can't catch you. Maybe it's easier for you to submit a patch than writing a lot a words to make me understand your idea.

I'm rather busy now. I might look into it towards end of the month.

Quoted 2 lines

I just don't understand why not to use the version to make things easier, is that not the original intent of version id?

This was the original idea but we stopped using version ids since they have many shortcomings.

Quoted 5 lines

If we want to extend the device and more states are needed, the idea you suggest can be used as a common solution?

Thanks!
Liang

The idea is to try to avoid adding more state. that's not always possible but in this case element was seen but not consumed yet, so it should be possible for destination to simply get it from the VQ again.

Quoted 2 lines
Quoted 2 lines

--
MST

Quoted 6 lines
Quoted 6 lines

Hi Michel,

Do you have time for this issue recently?

Thanks!
Liang

Quoted 6 lines

Hi Liang,

I should be able to look into it this week if you help me with testing.

Thanks,
Ladi

Please try the attached patch. I have tested it with a simple 'migrate' to save the state and then '-incoming' to load it back.

One question for you: is it expected that stats_poll_interval is not preserved by save/load? I had to explicitly set guest-stats-polling-interval on the receiving VM to start getting stats again. It's also the reason why the new virtio_balloon_receive_stats call is not under if (balloon_stats_enabled(s)) because this condition always evaluates to false for me.

Thanks!
Ladi

Quoted 7 lines
Quoted 7 lines

Sorry, doesn't look like I will.
Idea is to make sure balloon_stats_poll_cb runs
on source. This will set stats_vq_elem to NULL.

--
MST

From f2f779e12f4aa4d3469d1b44e54484e66f82a2d7 Mon Sep 17 00:00:00 2001
From: Ladi Prosek <[email protected]>
Date: Thu, 4 Aug 2016 15:22:05 +0200
Subject: [PATCH] balloon: preserve stats virtqueue state across migrations

---
 hw/virtio/virtio-balloon.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
hw/virtio/virtio-balloon.c +16 -0
index 5af429a..1293be0 100644
@@ -396,6 +396,19 @@ static void virtio_balloon_to_target(void *opaque, ram_addr_t target)
     trace_virtio_balloon_to_target(target, dev->num_pages);
 }
 
+static void virtio_balloon_save(QEMUFile *f, void *opaque, size_t size)
+{
+    VirtIOBalloon *s = VIRTIO_BALLOON(opaque);
+
+    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;
+    }
+
+    virtio_save(VIRTIO_DEVICE(opaque), f);
+}
+
 static void virtio_balloon_save_device(VirtIODevice *vdev, QEMUFile *f)
 {
     VirtIOBalloon *s = VIRTIO_BALLOON(vdev);
@@ -417,6 +430,9 @@ static int virtio_balloon_load_device(VirtIODevice *vdev, QEMUFile *f,
     s->num_pages = qemu_get_be32(f);
     s->actual = qemu_get_be32(f);
 
+    /* poll the queue for the element we may have discarded on save */
+    virtio_balloon_receive_stats(VIRTIO_DEVICE(s), s->svq);
+
     if (balloon_stats_enabled(s)) {
         balloon_stats_change_timer(s, s->stats_poll_interval);
     }

hw/virtio/virtio-balloon.c static void virtio_balloon_instance_init(Object *obj) · line 503

Quoted 8 lines
hw/virtio/virtio-balloon.c +1 -1
@@ -481,7 +497,7 @@ static void virtio_balloon_instance_init(Object *obj)
                         NULL, s, NULL);
 }
 
-VMSTATE_VIRTIO_DEVICE(balloon, 1, virtio_balloon_load, virtio_vmstate_save);
+VMSTATE_VIRTIO_DEVICE(balloon, 1, virtio_balloon_load, virtio_balloon_save);
 
 static Property virtio_balloon_properties[] = {
     DEFINE_PROP_BIT("deflate-on-oom", VirtIOBalloon, host_features,

So almost, but I think I'd be happier if instead of save/load we handled vm stop/run. Simply specify vmstate_change callback and check vm_running value.

Quoted 3 lines

This way we don't modify guest memory when vm is not running, and that is a useful invariant to keep (e.g. save+load+save will produce two identical images).

Will do. Thanks!

Quoted 5 lines
Quoted 4 lines

--
2.5.5

#12 lore raw
In reply to Ladi Prosek
Quoted 11 lines
Quoted 7 lines

Hi Liang,

I should be able to look into it this week if you help me with testing.

Thanks,
Ladi

Please try the attached patch. I have tested it with a simple 'migrate' to save the state and then '-incoming' to load it back.

Thanks for your work. I have already saw your v3 patch, so I will test that one.

Quoted 2 lines

One question for you: is it expected that stats_poll_interval is not preserved by save/load? I had to explicitly set guest-stats-polling-interval on the

Yes, I found that too. And I am not quite sure about that. IMO,
' stats_poll_interval ' should be treated as part of device state as well as the ' stats_vq_elem ', but they are not contained at the very beginning.

Quoted 4 lines

receiving VM to start getting stats again. It's also the reason why the new virtio_balloon_receive_stats call is not under if (balloon_stats_enabled(s)) because this condition always evaluates to false for me.

Thanks!
Liang