From nobody Thu Oct 30 15:20:09 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1525918362395229.5367308232751; Wed, 9 May 2018 19:12:42 -0700 (PDT) Received: from localhost ([::1]:59782 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGb4T-00060r-Fv for importer@patchew.org; Wed, 09 May 2018 22:12:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37315) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGb1Y-0003Q1-3i for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGb1V-0006pL-PT for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:38 -0400 Received: from mga01.intel.com ([192.55.52.88]:24344) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fGb1V-0006fc-Ee for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:37 -0400 Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 May 2018 19:09:37 -0700 Received: from robinhe-hp.sh.intel.com ([10.239.198.47]) by orsmga007.jf.intel.com with ESMTP; 09 May 2018 19:09:33 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,383,1520924400"; d="scan'208";a="39787377" From: junyan.he@gmx.com To: qemu-devel@nongnu.org Date: Thu, 10 May 2018 10:08:57 +0800 Message-Id: <1525918138-6189-9-git-send-email-junyan.he@gmx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1525918138-6189-1-git-send-email-junyan.he@gmx.com> References: <1525918138-6189-1-git-send-email-junyan.he@gmx.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.88 Subject: [Qemu-devel] [PATCH 8/9 V5] 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 , xiaoguangrong.eric@gmail.com, crosthwaite.peter@gmail.com, mst@redhat.com, dgilbert@redhat.com, ehabkost@redhat.com, quintela@redhat.com, Junyan He , stefanha@redhat.com, pbonzini@redhat.com, imammedo@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Junyan He 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 | 6 +++--- migration/xbzrle.c | 8 ++++++-- migration/xbzrle.h | 3 ++- tests/Makefile.include | 2 +- tests/test-xbzrle.c | 4 ++-- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index e0f3dbc..afe227e 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2441,7 +2441,7 @@ static void ram_save_pending(QEMUFile *f, void *opaqu= e, uint64_t max_size, } } =20 -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_p= mem) { unsigned int xh_len; int xh_flags; @@ -2467,7 +2467,7 @@ static int load_xbzrle(QEMUFile *f, ram_addr_t addr, = void *host) =20 /* decode RLE */ if (xbzrle_decode_buffer(loaded_data, xh_len, host, - TARGET_PAGE_SIZE) =3D=3D -1) { + TARGET_PAGE_SIZE, is_pmem) =3D=3D -1) { error_report("Failed to load XBZRLE page - decode error!"); return -1; } @@ -3083,7 +3083,7 @@ static int ram_load(QEMUFile *f, void *opaque, int ve= rsion_id) break; =20 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 =3D -EINVAL; diff --git a/migration/xbzrle.c b/migration/xbzrle.c index 1ba482d..ca713c3 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" =20 /* @@ -126,11 +127,14 @@ int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *n= ew_buf, int slen, return d; } =20 -int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int dlen) +int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int dlen, + bool is_pmem) { int i =3D 0, d =3D 0; int ret; uint32_t count =3D 0; + void *(*memcpy_func)(void *d, const void *s, size_t n) =3D + is_pmem ? pmem_memcpy_nodrain : memcpy; =20 while (i < slen) { =20 @@ -167,7 +171,7 @@ int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_= t *dst, int dlen) return -1; } =20 - memcpy(dst + d, src + i, count); + memcpy_func(dst + d, src + i, count); d +=3D count; i +=3D count; } diff --git a/migration/xbzrle.h b/migration/xbzrle.h index a0db507..f18f679 100644 --- a/migration/xbzrle.h +++ b/migration/xbzrle.h @@ -17,5 +17,6 @@ int xbzrle_encode_buffer(uint8_t *old_buf, uint8_t *new_buf, int slen, uint8_t *dst, int dlen); =20 -int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int dlen); +int xbzrle_decode_buffer(uint8_t *src, int slen, uint8_t *dst, int dlen, + bool is_pmem); #endif diff --git a/tests/Makefile.include b/tests/Makefile.include index 5c25b9b..23d7162 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -631,7 +631,7 @@ tests/test-thread-pool$(EXESUF): tests/test-thread-pool= .o $(test-block-obj-y) tests/test-iov$(EXESUF): tests/test-iov.o $(test-util-obj-y) tests/test-hbitmap$(EXESUF): tests/test-hbitmap.o $(test-util-obj-y) $(tes= t-crypto-obj-y) tests/test-x86-cpuid$(EXESUF): tests/test-x86-cpuid.o -tests/test-xbzrle$(EXESUF): tests/test-xbzrle.o migration/xbzrle.o migrati= on/page_cache.o $(test-util-obj-y) +tests/test-xbzrle$(EXESUF): tests/test-xbzrle.o migration/xbzrle.o migrati= on/page_cache.o stubs/pmem.o $(test-util-obj-y) tests/test-cutils$(EXESUF): tests/test-cutils.o util/cutils.o $(test-util-= obj-y) tests/test-int128$(EXESUF): tests/test-int128.o tests/rcutorture$(EXESUF): tests/rcutorture.o $(test-util-obj-y) diff --git a/tests/test-xbzrle.c b/tests/test-xbzrle.c index f5e08de..9afa0c4 100644 --- a/tests/test-xbzrle.c +++ b/tests/test-xbzrle.c @@ -101,7 +101,7 @@ static void test_encode_decode_1_byte(void) PAGE_SIZE); g_assert(dlen =3D=3D (uleb128_encode_small(&buf[0], 4095) + 2)); =20 - rc =3D xbzrle_decode_buffer(compressed, dlen, buffer, PAGE_SIZE); + rc =3D xbzrle_decode_buffer(compressed, dlen, buffer, PAGE_SIZE, false= ); g_assert(rc =3D=3D PAGE_SIZE); g_assert(memcmp(test, buffer, PAGE_SIZE) =3D=3D 0); =20 @@ -156,7 +156,7 @@ static void encode_decode_range(void) dlen =3D xbzrle_encode_buffer(test, buffer, PAGE_SIZE, compressed, PAGE_SIZE); =20 - rc =3D xbzrle_decode_buffer(compressed, dlen, test, PAGE_SIZE); + rc =3D xbzrle_decode_buffer(compressed, dlen, test, PAGE_SIZE, false); g_assert(rc < PAGE_SIZE); g_assert(memcmp(test, buffer, PAGE_SIZE) =3D=3D 0); =20 --=20 2.7.4