[PATCH REPOST v3 74/80] exec: cleanup qemu_minrampagesize()/qemu_maxrampagesize()

Igor Mammedov posted 80 patches 6 years ago
Maintainers: Andrzej Zaborowski <balrogg@gmail.com>, Eduardo Habkost <ehabkost@redhat.com>, Andrew Jeffery <andrew@aj.id.au>, Artyom Tarasenko <atar4qemu@gmail.com>, Paul Burton <pburton@wavecomp.com>, Thomas Huth <thuth@redhat.com>, Fabien Chouteau <chouteau@adacore.com>, Radoslaw Biernacki <radoslaw.biernacki@linaro.org>, Christian Borntraeger <borntraeger@de.ibm.com>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, KONRAD Frederic <frederic.konrad@adacore.com>, Cornelia Huck <cohuck@redhat.com>, "Philippe Mathieu-Daudé" <philmd@redhat.com>, Helge Deller <deller@gmx.de>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, "Cédric Le Goater" <clg@kaod.org>, Joel Stanley <joel@jms.id.au>, Andrew Baumann <Andrew.Baumann@microsoft.com>, BALATON Zoltan <balaton@eik.bme.hu>, Rob Herring <robh@kernel.org>, Paolo Bonzini <pbonzini@redhat.com>, Leif Lindholm <leif.lindholm@linaro.org>, Aleksandar Markovic <amarkovic@wavecomp.com>, Halil Pasic <pasic@linux.ibm.com>, Alistair Francis <alistair@alistair23.me>, Laurent Vivier <lvivier@redhat.com>, Sergio Lopez <slp@redhat.com>, David Hildenbrand <david@redhat.com>, Jean-Christophe Dubois <jcd@tribudubois.net>, Aurelien Jarno <aurelien@aurel32.net>, Antony Pavlov <antonynpavlov@gmail.com>, "Hervé Poussineau" <hpoussin@reactos.org>, Andrey Smirnov <andrew.smirnov@gmail.com>, Jan Kiszka <jan.kiszka@web.de>, Thomas Huth <huth@tuxfamily.org>, Michael Walle <michael@walle.cc>, Igor Mammedov <imammedo@redhat.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Richard Henderson <rth@twiddle.net>, Peter Chubb <peter.chubb@nicta.com.au>, Peter Maydell <peter.maydell@linaro.org>, "Michael S. Tsirkin" <mst@redhat.com>, Aleksandar Rikalo <aleksandar.rikalo@rt-rk.com>, Beniamino Galvani <b.galvani@gmail.com>, David Gibson <david@gibson.dropbear.id.au>
There is a newer version of this series
[PATCH REPOST v3 74/80] exec: cleanup qemu_minrampagesize()/qemu_maxrampagesize()
Posted by Igor Mammedov 6 years ago
Since all RAM is backed by hostmem backends, drop
global -mem-path invariant and simplify code.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
CC: pbonzini@redhat.com
CC: rth@twiddle.net
---
 exec.c | 51 +++++----------------------------------------------
 1 file changed, 5 insertions(+), 46 deletions(-)

