From patchwork Wed May 4 03:40:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liang Li X-Patchwork-Id: 9009331 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B60EC9F1C1 for ; Wed, 4 May 2016 03:44:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1FD3A202F0 for ; Wed, 4 May 2016 03:44:35 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4737A202B8 for ; Wed, 4 May 2016 03:44:34 +0000 (UTC) Received: from localhost ([::1]:45574 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1axnji-0005kK-Gv for patchwork-qemu-devel@patchwork.kernel.org; Tue, 03 May 2016 23:44:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50834) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1axnh8-0000tk-7I for qemu-devel@nongnu.org; Tue, 03 May 2016 23:41:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1axngw-0002ig-AZ for qemu-devel@nongnu.org; Tue, 03 May 2016 23:41:44 -0400 Received: from mga03.intel.com ([134.134.136.65]:15360) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1axngw-0002bE-4e for qemu-devel@nongnu.org; Tue, 03 May 2016 23:41:38 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP; 03 May 2016 20:41:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,574,1455004800"; d="scan'208";a="696512726" Received: from ll.sh.intel.com (HELO localhost) ([10.239.13.27]) by FMSMGA003.fm.intel.com with ESMTP; 03 May 2016 20:41:03 -0700 From: Liang Li To: qemu-devel@nongnu.org Date: Wed, 4 May 2016 11:40:56 +0800 Message-Id: <1462333259-3237-3-git-send-email-liang.z.li@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1462333259-3237-1-git-send-email-liang.z.li@intel.com> References: <1462333259-3237-1-git-send-email-liang.z.li@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.65 Subject: [Qemu-devel] [PATCH 2/5] migration: Fix a potential issue X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: amit.shah@redhat.com, Liang Li , dgilbert@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Signed-off-by: Liang Li --- 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;