Skip to contentSkip to conversation

Check migration enabled features on both sides

PATCH In review Juan Quintela 3 participants 10 messages Jun 13, 2017 – Jun 14, 2017

lore
Share & tools
lore
#0 lore raw

cover Check migration enabled features on both sides

Hi

This was part of my multifd series, it just "requires" that migartion features being enabled on both sides.
- XBZRLE: libvirt only enables it on source, so we don't test it

- compression threads: we check at reception when we receive a compression page that we have compression threads enabled. Otherwise we exit with one error.

- Now that we check if compression threads are enabled, we don't create the threads if they are not enabled.

It makes debugging much easier, because I have less threads on destination to search where things are hang up.

Please review,

Thanks, Juan.

Juan Quintela (2):
migration: Test for disabled features on reception
migration: Don't create decompression threads if not enabled

 migration/ram.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
Signature · 1 line
2.9.4
#1 lore raw

PATCH 1/2 migration: Test for disabled features on reception

Right now, if we receive a compressed page while this features are disabled, Bad Things (TM) can happen. Just add a test for them.

--

I had XBZRLE here also, but it don't need extra resources on destination, only on source. Additionally libvirt don't enable it on destination, so don't put it here.

---
 migration/ram.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
migration/ram.c +15 -1
index f35d65a..f2d1bce 100644
@@ -2477,7 +2477,7 @@ static int ram_load_postcopy(QEMUFile *f)
 
 static int ram_load(QEMUFile *f, void *opaque, int version_id)
 {
-    int flags = 0, ret = 0;
+    int flags = 0, ret = 0, invalid_flags;
     static uint64_t seq_iter;
     int len = 0;
     /*
@@ -2494,6 +2494,11 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
         ret = -EINVAL;
     }
 
+    invalid_flags = 0;
+
+    if (!migrate_use_compression()) {
+        invalid_flags |= RAM_SAVE_FLAG_COMPRESS_PAGE;
+    }
     /* This RCU critical section can be very long running.
      * When RCU reclaims in the code start to become numerous,
      * it will be necessary to reduce the granularity of this
@@ -2514,6 +2519,15 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
         flags = addr & ~TARGET_PAGE_MASK;
         addr &= TARGET_PAGE_MASK;
 
+        if (flags & invalid_flags) {
+            if (flags & invalid_flags  & RAM_SAVE_FLAG_COMPRESS_PAGE) {
+                error_report("Received an unexpected compressed page");
+            }
+
+            ret = -EINVAL;
+            break;
+        }
+
         if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE |
                      RAM_SAVE_FLAG_COMPRESS_PAGE | RAM_SAVE_FLAG_XBZRLE)) {
             RAMBlock *block = ram_block_from_stream(f, flags);
Signature · 1 line
2.9.4
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] migration: Test for disabled features on reception

Quoted 5 lines · * Juan Quintela ([email protected]) wrote:

Right now, if we receive a compressed page while this features are disabled, Bad Things (TM) can happen. Just add a test for them.

Yes, my R-b stands, there could be someone somewhere driving this by hand who might get caught out, but seems saner this way.

Quoted 23 lines

--

I had XBZRLE here also, but it don't need extra resources on destination, only on source. Additionally libvirt don't enable it on destination, so don't put it here.

---
 migration/ram.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
migration/ram.c +1 -1
index f35d65a..f2d1bce 100644
@@ -2477,7 +2477,7 @@ static int ram_load_postcopy(QEMUFile *f)
 
 static int ram_load(QEMUFile *f, void *opaque, int version_id)
 {
-    int flags = 0, ret = 0;
+    int flags = 0, ret = 0, invalid_flags;
     static uint64_t seq_iter;
     int len = 0;
     /*

migration/ram.c static int ram_load(QEMUFile *f, void *opaque, int version_id) · line 2497

Quoted 4 lines
migration/ram.c +1 -0
@@ -2494,6 +2494,11 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
         ret = -EINVAL;
     }
 
+    invalid_flags = 0;

why didn't you use = 0 in the declaration like the rest of the flags? (Only minor)

Dave

Quoted 26 lines
migration/ram.c +13 -0
+
+    if (!migrate_use_compression()) {
+        invalid_flags |= RAM_SAVE_FLAG_COMPRESS_PAGE;
+    }
     /* This RCU critical section can be very long running.
      * When RCU reclaims in the code start to become numerous,
      * it will be necessary to reduce the granularity of this
@@ -2514,6 +2519,15 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
         flags = addr & ~TARGET_PAGE_MASK;
         addr &= TARGET_PAGE_MASK;
 
+        if (flags & invalid_flags) {
+            if (flags & invalid_flags  & RAM_SAVE_FLAG_COMPRESS_PAGE) {
+                error_report("Received an unexpected compressed page");
+            }
+
+            ret = -EINVAL;
+            break;
+        }
+
         if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE |
                      RAM_SAVE_FLAG_COMPRESS_PAGE | RAM_SAVE_FLAG_XBZRLE)) {
             RAMBlock *block = ram_block_from_stream(f, flags);
Signature · 1 line
2.9.4

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

#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] migration: Test for disabled features on reception

Quoted 36 lines · Dr. David Alan Gilbert
Quoted 5 lines · * Juan Quintela ([email protected]) wrote:

Right now, if we receive a compressed page while this features are disabled, Bad Things (TM) can happen. Just add a test for them.

Yes, my R-b stands, there could be someone somewhere driving this by hand who might get caught out, but seems saner this way.

Quoted 26 lines

--

I had XBZRLE here also, but it don't need extra resources on destination, only on source. Additionally libvirt don't enable it on destination, so don't put it here.

---
 migration/ram.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
migration/ram.c +1 -1
index f35d65a..f2d1bce 100644
@@ -2477,7 +2477,7 @@ static int ram_load_postcopy(QEMUFile *f)
 
 static int ram_load(QEMUFile *f, void *opaque, int version_id)
 {
-    int flags = 0, ret = 0;
+    int flags = 0, ret = 0, invalid_flags;
     static uint64_t seq_iter;
     int len = 0;
     /*
@@ -2494,6 +2494,11 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
         ret = -EINVAL;
     }
 
Quoted 4 lines

migration/ram.c static int ram_load(QEMUFile *f, void *opaque, int version_id) · line 2497

Quoted 1 line
migration/ram.c +1 -0
+    invalid_flags = 0;

why didn't you use = 0 in the declaration like the rest of the flags? (Only minor)

Costume :-(

Changed to common style there.

Thanks, Juan.

Reviewed-by on v1 1/2
#4 lore raw

Re: [Qemu-devel] [PATCH 1/2] migration: Test for disabled features on reception

In reply to Juan Quintela
Quoted 29 lines · Juan Quintela

Right now, if we receive a compressed page while this features are disabled, Bad Things (TM) can happen. Just add a test for them.

--

I had XBZRLE here also, but it don't need extra resources on destination, only on source. Additionally libvirt don't enable it on destination, so don't put it here.

---
 migration/ram.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
migration/ram.c +1 -1
index f35d65a..f2d1bce 100644
@@ -2477,7 +2477,7 @@ static int ram_load_postcopy(QEMUFile *f)
 
 static int ram_load(QEMUFile *f, void *opaque, int version_id)
 {
-    int flags = 0, ret = 0;
+    int flags = 0, ret = 0, invalid_flags;
     static uint64_t seq_iter;
     int len = 0;
     /*

migration/ram.c static int ram_load(QEMUFile *f, void *opaque, int version_id) · line 2497

Quoted 4 lines
migration/ram.c +1 -0
@@ -2494,6 +2494,11 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
         ret = -EINVAL;
     }
 
+    invalid_flags = 0;

Nit: set zero when declare (just like flags, ret)?

migration/ram.c static int ram_load(QEMUFile *f, void *opaque, int version_id) · line 2523

Quoted 13 lines
migration/ram.c +6 -0
+
+    if (!migrate_use_compression()) {
+        invalid_flags |= RAM_SAVE_FLAG_COMPRESS_PAGE;
+    }
     /* This RCU critical section can be very long running.
      * When RCU reclaims in the code start to become numerous,
      * it will be necessary to reduce the granularity of this
@@ -2514,6 +2519,15 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
         flags = addr & ~TARGET_PAGE_MASK;
         addr &= TARGET_PAGE_MASK;
 
+        if (flags & invalid_flags) {
+            if (flags & invalid_flags  & RAM_SAVE_FLAG_COMPRESS_PAGE) {
                                        ^

Nit: one extra space -------------------+

Quoted 13 lines
migration/ram.c +7 -0
+                error_report("Received an unexpected compressed page");
+            }
+
+            ret = -EINVAL;
+            break;
+        }
+
         if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE |
                      RAM_SAVE_FLAG_COMPRESS_PAGE | RAM_SAVE_FLAG_XBZRLE)) {
             RAMBlock *block = ram_block_from_stream(f, flags);
Signature · 1 line
2.9.4

Besides the nits:

Signature · 1 line
Peter Xu
#5 lore raw

Re: [Qemu-devel] [PATCH 1/2] migration: Test for disabled features on reception

Quoted 33 lines · Peter Xu
Quoted 32 lines · Juan Quintela

Right now, if we receive a compressed page while this features are disabled, Bad Things (TM) can happen. Just add a test for them.

--

I had XBZRLE here also, but it don't need extra resources on destination, only on source. Additionally libvirt don't enable it on destination, so don't put it here.

---
 migration/ram.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
migration/ram.c +1 -1
index f35d65a..f2d1bce 100644
@@ -2477,7 +2477,7 @@ static int ram_load_postcopy(QEMUFile *f)
 
 static int ram_load(QEMUFile *f, void *opaque, int version_id)
 {
-    int flags = 0, ret = 0;
+    int flags = 0, ret = 0, invalid_flags;
     static uint64_t seq_iter;
     int len = 0;
     /*
@@ -2494,6 +2494,11 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
         ret = -EINVAL;
     }
 
Quoted 3 lines

migration/ram.c static int ram_load(QEMUFile *f, void *opaque, int version_id) · line 2497

Quoted 1 line
migration/ram.c +1 -0
+    invalid_flags = 0;

Nit: set zero when declare (just like flags, ret)?

Fixed.

As answered to dave, I use to do it that way. But here it is more consistant to do it the other way.

Quoted 11 lines
Quoted 11 lines
migration/ram.c +4 -0
+
+    if (!migrate_use_compression()) {
+        invalid_flags |= RAM_SAVE_FLAG_COMPRESS_PAGE;
+    }
     /* This RCU critical section can be very long running.
      * When RCU reclaims in the code start to become numerous,
      * it will be necessary to reduce the granularity of this
@@ -2514,6 +2519,15 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id)
         flags = addr & ~TARGET_PAGE_MASK;
         addr &= TARGET_PAGE_MASK;
 
Quoted 4 lines

migration/ram.c static int ram_load(QEMUFile *f, void *opaque, int version_id) · line 2523

Quoted 2 lines
migration/ram.c +2 -0
+        if (flags & invalid_flags) {
+            if (flags & invalid_flags  & RAM_SAVE_FLAG_COMPRESS_PAGE) {
                                        ^

Nit: one extra space -------------------+

Fixed.

Quoted 16 lines
Quoted 13 lines
migration/ram.c +7 -0
+                error_report("Received an unexpected compressed page");
+            }
+
+            ret = -EINVAL;
+            break;
+        }
+
         if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE |
                      RAM_SAVE_FLAG_COMPRESS_PAGE | RAM_SAVE_FLAG_XBZRLE)) {
             RAMBlock *block = ram_block_from_stream(f, flags);
Signature · 1 line
2.9.4

Besides the nits:

Quoted 1 line

Thanks.

#6 lore raw

PATCH 2/2 migration: Don't create decompression threads if not enabled

In reply to Juan Quintela

--

I removed the [HACK] part because previous patch just check that compression pages are not received.

---
 migration/ram.c | 6 ++++++
 1 file changed, 6 insertions(+)
migration/ram.c +6 -0
index f2d1bce..d475cf5 100644
@@ -2234,6 +2234,9 @@ static void compress_threads_load_setup(void)
 {
     int i, thread_count;
 
+    if (!migrate_use_compression()) {
+        return;
+    }
     thread_count = migrate_decompress_threads();
     decompress_threads = g_new0(QemuThread, thread_count);
     decomp_param = g_new0(DecompressParam, thread_count);
@@ -2255,6 +2258,9 @@ static void compress_threads_load_cleanup(void)
 {
     int i, thread_count;
 
+    if (!migrate_use_compression()) {
+        return;
+    }
     thread_count = migrate_decompress_threads();
     for (i = 0; i < thread_count; i++) {
         qemu_mutex_lock(&decomp_param[i].mutex);
Signature · 1 line
2.9.4
#7 lore raw

Re: [Qemu-devel] [PATCH 2/2] migration: Don't create decompression threads if not enabled

migration/ram.c static void compress_threads_load_setup(void)

Quoted 16 lines · Juan Quintela

--

I removed the [HACK] part because previous patch just check that compression pages are not received.

---
 migration/ram.c | 6 ++++++
 1 file changed, 6 insertions(+)
migration/ram.c +0 -0
index f2d1bce..d475cf5 100644
@@ -2234,6 +2234,9 @@ static void compress_threads_load_setup(void)

I cannot find compress_threads_load_setup() in my repo, but migrate_decompress_threads_create()?

Thanks,

Quoted 22 lines
migration/ram.c +6 -0
 {
     int i, thread_count;
 
+    if (!migrate_use_compression()) {
+        return;
+    }
     thread_count = migrate_decompress_threads();
     decompress_threads = g_new0(QemuThread, thread_count);
     decomp_param = g_new0(DecompressParam, thread_count);
@@ -2255,6 +2258,9 @@ static void compress_threads_load_cleanup(void)
 {
     int i, thread_count;
 
+    if (!migrate_use_compression()) {
+        return;
+    }
     thread_count = migrate_decompress_threads();
     for (i = 0; i < thread_count; i++) {
         qemu_mutex_lock(&decomp_param[i].mutex);
Signature · 1 line
2.9.4
Signature · 1 line
Peter Xu
#8 lore raw

Re: [Qemu-devel] [PATCH 2/2] migration: Don't create decompression threads if not enabled

Quoted 12 lines · Peter Xu
Quoted 11 lines · Juan Quintela

--

I removed the [HACK] part because previous patch just check that compression pages are not received.

---
 migration/ram.c | 6 ++++++
 1 file changed, 6 insertions(+)
Quoted 8 lines

migration/ram.c static void compress_threads_load_setup(void)

Quoted 5 lines
migration/ram.c +0 -0
index f2d1bce..d475cf5 100644
@@ -2234,6 +2234,9 @@ static void compress_threads_load_setup(void)

I cannot find compress_threads_load_setup() in my repo, but migrate_decompress_threads_create()?

Sorry, this patches are on top of load_setup/cleanup series.

Later, Juan.

Quoted 25 lines

Thanks,

Quoted 22 lines
migration/ram.c +6 -0
 {
     int i, thread_count;
 
+    if (!migrate_use_compression()) {
+        return;
+    }
     thread_count = migrate_decompress_threads();
     decompress_threads = g_new0(QemuThread, thread_count);
     decomp_param = g_new0(DecompressParam, thread_count);
@@ -2255,6 +2258,9 @@ static void compress_threads_load_cleanup(void)
 {
     int i, thread_count;
 
+    if (!migrate_use_compression()) {
+        return;
+    }
     thread_count = migrate_decompress_threads();
     for (i = 0; i < thread_count; i++) {
         qemu_mutex_lock(&decomp_param[i].mutex);
Signature · 1 line
2.9.4
Reviewed-by
#9 lore raw

Re: [Qemu-devel] [PATCH 2/2] migration: Don't create decompression threads if not enabled

Quoted 23 lines · Juan Quintela
Quoted 12 lines · Peter Xu
Quoted 11 lines · Juan Quintela

--

I removed the [HACK] part because previous patch just check that compression pages are not received.

---
 migration/ram.c | 6 ++++++
 1 file changed, 6 insertions(+)
Quoted 8 lines

migration/ram.c static void compress_threads_load_setup(void)

Quoted 5 lines
migration/ram.c +0 -0
index f2d1bce..d475cf5 100644
@@ -2234,6 +2234,9 @@ static void compress_threads_load_setup(void)

I cannot find compress_threads_load_setup() in my repo, but migrate_decompress_threads_create()?

Quoted 1 line

Sorry, this patches are on top of load_setup/cleanup series.

Got it. After all the content of the patch looks good to me, so please take my r-b as long as the patch can apply cleanly and correctly on where it should be based:

Thanks,

Signature · 1 line
Peter Xu