From nobody Fri Oct 24 22:16:59 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1518771583722564.1440251637563; Fri, 16 Feb 2018 00:59:43 -0800 (PST) Received: from localhost ([::1]:53274 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1embrl-0006m3-Qg for importer@patchew.org; Fri, 16 Feb 2018 03:59:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44483) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1embfm-0004UK-Ve for qemu-devel@nongnu.org; Fri, 16 Feb 2018 03:47:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1embfl-0001Mi-PV for qemu-devel@nongnu.org; Fri, 16 Feb 2018 03:47:15 -0500 Received: from mga17.intel.com ([192.55.52.151]:12665) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1embfl-0001Da-DH for qemu-devel@nongnu.org; Fri, 16 Feb 2018 03:47:13 -0500 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Feb 2018 00:47:12 -0800 Received: from hz-desktop.sh.intel.com (HELO localhost) ([10.239.13.35]) by orsmga003.jf.intel.com with ESMTP; 16 Feb 2018 00:47:10 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,519,1511856000"; d="scan'208";a="28535525" From: Haozhong Zhang To: qemu-devel@nongnu.org Date: Fri, 16 Feb 2018 16:46:13 +0800 Message-Id: <20180216084615.26483-7-haozhong.zhang@intel.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180216084615.26483-1-haozhong.zhang@intel.com> References: <20180216084615.26483-1-haozhong.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.151 Subject: [Qemu-devel] [PATCH v3 6/8] migration/ram: ensure write persistence on loading normal 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+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" When loading a normal page to persistent memory, load its data by libpmem function pmem_memcpy_nodrain() instead of memcpy(). Combined with a call to pmem_drain() at the end of memory loading, we can guarantee all those normal pages are persistenly loaded to PMEM. Signed-off-by: Haozhong Zhang --- include/migration/qemu-file-types.h | 2 ++ include/qemu/pmem.h | 1 + migration/qemu-file.c | 29 +++++++++++++++++++---------- migration/ram.c | 2 +- stubs/pmem.c | 5 +++++ tests/Makefile.include | 2 +- 6 files changed, 29 insertions(+), 12 deletions(-) diff --git a/include/migration/qemu-file-types.h b/include/migration/qemu-f= ile-types.h index bd6d7dd7f9..c7c3f665f9 100644 --- a/include/migration/qemu-file-types.h +++ b/include/migration/qemu-file-types.h @@ -33,6 +33,8 @@ void qemu_put_byte(QEMUFile *f, int v); void qemu_put_be16(QEMUFile *f, unsigned int v); void qemu_put_be32(QEMUFile *f, unsigned int v); void qemu_put_be64(QEMUFile *f, uint64_t v); +size_t qemu_get_buffer_common(QEMUFile *f, uint8_t *buf, size_t size, + bool is_pmem); size_t qemu_get_buffer(QEMUFile *f, uint8_t *buf, size_t size); =20 int qemu_get_byte(QEMUFile *f); diff --git a/include/qemu/pmem.h b/include/qemu/pmem.h index ce96379f3c..127b87c326 100644 --- a/include/qemu/pmem.h +++ b/include/qemu/pmem.h @@ -16,6 +16,7 @@ #include #else /* !CONFIG_LIBPMEM */ =20 +void *pmem_memcpy_nodrain(void *pmemdest, const void *src, size_t len); void *pmem_memcpy_persist(void *pmemdest, const void *src, size_t len); void *pmem_memset_nodrain(void *pmemdest, int c, size_t len); void pmem_drain(void); diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 2ab2bf362d..d19f677796 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -26,6 +26,7 @@ #include "qemu-common.h" #include "qemu/error-report.h" #include "qemu/iov.h" +#include "qemu/pmem.h" #include "migration.h" #include "qemu-file.h" #include "trace.h" @@ -471,18 +472,13 @@ size_t qemu_peek_buffer(QEMUFile *f, uint8_t **buf, s= ize_t size, size_t offset) return size; } =20 -/* - * Read 'size' bytes of data from the file into buf. - * 'size' can be larger than the internal buffer. - * - * It will return size bytes unless there was an error, in which case it w= ill - * return as many as it managed to read (assuming blocking fd's which - * all current QEMUFile are) - */ -size_t qemu_get_buffer(QEMUFile *f, uint8_t *buf, size_t size) +size_t qemu_get_buffer_common(QEMUFile *f, uint8_t *buf, size_t size, + bool is_pmem) { size_t pending =3D size; size_t done =3D 0; + void *(*memcpy_func)(void *d, const void *s, size_t n) =3D + is_pmem ? pmem_memcpy_nodrain : memcpy; =20 while (pending > 0) { size_t res; @@ -492,7 +488,7 @@ size_t qemu_get_buffer(QEMUFile *f, uint8_t *buf, size_= t size) if (res =3D=3D 0) { return done; } - memcpy(buf, src, res); + memcpy_func(buf, src, res); qemu_file_skip(f, res); buf +=3D res; pending -=3D res; @@ -501,6 +497,19 @@ size_t qemu_get_buffer(QEMUFile *f, uint8_t *buf, size= _t size) return done; } =20 +/* + * Read 'size' bytes of data from the file into buf. + * 'size' can be larger than the internal buffer. + * + * It will return size bytes unless there was an error, in which case it w= ill + * return as many as it managed to read (assuming blocking fd's which + * all current QEMUFile are) + */ +size_t qemu_get_buffer(QEMUFile *f, uint8_t *buf, size_t size) +{ + return qemu_get_buffer_common(f, buf, size, false); +} + /* * Read 'size' bytes of data from the file. * 'size' can be larger than the internal buffer. diff --git a/migration/ram.c b/migration/ram.c index cb93f9fafe..96f33018cf 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -2944,7 +2944,7 @@ static int ram_load(QEMUFile *f, void *opaque, int ve= rsion_id) break; =20 case RAM_SAVE_FLAG_PAGE: - qemu_get_buffer(f, host, TARGET_PAGE_SIZE); + qemu_get_buffer_common(f, host, TARGET_PAGE_SIZE, is_pmem); break; =20 case RAM_SAVE_FLAG_COMPRESS_PAGE: diff --git a/stubs/pmem.c b/stubs/pmem.c index a65b3bfc6b..e172f31174 100644 --- a/stubs/pmem.c +++ b/stubs/pmem.c @@ -26,3 +26,8 @@ void *pmem_memset_nodrain(void *pmemdest, int c, size_t l= en) void pmem_drain(void) { } + +void *pmem_memcpy_nodrain(void *pmemdest, const void *src, size_t len) +{ + return memcpy(pmemdest, src, len); +} diff --git a/tests/Makefile.include b/tests/Makefile.include index a1bcbffe12..9ffb0cf8eb 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -637,7 +637,7 @@ tests/test-qdev-global-props$(EXESUF): tests/test-qdev-= global-props.o \ $(test-qapi-obj-y) tests/test-vmstate$(EXESUF): tests/test-vmstate.o \ migration/vmstate.o migration/vmstate-types.o migration/qemu-file.o \ - migration/qemu-file-channel.o migration/qjson.o \ + migration/qemu-file-channel.o migration/qjson.o stubs/pmem.o \ $(test-io-obj-y) tests/test-timed-average$(EXESUF): tests/test-timed-average.o $(test-util-= obj-y) tests/test-base64$(EXESUF): tests/test-base64.o $(test-util-obj-y) --=20 2.16.1