diff --git a/exec.c b/exec.c
index 67e520d..809987c 100644
--- a/exec.c
+++ b/exec.c
@@ -1667,60 +1667,19 @@ static int find_max_backend_pagesize(Object *obj, void *opaque)
  */
 long qemu_minrampagesize(void)
 {
-    long hpsize = LONG_MAX;
-    long mainrampagesize;
-    Object *memdev_root;
-    MachineState *ms = MACHINE(qdev_get_machine());
-
-    mainrampagesize = qemu_mempath_getpagesize(mem_path);
-
-    /* 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
-     * hooks. we want to take these into account, but we
-     * also want to make sure these supported hugepage
-     * sizes are applicable across the entire range of memory
-     * we may boot from, so we take the min across all
-     * backends, and assume normal pages in cases where a
-     * backend isn't backed by hugepages.
-     */
-    memdev_root = object_resolve_path("/objects", NULL);
-    if (memdev_root) {
-        object_child_foreach(memdev_root, find_min_backend_pagesize, &hpsize);
-    }
-    if (hpsize == LONG_MAX) {
-        /* No additional memory regions found ==> Report main RAM page size */
-        return mainrampagesize;
-    }
-
-    /* If NUMA is disabled or the NUMA nodes are not backed with a
-     * memory-backend, then there is at least one node using "normal" RAM,
-     * so if its page size is smaller we have got to report that size instead.
-     */
-    if (hpsize > mainrampagesize &&
-        (ms->numa_state == NULL ||
-         ms->numa_state->num_nodes == 0 ||
-         ms->numa_state->nodes[0].node_memdev == NULL)) {
-        static bool warned;
-        if (!warned) {
-            error_report("Huge page support disabled (n/a for main memory).");
-            warned = true;
-        }
-        return mainrampagesize;
-    }
+    long hpsize;
+    Object *memdev_root = object_resolve_path("/objects", NULL);
 
+    object_child_foreach(memdev_root, find_min_backend_pagesize, &hpsize);
     return hpsize;
 }
 
 long qemu_maxrampagesize(void)
 {
-    long pagesize = qemu_mempath_getpagesize(mem_path);
+    long pagesize;
     Object *memdev_root = object_resolve_path("/objects", NULL);
 
-    if (memdev_root) {
-        object_child_foreach(memdev_root, find_max_backend_pagesize,
-                             &pagesize);
-    }
+    object_child_foreach(memdev_root, find_max_backend_pagesize, &pagesize);
     return pagesize;
 }
 #else
-- 
2.7.4


Re: [PATCH REPOST v3 74/80] exec: cleanup qemu_minrampagesize()/qemu_maxrampagesize()
Posted by Igor Mammedov 6 years ago
On Thu, 23 Jan 2020 12:38:39 +0100
Igor Mammedov <imammedo@redhat.com> wrote:

> Since all RAM is backed by hostmem backends, drop
> global -mem-path invariant and simplify code.

Looks like origin of removed here code is PPC,
could PPC folk review this please?

> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> CC: pbonzini@redhat.com
> CC: rth@twiddle.net
> ---
>  exec.c | 51 +++++----------------------------------------------
>  1 file changed, 5 insertions(+), 46 deletions(-)
> 
> diff --git a/exec.c b/exec.c
> index 67e520d..809987c 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1667,60 +1667,19 @@ static int find_max_backend_pagesize(Object *obj, void *opaque)
>   */
>  long qemu_minrampagesize(void)
>  {
> -    long hpsize = LONG_MAX;
> -    long mainrampagesize;
> -    Object *memdev_root;
> -    MachineState *ms = MACHINE(qdev_get_machine());
> -
> -    mainrampagesize = qemu_mempath_getpagesize(mem_path);
> -
> -    /* 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
> -     * hooks. we want to take these into account, but we
> -     * also want to make sure these supported hugepage
> -     * sizes are applicable across the entire range of memory
> -     * we may boot from, so we take the min across all
> -     * backends, and assume normal pages in cases where a
> -     * backend isn't backed by hugepages.
> -     */
> -    memdev_root = object_resolve_path("/objects", NULL);
> -    if (memdev_root) {
> -        object_child_foreach(memdev_root, find_min_backend_pagesize, &hpsize);
> -    }
> -    if (hpsize == LONG_MAX) {
> -        /* No additional memory regions found ==> Report main RAM page size */
> -        return mainrampagesize;
> -    }
> -
> -    /* If NUMA is disabled or the NUMA nodes are not backed with a
> -     * memory-backend, then there is at least one node using "normal" RAM,
> -     * so if its page size is smaller we have got to report that size instead.
> -     */
> -    if (hpsize > mainrampagesize &&
> -        (ms->numa_state == NULL ||
> -         ms->numa_state->num_nodes == 0 ||
> -         ms->numa_state->nodes[0].node_memdev == NULL)) {
> -        static bool warned;
> -        if (!warned) {
> -            error_report("Huge page support disabled (n/a for main memory).");
> -            warned = true;
> -        }
> -        return mainrampagesize;
> -    }
> +    long hpsize;
> +    Object *memdev_root = object_resolve_path("/objects", NULL);
>  
> +    object_child_foreach(memdev_root, find_min_backend_pagesize, &hpsize);
>      return hpsize;
>  }
>  
>  long qemu_maxrampagesize(void)
>  {
> -    long pagesize = qemu_mempath_getpagesize(mem_path);
> +    long pagesize;
>      Object *memdev_root = object_resolve_path("/objects", NULL);
>  
> -    if (memdev_root) {
> -        object_child_foreach(memdev_root, find_max_backend_pagesize,
> -                             &pagesize);
> -    }
> +    object_child_foreach(memdev_root, find_max_backend_pagesize, &pagesize);
>      return pagesize;
>  }
>  #else


