qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Liang Li <liang.z.li@intel.com>
To: qemu-devel@nongnu.org
Cc: quintela@redhat.com, amit.shah@redhat.com, berrange@redhat.com,
	dgilbert@redhat.com, Liang Li <liang.z.li@intel.com>
Subject: [Qemu-devel] [PATCH 2/5] migration: Fix a potential issue
Date: Wed,  4 May 2016 11:40:56 +0800	[thread overview]
Message-ID: <1462333259-3237-3-git-send-email-liang.z.li@intel.com> (raw)
In-Reply-To: <1462333259-3237-1-git-send-email-liang.z.li@intel.com>

At the end of live migration and before vm_start() on the destination
side, we should make sure all the decompression tasks are finished, if
this can not be guaranteed, the VM may get the incorrect memory data,
or the updated memory may be overwritten by the decompression thread.
Add the code to fix this potential issue.

Suggested-by: David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Liang Li <liang.z.li@intel.com>
---
 include/migration/migration.h |  1 +
 migration/migration.c         |  2 +-
 migration/ram.c               | 20 ++++++++++++++++++++
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/include/migration/migration.h b/include/migration/migration.h
index ac2c12c..1c9051e 100644
--- a/include/migration/migration.h
+++ b/include/migration/migration.h
@@ -223,6 +223,7 @@ void migrate_compress_threads_create(void);
 void migrate_compress_threads_join(void);
 void migrate_decompress_threads_create(void);
 void migrate_decompress_threads_join(void);
+void wait_for_decompress_done(void);
 uint64_t ram_bytes_remaining(void);
 uint64_t ram_bytes_transferred(void);
 uint64_t ram_bytes_total(void);
diff --git a/migration/migration.c b/migration/migration.c
index 991313a..5228c28 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -347,7 +347,7 @@ static void process_incoming_migration_bh(void *opaque)
     /* If global state section was not received or we are in running
        state, we need to obey autostart. Any other state is set with
        runstate_set. */
-
+    wait_for_decompress_done();
     if (!global_state_received() ||
         global_state_get_runstate() == RUN_STATE_RUNNING) {
         if (autostart) {
diff --git a/migration/ram.c b/migration/ram.c
index 7ab6ab5..4459b38 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -2220,6 +2220,26 @@ static void *do_data_decompress(void *opaque)
     return NULL;
 }
 
+void wait_for_decompress_done(void)
+{
+    int idx, thread_count;
+
+    if (!migrate_use_compression()) {
+        return;
+    }
+    thread_count = migrate_decompress_threads();
+    for (idx = 0; idx < thread_count; idx++) {
+        if (!decomp_param[idx].done) {
+            qemu_mutex_lock(&decomp_done_lock);
+            while (!decomp_param[idx].done) {
+                qemu_cond_wait(&decomp_done_cond, &decomp_done_lock);
+            }
+            qemu_mutex_unlock(&decomp_done_lock);
+        }
+    }
+
+}
+
 void migrate_decompress_threads_create(void)
 {
     int i, thread_count;
-- 
1.9.1

  parent reply	other threads:[~2016-05-04  3:41 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-04  3:40 [Qemu-devel] [PATCH 0/5] live migration bug fix and refine Liang Li
2016-05-04  3:40 ` [Qemu-devel] [PATCH 1/5] migration: Fix multi-thread compression bug Liang Li
2016-05-04  3:40 ` Liang Li [this message]
2016-05-04  8:47   ` [Qemu-devel] [PATCH 2/5] migration: Fix a potential issue Dr. David Alan Gilbert
2016-05-04 10:05     ` Li, Liang Z
2016-05-04  9:17   ` Juan Quintela
2016-05-04 14:13     ` Li, Liang Z
2016-05-04  3:40 ` [Qemu-devel] [PATCH 3/5] migration: remove useless code Liang Li
2016-05-04  9:18   ` Juan Quintela
2016-05-04  3:40 ` [Qemu-devel] [PATCH 4/5] qemu-file: Fix qemu_put_compression_data flaw Liang Li
2016-05-04  9:30   ` Juan Quintela
2016-05-04 14:32     ` Li, Liang Z
2016-05-04  3:40 ` [Qemu-devel] [PATCH 5/5] migration: refine ram_save_compressed_page Liang Li
2016-05-04  9:33   ` Juan Quintela

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=1462333259-3237-3-git-send-email-liang.z.li@intel.com \
    --to=liang.z.li@intel.com \
    --cc=amit.shah@redhat.com \
    --cc=berrange@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@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).