From patchwork Wed Feb 7 07:33:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haozhong Zhang X-Patchwork-Id: 10204699 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1FE21602D8 for ; Wed, 7 Feb 2018 07:40:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DCDB28DC4 for ; Wed, 7 Feb 2018 07:40:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0275A28E3D; Wed, 7 Feb 2018 07:40:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 52C8628DC4 for ; Wed, 7 Feb 2018 07:40:25 +0000 (UTC) Received: from localhost ([::1]:58773 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejKL9-0003YY-PX for patchwork-qemu-devel@patchwork.kernel.org; Wed, 07 Feb 2018 02:40:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43962) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejKFO-00053w-HT for qemu-devel@nongnu.org; Wed, 07 Feb 2018 02:34:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ejKFN-0000gY-8P for qemu-devel@nongnu.org; Wed, 07 Feb 2018 02:34:26 -0500 Received: from mga09.intel.com ([134.134.136.24]:13680) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ejKFM-0000Td-Rr for qemu-devel@nongnu.org; Wed, 07 Feb 2018 02:34:25 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Feb 2018 23:34:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,471,1511856000"; d="scan'208";a="17874031" Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.13.35]) by fmsmga002.fm.intel.com with ESMTP; 06 Feb 2018 23:34:22 -0800 From: Haozhong Zhang To: qemu-devel@nongnu.org Date: Wed, 7 Feb 2018 15:33:31 +0800 Message-Id: <20180207073331.14158-9-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180207073331.14158-1-haozhong.zhang@intel.com> References: <20180207073331.14158-1-haozhong.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.24 Subject: [Qemu-devel] [PATCH v2 8/8] migration/ram: ensure write persistence on loading xbzrle pages to PMEM 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: Haozhong Zhang , Xiao Guangrong , mst@redhat.com, Juan Quintela , dgilbert@redhat.com, Stefan Hajnoczi , Paolo Bonzini , Igor Mammedov , Dan Williams , Eduardo Habkost Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP When loading a xbzrle encoded page to persistent memory, load the data via libpmem function pmem_memcpy_nodrain() instead of memcpy(). Combined with a call to pmem_drain() at the end of memory loading, we can guarantee those xbzrle encoded pages are persistently loaded to PMEM. Signed-off-by: Haozhong Zhang --- migration/ram.c | 15 ++++++++++----- migration/xbzrle.c | 20 ++++++++++++++++++-- migration/xbzrle.h | 1 + 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 924d2b9537..87f977617d 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2388,10 +2388,10 @@ static void ram_save_pending(QEMUFile *f, void *opaque, uint64_t max_size, } } -static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void *host) +static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void *host, bool is_pmem) { unsigned int xh_len; - int xh_flags; + int xh_flags, rc; uint8_t *loaded_data; /* extract RLE header */ @@ -2413,8 +2413,13 @@ static int load_xbzrle(QEMUFile *f, ram_addr_t addr, void *host) qemu_get_buffer_in_place(f, &loaded_data, xh_len); /* decode RLE */ - if (xbzrle_decode_buffer(loaded_data, xh_len, host, - TARGET_PAGE_SIZE) == -1) { + if (!is_pmem) { + rc = xbzrle_decode_buffer(loaded_data, xh_len, host, TARGET_PAGE_SIZE); + } else { + rc = xbzrle_decode_buffer_to_pmem(loaded_data, xh_len, host, + TARGET_PAGE_SIZE); + } + if (rc == -1) { error_report("Failed to load XBZRLE page - decode error!"); return -1; } @@ -2974,7 +2979,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) break; case RAM_SAVE_FLAG_XBZRLE: - if (load_xbzrle(f, addr, host) < 0) { + if (load_xbzrle(f, addr, host, is_pmem) < 0) { error_report("Failed to decompress XBZRLE page at " RAM_ADDR_FMT, addr); ret = -EINVAL; diff --git a/migration/xbzrle.c b/migration/xbzrle.c index 1ba482ded9..499d8e1bfb 100644 --- a/migration/xbzrle.c +++ b/migration/xbzrle.c @@ -12,6 +12,7 @@ */ #include "qemu/osdep.h" #include "qemu/cutils.h" +#include "qemu/pmem.h" #include "xbzrle.h" /* @@ -126,7 +127,8 @@ int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen, return d; } -int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int dlen) +static int xbzrle_decode_buffer_common(uint8_t *src, int slen, uint8_t *dst, + int dlen, bool is_pmem) { int i = 0, d = 0; int ret; @@ -167,10 +169,24 @@ int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int dlen) return -1; } - memcpy(dst + d, src + i, count); + if (!is_pmem) { + memcpy(dst + d, src + i, count); + } else { + pmem_memcpy_nodrain(dst + d, src + i, count); + } d += count; i += count; } return d; } + +int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int dlen) +{ + return xbzrle_decode_buffer_common(src, slen, dst, dlen, false); +} + +int xbzrle_decode_buffer_to_pmem(uint8_t *src, int slen, uint8_t *dst, int dlen) +{ + return xbzrle_decode_buffer_common(src, slen, dst, dlen, true); +} diff --git a/migration/xbzrle.h b/migration/xbzrle.h index a0db507b9c..ac5ae32666 100644 --- a/migration/xbzrle.h +++ b/migration/xbzrle.h @@ -18,4 +18,5 @@ int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen, uint8_t *dst, int dlen); int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int dlen); +int xbzrle_decode_buffer_to_pmem(uint8_t *src, int slen, uint8_t *dst, int dlen); #endif