From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35448) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiqO7-0002Fr-NP for qemu-devel@nongnu.org; Wed, 23 Mar 2016 17:32:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aiqO3-0003ga-LL for qemu-devel@nongnu.org; Wed, 23 Mar 2016 17:32:23 -0400 Received: from e06smtp12.uk.ibm.com ([195.75.94.108]:43370) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aiqO3-0003eP-Ab for qemu-devel@nongnu.org; Wed, 23 Mar 2016 17:32:19 -0400 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 23 Mar 2016 21:32:14 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 363DE219004D for ; Wed, 23 Mar 2016 21:31:53 +0000 (GMT) Received: from d06av03.portsmouth.uk.ibm.com (d06av03.portsmouth.uk.ibm.com [9.149.37.213]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u2NLWBmo917768 for ; Wed, 23 Mar 2016 21:32:11 GMT Received: from d06av03.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av03.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u2NLWAhh000537 for ; Wed, 23 Mar 2016 15:32:11 -0600 From: Dominik Dingel Date: Wed, 23 Mar 2016 22:32:03 +0100 Message-Id: <1458768723-89242-1-git-send-email-dingel@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH] 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: Paolo Bonzini , Halil Pasic , Richard Henderson , Peter Crosthwaite 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 --- I thought about moving this alignment into qemu_ram_mmap but the result was a lot of code churn, the other possibility was to create an additional define ending up with two defines with the same semantics. --- exec.c | 16 ++++++++-------- include/qemu/osdep.h | 12 ++++++++++++ util/oslib-posix.c | 12 ------------ 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/exec.c b/exec.c index f398d21..2c4583f 100644 --- a/exec.c +++ b/exec.c @@ -1239,7 +1239,7 @@ static void *file_ram_alloc(RAMBlock *block, char *c; void *area; int fd; - int64_t page_size; + int64_t alignment; if (kvm_enabled() && !kvm_has_sync_mmu()) { error_setg(errp, @@ -1294,17 +1294,17 @@ static void *file_ram_alloc(RAMBlock *block, */ } - page_size = qemu_fd_getpagesize(fd); - block->mr->align = page_size; + alignment = MAX(qemu_fd_getpagesize(fd), QEMU_VMALLOC_ALIGN); + block->mr->align = alignment; - if (memory < page_size) { + if (memory < alignment) { error_setg(errp, "memory size 0x" RAM_ADDR_FMT " must be equal to " - "or larger than page size 0x%" PRIx64, - memory, page_size); + "or larger than needed alignment 0x%" PRIx64, + memory, alignment); goto error; } - memory = ROUND_UP(memory, page_size); + memory = ROUND_UP(memory, alignment); /* * ftruncate is not supported by hugetlbfs in older @@ -1316,7 +1316,7 @@ 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, alignment, 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 5bb374c..3d81672 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -231,6 +231,18 @@ void qemu_anon_ram_free(void *ptr, size_t size); #endif +#if defined(__linux__) && (defined(__x86_64__) || defined(__arm__)) + /* 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 05c44ed..52c621f 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -26,18 +26,6 @@ * THE SOFTWARE. */ -#if defined(__linux__) && (defined(__x86_64__) || defined(__arm__)) - /* 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 -- 2.6.5