Re: [PATCH REPOST v3 74/80] exec: cleanup qemu_minrampagesize()/qemu_maxrampagesize()
Posted by David Gibson 6 years ago
On Fri, Jan 24, 2020 at 11:25:11AM +0100, Igor Mammedov wrote:
> On Thu, 23 Jan 2020 12:38:39 +0100
> Igor Mammedov <imammedo@redhat.com> wrote:
> 
> > Since all RAM is backed by hostmem backends, drop
> > global -mem-path invariant and simplify code.
> 
> Looks like origin of removed here code is PPC,
> could PPC folk review this please?

Oh, sure.  I don't think I was CCed initially - I generally don't have
the bandwidth to scan qemu-devel.

I haven't looked at this series as a whole, only the bits which were
CCed to me (presumably because they touched ppc code).  But assuming
the statement above is correct, that everything is now backed by
hostmem backends, then the idea of this change should be fine.

But...

> 
> > Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> > ---
> > CC: pbonzini@redhat.com
> > CC: rth@twiddle.net
> > ---
> >  exec.c | 51 +++++----------------------------------------------
> >  1 file changed, 5 insertions(+), 46 deletions(-)
> > 
> > diff --git a/exec.c b/exec.c
> > index 67e520d..809987c 100644
> > --- a/exec.c
> > +++ b/exec.c
> > @@ -1667,60 +1667,19 @@ static int find_max_backend_pagesize(Object *obj, void *opaque)
> >   */
> >  long qemu_minrampagesize(void)
> >  {
> > -    long hpsize = LONG_MAX;
> > -    long mainrampagesize;
> > -    Object *memdev_root;
> > -    MachineState *ms = MACHINE(qdev_get_machine());
> > -
> > -    mainrampagesize = qemu_mempath_getpagesize(mem_path);
> > -
> > -    /* 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
> > -     * hooks. we want to take these into account, but we
> > -     * also want to make sure these supported hugepage
> > -     * sizes are applicable across the entire range of memory
> > -     * we may boot from, so we take the min across all
> > -     * backends, and assume normal pages in cases where a
> > -     * backend isn't backed by hugepages.
> > -     */
> > -    memdev_root = object_resolve_path("/objects", NULL);
> > -    if (memdev_root) {
> > -        object_child_foreach(memdev_root, find_min_backend_pagesize, &hpsize);
> > -    }
> > -    if (hpsize == LONG_MAX) {
> > -        /* No additional memory regions found ==> Report main RAM page size */
> > -        return mainrampagesize;
> > -    }
> > -
> > -    /* If NUMA is disabled or the NUMA nodes are not backed with a
> > -     * memory-backend, then there is at least one node using "normal" RAM,
> > -     * so if its page size is smaller we have got to report that size instead.
> > -     */
> > -    if (hpsize > mainrampagesize &&
> > -        (ms->numa_state == NULL ||
> > -         ms->numa_state->num_nodes == 0 ||
> > -         ms->numa_state->nodes[0].node_memdev == NULL)) {
> > -        static bool warned;
> > -        if (!warned) {
> > -            error_report("Huge page support disabled (n/a for main memory).");
> > -            warned = true;
> > -        }
> > -        return mainrampagesize;
> > -    }
> > +    long hpsize;

hpsize absolutely has to be initialized.  find_min_backend_pagesize()
reads it as well as writing it, so if it's uninitialized you'll have
UB.

> > +    Object *memdev_root = object_resolve_path("/objects", NULL);
> >  
> > +    object_child_foreach(memdev_root, find_min_backend_pagesize, &hpsize);
> >      return hpsize;
> >  }
> >  
> >  long qemu_maxrampagesize(void)
> >  {
> > -    long pagesize = qemu_mempath_getpagesize(mem_path);
> > +    long pagesize;

Same here.

> >      Object *memdev_root = object_resolve_path("/objects", NULL);
> >  
> > -    if (memdev_root) {
> > -        object_child_foreach(memdev_root, find_max_backend_pagesize,
> > -                             &pagesize);
> > -    }
> > +    object_child_foreach(memdev_root, find_max_backend_pagesize, &pagesize);
> >      return pagesize;
> >  }
> >  #else
> 

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
[PATCH v3.1 74/80] exec: cleanup qemu_minrampagesize()/qemu_maxrampagesize()
Posted by Igor Mammedov 6 years ago
Since all RAM is backed by hostmem backends, drop
global -mem-path invariant and simplify code.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
v4:
  * fix access to uninitialized pagesize/hpsize
    (David Gibson <david@gibson.dropbear.id.au>)

