From nobody Wed Oct 29 20:27:44 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 1525918428862848.5882719763813; Wed, 9 May 2018 19:13:48 -0700 (PDT) Received: from localhost ([::1]:59787 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGb5X-0006s3-Uz for importer@patchew.org; Wed, 09 May 2018 22:13:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37199) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGb19-0002Jx-Aq for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGb16-0006hT-Hn for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:15 -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 1fGb16-0006fc-67 for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:12 -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:11 -0700 Received: from robinhe-hp.sh.intel.com ([10.239.198.47]) by orsmga007.jf.intel.com with ESMTP; 09 May 2018 19:09:08 -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="39787321" From: junyan.he@gmx.com To: qemu-devel@nongnu.org Date: Thu, 10 May 2018 10:08:50 +0800 Message-Id: <1525918138-6189-2-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 1/9 V5] memory, exec: switch file ram allocation functions to 'flags' parameters 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 As more flag parameters besides the existing 'share' are going to be added to following functions memory_region_init_ram_from_file qemu_ram_alloc_from_fd qemu_ram_alloc_from_file let's switch them to use the 'flags' parameters so as to ease future flag additions. The existing 'share' flag is converted to the QEMU_RAM_SHARE bit in flags, and other flag bits are ignored by above functions right now. Signed-off-by: Haozhong Zhang --- backends/hostmem-file.c | 3 ++- exec.c | 7 ++++--- include/exec/memory.h | 10 ++++++++-- include/exec/ram_addr.h | 25 +++++++++++++++++++++++-- memory.c | 8 +++++--- numa.c | 2 +- 6 files changed, 43 insertions(+), 12 deletions(-) diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c index 134b08d..30df843 100644 --- a/backends/hostmem-file.c +++ b/backends/hostmem-file.c @@ -58,7 +58,8 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Err= or **errp) path =3D object_get_canonical_path(OBJECT(backend)); memory_region_init_ram_from_file(&backend->mr, OBJECT(backend), path, - backend->size, fb->align, backend->share, + backend->size, fb->align, + backend->share ? QEMU_RAM_SHARE : 0, fb->mem_path, errp); g_free(path); } diff --git a/exec.c b/exec.c index c7fcefa..fa33c29 100644 --- a/exec.c +++ b/exec.c @@ -2030,12 +2030,13 @@ static void ram_block_add(RAMBlock *new_block, Erro= r **errp, bool shared) =20 #ifdef __linux__ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, - bool share, int fd, + uint64_t flags, int fd, Error **errp) { RAMBlock *new_block; Error *local_err =3D NULL; int64_t file_size; + bool share =3D flags & QEMU_RAM_SHARE; =20 if (xen_enabled()) { error_setg(errp, "-mem-path not supported with Xen"); @@ -2091,7 +2092,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, Mem= oryRegion *mr, =20 =20 RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, - bool share, const char *mem_path, + uint64_t flags, const char *mem_path, Error **errp) { int fd; @@ -2103,7 +2104,7 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, M= emoryRegion *mr, return NULL; } =20 - block =3D qemu_ram_alloc_from_fd(size, mr, share, fd, errp); + block =3D qemu_ram_alloc_from_fd(size, mr, flags, fd, errp); if (!block) { if (created) { unlink(mem_path); diff --git a/include/exec/memory.h b/include/exec/memory.h index 31eae0a..0460313 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -507,6 +507,9 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr, void *host), Error **errp); #ifdef __linux__ + +#define QEMU_RAM_SHARE (1UL << 0) + /** * memory_region_init_ram_from_file: Initialize RAM memory region with a * mmap-ed backend. @@ -518,7 +521,10 @@ void memory_region_init_resizeable_ram(MemoryRegion *m= r, * @size: size of the region. * @align: alignment of the region base address; if 0, the default alignme= nt * (getpagesize()) will be used. - * @share: %true if memory must be mmaped with the MAP_SHARED flag + * @flags: specify properties of this memory region, which can be one or b= it-or + * of following values: + * - QEMU_RAM_SHARE: memory must be mmaped with the MAP_SHARED flag + * Other bits are ignored. * @path: the path in which to allocate the RAM. * @errp: pointer to Error*, to store an error if it happens. * @@ -530,7 +536,7 @@ void memory_region_init_ram_from_file(MemoryRegion *mr, const char *name, uint64_t size, uint64_t align, - bool share, + uint64_t flags, const char *path, Error **errp); =20 diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index cf2446a..b8b01d1 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -72,12 +72,33 @@ static inline unsigned long int ramblock_recv_bitmap_of= fset(void *host_addr, =20 long qemu_getrampagesize(void); unsigned long last_ram_page(void); + +/** + * qemu_ram_alloc_from_file, + * qemu_ram_alloc_from_fd: Allocate a ram block from the specified back + * file or device + * + * Parameters: + * @size: the size in bytes of the ram block + * @mr: the memory region where the ram block is + * @flags: specify the properties of the ram block, which can be one + * or bit-or of following values + * - QEMU_RAM_SHARE: mmap the back file or device with MAP_SHARED + * Other bits are ignored. + * @mem_path or @fd: specify the back file or device + * @errp: pointer to Error*, to store an error if it happens + * + * Return: + * On success, return a pointer to the ram block. + * On failure, return NULL. + */ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, - bool share, const char *mem_path, + uint64_t flags, const char *mem_path, Error **errp); RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, - bool share, int fd, + uint64_t flags, int fd, Error **errp); + RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr, Error **errp); RAMBlock *qemu_ram_alloc(ram_addr_t size, bool share, MemoryRegion *mr, diff --git a/memory.c b/memory.c index e70b64b..3522518 100644 --- a/memory.c +++ b/memory.c @@ -1552,7 +1552,7 @@ void memory_region_init_ram_from_file(MemoryRegion *m= r, const char *name, uint64_t size, uint64_t align, - bool share, + uint64_t flags, const char *path, Error **errp) { @@ -1561,7 +1561,7 @@ void memory_region_init_ram_from_file(MemoryRegion *m= r, mr->terminates =3D true; mr->destructor =3D memory_region_destructor_ram; mr->align =3D align; - mr->ram_block =3D qemu_ram_alloc_from_file(size, mr, share, path, errp= ); + mr->ram_block =3D qemu_ram_alloc_from_file(size, mr, flags, path, errp= ); mr->dirty_log_mask =3D tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; } =20 @@ -1577,7 +1577,9 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, mr->ram =3D true; mr->terminates =3D true; mr->destructor =3D memory_region_destructor_ram; - mr->ram_block =3D qemu_ram_alloc_from_fd(size, mr, share, fd, errp); + mr->ram_block =3D qemu_ram_alloc_from_fd(size, mr, + share ? QEMU_RAM_SHARE : 0, + fd, errp); mr->dirty_log_mask =3D tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; } #endif diff --git a/numa.c b/numa.c index 78a869e..d5b1578 100644 --- a/numa.c +++ b/numa.c @@ -457,7 +457,7 @@ static void allocate_system_memory_nonnuma(MemoryRegion= *mr, Object *owner, if (mem_path) { #ifdef __linux__ Error *err =3D NULL; - memory_region_init_ram_from_file(mr, owner, name, ram_size, 0, fal= se, + memory_region_init_ram_from_file(mr, owner, name, ram_size, 0, 0, mem_path, &err); if (err) { error_report_err(err); --=20 2.7.4 From nobody Wed Oct 29 20:27:44 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 152591828222864.37230759863678; Wed, 9 May 2018 19:11:22 -0700 (PDT) Received: from localhost ([::1]:59779 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGb3B-0004vh-6R for importer@patchew.org; Wed, 09 May 2018 22:11:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37216) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGb1C-0002Sm-6G for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGb1A-0006ij-Aa for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:18 -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 1fGb19-0006fc-UP for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:16 -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:15 -0700 Received: from robinhe-hp.sh.intel.com ([10.239.198.47]) by orsmga007.jf.intel.com with ESMTP; 09 May 2018 19:09:12 -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="39787329" From: junyan.he@gmx.com To: qemu-devel@nongnu.org Date: Thu, 10 May 2018 10:08:51 +0800 Message-Id: <1525918138-6189-3-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 2/9 V5] hostmem-file: add the 'pmem' option 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 QEMU emulates vNVDIMM labels and migrates vNVDIMM devices, it needs to know whether the backend storage is a real persistent memory, in order to decide whether special operations should be performed to ensure the data persistence. This boolean option 'pmem' allows users to specify whether the backend storage of memory-backend-file is a real persistent memory. If 'pmem=3Don', QEMU will set the flag RAM_PMEM in the RAM block of the corresponding memory region. Signed-off-by: Haozhong Zhang Reviewed-by: Stefan Hajnoczi --- backends/hostmem-file.c | 26 +++++++++++++++++++++++++- docs/nvdimm.txt | 14 ++++++++++++++ exec.c | 13 ++++++++++++- include/exec/memory.h | 2 ++ include/exec/ram_addr.h | 3 +++ qemu-options.hx | 7 +++++++ 6 files changed, 63 insertions(+), 2 deletions(-) diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c index 30df843..5d706d4 100644 --- a/backends/hostmem-file.c +++ b/backends/hostmem-file.c @@ -34,6 +34,7 @@ struct HostMemoryBackendFile { bool discard_data; char *mem_path; uint64_t align; + bool is_pmem; }; =20 static void @@ -59,7 +60,8 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Err= or **errp) memory_region_init_ram_from_file(&backend->mr, OBJECT(backend), path, backend->size, fb->align, - backend->share ? QEMU_RAM_SHARE : 0, + (backend->share ? QEMU_RAM_SHARE : 0) | + (fb->is_pmem ? QEMU_RAM_PMEM : 0), fb->mem_path, errp); g_free(path); } @@ -131,6 +133,25 @@ static void file_memory_backend_set_align(Object *o, V= isitor *v, error_propagate(errp, local_err); } =20 +static bool file_memory_backend_get_pmem(Object *o, Error **errp) +{ + return MEMORY_BACKEND_FILE(o)->is_pmem; +} + +static void file_memory_backend_set_pmem(Object *o, bool value, Error **er= rp) +{ + HostMemoryBackend *backend =3D MEMORY_BACKEND(o); + HostMemoryBackendFile *fb =3D MEMORY_BACKEND_FILE(o); + + if (host_memory_backend_mr_inited(backend)) { + error_setg(errp, "cannot change property 'pmem' of %s '%s'", + object_get_typename(o), backend->id); + return; + } + + fb->is_pmem =3D value; +} + static void file_backend_unparent(Object *obj) { HostMemoryBackend *backend =3D MEMORY_BACKEND(obj); @@ -162,6 +183,9 @@ file_backend_class_init(ObjectClass *oc, void *data) file_memory_backend_get_align, file_memory_backend_set_align, NULL, NULL, &error_abort); + object_class_property_add_bool(oc, "pmem", + file_memory_backend_get_pmem, file_memory_backend_set_pmem, + &error_abort); } =20 static void file_backend_instance_finalize(Object *o) diff --git a/docs/nvdimm.txt b/docs/nvdimm.txt index e903d8b..bcb2032 100644 --- a/docs/nvdimm.txt +++ b/docs/nvdimm.txt @@ -153,3 +153,17 @@ guest NVDIMM region mapping structure. This unarmed f= lag indicates guest software that this vNVDIMM device contains a region that cannot accept persistent writes. In result, for example, the guest Linux NVDIMM driver, marks such vNVDIMM device as read-only. + +If the vNVDIMM backend is on the host persistent memory that can be +accessed in SNIA NVM Programming Model [1] (e.g., Intel NVDIMM), it's +suggested to set the 'pmem' option of memory-backend-file to 'on'. When +'pmem=3Don' and QEMU is built with libpmem [2] support (configured with +--enable-libpmem), QEMU will take necessary operations to guarantee +the persistence of its own writes to the vNVDIMM backend (e.g., in +vNVDIMM label emulation and live migration). + +References +---------- + +[1] SNIA NVM Programming Model: https://www.snia.org/sites/default/files/t= echnical_work/final/NVMProgrammingModel_v1.2.pdf +[2] PMDK: http://pmem.io/pmdk/ diff --git a/exec.c b/exec.c index fa33c29..dedeb4d 100644 --- a/exec.c +++ b/exec.c @@ -52,6 +52,9 @@ #include #endif =20 +/* RAM is backed by the persistent memory. */ +#define RAM_PMEM (1 << 3) + #endif #include "qemu/rcu_queue.h" #include "qemu/main-loop.h" @@ -2037,6 +2040,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, Mem= oryRegion *mr, Error *local_err =3D NULL; int64_t file_size; bool share =3D flags & QEMU_RAM_SHARE; + bool is_pmem =3D flags & QEMU_RAM_PMEM; =20 if (xen_enabled()) { error_setg(errp, "-mem-path not supported with Xen"); @@ -2073,7 +2077,8 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, Mem= oryRegion *mr, new_block->mr =3D mr; new_block->used_length =3D size; new_block->max_length =3D size; - new_block->flags =3D share ? RAM_SHARED : 0; + new_block->flags =3D (share ? RAM_SHARED : 0) | + (is_pmem ? RAM_PMEM : 0); new_block->host =3D file_ram_alloc(new_block, size, fd, !file_size, er= rp); if (!new_block->host) { g_free(new_block); @@ -3836,6 +3841,11 @@ err: return ret; } =20 +bool ramblock_is_pmem(RAMBlock *rb) +{ + return rb->flags & RAM_PMEM; +} + #endif =20 void page_size_init(void) @@ -3934,3 +3944,4 @@ void mtree_print_dispatch(fprintf_function mon, void = *f, } =20 #endif + diff --git a/include/exec/memory.h b/include/exec/memory.h index 0460313..16385b5 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -509,6 +509,7 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr, #ifdef __linux__ =20 #define QEMU_RAM_SHARE (1UL << 0) +#define QEMU_RAM_PMEM (1UL << 1) =20 /** * memory_region_init_ram_from_file: Initialize RAM memory region with a @@ -524,6 +525,7 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr, * @flags: specify properties of this memory region, which can be one or b= it-or * of following values: * - QEMU_RAM_SHARE: memory must be mmaped with the MAP_SHARED flag + * - QEMU_RAM_PMEM: the backend @path is persistent memory * Other bits are ignored. * @path: the path in which to allocate the RAM. * @errp: pointer to Error*, to store an error if it happens. diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index b8b01d1..f8d8614 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -70,6 +70,8 @@ static inline unsigned long int ramblock_recv_bitmap_offs= et(void *host_addr, return host_addr_offset >> TARGET_PAGE_BITS; } =20 +bool ramblock_is_pmem(RAMBlock *rb); + long qemu_getrampagesize(void); unsigned long last_ram_page(void); =20 @@ -84,6 +86,7 @@ unsigned long last_ram_page(void); * @flags: specify the properties of the ram block, which can be one * or bit-or of following values * - QEMU_RAM_SHARE: mmap the back file or device with MAP_SHARED + * - QEMU_RAM_PMEM: the backend @mem_path or @fd is persistent me= mory * Other bits are ignored. * @mem_path or @fd: specify the back file or device * @errp: pointer to Error*, to store an error if it happens diff --git a/qemu-options.hx b/qemu-options.hx index c611766..3fe1121 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4047,6 +4047,13 @@ requires an alignment different than the default one= used by QEMU, eg the device DAX /dev/dax0.0 requires 2M alignment rather than 4K. In such cases, users can specify the required alignment via this option. =20 +The @option{pmem} option specifies whether the backend store specified +by @option{mem-path} is on the persistent memory that can be accessed +in the SNIA NVM programming model (e.g. Intel NVDIMM). +If @address@hidden, QEMU will take necessary operations to +guarantee the persistence of its own writes to @option{mem-path} +(e.g. in vNVDIMM label emulation and live migration). + @item -object memory-backend-ram,id=3D@var{id},merge=3D@var{on|off},dump= =3D@var{on|off},share=3D@var{on|off},prealloc=3D@var{on|off},size=3D@var{si= ze},host-nodes=3D@var{host-nodes},policy=3D@var{default|preferred|bind|inte= rleave} =20 Creates a memory backend object, which can be used to back the guest RAM. --=20 2.7.4 From nobody Wed Oct 29 20:27:44 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 1525918539001464.8707132754656; Wed, 9 May 2018 19:15:39 -0700 (PDT) Received: from localhost ([::1]:59800 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGb7G-0000Up-Ot for importer@patchew.org; Wed, 09 May 2018 22:15:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37240) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGb1F-0002Vn-0A for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGb1D-0006km-Qc for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:20 -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 1fGb1D-0006fc-ID for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:19 -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:19 -0700 Received: from robinhe-hp.sh.intel.com ([10.239.198.47]) by orsmga007.jf.intel.com with ESMTP; 09 May 2018 19:09:15 -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="39787342" From: junyan.he@gmx.com To: qemu-devel@nongnu.org Date: Thu, 10 May 2018 10:08:52 +0800 Message-Id: <1525918138-6189-4-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 3/9 V5] configure: add libpmem support 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 Add a pair of configure options --{enable,disable}-libpmem to control whether QEMU is compiled with PMDK libpmem [1]. QEMU may write to the host persistent memory (e.g. in vNVDIMM label emulation and live migration), so it must take the proper operations to ensure the persistence of its own writes. Depending on the CPU models and available instructions, the optimal operation can vary [2]. PMDK libpmem have already implemented those operations on multiple CPU models (x86 and ARM) and the logic to select the optimal ones, so QEMU can just use libpmem rather than re-implement them. [1] PMDK (formerly known as NMVL), https://github.com/pmem/pmdk/ [2] https://github.com/pmem/pmdk/blob/38bfa652721a37fd94c0130ce0e3f5d8baa3e= d40/src/libpmem/pmem.c#L33 Signed-off-by: Haozhong Zhang --- configure | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/configure b/configure index 1443422..cbb3793 100755 --- a/configure +++ b/configure @@ -456,6 +456,7 @@ jemalloc=3D"no" replication=3D"yes" vxhs=3D"" libxml2=3D"" +libpmem=3D"" =20 supported_cpu=3D"no" supported_os=3D"no" @@ -1379,6 +1380,10 @@ for opt do ;; --disable-git-update) git_update=3Dno ;; + --enable-libpmem) libpmem=3Dyes + ;; + --disable-libpmem) libpmem=3Dno + ;; *) echo "ERROR: unknown option $opt" echo "Try '$0 --help' for more information" @@ -1636,6 +1641,7 @@ disabled with --disable-FEATURE, default is enabled i= f available: crypto-afalg Linux AF_ALG crypto backend driver vhost-user vhost-user support capstone capstone disassembler support + libpmem libpmem support =20 NOTE: The object files are built at the place where configure is launched EOF @@ -5443,6 +5449,30 @@ EOF fi =20 ########################################## +# check for libpmem + +if test "$libpmem" !=3D "no"; then + cat > $TMPC < +int main(void) +{ + pmem_is_pmem(0, 0); + return 0; +} +EOF + libpmem_libs=3D"-lpmem" + if compile_prog "" "$libpmem_libs" ; then + libs_softmmu=3D"$libpmem_libs $libs_softmmu" + libpmem=3D"yes" + else + if test "$libpmem" =3D "yes" ; then + feature_not_found "libpmem" "Install nvml or pmdk" + fi + libpmem=3D"no" + fi +fi + +########################################## # End of CC checks # After here, no more $cc or $ld runs =20 @@ -5903,6 +5933,7 @@ echo "avx2 optimization $avx2_opt" echo "replication support $replication" echo "VxHS block device $vxhs" echo "capstone $capstone" +echo "libpmem support $libpmem" =20 if test "$sdl_too_old" =3D "yes"; then echo "-> Your SDL version is too old - please upgrade to have SDL support" @@ -6647,6 +6678,10 @@ if test "$vxhs" =3D "yes" ; then echo "VXHS_LIBS=3D$vxhs_libs" >> $config_host_mak fi =20 +if test "$libpmem" =3D "yes" ; then + echo "CONFIG_LIBPMEM=3Dy" >> $config_host_mak +fi + if test "$tcg_interpreter" =3D "yes"; then QEMU_INCLUDES=3D"-iquote \$(SRC_PATH)/tcg/tci $QEMU_INCLUDES" elif test "$ARCH" =3D "sparc64" ; then --=20 2.7.4 From nobody Wed Oct 29 20:27:44 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 1525918618359926.9220790728227; Wed, 9 May 2018 19:16:58 -0700 (PDT) Received: from localhost ([::1]:59811 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGb8b-0002Hh-JY for importer@patchew.org; Wed, 09 May 2018 22:16:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37258) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGb1K-0002lV-0i for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGb1H-0006lV-FJ for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:26 -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 1fGb1H-0006fc-3C for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:23 -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:22 -0700 Received: from robinhe-hp.sh.intel.com ([10.239.198.47]) by orsmga007.jf.intel.com with ESMTP; 09 May 2018 19:09:19 -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="39787347" From: junyan.he@gmx.com To: qemu-devel@nongnu.org Date: Thu, 10 May 2018 10:08:53 +0800 Message-Id: <1525918138-6189-5-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 4/9 V5] mem/nvdimm: ensure write persistence to PMEM in label emulation 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 Guest writes to vNVDIMM labels are intercepted and performed on the backend by QEMU. When the backend is a real persistent memort, QEMU needs to take proper operations to ensure its write persistence on the persistent memory. Otherwise, a host power failure may result in the loss of guest label configurations. Signed-off-by: Haozhong Zhang --- hw/mem/nvdimm.c | 9 ++++++++- include/qemu/pmem.h | 23 +++++++++++++++++++++++ stubs/Makefile.objs | 1 + stubs/pmem.c | 19 +++++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 include/qemu/pmem.h create mode 100644 stubs/pmem.c diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c index acb656b..0c962fd 100644 --- a/hw/mem/nvdimm.c +++ b/hw/mem/nvdimm.c @@ -23,6 +23,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/pmem.h" #include "qapi/error.h" #include "qapi/visitor.h" #include "hw/mem/nvdimm.h" @@ -155,11 +156,17 @@ static void nvdimm_write_label_data(NVDIMMDevice *nvd= imm, const void *buf, { MemoryRegion *mr; PCDIMMDevice *dimm =3D PC_DIMM(nvdimm); + bool is_pmem =3D object_property_get_bool(OBJECT(dimm->hostmem), + "pmem", NULL); uint64_t backend_offset; =20 nvdimm_validate_rw_label_data(nvdimm, size, offset); =20 - memcpy(nvdimm->label_data + offset, buf, size); + if (!is_pmem) { + memcpy(nvdimm->label_data + offset, buf, size); + } else { + pmem_memcpy_persist(nvdimm->label_data + offset, buf, size); + } =20 mr =3D host_memory_backend_get_memory(dimm->hostmem, &error_abort); backend_offset =3D memory_region_size(mr) - nvdimm->label_size + offse= t; diff --git a/include/qemu/pmem.h b/include/qemu/pmem.h new file mode 100644 index 0000000..00d6680 --- /dev/null +++ b/include/qemu/pmem.h @@ -0,0 +1,23 @@ +/* + * QEMU header file for libpmem. + * + * Copyright (c) 2018 Intel Corporation. + * + * Author: Haozhong Zhang + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#ifndef QEMU_PMEM_H +#define QEMU_PMEM_H + +#ifdef CONFIG_LIBPMEM +#include +#else /* !CONFIG_LIBPMEM */ + +void *pmem_memcpy_persist(void *pmemdest, const void *src, size_t len); + +#endif /* CONFIG_LIBPMEM */ + +#endif /* !QEMU_PMEM_H */ diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index 2d59d84..ba944b9 100644 --- a/stubs/Makefile.objs +++ b/stubs/Makefile.objs @@ -43,3 +43,4 @@ stub-obj-y +=3D xen-common.o stub-obj-y +=3D xen-hvm.o stub-obj-y +=3D pci-host-piix.o stub-obj-y +=3D ram-block.o +stub-obj-$(call lnot,$(CONFIG_LIBPMEM)) +=3D pmem.o \ No newline at end of file diff --git a/stubs/pmem.c b/stubs/pmem.c new file mode 100644 index 0000000..b4ec72d --- /dev/null +++ b/stubs/pmem.c @@ -0,0 +1,19 @@ +/* + * Stubs for libpmem. + * + * Copyright (c) 2018 Intel Corporation. + * + * Author: Haozhong Zhang + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include + +#include "qemu/pmem.h" + +void *pmem_memcpy_persist(void *pmemdest, const void *src, size_t len) +{ + return memcpy(pmemdest, src, len); +} --=20 2.7.4 From nobody Wed Oct 29 20:27:44 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 1525918296107390.53342695127026; Wed, 9 May 2018 19:11:36 -0700 (PDT) Received: from localhost ([::1]:59780 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGb3P-00055n-4k for importer@patchew.org; Wed, 09 May 2018 22:11:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37274) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGb1M-0002uj-IG for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGb1L-0006nO-2j for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:28 -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 1fGb1K-0006fc-Px for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:27 -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:26 -0700 Received: from robinhe-hp.sh.intel.com ([10.239.198.47]) by orsmga007.jf.intel.com with ESMTP; 09 May 2018 19:09:23 -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="39787355" From: junyan.he@gmx.com To: qemu-devel@nongnu.org Date: Thu, 10 May 2018 10:08:54 +0800 Message-Id: <1525918138-6189-6-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 5/9 V5] migration/ram: ensure write persistence on loading zero 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 zero page, check whether it will be loaded to persistent memory If yes, load it by libpmem function pmem_memset_nodrain(). Combined with a call to pmem_drain() at the end of RAM loading, we can guarantee all those zero pages are persistently loaded. Depending on the host HW/SW configurations, pmem_drain() can be "sfence". Therefore, we do not call pmem_drain() after each pmem_memset_nodrain(), or use pmem_memset_persist() (equally pmem_memset_nodrain() + pmem_drain()), in order to avoid unnecessary overhead. Signed-off-by: Haozhong Zhang --- include/qemu/pmem.h | 2 ++ migration/ram.c | 25 +++++++++++++++++++++---- migration/ram.h | 2 +- migration/rdma.c | 2 +- stubs/pmem.c | 9 +++++++++ 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/include/qemu/pmem.h b/include/qemu/pmem.h index 00d6680..9f39ce8 100644 --- a/include/qemu/pmem.h +++ b/include/qemu/pmem.h @@ -17,6 +17,8 @@ #else /* !CONFIG_LIBPMEM */ =20 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); =20 #endif /* CONFIG_LIBPMEM */ =20 diff --git a/migration/ram.c b/migration/ram.c index 912810c..e6ae9e3 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -51,6 +51,7 @@ #include "qemu/rcu_queue.h" #include "migration/colo.h" #include "migration/block.h" +#include "qemu/pmem.h" =20 /***********************************************************/ /* ram save/restore */ @@ -2529,11 +2530,16 @@ static inline void *host_from_ram_block_offset(RAMB= lock *block, * @host: host address for the zero page * @ch: what the page is filled from. We only support zero * @size: size of the zero page + * @is_pmem: whether @host is in the persistent memory */ -void ram_handle_compressed(void *host, uint8_t ch, uint64_t size) +void ram_handle_compressed(void *host, uint8_t ch, uint64_t size, bool is_= pmem) { if (ch !=3D 0 || !is_zero_range(host, size)) { - memset(host, ch, size); + if (!is_pmem) { + memset(host, ch, size); + } else { + pmem_memset_nodrain(host, ch, size); + } } } =20 @@ -2943,6 +2949,7 @@ static int ram_load(QEMUFile *f, void *opaque, int ve= rsion_id) bool postcopy_running =3D postcopy_is_running(); /* ADVISE is earlier, it shows the source has the postcopy capability = on */ bool postcopy_advised =3D postcopy_is_advised(); + bool need_pmem_drain =3D false; =20 seq_iter++; =20 @@ -2968,6 +2975,8 @@ static int ram_load(QEMUFile *f, void *opaque, int ve= rsion_id) ram_addr_t addr, total_ram_bytes; void *host =3D NULL; uint8_t ch; + RAMBlock *block =3D NULL; + bool is_pmem =3D false; =20 addr =3D qemu_get_be64(f); flags =3D addr & ~TARGET_PAGE_MASK; @@ -2984,7 +2993,7 @@ static int ram_load(QEMUFile *f, void *opaque, int ve= rsion_id) =20 if (flags & (RAM_SAVE_FLAG_ZERO | RAM_SAVE_FLAG_PAGE | RAM_SAVE_FLAG_COMPRESS_PAGE | RAM_SAVE_FLAG_XBZRLE)) { - RAMBlock *block =3D ram_block_from_stream(f, flags); + block =3D ram_block_from_stream(f, flags); =20 host =3D host_from_ram_block_offset(block, addr); if (!host) { @@ -2994,6 +3003,9 @@ static int ram_load(QEMUFile *f, void *opaque, int ve= rsion_id) } ramblock_recv_bitmap_set(block, host); trace_ram_load_loop(block->idstr, (uint64_t)addr, flags, host); + + is_pmem =3D ramblock_is_pmem(block); + need_pmem_drain =3D need_pmem_drain || is_pmem; } =20 switch (flags & ~RAM_SAVE_FLAG_CONTINUE) { @@ -3047,7 +3059,7 @@ static int ram_load(QEMUFile *f, void *opaque, int ve= rsion_id) =20 case RAM_SAVE_FLAG_ZERO: ch =3D qemu_get_byte(f); - ram_handle_compressed(host, ch, TARGET_PAGE_SIZE); + ram_handle_compressed(host, ch, TARGET_PAGE_SIZE, is_pmem); break; =20 case RAM_SAVE_FLAG_PAGE: @@ -3090,6 +3102,11 @@ static int ram_load(QEMUFile *f, void *opaque, int v= ersion_id) } =20 ret |=3D wait_for_decompress_done(); + + if (need_pmem_drain) { + pmem_drain(); + } + rcu_read_unlock(); trace_ram_load_complete(ret, seq_iter); return ret; diff --git a/migration/ram.h b/migration/ram.h index 5030be1..5c6a288 100644 --- a/migration/ram.h +++ b/migration/ram.h @@ -57,7 +57,7 @@ int ram_postcopy_send_discard_bitmap(MigrationState *ms); int ram_discard_range(const char *block_name, uint64_t start, size_t lengt= h); int ram_postcopy_incoming_init(MigrationIncomingState *mis); =20 -void ram_handle_compressed(void *host, uint8_t ch, uint64_t size); +void ram_handle_compressed(void *host, uint8_t ch, uint64_t size, bool is_= pmem); =20 int ramblock_recv_bitmap_test(RAMBlock *rb, void *host_addr); bool ramblock_recv_bitmap_test_byte_offset(RAMBlock *rb, uint64_t byte_off= set); diff --git a/migration/rdma.c b/migration/rdma.c index da474fc..573bcd2 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -3229,7 +3229,7 @@ static int qemu_rdma_registration_handle(QEMUFile *f,= void *opaque) host_addr =3D block->local_host_addr + (comp->offset - block->offset); =20 - ram_handle_compressed(host_addr, comp->value, comp->length); + ram_handle_compressed(host_addr, comp->value, comp->length, fa= lse); break; =20 case RDMA_CONTROL_REGISTER_FINISHED: diff --git a/stubs/pmem.c b/stubs/pmem.c index b4ec72d..2f07ae0 100644 --- a/stubs/pmem.c +++ b/stubs/pmem.c @@ -17,3 +17,12 @@ void *pmem_memcpy_persist(void *pmemdest, const void *sr= c, size_t len) { return memcpy(pmemdest, src, len); } + +void *pmem_memset_nodrain(void *pmemdest, int c, size_t len) +{ + return memset(pmemdest, c, len); +} + +void pmem_drain(void) +{ +} --=20 2.7.4 From nobody Wed Oct 29 20:27:44 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 1525918710411557.1229368908781; Wed, 9 May 2018 19:18:30 -0700 (PDT) Received: from localhost ([::1]:59814 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGbA3-0002sM-K9 for importer@patchew.org; Wed, 09 May 2018 22:18:27 -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 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 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 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="39787364" 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+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 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 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); =20 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 */ =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 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, 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; @@ -502,6 +498,19 @@ size_t qemu_get_buffer(QEMUFile *f, uint8_t *buf, size= _t 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) +{ + 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 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 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 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 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) --=20 2.7.4 From nobody Wed Oct 29 20:27:44 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 1525918442957516.0520774738661; Wed, 9 May 2018 19:14:02 -0700 (PDT) Received: from localhost ([::1]:59790 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGb5m-000753-62 for importer@patchew.org; Wed, 09 May 2018 22:14:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37304) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGb1V-0003MW-59 for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGb1S-0006og-4C for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:37 -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 1fGb1R-0006fc-Rm for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:34 -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:33 -0700 Received: from robinhe-hp.sh.intel.com ([10.239.198.47]) by orsmga007.jf.intel.com with ESMTP; 09 May 2018 19:09:30 -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="39787372" From: junyan.he@gmx.com To: qemu-devel@nongnu.org Date: Thu, 10 May 2018 10:08:56 +0800 Message-Id: <1525918138-6189-8-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 7/9 V5] migration/ram: ensure write persistence on loading compressed 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 compressed page to persistent memory, flush CPU cache after the data is decompressed. Combined with a call to pmem_drain() at the end of memory loading, we can guarantee those compressed pages are persistently loaded to PMEM. Signed-off-by: Haozhong Zhang --- include/qemu/pmem.h | 1 + migration/ram.c | 10 ++++++++-- stubs/pmem.c | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/qemu/pmem.h b/include/qemu/pmem.h index cb9fa5f..c9140fb 100644 --- a/include/qemu/pmem.h +++ b/include/qemu/pmem.h @@ -20,6 +20,7 @@ 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); +void pmem_flush(const void *addr, size_t len); =20 #endif /* CONFIG_LIBPMEM */ =20 diff --git a/migration/ram.c b/migration/ram.c index 2a180bc..e0f3dbc 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -286,6 +286,7 @@ struct DecompressParam { uint8_t *compbuf; int len; z_stream stream; + bool is_pmem; }; typedef struct DecompressParam DecompressParam; =20 @@ -2591,6 +2592,9 @@ static void *do_data_decompress(void *opaque) error_report("decompress data failed"); qemu_file_set_error(decomp_file, ret); } + if (param->is_pmem) { + pmem_flush(des, len); + } =20 qemu_mutex_lock(&decomp_done_lock); param->done =3D true; @@ -2702,7 +2706,8 @@ exit: } =20 static void decompress_data_with_multi_threads(QEMUFile *f, - void *host, int len) + void *host, int len, + bool is_pmem) { int idx, thread_count; =20 @@ -2716,6 +2721,7 @@ static void decompress_data_with_multi_threads(QEMUFi= le *f, qemu_get_buffer(f, decomp_param[idx].compbuf, len); decomp_param[idx].des =3D host; decomp_param[idx].len =3D len; + decomp_param[idx].is_pmem =3D is_pmem; qemu_cond_signal(&decomp_param[idx].cond); qemu_mutex_unlock(&decomp_param[idx].mutex); break; @@ -3073,7 +3079,7 @@ static int ram_load(QEMUFile *f, void *opaque, int ve= rsion_id) ret =3D -EINVAL; break; } - decompress_data_with_multi_threads(f, host, len); + decompress_data_with_multi_threads(f, host, len, is_pmem); break; =20 case RAM_SAVE_FLAG_XBZRLE: diff --git a/stubs/pmem.c b/stubs/pmem.c index b50c35e..9e7d86a 100644 --- a/stubs/pmem.c +++ b/stubs/pmem.c @@ -31,3 +31,7 @@ void *pmem_memcpy_nodrain(void *pmemdest, const void *src= , size_t len) { return memcpy(pmemdest, src, len); } + +void pmem_flush(const void *addr, size_t len) +{ +} --=20 2.7.4 From nobody Wed Oct 29 20:27:44 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 From nobody Wed Oct 29 20:27:44 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 1525918496960161.65467016812863; Wed, 9 May 2018 19:14:56 -0700 (PDT) Received: from localhost ([::1]:59795 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGb6Z-00081C-9n for importer@patchew.org; Wed, 09 May 2018 22:14:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37326) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGb1a-0003W9-0v for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGb1Z-0006qA-3e for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:42 -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 1fGb1Y-0006fc-Qa for qemu-devel@nongnu.org; Wed, 09 May 2018 22:09:41 -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:40 -0700 Received: from robinhe-hp.sh.intel.com ([10.239.198.47]) by orsmga007.jf.intel.com with ESMTP; 09 May 2018 19:09:37 -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="39787384" From: junyan.he@gmx.com To: qemu-devel@nongnu.org Date: Thu, 10 May 2018 10:08:58 +0800 Message-Id: <1525918138-6189-10-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 9/9 V5] migration/ram: Add check and info message to nvdimm post copy. 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: 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 The nvdimm kind memory does not support post copy now. We disable post copy if we have nvdimm memory and print some log hint to user. Signed-off-by: Junyan He --- migration/ram.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/migration/ram.c b/migration/ram.c index afe227e..aa6bb74 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3120,6 +3120,15 @@ static int ram_load(QEMUFile *f, void *opaque, int v= ersion_id) =20 static bool ram_has_postcopy(void *opaque) { + RAMBlock *rb; + RAMBLOCK_FOREACH(rb) { + if (ramblock_is_pmem(rb)) { + info_report("Block: %s, host: %p is a nvdimm memory, postcopy" + "is not supported now!", rb->idstr, rb->host); + return false; + } + } + return migrate_postcopy_ram(); } =20 --=20 2.7.4