From nobody Thu Nov 6 14:25:42 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linux.intel.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541405513751337.18138636410936; Mon, 5 Nov 2018 00:11:53 -0800 (PST) Received: from localhost ([::1]:33680 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJZzE-0001dB-3U for importer@patchew.org; Mon, 05 Nov 2018 03:11:52 -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 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 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) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,467,1534834800"; d="scan'208";a="247039365" 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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"); } =20 - area =3D qemu_ram_mmap(fd, memory, block->mr->align, - block->flags & RAM_SHARED); + area =3D qemu_ram_mmap(fd, memory, block->mr->align, block->flags); if (area =3D=3D 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); =20 size_t qemu_mempath_getpagesize(const char *mem_path); =20 -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 add= ress; + * otherwise, the alignment in use will be determined by QEMU. + * @flags: specifies additional properties of the mapping, which can be o= ne 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); =20 void qemu_ram_munmap(void *ptr, size_t size); =20 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" =20 #define HUGETLBFS_MAGIC 0x958458f6 =20 @@ -75,7 +76,7 @@ size_t qemu_mempath_getpagesize(const char *mem_path) return getpagesize(); } =20 -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 addr= ess @@ -92,11 +93,12 @@ void *qemu_ram_mmap(int fd, size_t size, size_t align, = bool shared) * anonymous memory is OK. */ int anonfd =3D fd =3D=3D -1 || qemu_fd_getpagesize(fd) =3D=3D getpages= ize() ? -1 : fd; - int flags =3D anonfd =3D=3D -1 ? MAP_ANONYMOUS : MAP_NORESERVE; - void *ptr =3D mmap(0, total, PROT_NONE, flags | MAP_PRIVATE, anonfd, 0= ); + int mmap_flags =3D anonfd =3D=3D -1 ? MAP_ANONYMOUS : MAP_NORESERVE; + void *ptr =3D mmap(0, total, PROT_NONE, mmap_flags | MAP_PRIVATE, anon= fd, 0); #else void *ptr =3D mmap(0, total, PROT_NONE, MAP_ANONYMOUS | MAP_PRIVATE, -= 1, 0); #endif + bool shared =3D flags & RAM_SHARED; size_t offset; void *ptr1; =20 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 =3D QEMU_VMALLOC_ALIGN; - void *ptr =3D qemu_ram_mmap(-1, size, align, shared); + uint32_t flags =3D 0; + flags |=3D shared; + void *ptr =3D qemu_ram_mmap(-1, size, align, flags); =20 if (ptr =3D=3D MAP_FAILED) { return NULL; --=20 2.7.4