From: Greg Kurz <groug@kaod.org>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: qemu-devel@nongnu.org, imammedo@redhat.com, qemu-ppc@nongnu.org,
ehabkost@redhat.com, pbonzini@redhat.com
Subject: Re: [Qemu-devel] [Qemu-ppc] [PATCH for-2.13] Add host_memory_backend_pagesize() helper
Date: Thu, 29 Mar 2018 11:56:35 +0200 [thread overview]
Message-ID: <20180329115635.151cc34d@bahia.lan> (raw)
In-Reply-To: <20180329083748.15264f31@bahia.lan>
On Thu, 29 Mar 2018 08:37:48 +0200
Greg Kurz <groug@kaod.org> wrote:
> On Thu, 29 Mar 2018 16:25:37 +1100
> David Gibson <david@gibson.dropbear.id.au> wrote:
>
> > 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, or for the default backend (-mem-path) if passed
> > NULL.
> >
> > Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> > ---
>
[...]
> > diff --git a/exec.c b/exec.c
> > index c09bd93df3..04856c2402 100644
> > --- a/exec.c
> > +++ b/exec.c
> > @@ -1488,18 +1488,13 @@ 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);
>
> ... ie, this code currently leaks mem_path. This should be fixed in 2.12...
>
FYI, I've sent a series to fix various object_property_get_str()-based
leaks, including this one.
https://lists.nongnu.org/archive/html/qemu-devel/2018-03/msg07266.html
> > - if (hpsize < *hpsize_min) {
> > - *hpsize_min = hpsize;
> > - }
> > - } else {
> > - *hpsize_min = getpagesize();
> > + long hpsize = host_memory_backend_pagesize(MEMORY_BACKEND(obj));
> > +
> > + if (hpsize < *hpsize_min) {
> > + *hpsize_min = hpsize;
> > }
> > }
> >
> > @@ -1509,15 +1504,9 @@ static int find_max_supported_pagesize(Object *obj, void *opaque)
> > long qemu_getrampagesize(void)
> > {
> > long hpsize = LONG_MAX;
> > - long mainrampagesize;
> > + long mainrampagesize = host_memory_backend_pagesize(NULL);
> > Object *memdev_root;
> >
> > - if (mem_path) {
> > - mainrampagesize = qemu_mempath_getpagesize(mem_path);
> > - } else {
> > - mainrampagesize = getpagesize();
> > - }
> > -
> > /* it's possible we have memory-backend objects with
> > * hugepage-backed RAM. these may get mapped into system
> > * address space via -numa parameters or memory hotplug
> > diff --git a/include/sysemu/hostmem.h b/include/sysemu/hostmem.h
> > index 47bc9846ac..f474ef97f6 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);
> > +long host_memory_backend_pagesize(HostMemoryBackend *memdev);
> > +
> > #endif
> > diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
> > index b329cd8173..0adcf18c9f 100644
> > --- a/target/ppc/kvm.c
> > +++ b/target/ppc/kvm.c
> > @@ -493,15 +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 = object_resolve_path(obj_path, NULL);
> > - char *mempath = object_property_get_str(mem_obj, "mem-path", NULL);
> > - long pagesize;
> > -
> > - if (mempath) {
> > - pagesize = qemu_mempath_getpagesize(mempath);
> > - g_free(mempath);
>
> ... but this code is ok. No leak :)
>
> > - } else {
> > - pagesize = getpagesize();
> > - }
> > + long pagesize = host_memory_backend_pagesize(MEMORY_BACKEND(mem_obj));
> >
> > return pagesize >= max_cpu_page_size;
> > }
>
>
next prev parent reply other threads:[~2018-03-29 9:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-29 5:25 [Qemu-devel] [PATCH for-2.13] Add host_memory_backend_pagesize() helper David Gibson
2018-03-29 6:37 ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
2018-03-29 9:56 ` Greg Kurz [this message]
2018-04-03 5:31 ` David Gibson
2018-03-31 8:00 ` [Qemu-devel] " no-reply
2018-04-03 2:22 ` Eduardo Habkost
2018-04-03 5:29 ` 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=20180329115635.151cc34d@bahia.lan \
--to=groug@kaod.org \
--cc=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).