From patchwork Thu May 10 02:08:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: junyan.he@gmx.com X-Patchwork-Id: 10391075 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 901FC60540 for ; Thu, 10 May 2018 02:18:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F9C3289DA for ; Thu, 10 May 2018 02:18:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 746D2289E3; Thu, 10 May 2018 02:18:11 +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=-7.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI,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 B636B289DA for ; Thu, 10 May 2018 02:18:10 +0000 (UTC) Received: from localhost ([::1]:59814 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGb9m-0002sM-0o for patchwork-qemu-devel@patchwork.kernel.org; Wed, 09 May 2018 22:18:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37292) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGb1Q-00036k-5S for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGb1O-0006oA-Pf for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:32 -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 1fGb1O-0006fc-GW for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:30 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False 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:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,383,1520924400"; d="scan'208";a="39787364" Received: from robinhe-hp.sh.intel.com ([10.239.198.47]) by orsmga007.jf.intel.com with ESMTP; 09 May 2018 19:09:26 -0700 From: junyan.he@gmx.com To: qemu-devel@nongnu.org Date: Thu, 10 May 2018 10:08:55 +0800 Message-Id: <1525918138-6189-7-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 6/9 V5] 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 , 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Junyan He 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-file-types.h index bd6d7dd..c7c3f66 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); int qemu_get_byte(QEMUFile *f); diff --git a/include/qemu/pmem.h b/include/qemu/pmem.h index 9f39ce8..cb9fa5f 100644 --- a/include/qemu/pmem.h +++ b/include/qemu/pmem.h @@ -16,6 +16,7 @@ #include #else /* !CONFIG_LIBPMEM */ +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 0463f4c..1ec31d5 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, size_t size, size_t offset) return size; } -/* - * 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 will - * 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 = size; size_t done = 0; + void *(*memcpy_func)(void *d, const void *s, size_t n) = + is_pmem ? pmem_memcpy_nodrain : memcpy; 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 == 0) { return done; } - memcpy(buf, src, res); + memcpy_func(buf, src, res); qemu_file_skip(f, res); buf += res; pending -= res; @@ -502,6 +498,19 @@ size_t qemu_get_buffer(QEMUFile *f, uint8_t *buf, size_t size) } /* + * 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 will + * 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 e6ae9e3..2a180bc 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3063,7 +3063,7 @@ static int ram_load(QEMUFile *f, void *opaque, int version_id) break; 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; case RAM_SAVE_FLAG_COMPRESS_PAGE: diff --git a/stubs/pmem.c b/stubs/pmem.c index 2f07ae0..b50c35e 100644 --- a/stubs/pmem.c +++ b/stubs/pmem.c @@ -26,3 +26,8 @@ void *pmem_memset_nodrain(void *pmemdest, int c, size_t len) 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 3b9a5e3..5c25b9b 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -652,7 +652,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)