From patchwork Thu Apr 7 21:31:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dingel@linux.vnet.ibm.com X-Patchwork-Id: 8777511 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0C0C59F36E for ; Thu, 7 Apr 2016 21:32:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 525F5201B9 for ; Thu, 7 Apr 2016 21:32:30 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 74C8E20142 for ; Thu, 7 Apr 2016 21:32:29 +0000 (UTC) Received: from localhost ([::1]:51956 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aoHXP-0003vS-IS for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Apr 2016 17:32:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52545) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aoHXC-0003qo-JF for qemu-devel@nongnu.org; Thu, 07 Apr 2016 17:32:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aoHX3-00077c-E4 for qemu-devel@nongnu.org; Thu, 07 Apr 2016 17:32:14 -0400 Received: from e06smtp05.uk.ibm.com ([195.75.94.101]:52419) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aoHX3-00074A-5Q for qemu-devel@nongnu.org; Thu, 07 Apr 2016 17:32:05 -0400 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 7 Apr 2016 22:32:01 +0100 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 7 Apr 2016 22:31:59 +0100 X-IBM-Helo: d06dlp01.portsmouth.uk.ibm.com X-IBM-MailFrom: dingel@linux.vnet.ibm.com X-IBM-RcptTo: qemu-devel@nongnu.org Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 1B9E717D8056 for ; Thu, 7 Apr 2016 22:32:40 +0100 (BST) Received: from d06av06.portsmouth.uk.ibm.com (d06av06.portsmouth.uk.ibm.com [9.149.37.217]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u37LVwJf6357392 for ; Thu, 7 Apr 2016 21:31:58 GMT Received: from d06av06.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u37LVvRO013709 for ; Thu, 7 Apr 2016 17:31:58 -0400 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u37LVvLN013706 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 7 Apr 2016 17:31:57 -0400 Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 2944) id 68C7D20F4F6; Thu, 7 Apr 2016 23:31:57 +0200 (CEST) From: Dominik Dingel To: qemu-devel@nongnu.org Date: Thu, 7 Apr 2016 23:31:51 +0200 Message-Id: <1460064711-93294-1-git-send-email-dingel@linux.vnet.ibm.com> X-Mailer: git-send-email 2.6.6 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16040721-0021-0000-0000-000012870CEA X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.75.94.101 Subject: [Qemu-devel] [PATCH v2] exec.c: Ensure right alignment also for file backed ram 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: Paolo Bonzini , Halil Pasic , Richard Henderson , Peter Crosthwaite Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- v1 -> v2: While enforcing alignments we allow memory sizes on page_size. On mmap the memory size will be round up to alignments. 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 | 8 +++++--- include/qemu/osdep.h | 12 ++++++++++++ util/oslib-posix.c | 12 ------------ 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/exec.c b/exec.c index c4f9036..1ae98e4 100644 --- a/exec.c +++ b/exec.c @@ -1241,6 +1241,7 @@ static void *file_ram_alloc(RAMBlock *block, void *area; int fd = -1; int64_t page_size; + int64_t alignment; if (kvm_enabled() && !kvm_has_sync_mmu()) { error_setg(errp, @@ -1296,7 +1297,8 @@ static void *file_ram_alloc(RAMBlock *block, } page_size = qemu_fd_getpagesize(fd); - block->mr->align = page_size; + alignment = MAX(page_size, QEMU_VMALLOC_ALIGN); + block->mr->align = alignment; if (memory < page_size) { error_setg(errp, "memory size 0x" RAM_ADDR_FMT " must be equal to " @@ -1305,7 +1307,7 @@ static void *file_ram_alloc(RAMBlock *block, goto error; } - memory = ROUND_UP(memory, page_size); + memory = ROUND_UP(memory, alignment); /* * ftruncate is not supported by hugetlbfs in older @@ -1317,7 +1319,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 408783f..a472372 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -247,6 +247,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 20ca141..4adde93 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