From nobody Fri Mar 29 01:41:17 2024 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 1531203053711683.0302801009991; Mon, 9 Jul 2018 23:10:53 -0700 (PDT) Received: from localhost ([::1]:45930 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fclrQ-0002B7-OI for importer@patchew.org; Tue, 10 Jul 2018 02:10:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45247) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fclnL-0007kL-4T for qemu-devel@nongnu.org; Tue, 10 Jul 2018 02:06:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fclnK-0007Io-72 for qemu-devel@nongnu.org; Tue, 10 Jul 2018 02:06:39 -0400 Received: from mga01.intel.com ([192.55.52.88]:23582) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fclnJ-0007HY-UO for qemu-devel@nongnu.org; Tue, 10 Jul 2018 02:06:38 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jul 2018 23:06:37 -0700 Received: from natrouter.sh.intel.com (HELO robinhe-hp.domain) ([10.239.13.3]) by FMSMGA003.fm.intel.com with ESMTP; 09 Jul 2018 23:06:35 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,333,1526367600"; d="scan'208";a="63525896" From: junyan.he@gmx.com To: qemu-devel@nongnu.org Date: Tue, 10 Jul 2018 14:06:24 +0800 Message-Id: <1531202789-31006-3-git-send-email-junyan.he@gmx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531202789-31006-1-git-send-email-junyan.he@gmx.com> References: <1531202789-31006-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/7 V8] memory, exec: Expose all memory block related flags. 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 We need to use these flags in other files rather than just in exec.c, For example, RAM_SHARED should be used when create a ram block from file. We expose them the exec/memory.h Signed-off-by: Junyan He Reviewed-by: Stefan Hajnoczi Reviewed-by: Igor Mammedov --- exec.c | 20 -------------------- include/exec/memory.h | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/exec.c b/exec.c index 4f5df07..cc042dc 100644 --- a/exec.c +++ b/exec.c @@ -87,26 +87,6 @@ AddressSpace address_space_memory; =20 MemoryRegion io_mem_rom, io_mem_notdirty; static MemoryRegion io_mem_unassigned; - -/* RAM is pre-allocated and passed into qemu_ram_alloc_from_ptr */ -#define RAM_PREALLOC (1 << 0) - -/* RAM is mmap-ed with MAP_SHARED */ -#define RAM_SHARED (1 << 1) - -/* Only a portion of RAM (used_length) is actually used, and migrated. - * This used_length size can change across reboots. - */ -#define RAM_RESIZEABLE (1 << 2) - -/* UFFDIO_ZEROPAGE is available on this RAMBlock to atomically - * zero the page and wake waiting processes. - * (Set during postcopy) - */ -#define RAM_UF_ZEROPAGE (1 << 3) - -/* RAM can be migrated */ -#define RAM_MIGRATABLE (1 << 4) #endif =20 #ifdef TARGET_PAGE_BITS_VARY diff --git a/include/exec/memory.h b/include/exec/memory.h index 448d41a..6d0af29 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -103,6 +103,26 @@ struct IOMMUNotifier { }; typedef struct IOMMUNotifier IOMMUNotifier; =20 +/* RAM is pre-allocated and passed into qemu_ram_alloc_from_ptr */ +#define RAM_PREALLOC (1 << 0) + +/* RAM is mmap-ed with MAP_SHARED */ +#define RAM_SHARED (1 << 1) + +/* Only a portion of RAM (used_length) is actually used, and migrated. + * This used_length size can change across reboots. + */ +#define RAM_RESIZEABLE (1 << 2) + +/* UFFDIO_ZEROPAGE is available on this RAMBlock to atomically + * zero the page and wake waiting processes. + * (Set during postcopy) + */ +#define RAM_UF_ZEROPAGE (1 << 3) + +/* RAM can be migrated */ +#define RAM_MIGRATABLE (1 << 4) + static inline void iommu_notifier_init(IOMMUNotifier *n, IOMMUNotify fn, IOMMUNotifierFlag flags, hwaddr start, hwaddr end, --=20 2.7.4 From nobody Fri Mar 29 01:41:17 2024 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 1531202919420611.5747938008642; Mon, 9 Jul 2018 23:08:39 -0700 (PDT) Received: from localhost ([::1]:45916 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fclp8-00008m-Jx for importer@patchew.org; Tue, 10 Jul 2018 02:08:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45240) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fclnK-0007kH-Hj for qemu-devel@nongnu.org; Tue, 10 Jul 2018 02:06:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fclnH-0007IL-UF for qemu-devel@nongnu.org; Tue, 10 Jul 2018 02:06:38 -0400 Received: from mga01.intel.com ([192.55.52.88]:23582) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fclnH-0007HY-Jt for qemu-devel@nongnu.org; Tue, 10 Jul 2018 02:06:35 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jul 2018 23:06:35 -0700 Received: from natrouter.sh.intel.com (HELO robinhe-hp.domain) ([10.239.13.3]) by FMSMGA003.fm.intel.com with ESMTP; 09 Jul 2018 23:06: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.51,333,1526367600"; d="scan'208";a="63525885" From: junyan.he@gmx.com To: qemu-devel@nongnu.org Date: Tue, 10 Jul 2018 14:06:23 +0800 Message-Id: <1531202789-31006-2-git-send-email-junyan.he@gmx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531202789-31006-1-git-send-email-junyan.he@gmx.com> References: <1531202789-31006-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/7 V8] 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 RAM_SHARED bit in ram_flags, and other flag bits are ignored by above functions right now. Signed-off-by: Junyan He Signed-off-by: Haozhong Zhang Reviewed-by: Stefan Hajnoczi Reviewed-by: Igor Mammedov --- backends/hostmem-file.c | 3 ++- exec.c | 10 +++++----- include/exec/memory.h | 7 +++++-- include/exec/ram_addr.h | 25 +++++++++++++++++++++++-- memory.c | 8 +++++--- numa.c | 2 +- 6 files changed, 41 insertions(+), 14 deletions(-) diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c index 134b08d..34c68bb 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 ? RAM_SHARED : 0, fb->mem_path, errp); g_free(path); } diff --git a/exec.c b/exec.c index cc042dc..1ec539d 100644 --- a/exec.c +++ b/exec.c @@ -2238,7 +2238,7 @@ static void ram_block_add(RAMBlock *new_block, Error = **errp, bool shared) =20 #ifdef __linux__ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, - bool share, int fd, + uint64_t ram_flags, int fd, Error **errp) { RAMBlock *new_block; @@ -2280,14 +2280,14 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, M= emoryRegion *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 ram_flags; new_block->host =3D file_ram_alloc(new_block, size, fd, !file_size, er= rp); if (!new_block->host) { g_free(new_block); return NULL; } =20 - ram_block_add(new_block, &local_err, share); + ram_block_add(new_block, &local_err, ram_flags & RAM_SHARED); if (local_err) { g_free(new_block); error_propagate(errp, local_err); @@ -2299,7 +2299,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 ram_flags, const char *mem_pat= h, Error **errp) { int fd; @@ -2311,7 +2311,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, ram_flags, fd, errp); if (!block) { if (created) { unlink(mem_path); diff --git a/include/exec/memory.h b/include/exec/memory.h index 6d0af29..513ec8d 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -640,6 +640,7 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr, void *host), Error **errp); #ifdef __linux__ + /** * memory_region_init_ram_from_file: Initialize RAM memory region with a * mmap-ed backend. @@ -651,7 +652,9 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr, * @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 + * @ram_flags: Memory region features: + * - RAM_SHARED: memory must be mmaped with the MAP_SHARED flag + * Other bits are ignored now. * @path: the path in which to allocate the RAM. * @errp: pointer to Error*, to store an error if it happens. * @@ -663,7 +666,7 @@ void memory_region_init_ram_from_file(MemoryRegion *mr, const char *name, uint64_t size, uint64_t align, - bool share, + uint64_t ram_flags, const char *path, Error **errp); =20 diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index cf4ce06..bb0a09b 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -71,12 +71,33 @@ static inline unsigned long int ramblock_recv_bitmap_of= fset(void *host_addr, } =20 long qemu_getrampagesize(void); + +/** + * qemu_ram_alloc_from_file, + * qemu_ram_alloc_from_fd: Allocate a ram block from the specified backing + * file or device + * + * Parameters: + * @size: the size in bytes of the ram block + * @mr: the memory region where the ram block is + * @ram_flags: specify the properties of the ram block, which can be one + * or bit-or of following values + * - RAM_SHARED: mmap the backing file or device with MAP_SHA= RED + * Other bits are ignored. + * @mem_path or @fd: specify the backing 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 ram_flags, const char *mem_pat= h, Error **errp); RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, - bool share, int fd, + uint64_t ram_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 e9cd446..7c5695c 100644 --- a/memory.c +++ b/memory.c @@ -1551,7 +1551,7 @@ void memory_region_init_ram_from_file(MemoryRegion *m= r, const char *name, uint64_t size, uint64_t align, - bool share, + uint64_t ram_flags, const char *path, Error **errp) { @@ -1560,7 +1560,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, ram_flags, path, = errp); mr->dirty_log_mask =3D tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; } =20 @@ -1576,7 +1576,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 ? RAM_SHARED : 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 5f6367b..81542d4 100644 --- a/numa.c +++ b/numa.c @@ -479,7 +479,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 Fri Mar 29 01:41:17 2024 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 15312031830356.610516320369925; Mon, 9 Jul 2018 23:13:03 -0700 (PDT) Received: from localhost ([::1]:45946 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcltV-0003kH-VY for importer@patchew.org; Tue, 10 Jul 2018 02:13:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45272) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fclnO-0007m8-OZ for qemu-devel@nongnu.org; Tue, 10 Jul 2018 02:06:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fclnM-0007Jb-OJ for qemu-devel@nongnu.org; Tue, 10 Jul 2018 02:06:42 -0400 Received: from mga01.intel.com ([192.55.52.88]:23582) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fclnM-0007HY-Bx for qemu-devel@nongnu.org; Tue, 10 Jul 2018 02:06:40 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jul 2018 23:06:40 -0700 Received: from natrouter.sh.intel.com (HELO robinhe-hp.domain) ([10.239.13.3]) by FMSMGA003.fm.intel.com with ESMTP; 09 Jul 2018 23:06: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.51,333,1526367600"; d="scan'208";a="63525902" From: junyan.he@gmx.com To: qemu-devel@nongnu.org Date: Tue, 10 Jul 2018 14:06:25 +0800 Message-Id: <1531202789-31006-4-git-send-email-junyan.he@gmx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531202789-31006-1-git-send-email-junyan.he@gmx.com> References: <1531202789-31006-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/7 V8] 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. If 'pmem' is set while lack of libpmem support, a error is generated. Signed-off-by: Junyan He Signed-off-by: Haozhong Zhang Reviewed-by: Stefan Hajnoczi --- backends/hostmem-file.c | 42 +++++++++++++++++++++++++++++++++++++++++- docs/nvdimm.txt | 23 +++++++++++++++++++++++ exec.c | 9 +++++++++ include/exec/memory.h | 4 ++++ include/exec/ram_addr.h | 3 +++ qemu-options.hx | 7 +++++++ 6 files changed, 87 insertions(+), 1 deletion(-) diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c index 34c68bb..dbdaf17 100644 --- a/backends/hostmem-file.c +++ b/backends/hostmem-file.c @@ -12,6 +12,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "qemu-common.h" +#include "qemu/error-report.h" #include "sysemu/hostmem.h" #include "sysemu/sysemu.h" #include "qom/object_interfaces.h" @@ -34,6 +35,7 @@ struct HostMemoryBackendFile { bool discard_data; char *mem_path; uint64_t align; + bool is_pmem; }; =20 static void @@ -59,7 +61,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 ? RAM_SHARED : 0, + (backend->share ? RAM_SHARED : 0) | + (fb->is_pmem ? RAM_PMEM : 0), fb->mem_path, errp); g_free(path); } @@ -131,6 +134,40 @@ 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), + object_get_canonical_path_component(o)); + return; + } + +#ifndef CONFIG_LIBPMEM + if (value) { + Error *local_err =3D NULL; + error_setg(&local_err, + "Lack of libpmem support while setting the 'pmem=3Don'" + " of %s '%s'. We can not ensure the persistence of it" + " without libpmem support, this may cause serious" + " problems." , object_get_typename(o), + object_get_canonical_path_component(o)); + error_propagate(errp, local_err); + return; + } +#endif + + fb->is_pmem =3D value; +} + static void file_backend_unparent(Object *obj) { HostMemoryBackend *backend =3D MEMORY_BACKEND(obj); @@ -162,6 +199,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 24b443b..b8bb43a 100644 --- a/docs/nvdimm.txt +++ b/docs/nvdimm.txt @@ -173,3 +173,26 @@ There are currently two valid values for this option: the NVDIMMs in the event of power loss. This implies that the platform also supports flushing dirty data through the memory controller on power loss. + +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' is 'on' 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). If 'pmem' is 'on' while there is no libpmem +support, qemu will exit and report a "lack of libpmem suopport" message to +ensure the persistence is available. For example, we want to ensure the +persistence for some backend file: + + -object memory-backend-file,id=3Dnv_mem,mem-path=3D/XXX/yyy,size=3D4G,= pmem + +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 1ec539d..1a61b44 100644 --- a/exec.c +++ b/exec.c @@ -2245,6 +2245,9 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, Mem= oryRegion *mr, Error *local_err =3D NULL; int64_t file_size; =20 + /* Just support these ram flags by now. */ + assert(ram_flags =3D=3D 0 || (ram_flags & (RAM_SHARED | RAM_PMEM))); + if (xen_enabled()) { error_setg(errp, "-mem-path not supported with Xen"); return NULL; @@ -4072,6 +4075,11 @@ err: return ret; } =20 +bool ramblock_is_pmem(RAMBlock *rb) +{ + return rb->flags & RAM_PMEM; +} + #endif =20 void page_size_init(void) @@ -4170,3 +4178,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 513ec8d..a3baa2a 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -123,6 +123,9 @@ typedef struct IOMMUNotifier IOMMUNotifier; /* RAM can be migrated */ #define RAM_MIGRATABLE (1 << 4) =20 +/* RAM is a persistent kind memory */ +#define RAM_PMEM (1 << 5) + static inline void iommu_notifier_init(IOMMUNotifier *n, IOMMUNotify fn, IOMMUNotifierFlag flags, hwaddr start, hwaddr end, @@ -654,6 +657,7 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr, * (getpagesize()) will be used. * @ram_flags: Memory region features: * - RAM_SHARED: memory must be mmaped with the MAP_SHARED flag + * - RAM_PMEM: the memory is persistent memory * Other bits are ignored now. * @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 bb0a09b..f1f8ac0 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); =20 /** @@ -83,6 +85,7 @@ long qemu_getrampagesize(void); * @ram_flags: specify the properties of the ram block, which can be one * or bit-or of following values * - RAM_SHARED: mmap the backing file or device with MAP_SHA= RED + * - RAM_PMEM: the backend @mem_path or @fd is persistent mem= ory * Other bits are ignored. * @mem_path or @fd: specify the backing 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 16208f6..3f92281 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4057,6 +4057,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 backing file specified +by @option{mem-path} is on the persistent memory that can be accessed +using the SNIA NVM programming model (e.g. Intel NVDIMM). +If @option{pmem}, 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 Fri Mar 29 01:41:17 2024 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 1531203296923288.5512864231748; Mon, 9 Jul 2018 23:14:56 -0700 (PDT) Received: from localhost ([::1]:45962 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fclvG-00057V-Pw for importer@patchew.org; Tue, 10 Jul 2018 02:14:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45287) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fclnQ-0007nY-E6 for qemu-devel@nongnu.org; Tue, 10 Jul 2018 02:06:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fclnP-0007KL-4y for qemu-devel@nongnu.org; Tue, 10 Jul 2018 02:06:44 -0400 Received: from mga01.intel.com ([192.55.52.88]:23582) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fclnO-0007HY-PE for qemu-devel@nongnu.org; Tue, 10 Jul 2018 02:06:43 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jul 2018 23:06:42 -0700 Received: from natrouter.sh.intel.com (HELO robinhe-hp.domain) ([10.239.13.3]) by FMSMGA003.fm.intel.com with ESMTP; 09 Jul 2018 23:06:40 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,333,1526367600"; d="scan'208";a="63525913" From: junyan.he@gmx.com To: qemu-devel@nongnu.org Date: Tue, 10 Jul 2018 14:06:26 +0800 Message-Id: <1531202789-31006-5-git-send-email-junyan.he@gmx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531202789-31006-1-git-send-email-junyan.he@gmx.com> References: <1531202789-31006-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/7 V8] 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: Junyan He Signed-off-by: Haozhong Zhang Reviewed-by: Stefan Hajnoczi Reviewed-by: Igor Mammedov --- configure | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/configure b/configure index 2a7796e..1c9288b 100755 --- a/configure +++ b/configure @@ -475,6 +475,7 @@ vxhs=3D"" libxml2=3D"" docker=3D"no" debug_mutex=3D"no" +libpmem=3D"" =20 # cross compilers defaults, can be overridden with --cross-cc-ARCH cross_cc_aarch64=3D"aarch64-linux-gnu-gcc" @@ -1435,6 +1436,10 @@ for opt do ;; --disable-debug-mutex) debug_mutex=3Dno ;; + --enable-libpmem) libpmem=3Dyes + ;; + --disable-libpmem) libpmem=3Dno + ;; *) echo "ERROR: unknown option $opt" echo "Try '$0 --help' for more information" @@ -1710,6 +1715,7 @@ disabled with --disable-FEATURE, default is enabled i= f available: vhost-user vhost-user support capstone capstone disassembler support debug-mutex mutex debugging support + libpmem libpmem support =20 NOTE: The object files are built at the place where configure is launched EOF @@ -5546,6 +5552,24 @@ if has "docker"; then fi =20 ########################################## +# check for libpmem + +if test "$libpmem" !=3D "no"; then + if $pkg_config --exists "libpmem"; then + libpmem=3D"yes" + libpmem_libs=3D$($pkg_config --libs libpmem) + libpmem_cflags=3D$($pkg_config --cflags libpmem) + libs_softmmu=3D"$libs_softmmu $libpmem_libs" + QEMU_CFLAGS=3D"$QEMU_CFLAGS $libpmem_cflags" + 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 @@ -6010,6 +6034,7 @@ echo "replication support $replication" echo "VxHS block device $vxhs" echo "capstone $capstone" echo "docker $docker" +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" @@ -6763,6 +6788,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 Fri Mar 29 01:41:17 2024 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 1531203053423654.4416272615514; Mon, 9 Jul 2018 23:10:53 -0700 (PDT) Received: from localhost ([::1]:45929 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fclrQ-0002Az-8L for importer@patchew.org; Tue, 10 Jul 2018 02:10:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45311) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fclnT-0007ok-NM for qemu-devel@nongnu.org; Tue, 10 Jul 2018 02:06:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fclnR-0007L6-S2 for qemu-devel@nongnu.org; Tue, 10 Jul 2018 02:06:47 -0400 Received: from mga01.intel.com ([192.55.52.88]:23582) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fclnR-0007HY-A6 for qemu-devel@nongnu.org; Tue, 10 Jul 2018 02:06:45 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jul 2018 23:06:45 -0700 Received: from natrouter.sh.intel.com (HELO robinhe-hp.domain) ([10.239.13.3]) by FMSMGA003.fm.intel.com with ESMTP; 09 Jul 2018 23:06:42 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,333,1526367600"; d="scan'208";a="63525927" From: junyan.he@gmx.com To: qemu-devel@nongnu.org Date: Tue, 10 Jul 2018 14:06:27 +0800 Message-Id: <1531202789-31006-6-git-send-email-junyan.he@gmx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531202789-31006-1-git-send-email-junyan.he@gmx.com> References: <1531202789-31006-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/7 V8] 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 Reviewed-by: Stefan Hajnoczi Reviewed-by: Igor Mammedov --- 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 021d1c3..1c6674c 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" @@ -164,11 +165,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); 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 53d3f32..be9a042 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 Fri Mar 29 01:41:17 2024 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 1531202925471733.5509223886504; Mon, 9 Jul 2018 23:08:45 -0700 (PDT) Received: from localhost ([::1]:45918 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fclpI-0000HI-9v for importer@patchew.org; Tue, 10 Jul 2018 02:08:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45324) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fclnU-0007p7-KX for qemu-devel@nongnu.org; Tue, 10 Jul 2018 02:06:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fclnT-0007MU-Sl for qemu-devel@nongnu.org; Tue, 10 Jul 2018 02:06:48 -0400 Received: from mga01.intel.com ([192.55.52.88]:23582) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fclnT-0007HY-Ir for qemu-devel@nongnu.org; Tue, 10 Jul 2018 02:06:47 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jul 2018 23:06:47 -0700 Received: from natrouter.sh.intel.com (HELO robinhe-hp.domain) ([10.239.13.3]) by FMSMGA003.fm.intel.com with ESMTP; 09 Jul 2018 23:06:45 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,333,1526367600"; d="scan'208";a="63525932" From: junyan.he@gmx.com To: qemu-devel@nongnu.org Date: Tue, 10 Jul 2018 14:06:28 +0800 Message-Id: <1531202789-31006-7-git-send-email-junyan.he@gmx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531202789-31006-1-git-send-email-junyan.he@gmx.com> References: <1531202789-31006-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/7 V8] 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 Reviewed-by: Stefan Hajnoczi Reviewed-by: Igor Mammedov --- migration/ram.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/migration/ram.c b/migration/ram.c index 1cd98d6..9c03e2b 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -3895,6 +3895,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 From nobody Fri Mar 29 01:41:17 2024 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 1531203065649412.3134605450331; Mon, 9 Jul 2018 23:11:05 -0700 (PDT) Received: from localhost ([::1]:45934 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fclrc-0002Nw-Hz for importer@patchew.org; Tue, 10 Jul 2018 02:11:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45354) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fclnX-0007r6-5E for qemu-devel@nongnu.org; Tue, 10 Jul 2018 02:06:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fclnW-0007Or-6v for qemu-devel@nongnu.org; Tue, 10 Jul 2018 02:06:51 -0400 Received: from mga01.intel.com ([192.55.52.88]:23582) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fclnV-0007HY-V1 for qemu-devel@nongnu.org; Tue, 10 Jul 2018 02:06:50 -0400 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jul 2018 23:06:49 -0700 Received: from natrouter.sh.intel.com (HELO robinhe-hp.domain) ([10.239.13.3]) by FMSMGA003.fm.intel.com with ESMTP; 09 Jul 2018 23:06:47 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,333,1526367600"; d="scan'208";a="63525940" From: junyan.he@gmx.com To: qemu-devel@nongnu.org Date: Tue, 10 Jul 2018 14:06:29 +0800 Message-Id: <1531202789-31006-8-git-send-email-junyan.he@gmx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531202789-31006-1-git-send-email-junyan.he@gmx.com> References: <1531202789-31006-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/7 V8] migration/ram: ensure write persistence on loading all data 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: 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 Because we need to make sure the pmem kind memory data is synced after migration, we choose to call pmem_persist() when the migration finish. This will make sure the data of pmem is safe and will not lose if power is off. Signed-off-by: Junyan He Reviewed-by: Stefan Hajnoczi Reviewed-by: Igor Mammedov --- include/qemu/pmem.h | 1 + migration/ram.c | 10 +++++++++- stubs/pmem.c | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/qemu/pmem.h b/include/qemu/pmem.h index 00d6680..8f52b08 100644 --- a/include/qemu/pmem.h +++ b/include/qemu/pmem.h @@ -17,6 +17,7 @@ #else /* !CONFIG_LIBPMEM */ =20 void *pmem_memcpy_persist(void *pmemdest, const void *src, size_t len); +void pmem_persist(const void *addr, size_t len); =20 #endif /* CONFIG_LIBPMEM */ =20 diff --git a/migration/ram.c b/migration/ram.c index 9c03e2b..62dfe75 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -33,6 +33,7 @@ #include "qemu/bitops.h" #include "qemu/bitmap.h" #include "qemu/main-loop.h" +#include "qemu/pmem.h" #include "xbzrle.h" #include "ram.h" #include "migration.h" @@ -3541,6 +3542,13 @@ static int ram_load_setup(QEMUFile *f, void *opaque) static int ram_load_cleanup(void *opaque) { RAMBlock *rb; + + RAMBLOCK_FOREACH_MIGRATABLE(rb) { + if (ramblock_is_pmem(rb)) { + pmem_persist(rb->host, rb->used_length); + } + } + xbzrle_load_cleanup(); compress_threads_load_cleanup(); =20 @@ -3896,7 +3904,7 @@ static int ram_load(QEMUFile *f, void *opaque, int ve= rsion_id) static bool ram_has_postcopy(void *opaque) { RAMBlock *rb; - RAMBLOCK_FOREACH(rb) { + RAMBLOCK_FOREACH_MIGRATABLE(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); diff --git a/stubs/pmem.c b/stubs/pmem.c index b4ec72d..f794262 100644 --- a/stubs/pmem.c +++ b/stubs/pmem.c @@ -17,3 +17,7 @@ void *pmem_memcpy_persist(void *pmemdest, const void *src= , size_t len) { return memcpy(pmemdest, src, len); } + +void pmem_persist(const void *addr, size_t len) +{ +} --=20 2.7.4