From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37473) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b4rUk-0002A5-15 for qemu-devel@nongnu.org; Mon, 23 May 2016 11:10:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b4rUa-0003yl-SO for qemu-devel@nongnu.org; Mon, 23 May 2016 11:10:13 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:33918) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b4rUa-0003yf-Ef for qemu-devel@nongnu.org; Mon, 23 May 2016 11:10:04 -0400 Received: by mail-wm0-x241.google.com with SMTP id n129so16050599wmn.1 for ; Mon, 23 May 2016 08:10:04 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Mon, 23 May 2016 17:09:36 +0200 Message-Id: <1464016199-43768-2-git-send-email-pbonzini@redhat.com> In-Reply-To: <1464016199-43768-1-git-send-email-pbonzini@redhat.com> References: <1464016199-43768-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 01/24] exec.c: Ensure right alignment also for file backed ram List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Dominik Dingel From: Dominik Dingel While in the anonymous ram case we already take care of the right alignment such an alignment gurantee does not exist for file backed ram allocation. Instead, pagesize is used for alignment. On s390 this is not enough for gmap, as we need to satisfy an alignment up to segments. Reported-by: Halil Pasic Signed-off-by: Dominik Dingel Message-Id: <1461585338-45863-1-git-send-email-dingel@linux.vnet.ibm.com> Signed-off-by: Paolo Bonzini --- exec.c | 5 +++-- include/qemu/osdep.h | 13 +++++++++++++ util/oslib-posix.c | 13 ------------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/exec.c b/exec.c index 2e363f0..59aed17 100644 --- a/exec.c +++ b/exec.c @@ -1299,7 +1299,7 @@ static void *file_ram_alloc(RAMBlock *block, } page_size = qemu_fd_getpagesize(fd); - block->mr->align = page_size; + block->mr->align = MAX(page_size, QEMU_VMALLOC_ALIGN); if (memory < page_size) { error_setg(errp, "memory size 0x" RAM_ADDR_FMT " must be equal to " @@ -1320,7 +1320,8 @@ static void *file_ram_alloc(RAMBlock *block, perror("ftruncate"); } - area = qemu_ram_mmap(fd, memory, page_size, block->flags & RAM_SHARED); + area = qemu_ram_mmap(fd, memory, block->mr->align, + block->flags & RAM_SHARED); if (area == MAP_FAILED) { error_setg_errno(errp, errno, "unable to map backing store for guest RAM"); diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 268ec66..994bfa0 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -263,6 +263,19 @@ void qemu_anon_ram_free(void *ptr, size_t size); #endif +#if defined(__linux__) && \ + (defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)) + /* Use 2 MiB alignment so transparent hugepages can be used by KVM. + Valgrind does not support alignments larger than 1 MiB, + therefore we need special code which handles running on Valgrind. */ +# define QEMU_VMALLOC_ALIGN (512 * 4096) +#elif defined(__linux__) && defined(__s390x__) + /* Use 1 MiB (segment size) alignment so gmap can be used by KVM. */ +# define QEMU_VMALLOC_ALIGN (256 * 4096) +#else +# define QEMU_VMALLOC_ALIGN getpagesize() +#endif + int qemu_madvise(void *addr, size_t len, int advice); int qemu_open(const char *name, int flags, ...); diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 6cc4b8f..4adde93 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -26,19 +26,6 @@ * THE SOFTWARE. */ -#if defined(__linux__) && \ - (defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)) - /* Use 2 MiB alignment so transparent hugepages can be used by KVM. - Valgrind does not support alignments larger than 1 MiB, - therefore we need special code which handles running on Valgrind. */ -# define QEMU_VMALLOC_ALIGN (512 * 4096) -#elif defined(__linux__) && defined(__s390x__) - /* Use 1 MiB (segment size) alignment so gmap can be used by KVM. */ -# define QEMU_VMALLOC_ALIGN (256 * 4096) -#else -# define QEMU_VMALLOC_ALIGN getpagesize() -#endif - #include "qemu/osdep.h" #include #include -- 1.8.3.1