From nobody Wed Oct 29 09:27:42 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524823140339954.950756150102; Fri, 27 Apr 2018 02:59:00 -0700 (PDT) Received: from localhost ([::1]:46902 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fC09b-0002Lw-HF for importer@patchew.org; Fri, 27 Apr 2018 05:58:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59945) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBzad-0002GD-K2 for qemu-devel@nongnu.org; Fri, 27 Apr 2018 05:22:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBzac-0002MH-Hy for qemu-devel@nongnu.org; Fri, 27 Apr 2018 05:22:51 -0400 Received: from ozlabs.org ([203.11.71.1]:49763) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fBzab-0002Kx-Tf; Fri, 27 Apr 2018 05:22:50 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 40XT2r17ktz9s7L; Fri, 27 Apr 2018 19:21:35 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1524820900; bh=4m7lOiZ/JnMbFOg7kC1+gWti5kHOQlej5pglFRNF1kU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TxdqNAA10VouUQjxVjF2FAd3K9QqcKQBHLiw2kVVmKfgLlRmwt6xrPYFG/ZrnuiZ/ +J/A8MXaKlrLRHqq2PW7aMUiclSvnTGq8oF9AqMkponEcQRsrEVDkb7/2FZlDrGGwh w20VtrVS2xFAaauf7+SjSt3+RErkFlH9amAFZARY= From: David Gibson To: peter.maydell@linaro.org Date: Fri, 27 Apr 2018 19:21:03 +1000 Message-Id: <20180427092126.24812-27-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180427092126.24812-1-david@gibson.dropbear.id.au> References: <20180427092126.24812-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 203.11.71.1 Subject: [Qemu-devel] [PULL 26/49] 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: David Gibson , qemu-ppc@nongnu.org, groug@kaod.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Acked-by: Paolo Bonzini --- 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 =3D opaque; =20 if (object_dynamic_cast(obj, TYPE_MEMORY_BACKEND)) { - mem_path =3D object_property_get_str(obj, "mem-path", NULL); - if (mem_path) { - long hpsize =3D qemu_mempath_getpagesize(mem_path); - g_free(mem_path); - if (hpsize < *hpsize_min) { - *hpsize_min =3D hpsize; - } - } else { - *hpsize_min =3D getpagesize(); + char *mem_path =3D object_property_get_str(obj, "mem-path", NULL); + long hpsize =3D qemu_mempath_getpagesize(mem_path); + g_free(mem_path); + if (hpsize < *hpsize_min) { + *hpsize_min =3D hpsize; } } =20 @@ -1513,11 +1508,7 @@ long qemu_getrampagesize(void) long mainrampagesize; Object *memdev_root; =20 - if (mem_path) { - mainrampagesize =3D qemu_mempath_getpagesize(mem_path); - } else { - mainrampagesize =3D getpagesize(); - } + mainrampagesize =3D qemu_mempath_getpagesize(mem_path); =20 /* 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 *ob= j_path) char *mempath =3D object_property_get_str(mem_obj, "mem-path", NULL); long pagesize; =20 - if (mempath) { - pagesize =3D qemu_mempath_getpagesize(mempath); - g_free(mempath); - } else { - pagesize =3D getpagesize(); - } + pagesize =3D qemu_mempath_getpagesize(mempath); + g_free(mempath); =20 return pagesize >=3D 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; =20 - do { - ret =3D statfs(mem_path, &fs); - } while (ret !=3D 0 && errno =3D=3D EINTR); - - if (ret !=3D 0) { - fprintf(stderr, "Couldn't statfs() memory path: %s\n", - strerror(errno)); - exit(1); - } + if (mem_path) { + do { + ret =3D statfs(mem_path, &fs); + } while (ret !=3D 0 && errno =3D=3D EINTR); =20 - if (fs.f_type =3D=3D HUGETLBFS_MAGIC) { - /* It's hugepage, return the huge page size */ - return fs.f_bsize; + if (ret !=3D 0) { + fprintf(stderr, "Couldn't statfs() memory path: %s\n", + strerror(errno)); + exit(1); + } + + if (fs.f_type =3D=3D HUGETLBFS_MAGIC) { + /* It's hugepage, return the huge page size */ + return fs.f_bsize; + } } #ifdef __sparc__ /* SPARC Linux needs greater alignment than the pagesize */ --=20 2.14.3