From patchwork Mon Nov 5 08:08:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Yi" X-Patchwork-Id: 10667559 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 905EB1709 for ; Mon, 5 Nov 2018 08:11:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82E792955F for ; Mon, 5 Nov 2018 08:11:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 76E2729565; Mon, 5 Nov 2018 08:11:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 356DC2955F for ; Mon, 5 Nov 2018 08:11:26 +0000 (UTC) Received: from localhost ([::1]:33681 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJZyn-0001dp-H3 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Nov 2018 03:11:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36742) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJZxf-0000uR-VH for qemu-devel@nongnu.org; Mon, 05 Nov 2018 03:10:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJZwC-0005DL-Sz for qemu-devel@nongnu.org; Mon, 05 Nov 2018 03:08:48 -0500 Received: from mga05.intel.com ([192.55.52.43]:49607) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJZwC-00050T-C7 for qemu-devel@nongnu.org; Mon, 05 Nov 2018 03:08:44 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Nov 2018 00:08:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,467,1534834800"; d="scan'208";a="105323337" Received: from linux.intel.com ([10.54.29.200]) by fmsmga001.fm.intel.com with ESMTP; 05 Nov 2018 00:08:37 -0800 Received: from dazhang1-ssd.sh.intel.com (unknown [10.239.48.128]) by linux.intel.com (Postfix) with ESMTP id 307A558048E; Mon, 5 Nov 2018 00:08:35 -0800 (PST) From: Zhang Yi To: xiaoguangrong.eric@gmail.com, dan.j.williams@intel.com, stefanha@redhat.com, pbonzini@redhat.com, yu.c.zhang@linux.intel.com Date: Mon, 5 Nov 2018 16:08:02 +0800 Message-Id: <4773dd7667ce53e3894ac705badd6e580808c6ce.1541425595.git.yi.z.zhang@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.43 Subject: [Qemu-devel] [PATCH v5 1/7] numa: Fixed the memory leak of numa error message 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: imammedo@redhat.com, Zhang Yi , qemu-devel@nongnu.org, ehabkost@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP object_get_canonical_path_component() returns a string which must be freed using g_free(). Signed-off-by: Zhang Yi --- numa.c | 1 + 1 file changed, 1 insertion(+) diff --git a/numa.c b/numa.c index 50ec016..3875e1e 100644 --- a/numa.c +++ b/numa.c @@ -533,6 +533,7 @@ void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner, error_report("memory backend %s is used multiple times. Each " "-numa option must use a different memdev value.", path); + g_free(path); exit(1); } From patchwork Mon Nov 5 08:08:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Yi" X-Patchwork-Id: 10667557 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D29FD15A6 for ; Mon, 5 Nov 2018 08:11:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3A3F2955F for ; Mon, 5 Nov 2018 08:11:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B484E29565; Mon, 5 Nov 2018 08:11:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2B4E62955F for ; Mon, 5 Nov 2018 08:11:24 +0000 (UTC) Received: from localhost ([::1]:33680 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJZyl-0001dB-Vr for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Nov 2018 03:11:24 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36750) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJZxf-0000ub-V1 for qemu-devel@nongnu.org; Mon, 05 Nov 2018 03:10:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJZwG-0005N6-Hh for qemu-devel@nongnu.org; Mon, 05 Nov 2018 03:08:51 -0500 Received: from mga02.intel.com ([134.134.136.20]:64084) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJZwG-0005KA-79 for qemu-devel@nongnu.org; Mon, 05 Nov 2018 03:08:48 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Nov 2018 00:08:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,467,1534834800"; d="scan'208";a="247039365" Received: from linux.intel.com ([10.54.29.200]) by orsmga004.jf.intel.com with ESMTP; 05 Nov 2018 00:08:46 -0800 Received: from dazhang1-ssd.sh.intel.com (unknown [10.239.48.128]) by linux.intel.com (Postfix) with ESMTP id 9114A58048E; Mon, 5 Nov 2018 00:08:44 -0800 (PST) From: Zhang Yi To: xiaoguangrong.eric@gmail.com, dan.j.williams@intel.com, stefanha@redhat.com, pbonzini@redhat.com, yu.c.zhang@linux.intel.com Date: Mon, 5 Nov 2018 16:08:12 +0800 Message-Id: <9e6954b1c07ad802c6b58be23781188d9914a0fd.1541425595.git.yi.z.zhang@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.20 Subject: [Qemu-devel] [PATCH v5 2/7] util/mmap-alloc: switch qemu_ram_mmap() to 'flags' parameter 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: imammedo@redhat.com, Zhang Yi , qemu-devel@nongnu.org, ehabkost@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP As more flag parameters besides the existing 'shared' are going to be added to qemu_ram_mmap(), let's switch 'shared' to a 'flags' parameter in advance, so as to ease the further additions. Signed-off-by: Haozhong Zhang Signed-off-by: Zhang Yi --- exec.c | 3 +-- include/qemu/mmap-alloc.h | 19 ++++++++++++++++++- util/mmap-alloc.c | 8 +++++--- util/oslib-posix.c | 4 +++- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/exec.c b/exec.c index bb6170d..273f668 100644 --- a/exec.c +++ b/exec.c @@ -1859,8 +1859,7 @@ static void *file_ram_alloc(RAMBlock *block, perror("ftruncate"); } - area = qemu_ram_mmap(fd, memory, block->mr->align, - block->flags & RAM_SHARED); + area = qemu_ram_mmap(fd, memory, block->mr->align, block->flags); if (area == MAP_FAILED) { error_setg_errno(errp, errno, "unable to map backing store for guest RAM"); diff --git a/include/qemu/mmap-alloc.h b/include/qemu/mmap-alloc.h index 50385e3..6fe6ed4 100644 --- a/include/qemu/mmap-alloc.h +++ b/include/qemu/mmap-alloc.h @@ -7,7 +7,24 @@ size_t qemu_fd_getpagesize(int fd); size_t qemu_mempath_getpagesize(const char *mem_path); -void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared); +/** + * qemu_ram_mmap: mmap the specified file or device. + * + * Parameters: + * @fd: the file or the device to mmap + * @size: the number of bytes to be mmaped + * @align: if not zero, specify the alignment of the starting mapping address; + * otherwise, the alignment in use will be determined by QEMU. + * @flags: specifies additional properties of the mapping, which can be one or + * bit-or of following values + * - RAM_SHARED: mmap with MAP_SHARED flag + * Other bits are ignored. + * + * Return: + * On success, return a pointer to the mapped area. + * On failure, return MAP_FAILED. + */ +void *qemu_ram_mmap(int fd, size_t size, size_t align, uint32_t flags); void qemu_ram_munmap(void *ptr, size_t size); diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index fd329ec..8f0a740 100644 --- a/util/mmap-alloc.c +++ b/util/mmap-alloc.c @@ -13,6 +13,7 @@ #include "qemu/osdep.h" #include "qemu/mmap-alloc.h" #include "qemu/host-utils.h" +#include "exec/memory.h" #define HUGETLBFS_MAGIC 0x958458f6 @@ -75,7 +76,7 @@ size_t qemu_mempath_getpagesize(const char *mem_path) return getpagesize(); } -void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared) +void *qemu_ram_mmap(int fd, size_t size, size_t align, uint32_t flags) { /* * Note: this always allocates at least one extra page of virtual address @@ -92,11 +93,12 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, bool shared) * anonymous memory is OK. */ int anonfd = fd == -1 || qemu_fd_getpagesize(fd) == getpagesize() ? -1 : fd; - int flags = anonfd == -1 ? MAP_ANONYMOUS : MAP_NORESERVE; - void *ptr = mmap(0, total, PROT_NONE, flags | MAP_PRIVATE, anonfd, 0); + int mmap_flags = anonfd == -1 ? MAP_ANONYMOUS : MAP_NORESERVE; + void *ptr = mmap(0, total, PROT_NONE, mmap_flags | MAP_PRIVATE, anonfd, 0); #else void *ptr = mmap(0, total, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); #endif + bool shared = flags & RAM_SHARED; size_t offset; void *ptr1; diff --git a/util/oslib-posix.c b/util/oslib-posix.c index fbd0dc8..c28869d 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -203,7 +203,9 @@ void *qemu_memalign(size_t alignment, size_t size) void *qemu_anon_ram_alloc(size_t size, uint64_t *alignment, bool shared) { size_t align = QEMU_VMALLOC_ALIGN; - void *ptr = qemu_ram_mmap(-1, size, align, shared); + uint32_t flags = 0; + flags |= shared; + void *ptr = qemu_ram_mmap(-1, size, align, flags); if (ptr == MAP_FAILED) { return NULL; From patchwork Mon Nov 5 08:29:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Yi" X-Patchwork-Id: 10667581 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7106814BD for ; Mon, 5 Nov 2018 08:32:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6261329320 for ; Mon, 5 Nov 2018 08:32:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 56C5C29329; Mon, 5 Nov 2018 08:32:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E826E29320 for ; Mon, 5 Nov 2018 08:32:20 +0000 (UTC) Received: from localhost ([::1]:33804 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJaJ2-0002dU-6l for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Nov 2018 03:32:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44543) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJaGg-00082S-86 for qemu-devel@nongnu.org; Mon, 05 Nov 2018 03:29:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJaGb-0002l9-9a for qemu-devel@nongnu.org; Mon, 05 Nov 2018 03:29:54 -0500 Received: from mga03.intel.com ([134.134.136.65]:1761) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJaGa-00026O-Sl for qemu-devel@nongnu.org; Mon, 05 Nov 2018 03:29:49 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Nov 2018 00:29:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,467,1534834800"; d="scan'208";a="278377674" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 05 Nov 2018 00:29:43 -0800 Received: from dazhang1-ssd.sh.intel.com (unknown [10.239.48.128]) by linux.intel.com (Postfix) with ESMTP id 5C6F258048E; Mon, 5 Nov 2018 00:29:41 -0800 (PST) From: Zhang Yi To: xiaoguangrong.eric@gmail.com, dan.j.williams@intel.com, stefanha@redhat.com, pbonzini@redhat.com, yu.c.zhang@linux.intel.com Date: Mon, 5 Nov 2018 16:29:08 +0800 Message-Id: <9619c036a6dc6cb4966f46d2405084f11666e14d.1541425595.git.yi.z.zhang@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.65 Subject: [Qemu-devel] [PATCH v5 3/7] exec: switch qemu_ram_alloc_from_{file, fd} to the 'flags' parameter 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: imammedo@redhat.com, Zhang Yi , qemu-devel@nongnu.org, ehabkost@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP As more flag parameters besides the existing 'share' are going to be added to qemu_ram_alloc_from_{file,fd}(), let's swith 'share' to a 'flags' parameters in advance, so as to ease the further additions. Signed-off-by: Haozhong Zhang Signed-off-by: Zhang Yi --- exec.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/exec.c b/exec.c index 273f668..e92a7da 100644 --- a/exec.c +++ b/exec.c @@ -1810,6 +1810,7 @@ static void *file_ram_alloc(RAMBlock *block, ram_addr_t memory, int fd, bool truncate, + uint32_t flags, Error **errp) { void *area; @@ -1859,7 +1860,7 @@ static void *file_ram_alloc(RAMBlock *block, perror("ftruncate"); } - area = qemu_ram_mmap(fd, memory, block->mr->align, block->flags); + area = qemu_ram_mmap(fd, memory, block->mr->align, flags); if (area == MAP_FAILED) { error_setg_errno(errp, errno, "unable to map backing store for guest RAM"); @@ -2278,7 +2279,8 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, new_block->used_length = size; new_block->max_length = size; new_block->flags = ram_flags; - new_block->host = file_ram_alloc(new_block, size, fd, !file_size, errp); + new_block->host = file_ram_alloc(new_block, size, fd, !file_size, + ram_flags, errp); if (!new_block->host) { g_free(new_block); return NULL; From patchwork Mon Nov 5 08:29:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Yi" X-Patchwork-Id: 10667575 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D13C214BD for ; Mon, 5 Nov 2018 08:31:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C15F429320 for ; Mon, 5 Nov 2018 08:31:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B267429329; Mon, 5 Nov 2018 08:31:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2075829320 for ; Mon, 5 Nov 2018 08:31:28 +0000 (UTC) Received: from localhost ([::1]:33801 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJaIB-00020L-AQ for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Nov 2018 03:31:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44613) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJaGn-00087C-TZ for qemu-devel@nongnu.org; Mon, 05 Nov 2018 03:30:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJaGj-0003dT-0Y for qemu-devel@nongnu.org; Mon, 05 Nov 2018 03:30:01 -0500 Received: from mga11.intel.com ([192.55.52.93]:46645) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJaGi-0003Wg-Me for qemu-devel@nongnu.org; Mon, 05 Nov 2018 03:29:56 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Nov 2018 00:29:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,467,1534834800"; d="scan'208";a="84038659" Received: from linux.intel.com ([10.54.29.200]) by fmsmga008.fm.intel.com with ESMTP; 05 Nov 2018 00:29:55 -0800 Received: from dazhang1-ssd.sh.intel.com (unknown [10.239.48.128]) by linux.intel.com (Postfix) with ESMTP id 56E6E58041B; Mon, 5 Nov 2018 00:29:53 -0800 (PST) From: Zhang Yi To: xiaoguangrong.eric@gmail.com, dan.j.williams@intel.com, stefanha@redhat.com, pbonzini@redhat.com, yu.c.zhang@linux.intel.com Date: Mon, 5 Nov 2018 16:29:20 +0800 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.93 Subject: [Qemu-devel] [PATCH v5 4/7] util/mmap-alloc: support MAP_SYNC in qemu_ram_mmap() 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: imammedo@redhat.com, Zhang Yi , qemu-devel@nongnu.org, ehabkost@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP When a file supporting DAX is used as vNVDIMM backend, mmap it with MAP_SYNC flag in addition can guarantee the persistence of guest write to the backend file without other QEMU actions (e.g., periodic fsync() by QEMU). A set of RAM_SYNC flags are added to qemu_ram_mmap(): Signed-off-by: Haozhong Zhang Signed-off-by: Zhang Yi --- exec.c | 2 +- include/exec/memory.h | 3 +++ include/exec/ram_addr.h | 1 + include/qemu/mmap-alloc.h | 1 + include/standard-headers/linux/mman.h | 44 +++++++++++++++++++++++++++++++++++ util/mmap-alloc.c | 14 +++++++---- 6 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 include/standard-headers/linux/mman.h diff --git a/exec.c b/exec.c index e92a7da..dc4d180 100644 --- a/exec.c +++ b/exec.c @@ -2241,7 +2241,7 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, int64_t file_size; /* Just support these ram flags by now. */ - assert((ram_flags & ~(RAM_SHARED | RAM_PMEM)) == 0); + assert((ram_flags & ~(RAM_SHARED | RAM_PMEM | RAM_SYNC)) == 0); if (xen_enabled()) { error_setg(errp, "-mem-path not supported with Xen"); diff --git a/include/exec/memory.h b/include/exec/memory.h index 667466b..33a4e2c 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -126,6 +126,9 @@ typedef struct IOMMUNotifier IOMMUNotifier; /* RAM is a persistent kind memory */ #define RAM_PMEM (1 << 5) +/* RAM can be mmap by a MAP_SYNC flag */ +#define RAM_SYNC (1 << 6) + static inline void iommu_notifier_init(IOMMUNotifier *n, IOMMUNotify fn, IOMMUNotifierFlag flags, hwaddr start, hwaddr end, diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 9ecd911..d239ce7 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -87,6 +87,7 @@ long qemu_getrampagesize(void); * or bit-or of following values * - RAM_SHARED: mmap the backing file or device with MAP_SHARED * - RAM_PMEM: the backend @mem_path or @fd is persistent memory + * - RAM_SYNC: mmap with MAP_SYNC flag * 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/include/qemu/mmap-alloc.h b/include/qemu/mmap-alloc.h index 6fe6ed4..1755a8b 100644 --- a/include/qemu/mmap-alloc.h +++ b/include/qemu/mmap-alloc.h @@ -18,6 +18,7 @@ size_t qemu_mempath_getpagesize(const char *mem_path); * @flags: specifies additional properties of the mapping, which can be one or * bit-or of following values * - RAM_SHARED: mmap with MAP_SHARED flag + * - RAM_SYNC: mmap with MAP_SYNC flag * Other bits are ignored. * * Return: diff --git a/include/standard-headers/linux/mman.h b/include/standard-headers/linux/mman.h new file mode 100644 index 0000000..ea1fc47 --- /dev/null +++ b/include/standard-headers/linux/mman.h @@ -0,0 +1,44 @@ +/* + * Definitions of Linux-specific mmap flags. + * + * Copyright Intel Corporation, 2018 + * + * Author: Haozhong Zhang + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * later. See the COPYING file in the top-level directory. + */ + +#ifndef _LINUX_MMAN_H +#define _LINUX_MMAN_H + +/* + * MAP_SHARED_VALIDATE and MAP_SYNC are introduced in Linux kernel + * 4.15, so they may not be defined when compiling on older kernels. + */ +#ifdef CONFIG_LINUX + +#include + +#ifndef MAP_SHARED_VALIDATE +#define MAP_SHARED_VALIDATE 0x3 +#endif + +#ifndef MAP_SYNC +#define MAP_SYNC 0x80000 +#endif + +/* MAP_SYNC is only available with MAP_SHARED_VALIDATE. */ +#define MAP_SYNC_FLAGS (MAP_SYNC | MAP_SHARED_VALIDATE) + +#else /* !CONFIG_LINUX */ + +#define MAP_SHARED_VALIDATE 0x0 +#define MAP_SYNC 0x0 + +#define QEMU_HAS_MAP_SYNC false +#define MAP_SYNC_FLAGS 0 + +#endif /* CONFIG_LINUX */ + +#endif /* !_LINUX_MMAN_H */ diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index 8f0a740..f411df7 100644 --- a/util/mmap-alloc.c +++ b/util/mmap-alloc.c @@ -14,6 +14,7 @@ #include "qemu/mmap-alloc.h" #include "qemu/host-utils.h" #include "exec/memory.h" +#include "standard-headers/linux/mman.h" #define HUGETLBFS_MAGIC 0x958458f6 @@ -99,6 +100,7 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, uint32_t flags) void *ptr = mmap(0, total, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); #endif bool shared = flags & RAM_SHARED; + int mmap_xflags = 0; size_t offset; void *ptr1; @@ -109,16 +111,20 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, uint32_t flags) assert(is_power_of_2(align)); /* Always align to host page size */ assert(align >= getpagesize()); + if ((flags & RAM_SYNC) && shared) { + mmap_xflags |= MAP_SYNC_FLAGS; + } offset = QEMU_ALIGN_UP((uintptr_t)ptr, align) - (uintptr_t)ptr; + retry_mmap_fd: ptr1 = mmap(ptr + offset, size, PROT_READ | PROT_WRITE, MAP_FIXED | (fd == -1 ? MAP_ANONYMOUS : 0) | - (shared ? MAP_SHARED : MAP_PRIVATE), + (shared ? MAP_SHARED : MAP_PRIVATE) | mmap_xflags, fd, 0); - if (ptr1 == MAP_FAILED) { - munmap(ptr, total); - return MAP_FAILED; + if ((ptr1 == MAP_FAILED) && (mmap_xflags & MAP_SYNC_FLAGS)) { + mmap_xflags &= ~MAP_SYNC_FLAGS; + goto retry_mmap_fd; } if (offset > 0) { From patchwork Mon Nov 5 08:29:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Yi" X-Patchwork-Id: 10667577 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AD16613A4 for ; Mon, 5 Nov 2018 08:31:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9EB3929320 for ; Mon, 5 Nov 2018 08:31:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 92F7529329; Mon, 5 Nov 2018 08:31:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3985B29320 for ; Mon, 5 Nov 2018 08:31:46 +0000 (UTC) Received: from localhost ([::1]:33802 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJaIT-0002EB-Bc for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Nov 2018 03:31:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44651) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJaGy-0008ID-F4 for qemu-devel@nongnu.org; Mon, 05 Nov 2018 03:30:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJaGt-0004sD-Aa for qemu-devel@nongnu.org; Mon, 05 Nov 2018 03:30:12 -0500 Received: from mga06.intel.com ([134.134.136.31]:44255) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJaGs-0004kX-WA for qemu-devel@nongnu.org; Mon, 05 Nov 2018 03:30:07 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Nov 2018 00:30:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,467,1534834800"; d="scan'208";a="278377787" Received: from linux.intel.com ([10.54.29.200]) by fmsmga006.fm.intel.com with ESMTP; 05 Nov 2018 00:30:05 -0800 Received: from dazhang1-ssd.sh.intel.com (unknown [10.239.48.128]) by linux.intel.com (Postfix) with ESMTP id 5934058048E; Mon, 5 Nov 2018 00:30:03 -0800 (PST) From: Zhang Yi To: xiaoguangrong.eric@gmail.com, dan.j.williams@intel.com, stefanha@redhat.com, pbonzini@redhat.com, yu.c.zhang@linux.intel.com Date: Mon, 5 Nov 2018 16:29:30 +0800 Message-Id: <904316e1b1eb22d7a2d19fa00ffba17e65acda3b.1541425595.git.yi.z.zhang@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.31 Subject: [Qemu-devel] [PATCH v5 5/7] util/mmap-alloc: Switch the RAM_SYNC flags to OnOffAuto 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: imammedo@redhat.com, Zhang Yi , qemu-devel@nongnu.org, ehabkost@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Zhang Yi A set of RAM_SYNC_ON_OFF_AUTO{AUTO,ON,OFF} flags are added to qemu_ram_mmap(): - If RAM_SYNC_ON_OFF_AUTO_ON is present, qemu_ram_mmap() will try to pass MAP_SYNC to mmap(). It will then fail if the host OS or the backend file do not support MAP_SYNC, or MAP_SYNC is conflict with other flags. - If RAM_SYNC_ON_OFF_AUTO_OFF is present, qemu_ram_mmap() will never pass MAP_SYNC to mmap(). - If RAM_SYNC_ON_OFF_AUTO_AUTO is present, and * if the host OS and the backend file support MAP_SYNC, and MAP_SYNC is not conflict with other flags, qemu_ram_mmap() will work as if RAM_SYNC_ON_OFF_AUTO_ON is present; * otherwise, qemu_ram_mmap() will work as if RAM_SYNC_ON_OFF_AUTO_OFF is present. --- include/exec/memory.h | 9 ++++++++- util/mmap-alloc.c | 12 ++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index 33a4e2c..c74c467 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -127,7 +127,14 @@ typedef struct IOMMUNotifier IOMMUNotifier; #define RAM_PMEM (1 << 5) /* RAM can be mmap by a MAP_SYNC flag */ -#define RAM_SYNC (1 << 6) +#define RAM_SYNC_SHIFT 6 +#define RAM_SYNC_SHIFT_AUTO 7 + +#define RAM_SYNC_ON_OFF_AUTO_ON (1UL << RAM_SYNC_SHIFT) +#define RAM_SYNC_ON_OFF_AUTO_OFF (0UL << RAM_SYNC_SHIFT) +#define RAM_SYNC_ON_OFF_AUTO_AUTO (1UL << RAM_SYNC_SHIFT_AUTO) + +#define RAM_SYNC (RAM_SYNC_ON_OFF_AUTO_ON | RAM_SYNC_ON_OFF_AUTO_AUTO) static inline void iommu_notifier_init(IOMMUNotifier *n, IOMMUNotify fn, IOMMUNotifierFlag flags, diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index f411df7..fe9303f 100644 --- a/util/mmap-alloc.c +++ b/util/mmap-alloc.c @@ -111,6 +111,10 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, uint32_t flags) assert(is_power_of_2(align)); /* Always align to host page size */ assert(align >= getpagesize()); + if ((flags & RAM_SYNC_ON_OFF_AUTO_ON) && + (!shared || !MAP_SYNC_FLAGS)) { + return MAP_FAILED; + } if ((flags & RAM_SYNC) && shared) { mmap_xflags |= MAP_SYNC_FLAGS; } @@ -123,8 +127,12 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, uint32_t flags) (shared ? MAP_SHARED : MAP_PRIVATE) | mmap_xflags, fd, 0); if ((ptr1 == MAP_FAILED) && (mmap_xflags & MAP_SYNC_FLAGS)) { - mmap_xflags &= ~MAP_SYNC_FLAGS; - goto retry_mmap_fd; + if (flags & RAM_SYNC_ON_OFF_AUTO_AUTO) { + mmap_xflags &= ~MAP_SYNC_FLAGS; + goto retry_mmap_fd; + } + munmap(ptr, total); + return MAP_FAILED; } if (offset > 0) { From patchwork Mon Nov 5 08:29:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Yi" X-Patchwork-Id: 10667583 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2D5A214BD for ; Mon, 5 Nov 2018 08:34:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E8BA29351 for ; Mon, 5 Nov 2018 08:34:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 113182935A; Mon, 5 Nov 2018 08:34:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A79CE29351 for ; Mon, 5 Nov 2018 08:34:27 +0000 (UTC) Received: from localhost ([::1]:33814 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJaL4-0005uB-Cd for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Nov 2018 03:34:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44693) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJaH7-0000Dg-BS for qemu-devel@nongnu.org; Mon, 05 Nov 2018 03:30:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJaH2-0005mE-14 for qemu-devel@nongnu.org; Mon, 05 Nov 2018 03:30:21 -0500 Received: from mga03.intel.com ([134.134.136.65]:1793) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJaH1-0005fS-NF for qemu-devel@nongnu.org; Mon, 05 Nov 2018 03:30:15 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Nov 2018 00:30:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,467,1534834800"; d="scan'208";a="84038802" Received: from linux.intel.com ([10.54.29.200]) by fmsmga008.fm.intel.com with ESMTP; 05 Nov 2018 00:30:13 -0800 Received: from dazhang1-ssd.sh.intel.com (unknown [10.239.48.128]) by linux.intel.com (Postfix) with ESMTP id 02C4358048E; Mon, 5 Nov 2018 00:30:11 -0800 (PST) From: Zhang Yi To: xiaoguangrong.eric@gmail.com, dan.j.williams@intel.com, stefanha@redhat.com, pbonzini@redhat.com, yu.c.zhang@linux.intel.com Date: Mon, 5 Nov 2018 16:29:39 +0800 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.65 Subject: [Qemu-devel] [PATCH v5 6/7] hostmem: add more information in error messages 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: imammedo@redhat.com, Zhang Yi , qemu-devel@nongnu.org, ehabkost@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP When there are multiple memory backends in use, including the object type name, ID and the property name in the error message can help users to locate the error. Signed-off-by: Haozhong Zhang Signed-off-by: Zhang Yi --- backends/hostmem-file.c | 6 ++++-- backends/hostmem.c | 8 +++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c index e640749..0dd7a90 100644 --- a/backends/hostmem-file.c +++ b/backends/hostmem-file.c @@ -82,7 +82,8 @@ static void set_mem_path(Object *o, const char *str, Error **errp) HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(o); if (host_memory_backend_mr_inited(backend)) { - error_setg(errp, "cannot change property value"); + error_setg(errp, "cannot change property 'mem-path' of %s", + object_get_typename(o)); return; } g_free(fb->mem_path); @@ -120,7 +121,8 @@ static void file_memory_backend_set_align(Object *o, Visitor *v, uint64_t val; if (host_memory_backend_mr_inited(backend)) { - error_setg(&local_err, "cannot change property value"); + error_setg(&local_err, "cannot change property '%s' of %s", + name, object_get_typename(o)); goto out; } diff --git a/backends/hostmem.c b/backends/hostmem.c index 1a89342..e2bcf9f 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -47,7 +47,8 @@ host_memory_backend_set_size(Object *obj, Visitor *v, const char *name, uint64_t value; if (host_memory_backend_mr_inited(backend)) { - error_setg(&local_err, "cannot change property value"); + error_setg(&local_err, "cannot change property %s of %s ", + name, object_get_typename(obj)); goto out; } @@ -56,8 +57,9 @@ host_memory_backend_set_size(Object *obj, Visitor *v, const char *name, goto out; } if (!value) { - error_setg(&local_err, "Property '%s.%s' doesn't take value '%" - PRIu64 "'", object_get_typename(obj), name, value); + error_setg(&local_err, + "property '%s' of %s doesn't take value '%" PRIu64 "'", + name, object_get_typename(obj), value); goto out; } backend->size = value; From patchwork Mon Nov 5 08:29:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Yi" X-Patchwork-Id: 10667579 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9683813A4 for ; Mon, 5 Nov 2018 08:32:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 864C229320 for ; Mon, 5 Nov 2018 08:32:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A5CF29329; Mon, 5 Nov 2018 08:32:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C023129320 for ; Mon, 5 Nov 2018 08:32:16 +0000 (UTC) Received: from localhost ([::1]:33803 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJaIy-0002aM-1n for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Nov 2018 03:32:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44786) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJaHL-0000mB-3C for qemu-devel@nongnu.org; Mon, 05 Nov 2018 03:30:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJaHG-00076d-4I for qemu-devel@nongnu.org; Mon, 05 Nov 2018 03:30:35 -0500 Received: from mga12.intel.com ([192.55.52.136]:25515) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gJaHA-0006Pg-EF for qemu-devel@nongnu.org; Mon, 05 Nov 2018 03:30:26 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Nov 2018 00:30:22 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,467,1534834800"; d="scan'208";a="247044084" Received: from linux.intel.com ([10.54.29.200]) by orsmga004.jf.intel.com with ESMTP; 05 Nov 2018 00:30:22 -0800 Received: from dazhang1-ssd.sh.intel.com (unknown [10.239.48.128]) by linux.intel.com (Postfix) with ESMTP id 2518A58041B; Mon, 5 Nov 2018 00:30:19 -0800 (PST) From: Zhang Yi To: xiaoguangrong.eric@gmail.com, dan.j.williams@intel.com, stefanha@redhat.com, pbonzini@redhat.com, yu.c.zhang@linux.intel.com Date: Mon, 5 Nov 2018 16:29:47 +0800 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.136 Subject: [Qemu-devel] [PATCH v5 7/7] hostmem-file: add 'sync' 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: imammedo@redhat.com, Zhang Yi , qemu-devel@nongnu.org, ehabkost@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This option controls whether QEMU mmap(2) the memory backend file with MAP_SYNC flag, which can fully guarantee the guest write persistence to the backend, if MAP_SYNC flag is supported by the host kernel (Linux kernel 4.15 and later) and the backend is a file supporting DAX (e.g., file on ext4/xfs file system mounted with '-o dax'). It can take one of following values: - on: try to pass MAP_SYNC to mmap(2); if MAP_SYNC is not supported or 'share=off', QEMU will abort - off: never pass MAP_SYNC to mmap(2) - auto (default): if MAP_SYNC is supported and 'share=on', work as if 'sync=on'; otherwise, work as if 'sync=off' Signed-off-by: Haozhong Zhang Signed-off-by: Zhang Yi --- backends/hostmem-file.c | 39 +++++++++++++++++++++++++++++++++++++++ docs/nvdimm.txt | 20 +++++++++++++++++++- include/exec/memory.h | 8 ++++++++ qemu-options.hx | 22 +++++++++++++++++++++- 4 files changed, 87 insertions(+), 2 deletions(-) diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c index 0dd7a90..73cf181 100644 --- a/backends/hostmem-file.c +++ b/backends/hostmem-file.c @@ -16,6 +16,7 @@ #include "sysemu/hostmem.h" #include "sysemu/sysemu.h" #include "qom/object_interfaces.h" +#include "qapi/qapi-visit.h" /* hostmem-file.c */ /** @@ -36,6 +37,7 @@ struct HostMemoryBackendFile { uint64_t align; bool discard_data; bool is_pmem; + OnOffAuto sync; }; static void @@ -62,6 +64,7 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp) path, backend->size, fb->align, (backend->share ? RAM_SHARED : 0) | + qemu_ram_sync_flags(fb->sync) | (fb->is_pmem ? RAM_PMEM : 0), fb->mem_path, errp); g_free(path); @@ -136,6 +139,39 @@ static void file_memory_backend_set_align(Object *o, Visitor *v, error_propagate(errp, local_err); } +static void file_memory_backend_get_sync( + Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) +{ + HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(obj); + OnOffAuto value = fb->sync; + + visit_type_OnOffAuto(v, name, &value, errp); +} + +static void file_memory_backend_set_sync( + Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) +{ + HostMemoryBackend *backend = MEMORY_BACKEND(obj); + HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(obj); + Error *local_err = NULL; + OnOffAuto value; + + if (host_memory_backend_mr_inited(backend)) { + error_setg(&local_err, "cannot change property '%s' of %s", + name, object_get_typename(obj)); + goto out; + } + + visit_type_OnOffAuto(v, name, &value, &local_err); + if (local_err) { + goto out; + } + fb->sync = value; + + out: + error_propagate(errp, local_err); +} + static bool file_memory_backend_get_pmem(Object *o, Error **errp) { return MEMORY_BACKEND_FILE(o)->is_pmem; @@ -203,6 +239,9 @@ file_backend_class_init(ObjectClass *oc, void *data) object_class_property_add_bool(oc, "pmem", file_memory_backend_get_pmem, file_memory_backend_set_pmem, &error_abort); + object_class_property_add(oc, "sync", "OnOffAuto", + file_memory_backend_get_sync, file_memory_backend_set_sync, + NULL, NULL, &error_abort); } static void file_backend_instance_finalize(Object *o) diff --git a/docs/nvdimm.txt b/docs/nvdimm.txt index 5f158a6..3d89174 100644 --- a/docs/nvdimm.txt +++ b/docs/nvdimm.txt @@ -142,11 +142,29 @@ backend of vNVDIMM: Guest Data Persistence ---------------------- +vNVDIMM is designed and implemented to guarantee the guest data +persistence on the backends even on the host crash and power +failures. However, there are still some requirements and limitations +as explained below. + Though QEMU supports multiple types of vNVDIMM backends on Linux, -currently the only one that can guarantee the guest write persistence +if MAP_SYNC is not supported by the host kernel and the backends, +the only backend that can guarantee the guest write persistence is the device DAX on the real NVDIMM device (e.g., /dev/dax0.0), to which all guest access do not involve any host-side kernel cache. +mmap(2) flag MAP_SYNC is added since Linux kernel 4.15. On such +systems, QEMU can mmap(2) the backend with MAP_SYNC, which can +guarantee the guest write persistence to vNVDIMM. Besides the host +kernel support, enabling MAP_SYNC in QEMU also requires: + + - the backend is a file supporting DAX, e.g., a file on an ext4 or + xfs file system mounted with '-o dax', + + - 'sync' option of memory-backend-file is not 'off', and + + - 'share' option of memory-backend-file is 'on'. + When using other types of backends, it's suggested to set 'unarmed' option of '-device nvdimm' to 'on', which sets the unarmed flag of the guest NVDIMM region mapping structure. This unarmed flag indicates diff --git a/include/exec/memory.h b/include/exec/memory.h index c74c467..b398abb 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -26,6 +26,7 @@ #include "qom/object.h" #include "qemu/rcu.h" #include "hw/qdev-core.h" +#include "qapi/error.h" #define RAM_ADDR_INVALID (~(ram_addr_t)0) @@ -136,6 +137,13 @@ typedef struct IOMMUNotifier IOMMUNotifier; #define RAM_SYNC (RAM_SYNC_ON_OFF_AUTO_ON | RAM_SYNC_ON_OFF_AUTO_AUTO) +static inline uint64_t qemu_ram_sync_flags(OnOffAuto v) +{ + return v == ON_OFF_AUTO_OFF ? RAM_SYNC_ON_OFF_AUTO_OFF : + v == ON_OFF_AUTO_ON ? RAM_SYNC_ON_OFF_AUTO_ON : + RAM_SYNC_ON_OFF_AUTO_AUTO; +} + static inline void iommu_notifier_init(IOMMUNotifier *n, IOMMUNotify fn, IOMMUNotifierFlag flags, hwaddr start, hwaddr end, diff --git a/qemu-options.hx b/qemu-options.hx index 08f8516..77e8810 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3928,7 +3928,7 @@ property must be set. These objects are placed in the @table @option -@item -object memory-backend-file,id=@var{id},size=@var{size},mem-path=@var{dir},share=@var{on|off},discard-data=@var{on|off},merge=@var{on|off},dump=@var{on|off},prealloc=@var{on|off},host-nodes=@var{host-nodes},policy=@var{default|preferred|bind|interleave},align=@var{align} +@item -object memory-backend-file,id=@var{id},size=@var{size},mem-path=@var{dir},share=@var{on|off},discard-data=@var{on|off},merge=@var{on|off},dump=@var{on|off},prealloc=@var{on|off},host-nodes=@var{host-nodes},policy=@var{default|preferred|bind|interleave},align=@var{align},sync=@var{on|off|auto} Creates a memory file backend object, which can be used to back the guest RAM with huge pages. @@ -4003,6 +4003,26 @@ If @option{pmem} is set to 'on', 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). +The @option{sync} option specifies whether QEMU mmap(2) @option{mem-path} +with MAP_SYNC flag, which can guarantee the guest write persistence to +@option{mem-path} even on the host crash and power failures. MAP_SYNC +requires supports from both the host kernel (since Linux kernel 4.15) +and @option{mem-path} (only files supporting DAX). It can take one of +following values: + +@table @option +@item @var{on} +try to pass MAP_SYNC to mmap(2); if MAP_SYNC is not supported or +@option{share}=@var{off}, QEMU will abort + +@item @var{off} +never pass MAP_SYNC to mmap(2) + +@item @var{auto} (default) +if MAP_SYNC is supported and @option{share}=@var{on}, work as if +@option{sync}=@var{on}; otherwise, work as if @option{sync}=@var{off} +@end table + @item -object memory-backend-ram,id=@var{id},merge=@var{on|off},dump=@var{on|off},share=@var{on|off},prealloc=@var{on|off},size=@var{size},host-nodes=@var{host-nodes},policy=@var{default|preferred|bind|interleave} Creates a memory backend object, which can be used to back the guest RAM.