CC: thuth@redhat.com
CC: aik@ozlabs.ru
CC: mdroth@linux.vnet.ibm.com
CC: david@gibson.dropbear.id.au
CC: qemu-ppc@nongnu.org
CC: pbonzini@redhat.com
CC: rth@twiddle.net
---
 exec.c | 49 ++++---------------------------------------------
 1 file changed, 4 insertions(+), 45 deletions(-)

diff --git a/exec.c b/exec.c
index 67e520d..9f5421c 100644
--- a/exec.c
+++ b/exec.c
@@ -1668,59 +1668,18 @@ static int find_max_backend_pagesize(Object *obj, void *opaque)
 long qemu_minrampagesize(void)
 {
     long hpsize = LONG_MAX;
-    long mainrampagesize;
-    Object *memdev_root;
-    MachineState *ms = MACHINE(qdev_get_machine());
-
-    mainrampagesize = qemu_mempath_getpagesize(mem_path);
-
-    /* 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
-     * hooks. we want to take these into account, but we
-     * also want to make sure these supported hugepage
-     * sizes are applicable across the entire range of memory
-     * we may boot from, so we take the min across all
-     * backends, and assume normal pages in cases where a
-     * backend isn't backed by hugepages.
-     */
-    memdev_root = object_resolve_path("/objects", NULL);
-    if (memdev_root) {
-        object_child_foreach(memdev_root, find_min_backend_pagesize, &hpsize);
-    }
-    if (hpsize == LONG_MAX) {
-        /* No additional memory regions found ==> Report main RAM page size */
-        return mainrampagesize;
-    }
-
-    /* If NUMA is disabled or the NUMA nodes are not backed with a
-     * memory-backend, then there is at least one node using "normal" RAM,
-     * so if its page size is smaller we have got to report that size instead.
-     */
-    if (hpsize > mainrampagesize &&
-        (ms->numa_state == NULL ||
-         ms->numa_state->num_nodes == 0 ||
-         ms->numa_state->nodes[0].node_memdev == NULL)) {
-        static bool warned;
-        if (!warned) {
-            error_report("Huge page support disabled (n/a for main memory).");
-            warned = true;
-        }
-        return mainrampagesize;
-    }
+    Object *memdev_root = object_resolve_path("/objects", NULL);
 
+    object_child_foreach(memdev_root, find_min_backend_pagesize, &hpsize);
     return hpsize;
 }
 
 long qemu_maxrampagesize(void)
 {
-    long pagesize = qemu_mempath_getpagesize(mem_path);
+    long pagesize = 0;
     Object *memdev_root = object_resolve_path("/objects", NULL);
 
-    if (memdev_root) {
-        object_child_foreach(memdev_root, find_max_backend_pagesize,
-                             &pagesize);
-    }
+    object_child_foreach(memdev_root, find_max_backend_pagesize, &pagesize);
     return pagesize;
 }
 #else
