From: David Gibson <david@gibson.dropbear.id.au>
To: ehabkost@redhat.com, imammedo@redhat.com
Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org, pbonzini@redhat.com,
David Gibson <david@gibson.dropbear.id.au>
Subject: [Qemu-devel] [PATCHv3 for-2.13 2/2] Add host_memory_backend_pagesize() helper
Date: Wed, 11 Apr 2018 17:04:18 +1000 [thread overview]
Message-ID: <20180411070418.6304-3-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20180411070418.6304-1-david@gibson.dropbear.id.au>
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 <david@gibson.dropbear.id.au>
Reviewed-by: Greg Kurz <groug@kaod.org>
---
backends/hostmem.c | 18 ++++++++++++++++++
exec.c | 5 ++---
include/sysemu/hostmem.h | 2 ++
target/ppc/kvm.c | 6 +-----
4 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/backends/hostmem.c b/backends/hostmem.c
index f61093654e..6a0c474222 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"
#ifdef CONFIG_NUMA
#include <numaif.h>
@@ -262,6 +263,23 @@ bool host_memory_backend_is_mapped(HostMemoryBackend *backend)
return backend->is_mapped;
}
+#ifdef __linux__
+size_t host_memory_backend_pagesize(HostMemoryBackend *memdev)
+{
+ Object *obj = OBJECT(memdev);
+ char *path = object_property_get_str(obj, "mem-path", NULL);
+ size_t pagesize = qemu_mempath_getpagesize(path);
+
+ g_free(path);
+ return pagesize;
+}
+#else
+size_t host_memory_backend_pagesize(HostMemoryBackend *memdev)
+{
+ return getpagesize();
+}
+#endif
+
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, void *opaque)
long *hpsize_min = opaque;
if (object_dynamic_cast(obj, TYPE_MEMORY_BACKEND)) {
- char *mem_path = object_property_get_str(obj, "mem-path", NULL);
- long hpsize = qemu_mempath_getpagesize(mem_path);
- g_free(mem_path);
+ long hpsize = host_memory_backend_pagesize(MEMORY_BACKEND(obj));
+
if (hpsize < *hpsize_min) {
*hpsize_min = 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(HostMemoryBackend *backend,
void host_memory_backend_set_mapped(HostMemoryBackend *backend, bool mapped);
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 e24fa50dc9..f62f7ac288 100644
--- a/target/ppc/kvm.c
+++ b/target/ppc/kvm.c
@@ -496,11 +496,7 @@ static void kvm_fixup_page_sizes(PowerPCCPU *cpu)
bool kvmppc_is_mem_backend_page_size_ok(const char *obj_path)
{
Object *mem_obj = object_resolve_path(obj_path, NULL);
- char *mempath = object_property_get_str(mem_obj, "mem-path", NULL);
- long pagesize;
-
- pagesize = qemu_mempath_getpagesize(mempath);
- g_free(mempath);
+ long pagesize = host_memory_backend_pagesize(MEMORY_BACKEND(mem_obj));
return pagesize >= max_cpu_page_size;
}
--
2.14.3
next prev parent reply other threads:[~2018-04-11 7:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-11 7:04 [Qemu-devel] [PATCHv3 for-2.13 0/2] Helpers to obtain host page sizes for guest RAM David Gibson
2018-04-11 7:04 ` [Qemu-devel] [PATCHv3 for-2.13 1/2] Make qemu_mempath_getpagesize() accept NULL David Gibson
2018-04-11 7:04 ` David Gibson [this message]
2018-04-11 13:54 ` [Qemu-devel] [PATCHv3 for-2.13 0/2] Helpers to obtain host page sizes for guest RAM Paolo Bonzini
2018-04-12 0:30 ` David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180411070418.6304-3-david@gibson.dropbear.id.au \
--to=david@gibson.dropbear.id.au \
--cc=ehabkost@redhat.com \
--cc=imammedo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).