From nobody Fri May 3 04:37:26 2024 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1522894991520683.22955432116; Wed, 4 Apr 2018 19:23:11 -0700 (PDT) Received: from localhost ([::1]:48553 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f3uXw-0007UD-KD for importer@patchew.org; Wed, 04 Apr 2018 22:22:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36862) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f3uVV-0005qQ-IB for qemu-devel@nongnu.org; Wed, 04 Apr 2018 22:20:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f3uVU-0003zj-7b for qemu-devel@nongnu.org; Wed, 04 Apr 2018 22:20:09 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:58037) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f3uVT-0003yB-KY; Wed, 04 Apr 2018 22:20:08 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 40GmkY26z2z9s21; Thu, 5 Apr 2018 12:20:05 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1522894805; bh=UOwuMjUK3P2rfuuHh6lO1iOVX1NuKhvlASU0yVkGels=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JPT5M3bBAfu6CDpUN/Hw0g2F3LJFfhIGVcP7zMOJoC3AKquqdqIW+iJt6X9JkoS4Q mRrjQGryE/ib8JjbO0edu6TxZl+3I2a/yXRFayi8fcSpze1dXmtnmJJdWuqBvBbCbR JfnUBE/6ueZG31/tIlvsnFR+MJl5i3TLUe6U4AN4= From: David Gibson To: ehabkost@redhat.com, imammedo@redhat.com Date: Thu, 5 Apr 2018 12:20:01 +1000 Message-Id: <20180405022002.17809-2-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180405022002.17809-1-david@gibson.dropbear.id.au> References: <20180405022002.17809-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] [PATCHv2 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+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 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 =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 1bd38c6a90..f393eae127 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -496,12 +496,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 From nobody Fri May 3 04:37:26 2024 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 1522895613365939.7711656443627; Wed, 4 Apr 2018 19:33:33 -0700 (PDT) Received: from localhost ([::1]:49387 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f3uiS-0000Jg-3C for importer@patchew.org; Wed, 04 Apr 2018 22:33:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36858) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f3uVV-0005q6-8n for qemu-devel@nongnu.org; Wed, 04 Apr 2018 22:20:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f3uVU-0003zK-1I for qemu-devel@nongnu.org; Wed, 04 Apr 2018 22:20:09 -0400 Received: from ozlabs.org ([2401:3900:2:1::2]:52783) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f3uVT-0003y2-EH; Wed, 04 Apr 2018 22:20:07 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 40GmkY1DBFz9s0q; Thu, 5 Apr 2018 12:20:05 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1522894805; bh=tHhmVIxcXzJwjmWJWRKASiK068xcBpvBQW3EbSMAYbE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p8q2Sd7RdUvPlvh55diDJNACsfZEFRDtsIpheTA1ezAY56LSLFgH62IV+HfeYoX1j +/d5A/gWYN3STACqZAdS4cbGB3wEpIVmjcPnthlCT4Aktfy+clUkKG2x/xyH3u1rAU WpBlARrtCOJWRjvzGcT6vHKRWfFKnE1D3sefgfM0= From: David Gibson To: ehabkost@redhat.com, imammedo@redhat.com Date: Thu, 5 Apr 2018 12:20:02 +1000 Message-Id: <20180405022002.17809-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180405022002.17809-1-david@gibson.dropbear.id.au> References: <20180405022002.17809-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] [PATCHv2 for-2.13 2/2] Add host_memory_backend_pagesize() helper 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+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" There are a couple places (one generic, one target specific) where we need to get the host page size associated with a particular memory backend. I have some upcoming code which will add another place which wants this. So, for convenience, add a helper function to calculate this. host_memory_backend_pagesize() returns the host pagesize for a given HostMemoryBackend object. Signed-off-by: David Gibson Reviewed-by: Greg Kurz --- backends/hostmem.c | 11 +++++++++++ exec.c | 5 ++--- include/sysemu/hostmem.h | 2 ++ target/ppc/kvm.c | 6 +----- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/backends/hostmem.c b/backends/hostmem.c index f61093654e..ff2bb0489c 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -18,6 +18,7 @@ #include "qapi/visitor.h" #include "qemu/config-file.h" #include "qom/object_interfaces.h" +#include "qemu/mmap-alloc.h" =20 #ifdef CONFIG_NUMA #include @@ -262,6 +263,16 @@ bool host_memory_backend_is_mapped(HostMemoryBackend *= backend) return backend->is_mapped; } =20 +size_t host_memory_backend_pagesize(HostMemoryBackend *memdev) +{ + Object *obj =3D OBJECT(memdev); + char *path =3D object_property_get_str(obj, "mem-path", NULL); + size_t pagesize =3D qemu_mempath_getpagesize(path); + + g_free(path); + return pagesize; +} + static void host_memory_backend_memory_complete(UserCreatable *uc, Error **errp) { diff --git a/exec.c b/exec.c index b38b004563..c7fcefa851 100644 --- a/exec.c +++ b/exec.c @@ -1491,9 +1491,8 @@ static int find_max_supported_pagesize(Object *obj, v= oid *opaque) long *hpsize_min =3D opaque; =20 if (object_dynamic_cast(obj, TYPE_MEMORY_BACKEND)) { - char *mem_path =3D object_property_get_str(obj, "mem-path", NULL); - long hpsize =3D qemu_mempath_getpagesize(mem_path); - g_free(mem_path); + long hpsize =3D host_memory_backend_pagesize(MEMORY_BACKEND(obj)); + if (hpsize < *hpsize_min) { *hpsize_min =3D hpsize; } diff --git a/include/sysemu/hostmem.h b/include/sysemu/hostmem.h index 47bc9846ac..bc36899bb8 100644 --- a/include/sysemu/hostmem.h +++ b/include/sysemu/hostmem.h @@ -68,4 +68,6 @@ MemoryRegion *host_memory_backend_get_memory(HostMemoryBa= ckend *backend, =20 void host_memory_backend_set_mapped(HostMemoryBackend *backend, bool mappe= d); bool host_memory_backend_is_mapped(HostMemoryBackend *backend); +size_t host_memory_backend_pagesize(HostMemoryBackend *memdev); + #endif diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index f393eae127..1ab9cf3a8a 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -493,11 +493,7 @@ static void kvm_fixup_page_sizes(PowerPCCPU *cpu) bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path) { Object *mem_obj =3D object_resolve_path(obj_path, NULL); - char *mempath =3D object_property_get_str(mem_obj, "mem-path", NULL); - long pagesize; - - pagesize =3D qemu_mempath_getpagesize(mempath); - g_free(mempath); + long pagesize =3D host_memory_backend_pagesize(MEMORY_BACKEND(mem_obj)= ); =20 return pagesize >=3D max_cpu_page_size; } --=20 2.14.3