-- 
2.7.4


Re: [PATCH v3.1 74/80] exec: cleanup qemu_minrampagesize()/qemu_maxrampagesize()
Posted by David Gibson 6 years ago
On Mon, Jan 27, 2020 at 09:06:48AM +0100, Igor Mammedov wrote:
> Since all RAM is backed by hostmem backends, drop
> global -mem-path invariant and simplify code.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> v4:
>   * fix access to uninitialized pagesize/hpsize
>     (David Gibson <david@gibson.dropbear.id.au>)

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> CC: thuth@redhat.com
> CC: aik@ozlabs.ru
> CC: mdroth@linux.vnet.ibm.com
> CC: david@gibson.dropbear.id.au
> CC: qemu-ppc@nongnu.org
> CC: pbonzini@redhat.com
> CC: rth@twiddle.net
> ---
>  exec.c | 49 ++++---------------------------------------------
>  1 file changed, 4 insertions(+), 45 deletions(-)
> 
> diff --git a/exec.c b/exec.c
> index 67e520d..9f5421c 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -1668,59 +1668,18 @@ static int find_max_backend_pagesize(Object *obj, void *opaque)
>  long qemu_minrampagesize(void)
>  {
>      long hpsize = LONG_MAX;
> -    long mainrampagesize;
> -    Object *memdev_root;
> -    MachineState *ms = MACHINE(qdev_get_machine());
> -
> -    mainrampagesize = qemu_mempath_getpagesize(mem_path);
> -
> -    /* 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
> -     * hooks. we want to take these into account, but we
> -     * also want to make sure these supported hugepage
> -     * sizes are applicable across the entire range of memory
> -     * we may boot from, so we take the min across all
> -     * backends, and assume normal pages in cases where a
> -     * backend isn't backed by hugepages.
> -     */
> -    memdev_root = object_resolve_path("/objects", NULL);
> -    if (memdev_root) {
> -        object_child_foreach(memdev_root, find_min_backend_pagesize, &hpsize);
> -    }
> -    if (hpsize == LONG_MAX) {
> -        /* No additional memory regions found ==> Report main RAM page size */
> -        return mainrampagesize;
> -    }
> -
> -    /* If NUMA is disabled or the NUMA nodes are not backed with a
> -     * memory-backend, then there is at least one node using "normal" RAM,
> -     * so if its page size is smaller we have got to report that size instead.
> -     */
> -    if (hpsize > mainrampagesize &&
> -        (ms->numa_state == NULL ||
> -         ms->numa_state->num_nodes == 0 ||
> -         ms->numa_state->nodes[0].node_memdev == NULL)) {
> -        static bool warned;
> -        if (!warned) {
> -            error_report("Huge page support disabled (n/a for main memory).");
> -            warned = true;
> -        }
> -        return mainrampagesize;
> -    }
> +    Object *memdev_root = object_resolve_path("/objects", NULL);
>  
> +    object_child_foreach(memdev_root, find_min_backend_pagesize, &hpsize);
>      return hpsize;
>  }
>  
>  long qemu_maxrampagesize(void)
>  {
> -    long pagesize = qemu_mempath_getpagesize(mem_path);
> +    long pagesize = 0;
>      Object *memdev_root = object_resolve_path("/objects", NULL);
>  
> -    if (memdev_root) {
> -        object_child_foreach(memdev_root, find_max_backend_pagesize,
> -                             &pagesize);
> -    }
> +    object_child_foreach(memdev_root, find_max_backend_pagesize, &pagesize);
>      return pagesize;
>  }
>  #else

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson