Skip to contentSkip to conversation

migrate: Migration aborts abruptly for machine "none"

PATCH In review Ashijeet Acharya 6 participants 14 messages Jan 26, 2017 – Feb 1, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 migrate: Migration aborts abruptly for machine "none"

Migration of a "none" machine with no RAM crashes abruptly as bitmap_new() fails and thus aborts. Instead, place a check for last_ram_offset() being '0' at the start of ram_save_setup() and error out with a meaningful error message.

---
 migration/ram.c | 5 +++++
 1 file changed, 5 insertions(+)
migration/ram.c +5 -0
index ef8fadf..bf05d69 100644
@@ -1947,6 +1947,11 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
 {
     RAMBlock *block;
 
+    if (last_ram_offset() == 0) {
+        error_report("Failed to migrate: No RAM available!");
+        return -1;
+    }
+
     /* migration has already setup the bitmap, reuse it. */
     if (!migration_in_colo_state()) {
         if (ram_save_init_globals() < 0) {
Signature · 1 line
2.6.2
#1 lore raw
Quoted 9 lines · Ashijeet Acharya

Migration of a "none" machine with no RAM crashes abruptly as bitmap_new() fails and thus aborts. Instead, place a check for last_ram_offset() being '0' at the start of ram_save_setup() and error out with a meaningful error message.

---
 migration/ram.c | 5 +++++
 1 file changed, 5 insertions(+)

You state the problem in the one-line Git commit summary message, it's usually preferred to summarize the _fix_ that you're making :-). If the below variant sounds any better, maybe the maintainer can reword it upon applying:

migrate: Gracefully handle crash of a 'none' machine with no RAM

[...]

Signature · 1 line
/kashyap
Reviewed-by on v1 1/1
#2 lore raw
In reply to Ashijeet Acharya
Quoted 15 lines · * Ashijeet Acharya ([email protected]) wrote:

Migration of a "none" machine with no RAM crashes abruptly as bitmap_new() fails and thus aborts. Instead, place a check for last_ram_offset() being '0' at the start of ram_save_setup() and error out with a meaningful error message.

---
 migration/ram.c | 5 +++++
 1 file changed, 5 insertions(+)
migration/ram.c +0 -0
index ef8fadf..bf05d69 100644

migration/ram.c static int ram_save_setup(QEMUFile *f, void *opaque) · line 1954

Quoted 8 lines
migration/ram.c +5 -0
@@ -1947,6 +1947,11 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
 {
     RAMBlock *block;
 
+    if (last_ram_offset() == 0) {
+        error_report("Failed to migrate: No RAM available!");
+        return -1;
+    }
+

Dave

Quoted 6 lines
migration/ram.c +0 -0
     /* migration has already setup the bitmap, reuse it. */
     if (!migration_in_colo_state()) {
         if (ram_save_init_globals() < 0) {
Signature · 1 line
2.6.2

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#3 lore raw
In reply to Ashijeet Acharya
Quoted 15 lines · Ashijeet Acharya

Migration of a "none" machine with no RAM crashes abruptly as bitmap_new() fails and thus aborts. Instead, place a check for last_ram_offset() being '0' at the start of ram_save_setup() and error out with a meaningful error message.

---
 migration/ram.c | 5 +++++
 1 file changed, 5 insertions(+)
migration/ram.c +0 -0
index ef8fadf..bf05d69 100644

migration/ram.c static int ram_save_setup(QEMUFile *f, void *opaque) · line 1954

Quoted 8 lines
migration/ram.c +5 -0
@@ -1947,6 +1947,11 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
 {
     RAMBlock *block;
 
+    if (last_ram_offset() == 0) {
+        error_report("Failed to migrate: No RAM available!");
+        return -1;
+    }
+

If we're merely going to block migration, as opposed to making it work, then IMHO we should use migration blockers registered at machine setup for this task.

We have a new cli arg added to QEMU to tell it to abort startup if the machine configuration is not migratable. That only works if using migration blockers - this check you've added is too late to be detected at startup.

Regards,
Daniel

Signature · 3 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://entangle-photo.org       -o-    http://search.cpan.org/~danberr/ :|
#4 lore raw
Quoted 29 lines · * Daniel P. Berrange ([email protected]) wrote:
Quoted 15 lines · Ashijeet Acharya

Migration of a "none" machine with no RAM crashes abruptly as bitmap_new() fails and thus aborts. Instead, place a check for last_ram_offset() being '0' at the start of ram_save_setup() and error out with a meaningful error message.

---
 migration/ram.c | 5 +++++
 1 file changed, 5 insertions(+)
migration/ram.c +0 -0
index ef8fadf..bf05d69 100644

migration/ram.c static int ram_save_setup(QEMUFile *f, void *opaque) · line 1954

Quoted 8 lines
migration/ram.c +5 -0
@@ -1947,6 +1947,11 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
 {
     RAMBlock *block;
 
+    if (last_ram_offset() == 0) {
+        error_report("Failed to migrate: No RAM available!");
+        return -1;
+    }
+

If we're merely going to block migration, as opposed to making it work, then IMHO we should use migration blockers registered at machine setup for this task.

Quoted 4 lines

We have a new cli arg added to QEMU to tell it to abort startup if the machine configuration is not migratable. That only works if using migration blockers - this check you've added is too late to be detected at startup.

Hmm, yes you're right, that would be better.
Although it does lead to an interesting situation where starting with a 'none' and constructing it component at a time would get rejected by --only-migratable even though the final construction is fine.

Dave

Quoted 7 lines

Regards,
Daniel

Signature · 3 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://entangle-photo.org       -o-    http://search.cpan.org/~danberr/ :|

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#5 lore raw
Quoted 35 lines · Dr. David Alan Gilbert
Quoted 29 lines · * Daniel P. Berrange ([email protected]) wrote:
Quoted 15 lines · Ashijeet Acharya

Migration of a "none" machine with no RAM crashes abruptly as bitmap_new() fails and thus aborts. Instead, place a check for last_ram_offset() being '0' at the start of ram_save_setup() and error out with a meaningful error message.

---
 migration/ram.c | 5 +++++
 1 file changed, 5 insertions(+)
migration/ram.c +0 -0
index ef8fadf..bf05d69 100644

migration/ram.c static int ram_save_setup(QEMUFile *f, void *opaque) · line 1954

Quoted 8 lines
migration/ram.c +5 -0
@@ -1947,6 +1947,11 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
 {
     RAMBlock *block;
 
+    if (last_ram_offset() == 0) {
+        error_report("Failed to migrate: No RAM available!");
+        return -1;
+    }
+

If we're merely going to block migration, as opposed to making it work, then IMHO we should use migration blockers registered at machine setup for this task.

Quoted 4 lines

We have a new cli arg added to QEMU to tell it to abort startup if the machine configuration is not migratable. That only works if using migration blockers - this check you've added is too late to be detected at startup.

Quoted 4 lines

Hmm, yes you're right, that would be better.
Although it does lead to an interesting situation where starting with a 'none' and constructing it component at a time would get rejected by --only-migratable even though the final construction is fine.

Even in that case I would expect the ram to be specified upfront e.g.

$qemu -machine none -m 500

thus avoiding addition of the migration blocker

Regards,
Daniel

Signature · 3 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://entangle-photo.org       -o-    http://search.cpan.org/~danberr/ :|
#6 lore raw
In reply to Daniel P. Berrange

Okay

Quoted 27 lines · Daniel P. Berrange
Quoted 6 lines · Ashijeet Acharya

Migration of a "none" machine with no RAM crashes abruptly as bitmap_new() fails and thus aborts. Instead, place a check for last_ram_offset() being '0' at the start of ram_save_setup() and error out with a meaningful error message.

<javascript:;>>

migration/ram.c static int ram_save_setup(QEMUFile *f, void

Quoted 9 lines
---
 migration/ram.c | 5 +++++
 1 file changed, 5 insertions(+)
migration/ram.c +0 -0
index ef8fadf..bf05d69 100644
@@ -1947,6 +1947,11 @@ static int ram_save_setup(QEMUFile *f, void

*opaque)

migration/ram.c static int ram_save_setup(QEMUFile *f, void *opaque) · line 1954

Quoted 8 lines
migration/ram.c +5 -0
 {
     RAMBlock *block;
 
+    if (last_ram_offset() == 0) {
+        error_report("Failed to migrate: No RAM available!");
+        return -1;
+    }
+
Quoted 6 lines

If we're merely going to block migration, as opposed to making it work, then IMHO we should use migration blockers registered at machine setup for this task.

We have a new cli arg added to QEMU to tell it to abort startup if the machine configuration is not migratable. That only works if using

Are you referring to the new "--only-migratable" option I added along with John last week?

migration blockers - this check you've added is too late to be detected

Quoted 1 line

at startup.

I think that the machine is not completely 'non-migratable' because if I boot qemu with "-m 1G" (say) the migration actually completes successfully.

Ashijeet

Quoted 11 lines

Regards,
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/
:|
|: http://libvirt.org -o- http://virt-manager.org
:|
|: http://entangle-photo.org -o- http://search.cpan.org/~danberr/
:|

#7 lore raw
Quoted 42 lines · Ashijeet Acharya

Okay

Quoted 27 lines · Daniel P. Berrange
Quoted 6 lines · Ashijeet Acharya

Migration of a "none" machine with no RAM crashes abruptly as bitmap_new() fails and thus aborts. Instead, place a check for last_ram_offset() being '0' at the start of ram_save_setup() and error out with a meaningful error message.

<javascript:;>>

migration/ram.c static int ram_save_setup(QEMUFile *f, void

Quoted 9 lines
---
 migration/ram.c | 5 +++++
 1 file changed, 5 insertions(+)
migration/ram.c +0 -0
index ef8fadf..bf05d69 100644
@@ -1947,6 +1947,11 @@ static int ram_save_setup(QEMUFile *f, void

*opaque)

migration/ram.c static int ram_save_setup(QEMUFile *f, void *opaque) · line 1954

Quoted 8 lines
migration/ram.c +5 -0
 {
     RAMBlock *block;
 
+    if (last_ram_offset() == 0) {
+        error_report("Failed to migrate: No RAM available!");
+        return -1;
+    }
+
Quoted 6 lines

If we're merely going to block migration, as opposed to making it work, then IMHO we should use migration blockers registered at machine setup for this task.

We have a new cli arg added to QEMU to tell it to abort startup if the machine configuration is not migratable. That only works if using

Are you referring to the new "--only-migratable" option I added along with John last week?

Quoted 6 lines

migration blockers - this check you've added is too late to be detected

Quoted 1 line

at startup.

I think that the machine is not completely 'non-migratable' because if I boot qemu with "-m 1G" (say) the migration actually completes successfully.

Of course - you would only add the migration blocker when ram size is 0

Regards,
Daniel

Signature · 3 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://entangle-photo.org       -o-    http://search.cpan.org/~danberr/ :|
#8 lore raw
In reply to Ashijeet Acharya
Quoted 7 lines · On Thu, 26 Jan 2017 14:46:52 +0530 Ashijeet Acharya…

Migration of a "none" machine with no RAM crashes abruptly as bitmap_new() fails and thus aborts. Instead, place a check for last_ram_offset() being '0' at the start of ram_save_setup() and error out with a meaningful error message.

---

Maybe a naive question: why a "none" machine with zero RAM should fail to migrate ?

Quoted 19 lines
 migration/ram.c | 5 +++++
 1 file changed, 5 insertions(+)
migration/ram.c +5 -0
index ef8fadf..bf05d69 100644
@@ -1947,6 +1947,11 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
 {
     RAMBlock *block;
 
+    if (last_ram_offset() == 0) {
+        error_report("Failed to migrate: No RAM available!");
+        return -1;
+    }
+
     /* migration has already setup the bitmap, reuse it. */
     if (!migration_in_colo_state()) {
         if (ram_save_init_globals() < 0) {
#9 lore raw
Quoted 11 lines · Greg Kurz
Quoted 7 lines · On Thu, 26 Jan 2017 14:46:52 +0530 Ashijeet Acharya…

Migration of a "none" machine with no RAM crashes abruptly as bitmap_new() fails and thus aborts. Instead, place a check for last_ram_offset() being '0' at the start of ram_save_setup() and error out with a meaningful error message.

---

cc'ing Paolo in : I had an IRC chat with him and he has a very interesting twist in the tale to add here.

Quoted 2 lines

Maybe a naive question: why a "none" machine with zero RAM should fail to migrate ?

Assuming you are referring to why its failing ATM; it fails because g_try_malloc0() inside bitmap_try_new() returns a NULL pointer for zero bits and thus the check for NULL inside bitmap_new() becomes true and it aborts. Check bitmap_new() for convenience.

Ignore the noise if you already knew this! :-)

Ashijeet

#10 lore raw
Quoted 13 lines · On Sun, 29 Jan 2017 01:06:47 +0530 Ashijeet Acharya…
Quoted 11 lines · Greg Kurz
Quoted 7 lines · On Thu, 26 Jan 2017 14:46:52 +0530 Ashijeet Acharya…

Migration of a "none" machine with no RAM crashes abruptly as bitmap_new() fails and thus aborts. Instead, place a check for last_ram_offset() being '0' at the start of ram_save_setup() and error out with a meaningful error message.

---

Quoted 7 lines

cc'ing Paolo in : I had an IRC chat with him and he has a very interesting twist in the tale to add here.

Quoted 2 lines

Maybe a naive question: why a "none" machine with zero RAM should fail to migrate ?

Assuming you are referring to why its failing ATM; it fails because

My question was more: why deciding to fail migration instead of fixing the crash ? One would naively think that no RAM is *just* less state to migrate... but maybe the current code assumes that a machine always has RAM.

Quoted 6 lines

g_try_malloc0() inside bitmap_try_new() returns a NULL pointer for zero bits and thus the check for NULL inside bitmap_new() becomes true and it aborts. Check bitmap_new() for convenience.

Ignore the noise if you already knew this! :-)

I hadn't checked, thanks for the details.

Cheers.

--
Greg

Quoted 1 line

Ashijeet

#11 lore raw
Quoted 22 lines · Greg Kurz
Quoted 19 lines · On Sun, 29 Jan 2017 01:06:47 +0530 Ashijeet Acharya…
Quoted 11 lines · Greg Kurz
Quoted 7 lines · On Thu, 26 Jan 2017 14:46:52 +0530 Ashijeet Acharya…

Migration of a "none" machine with no RAM crashes abruptly as bitmap_new() fails and thus aborts. Instead, place a check for last_ram_offset() being '0' at the start of ram_save_setup() and error out with a meaningful error message.

---

cc'ing Paolo in : I had an IRC chat with him and he has a very interesting twist in the tale to add here.

Quoted 2 lines

Maybe a naive question: why a "none" machine with zero RAM should fail to migrate ?

Quoted 6 lines
Quoted 1 line

Assuming you are referring to why its failing ATM; it fails because

My question was more: why deciding to fail migration instead of fixing the crash ? One would naively think that no RAM is *just* less state to migrate... but maybe the current code assumes that a machine always has RAM.

Actually, I think, the current code does assume that the machine always has RAM which is why it crashes here. I am not aware if we can also boot machines other than 'none' with zero RAM so I have not tested that case.
Also, Paolo has a similar opinion to yours that we should fix it instead of blocking it. He suggests to migrate only the device states and skip all the RAM related stuff. Maybe he can explain it better when he is available.

I have had mixed opinions on this one which is why I am waiting until we reach a common ground.

Ashijeet

Quoted 17 lines
Quoted 7 lines

g_try_malloc0() inside bitmap_try_new() returns a NULL pointer for zero bits and thus the check for NULL inside bitmap_new() becomes true and it aborts. Check bitmap_new() for convenience.

Ignore the noise if you already knew this! :-)

I hadn't checked, thanks for the details.

Cheers.

--
Greg

Quoted 1 line

Ashijeet

#12 lore raw
Quoted 4 lines · Ashijeet Acharya

Also, Paolo has a similar opinion to yours that we should fix it instead of blocking it. He suggests to migrate only the device states and skip all the RAM related stuff. Maybe he can explain it better when he is available.

Yes, there is even support already in ram_migration_cleanup for not allocating the bitmap:

    struct BitmapRcu *bitmap = migration_bitmap_rcu;
    atomic_rcu_set(&migration_bitmap_rcu, NULL);
    if (bitmap) {
        memory_global_dirty_log_stop();
        call_rcu(bitmap, migration_bitmap_free, rcu);
    }

I think you should just iterate until you find no more misbehaving code.
The allocation is one, but ram_find_and_save_block should also return 0
if QLIST_FIRST_RCU(&ram_list.blocks) is NULL, for example.

Paolo

#13 lore raw
Quoted 18 lines · Paolo Bonzini
Quoted 4 lines · Ashijeet Acharya

Also, Paolo has a similar opinion to yours that we should fix it instead of blocking it. He suggests to migrate only the device states and skip all the RAM related stuff. Maybe he can explain it better when he is available.

Yes, there is even support already in ram_migration_cleanup for not allocating the bitmap:

    struct BitmapRcu *bitmap = migration_bitmap_rcu;
    atomic_rcu_set(&migration_bitmap_rcu, NULL);
    if (bitmap) {
        memory_global_dirty_log_stop();
        call_rcu(bitmap, migration_bitmap_free, rcu);
    }
Quoted 4 lines

I think you should just iterate until you find no more misbehaving code.
The allocation is one, but ram_find_and_save_block should also return 0
if QLIST_FIRST_RCU(&ram_list.blocks) is NULL, for example.

Okay, I will drop the idea of adding a migration blocker in this case and proceed as you say.

Ashijeet

Quoted 1 line

Paolo