From patchwork Wed Apr 11 07:04:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Gibson X-Patchwork-Id: 10334921 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 49C6860365 for ; Wed, 11 Apr 2018 07:05:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3844E286EB for ; Wed, 11 Apr 2018 07:05:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2CD0B28707; Wed, 11 Apr 2018 07:05:51 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, 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 4E99D286EB for ; Wed, 11 Apr 2018 07:05:50 +0000 (UTC) Received: from localhost ([::1]:57846 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f69pF-0001Dx-FP for patchwork-qemu-devel@patchwork.kernel.org; Wed, 11 Apr 2018 03:05:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44033) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f69ny-0008Lk-Gw for qemu-devel@nongnu.org; Wed, 11 Apr 2018 03:04:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f69nu-0002xB-J2 for qemu-devel@nongnu.org; Wed, 11 Apr 2018 03:04:30 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:46397) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f69nt-0002vo-SA; Wed, 11 Apr 2018 03:04:26 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 40LZln23WNz9s1r; Wed, 11 Apr 2018 17:04:21 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1523430261; bh=pPyHLICDo1gf7jBlwKcarsXobTeE3ZYeRRUKXg7UMaM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IiDiqZrA/gPwPzTmJZNOd9VXbA7MTDve33Azry8pHS1ptrvlFqFmZOJw7qMBIkIR3 Rc4bzhJVJ37UrM/KONEb3euHQr4DOwBU6WUwPWo9aQxsb0rhjTjg05gpNUO+kc2XdJ wdKNxUy4HjRfYiQhU8m2u07ghY5wymfoEb1k0ELI= From: David Gibson To: ehabkost@redhat.com, imammedo@redhat.com Date: Wed, 11 Apr 2018 17:04:17 +1000 Message-Id: <20180411070418.6304-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180411070418.6304-1-david@gibson.dropbear.id.au> References: <20180411070418.6304-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2401:3900:2:1::2 Subject: [Qemu-devel] [PATCHv3 for-2.13 1/2] Make qemu_mempath_getpagesize() accept NULL 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: pbonzini@redhat.com, qemu-ppc@nongnu.org, qemu-devel@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP qemu_mempath_getpagesize() gets the effective (host side) page size for a block of memory backed by an mmap()ed file on the host. It requires the mem_path parameter to be non-NULL. This ends up meaning all the callers need a different case for handling anonymous memory (for memory-backend-ram or default memory with -mem-path is not specified). We can make all those callers a little simpler by having qemu_mempath_getpagesize() accept NULL, and treat that as the anonymous memory case. Signed-off-by: David Gibson Reviewed-by: Greg Kurz --- exec.c | 21 ++++++--------------- target/ppc/kvm.c | 8 ++------ util/mmap-alloc.c | 26 ++++++++++++++------------ 3 files changed, 22 insertions(+), 33 deletions(-) diff --git a/exec.c b/exec.c index 02b1efebb7..b38b004563 100644 --- a/exec.c +++ b/exec.c @@ -1488,19 +1488,14 @@ void ram_block_dump(Monitor *mon) */ static int find_max_supported_pagesize(Object *obj, void *opaque) { - char *mem_path; long *hpsize_min = opaque; if (object_dynamic_cast(obj, TYPE_MEMORY_BACKEND)) { - mem_path = object_property_get_str(obj, "mem-path", NULL); - if (mem_path) { - long hpsize = qemu_mempath_getpagesize(mem_path); - g_free(mem_path); - if (hpsize < *hpsize_min) { - *hpsize_min = hpsize; - } - } else { - *hpsize_min = getpagesize(); + char *mem_path = object_property_get_str(obj, "mem-path", NULL); + long hpsize = qemu_mempath_getpagesize(mem_path); + g_free(mem_path); + if (hpsize < *hpsize_min) { + *hpsize_min = hpsize; } } @@ -1513,11 +1508,7 @@ long qemu_getrampagesize(void) long mainrampagesize; Object *memdev_root; - if (mem_path) { - mainrampagesize = qemu_mempath_getpagesize(mem_path); - } else { - mainrampagesize = getpagesize(); - } + mainrampagesize = qemu_mempath_getpagesize(mem_path); /* it's possible we have memory-backend objects with * hugepage-backed RAM. these may get mapped into system diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 79a436a384..e24fa50dc9 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -499,12 +499,8 @@ bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path) char *mempath = object_property_get_str(mem_obj, "mem-path", NULL); long pagesize; - if (mempath) { - pagesize = qemu_mempath_getpagesize(mempath); - g_free(mempath); - } else { - pagesize = getpagesize(); - } + pagesize = qemu_mempath_getpagesize(mempath); + g_free(mempath); return pagesize >= max_cpu_page_size; } diff --git a/util/mmap-alloc.c b/util/mmap-alloc.c index 2fd8cbcc6f..fd329eccd8 100644 --- a/util/mmap-alloc.c +++ b/util/mmap-alloc.c @@ -50,19 +50,21 @@ size_t qemu_mempath_getpagesize(const char *mem_path) struct statfs fs; int ret; - do { - ret = statfs(mem_path, &fs); - } while (ret != 0 && errno == EINTR); - - if (ret != 0) { - fprintf(stderr, "Couldn't statfs() memory path: %s\n", - strerror(errno)); - exit(1); - } + if (mem_path) { + do { + ret = statfs(mem_path, &fs); + } while (ret != 0 && errno == EINTR); - if (fs.f_type == HUGETLBFS_MAGIC) { - /* It's hugepage, return the huge page size */ - return fs.f_bsize; + if (ret != 0) { + fprintf(stderr, "Couldn't statfs() memory path: %s\n", + strerror(errno)); + exit(1); + } + + if (fs.f_type == HUGETLBFS_MAGIC) { + /* It's hugepage, return the huge page size */ + return fs.f_bsize; + } } #ifdef __sparc__ /* SPARC Linux needs greater alignment than the pagesize */