From patchwork Mon May 23 15:09:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 9132043 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4B382607D5 for ; Mon, 23 May 2016 15:23:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41D802822F for ; Mon, 23 May 2016 15:23:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 36C0E2823D; Mon, 23 May 2016 15:23:22 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 C5A0C2822F for ; Mon, 23 May 2016 15:23:21 +0000 (UTC) Received: from localhost ([::1]:48861 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b4rhQ-0004xr-Mj for patchwork-qemu-devel@patchwork.kernel.org; Mon, 23 May 2016 11:23:20 -0400 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=uUV2PlcL3lp9+97OmKTLTmGfRUEHu4b4Puqadfl6z3M=; b=J/YS5jVQztQ9fxdwkp6VLIuiE/gPFOQ69GxOKhsjY0JDFblROFqLw0NBCbj4ewZEks 03mC9sR54D8lIeo97aTtddlDvC2OcHYA8rxW2V2JRW1mtiRExZNvTlfsL9rr25JlEvp5 NF+T8Ri9Nj7rTmkTv6HkXVkdG0lCHyj6fUI8swuuPWBaC1fWr8ZxVZgewxje7aYVNLr4 P6fXHFonxe8X+20NYsBR1th9SjrW/GJWzw/JiUZFIyvdA5196KGrmX27zWh0eMzrW61j oP7BQCt5NhxrYlSY69kFz/Hn5KSEjLaVZENHuk2GV3aZL7EGn0bHY6kf3TeArMPcnxCh WzAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=uUV2PlcL3lp9+97OmKTLTmGfRUEHu4b4Puqadfl6z3M=; b=ATkGU4LPWNPLR0mRFLse7oVGs9P6O+dcGIgzQw+I3FmnOcNzKA2kHA5lPjSNp8U+Lt 7P5Icu01pVommSlSXYrRLDuVS8Po+u/FO0phBE2r1XcSghzgEyMkAfGYA0zgvFEW6HM+ nAmPOMw1tTJcVPCNKpkHGgErLx8AkpajfP0HQAffIyxj57LTXsG9IHbMPtEKGyPmYULE SlnkduxTAEKOB2Lby9S+y4FZ+MCOMTYdQUUJcOBIX7i2Mwyr0EkkZUXcqQQWz1YvUAbz /vFVVRaBy/AA4XCgn/H2G7aLJbkvNakjQvG7dNtm3HsMup9b9BQZhG//dP2wX1+FjNte AvkQ== X-Gm-Message-State: AOPr4FXLP0WItTYp5ZQDWDfOWshQqceYPH/y9my0uSVYA3NWsylCTVBhELjvlkmbgL3vYw== X-Received: by 10.28.11.82 with SMTP id 79mr17676931wml.33.1464016203773; Mon, 23 May 2016 08:10:03 -0700 (PDT) Received: from 640k.lan (dynamic-adsl-78-12-252-58.clienti.tiscali.it. [78.12.252.58]) by smtp.gmail.com with ESMTPSA id ac2sm19250359wjc.35.2016.05.23.08.10.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 May 2016 08:10:02 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 23 May 2016 17:09:36 +0200 Message-Id: <1464016199-43768-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1464016199-43768-1-git-send-email-pbonzini@redhat.com> References: <1464016199-43768-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PULL 01/24] 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: Dominik Dingel Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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