Skip to contentSkip to conversation

Add host_memory_backend_pagesize() helper

PATCH In review David Gibson 4 participants 7 messages Mar 29, 2018 – Apr 3, 2018 Arm STM32

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add host_memory_backend_pagesize() helper

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.

---
 backends/hostmem.c       | 20 ++++++++++++++++++++
 exec.c                   | 21 +++++----------------
 include/sysemu/hostmem.h |  2 ++
 target/ppc/kvm.c         | 10 +---------
 4 files changed, 28 insertions(+), 25 deletions(-)
backends/hostmem.c +20 -0
index f61093654e..b6a60cfc5d 100644
@@ -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,25 @@ bool host_memory_backend_is_mapped(HostMemoryBackend *backend)
     return backend->is_mapped;
 }
 
+long host_memory_backend_pagesize(HostMemoryBackend *memdev)
+{
+    const char *path = NULL;
+
+#ifdef __linux__
+    if (memdev) {
+        path = object_property_get_str(OBJECT(memdev), "mem-path", NULL);
+    } else {
+        path = mem_path;
+    }
+#endif
+
+    if (path) {
+        return qemu_mempath_getpagesize(path);
+    } else {
+        return getpagesize();
+    }
+}
+
 static void
 host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
 {
exec.c +5 -16
index c09bd93df3..04856c2402 100644
@@ -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);
-            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
include/sysemu/hostmem.h +2 -0
index 47bc9846ac..f474ef97f6 100644
@@ -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
target/ppc/kvm.c +1 -9
index b329cd8173..0adcf18c9f 100644
@@ -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);
-    } else {
-        pagesize = getpagesize();
-    }
+    long pagesize = host_memory_backend_pagesize(MEMORY_BACKEND(mem_obj));
 
     return pagesize >= max_cpu_page_size;
 }
Signature · 1 line
2.14.3
#1 lore raw
Quoted 11 lines · On Thu, 29 Mar 2018 16:25:37 +1100 David Gibson <[email protected]>…

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.

---

The idea is good but there's a small issue. See below.

Quoted 19 lines
 backends/hostmem.c       | 20 ++++++++++++++++++++
 exec.c                   | 21 +++++----------------
 include/sysemu/hostmem.h |  2 ++
 target/ppc/kvm.c         | 10 +---------
 4 files changed, 28 insertions(+), 25 deletions(-)
backends/hostmem.c +1 -0
index f61093654e..b6a60cfc5d 100644
@@ -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>

backends/hostmem.c bool host_memory_backend_is_mapped(HostMemoryBackend *backend) · line 272

Quoted 10 lines
backends/hostmem.c +7 -0
@@ -262,6 +263,25 @@ bool host_memory_backend_is_mapped(HostMemoryBackend *backend)
     return backend->is_mapped;
 }
 
+long host_memory_backend_pagesize(HostMemoryBackend *memdev)
+{
+    const char *path = NULL;
+
+#ifdef __linux__
+    if (memdev) {
+        path = object_property_get_str(OBJECT(memdev), "mem-path", NULL);

object_property_get_str() returns an allocated string. It should be freed before returning.

Quoted 20 lines
backends/hostmem.c +12 -0
+    } else {
+        path = mem_path;
+    }
+#endif
+
+    if (path) {
+        return qemu_mempath_getpagesize(path);
+    } else {
+        return getpagesize();
+    }
+}
+
 static void
 host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
 {
exec.c +0 -0
index c09bd93df3..04856c2402 100644

exec.c void ram_block_dump(Monitor *mon) · line 1497

Quoted 10 lines
exec.c +0 -4
@@ -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...

Quoted 45 lines
exec.c +5 -12
-            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
include/sysemu/hostmem.h +2 -0
index 47bc9846ac..f474ef97f6 100644
@@ -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
target/ppc/kvm.c +0 -0
index b329cd8173..0adcf18c9f 100644

target/ppc/kvm.c static void kvm_fixup_page_sizes(PowerPCCPU *cpu) · line 501

Quoted 9 lines
target/ppc/kvm.c +0 -6
@@ -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 :)

Quoted 7 lines
target/ppc/kvm.c +1 -3
-    } else {
-        pagesize = getpagesize();
-    }
+    long pagesize = host_memory_backend_pagesize(MEMORY_BACKEND(mem_obj));
 
     return pagesize >= max_cpu_page_size;
 }
#2 lore raw
Quoted 15 lines · On Thu, 29 Mar 2018 08:37:48 +0200 Greg Kurz <[email protected]> wrote:
Quoted 11 lines · On Thu, 29 Mar 2018 16:25:37 +1100 David Gibson <[email protected]>…

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.

---

[...]

Quoted 11 lines
Quoted 11 lines
exec.c +0 -1
index c09bd93df3..04856c2402 100644
@@ -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;
 
Quoted 7 lines

exec.c void ram_block_dump(Monitor *mon) · line 1497

Quoted 4 lines
exec.c +0 -3
     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

Quoted 66 lines
Quoted 45 lines
exec.c +5 -12
-            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
include/sysemu/hostmem.h +2 -0
index 47bc9846ac..f474ef97f6 100644
@@ -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
target/ppc/kvm.c +0 -0
index b329cd8173..0adcf18c9f 100644

target/ppc/kvm.c static void kvm_fixup_page_sizes(PowerPCCPU *cpu) · line 501

Quoted 9 lines
target/ppc/kvm.c +0 -6
@@ -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 :)

Quoted 7 lines
target/ppc/kvm.c +1 -3
-    } else {
-        pagesize = getpagesize();
-    }
+    long pagesize = host_memory_backend_pagesize(MEMORY_BACKEND(mem_obj));
 
     return pagesize >= max_cpu_page_size;
 }  
#3 lore raw
In reply to Greg Kurz
Quoted 39 lines · Greg Kurz
Quoted 11 lines · On Thu, 29 Mar 2018 16:25:37 +1100 David Gibson <[email protected]>…

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.

---

The idea is good but there's a small issue. See below.

Quoted 22 lines
 backends/hostmem.c       | 20 ++++++++++++++++++++
 exec.c                   | 21 +++++----------------
 include/sysemu/hostmem.h |  2 ++
 target/ppc/kvm.c         | 10 +---------
 4 files changed, 28 insertions(+), 25 deletions(-)
backends/hostmem.c +1 -0
index f61093654e..b6a60cfc5d 100644
@@ -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,25 @@ bool host_memory_backend_is_mapped(HostMemoryBackend *backend)
     return backend->is_mapped;
 }
 
Quoted 10 lines

backends/hostmem.c bool host_memory_backend_is_mapped(HostMemoryBackend *backend) · line 272

Quoted 7 lines
backends/hostmem.c +7 -0
+long host_memory_backend_pagesize(HostMemoryBackend *memdev)
+{
+    const char *path = NULL;
+
+#ifdef __linux__
+    if (memdev) {
+        path = object_property_get_str(OBJECT(memdev), "mem-path", NULL);

object_property_get_str() returns an allocated string. It should be freed before returning.

Ah, nice catch, I'll correct that.

Signature · 4 lines
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
#4 lore raw
In reply to David Gibson
This series failed docker-build@min-glib build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.

Hi,

This series failed docker-build@min-glib build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.

Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH for-2.13] Add host_memory_backend_pagesize() helper

=== TEST SCRIPT BEGIN ===
#!/bin/bash
set -e
git submodule update --init dtc
# Let docker tests dump environment info export SHOW_ENV=1
export J=8
time make docker-test-build@min-glib === TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 Switched to a new branch 'test'
d792ec03e0 Add host_memory_backend_pagesize() helper

=== OUTPUT BEGIN ===
Submodule 'dtc' (git://git.qemu-project.org/dtc.git) registered for path 'dtc'
Cloning into '/var/tmp/patchew-tester-tmp-zb9x6tst/src/dtc'...
Submodule path 'dtc': checked out 'e54388015af1fb4bf04d0bca99caba1074d9cc42'
BUILD min-glib
make[1]: Entering directory '/var/tmp/patchew-tester-tmp-zb9x6tst/src'
GEN /var/tmp/patchew-tester-tmp-zb9x6tst/src/docker-src.2018-03-31-03.59.56.9769/qemu.tar
Cloning into '/var/tmp/patchew-tester-tmp-zb9x6tst/src/docker-src.2018-03-31-03.59.56.9769/qemu.tar.vroot'... done.

Checking out files:  25% (1567/6066)   
Checking out files:  26% (1578/6066)   
Checking out files:  27% (1638/6066)   
Checking out files:  28% (1699/6066)   
Checking out files:  29% (1760/6066)   
Checking out files:  30% (1820/6066)   
Checking out files:  31% (1881/6066)   
Checking out files:  31% (1902/6066)   
Checking out files:  32% (1942/6066)   
Checking out files:  33% (2002/6066)   
Checking out files:  34% (2063/6066)   
Checking out files:  35% (2124/6066)   
Checking out files:  36% (2184/6066)   
Checking out files:  37% (2245/6066)   
Checking out files:  38% (2306/6066)   
Checking out files:  39% (2366/6066)   
Checking out files:  40% (2427/6066)   
Checking out files:  41% (2488/6066)   
Checking out files:  42% (2548/6066)   
Checking out files:  43% (2609/6066)   
Checking out files:  44% (2670/6066)   
Checking out files:  45% (2730/6066)   
Checking out files:  46% (2791/6066)   
Checking out files:  47% (2852/6066)   
Checking out files:  48% (2912/6066)   
Checking out files:  49% (2973/6066)   
Checking out files:  50% (3033/6066)   
Checking out files:  51% (3094/6066)   
Checking out files:  52% (3155/6066)   
Checking out files:  53% (3215/6066)   
Checking out files:  53% (3254/6066)   
Checking out files:  54% (3276/6066)   
Checking out files:  55% (3337/6066)   
Checking out files:  56% (3397/6066)   
Checking out files:  57% (3458/6066)   
Checking out files:  58% (3519/6066)   
Checking out files:  59% (3579/6066)   
Checking out files:  60% (3640/6066)   
Checking out files:  61% (3701/6066)   
Checking out files:  62% (3761/6066)   
Checking out files:  63% (3822/6066)   
Checking out files:  64% (3883/6066)   
Checking out files:  65% (3943/6066)   
Checking out files:  66% (4004/6066)   
Checking out files:  67% (4065/6066)   
Checking out files:  68% (4125/6066)   
Checking out files:  69% (4186/6066)   
Checking out files:  70% (4247/6066)   
Checking out files:  71% (4307/6066)   
Checking out files:  72% (4368/6066)   
Checking out files:  73% (4429/6066)   
Checking out files:  74% (4489/6066)   
Checking out files:  75% (4550/6066)   
Checking out files:  76% (4611/6066)   
Checking out files:  77% (4671/6066)   
Checking out files:  78% (4732/6066)   
Checking out files:  79% (4793/6066)   
Checking out files:  80% (4853/6066)   
Checking out files:  81% (4914/6066)   
Checking out files:  82% (4975/6066)   
Checking out files:  82% (5033/6066)   
Checking out files:  83% (5035/6066)   
Checking out files:  84% (5096/6066)   
Checking out files:  85% (5157/6066)   
Checking out files:  86% (5217/6066)   
Checking out files:  87% (5278/6066)   
Checking out files:  88% (5339/6066)   
Checking out files:  89% (5399/6066)   
Checking out files:  90% (5460/6066)   
Checking out files:  91% (5521/6066)   
Checking out files:  92% (5581/6066)   
Checking out files:  93% (5642/6066)   
Checking out files:  94% (5703/6066)   
Checking out files:  95% (5763/6066)   
Checking out files:  96% (5824/6066)   
Checking out files:  97% (5885/6066)   
Checking out files:  98% (5945/6066)   
Checking out files:  99% (6006/6066)   
Checking out files: 100% (6066/6066)   
Checking out files: 100% (6066/6066), done.

Your branch is up-to-date with 'origin/test'.
Submodule 'dtc' (git://git.qemu-project.org/dtc.git) registered for path 'dtc'
Cloning into '/var/tmp/patchew-tester-tmp-zb9x6tst/src/docker-src.2018-03-31-03.59.56.9769/qemu.tar.vroot/dtc'... Submodule path 'dtc': checked out 'e54388015af1fb4bf04d0bca99caba1074d9cc42'
Submodule 'ui/keycodemapdb' (git://git.qemu.org/keycodemapdb.git) registered for path 'ui/keycodemapdb' Cloning into '/var/tmp/patchew-tester-tmp-zb9x6tst/src/docker-src.2018-03-31-03.59.56.9769/qemu.tar.vroot/ui/keycodemapdb'... Submodule path 'ui/keycodemapdb': checked out '6b3d716e2b6472eb7189d3220552280ef3d832ce'
tar: /var/tmp/patchew-tester-tmp-zb9x6tst/src/docker-src.2018-03-31-03.59.56.9769/qemu.tar: Wrote only 2048 of 10240 bytes
tar: Error is not recoverable: exiting now
failed to create tar file
COPY RUNNER
RUN test-build in qemu:min-glib
tar: Unexpected EOF in archive
tar: rmtlseek not stopped at a record boundary
tar: Error is not recoverable: exiting now
/var/tmp/qemu/run: line 32: prep_fail: command not found
Environment variables:
HOSTNAME=7f3db3fced08
MAKEFLAGS= -j8
J=8
CCACHE_DIR=/var/tmp/ccache
EXTRA_CONFIGURE_OPTS=
V=
SHOW_ENV=1 PATH=/usr/lib/ccache:/usr/lib64/ccache:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/
TARGET_LIST=
SHLVL=1
HOME=/root
TEST_DIR=/tmp/qemu-test
FEATURES= dtc
DEBUG=
_=/usr/bin/env

/var/tmp/qemu/run: line 52: cd: /tmp/qemu-test/src/tests/docker: No such file or directory /var/tmp/qemu/run: line 57: /test-build: No such file or directory /var/tmp/qemu/run: line 57: exec: /test-build: cannot execute: No such file or directory Traceback (most recent call last):
File "./tests/docker/docker.py", line 407, in <module>

    sys.exit(main())

File "./tests/docker/docker.py", line 404, in main
return args.cmdobj.run(args, argv)
File "./tests/docker/docker.py", line 261, in run
return Docker().run(argv, args.keep, quiet=args.quiet)
File "./tests/docker/docker.py", line 229, in run
quiet=quiet)
File "./tests/docker/docker.py", line 147, in _do_check
return subprocess.check_call(self._command + cmd, **kwargs)
File "/usr/lib64/python2.7/subprocess.py", line 186, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['docker', 'run', '--label', 'com.qemu.instance.uuid=8e141b9234b911e8a3e452540069c830', '-u', '0', '--security-opt', 'seccomp=unconfined', '--rm', '--net=none', '-e', 'TARGET_LIST=', '-e', 'EXTRA_CONFIGURE_OPTS=', '-e', 'V=', '-e', 'J=8', '-e', 'DEBUG=', '-e', 'SHOW_ENV=1', '-e', 'CCACHE_DIR=/var/tmp/ccache', '-v', '/root/.cache/qemu-docker-ccache:/var/tmp/ccache:z', '-v', '/var/tmp/patchew-tester-tmp-zb9x6tst/src/docker-src.2018-03-31-03.59.56.9769:/var/tmp/qemu:z,ro', 'qemu:min-glib', '/var/tmp/qemu/run', 'test-build']' returned non-zero exit status 126 make[1]: *** [tests/docker/Makefile.include:129: docker-run] Error 1
make[1]: Leaving directory '/var/tmp/patchew-tester-tmp-zb9x6tst/src'
make: *** [tests/docker/Makefile.include:163: docker-run-test-build@min-glib] Error 2

real 0m36.746s
user 0m9.045s
sys 0m6.498s
=== OUTPUT END ===

Test command exited with code: 2

---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]

#5 lore raw
In reply to David Gibson
Quoted 30 lines · David Gibson

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.

---
 backends/hostmem.c       | 20 ++++++++++++++++++++
 exec.c                   | 21 +++++----------------
 include/sysemu/hostmem.h |  2 ++
 target/ppc/kvm.c         | 10 +---------
 4 files changed, 28 insertions(+), 25 deletions(-)
backends/hostmem.c +1 -0
index f61093654e..b6a60cfc5d 100644
@@ -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>

backends/hostmem.c bool host_memory_backend_is_mapped(HostMemoryBackend *backend) · line 266

Quoted 4 lines
backends/hostmem.c +1 -0
@@ -262,6 +263,25 @@ bool host_memory_backend_is_mapped(HostMemoryBackend *backend)
     return backend->is_mapped;
 }
 
+long host_memory_backend_pagesize(HostMemoryBackend *memdev)

qemu_mempath_getpagesize() returns size_t. Why are you using long here?

Quoted 5 lines
backends/hostmem.c +5 -0
+{
+    const char *path = NULL;
+
+#ifdef __linux__
+    if (memdev) {

backends/hostmem.c bool host_memory_backend_is_mapped(HostMemoryBackend *backend) · line 281

Quoted 10 lines
backends/hostmem.c +10 -0
+        path = object_property_get_str(OBJECT(memdev), "mem-path", NULL);
+    } else {
+        path = mem_path;
+    }
+#endif
+
+    if (path) {
+        return qemu_mempath_getpagesize(path);
+    } else {
+        return getpagesize();

Isn't it simpler to make qemu_mempath_getpagesize() handle path==NULL?

Quoted 17 lines
backends/hostmem.c +3 -0
+    }
+}
+
 static void
 host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
 {
exec.c +0 -1
index c09bd93df3..04856c2402 100644
@@ -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;
 

exec.c void ram_block_dump(Monitor *mon) · line 1494

Quoted 10 lines
exec.c +1 -8
     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);
-            if (hpsize < *hpsize_min) {
-                *hpsize_min = hpsize;
-            }
-        } else {
-            *hpsize_min = getpagesize();
+        long hpsize = host_memory_backend_pagesize(MEMORY_BACKEND(obj));

So in this caller, backend is always non-NULL...

exec.c static int find_max_supported_pagesize(Object *obj, void *opaque) · line 1507

Quoted 12 lines
exec.c +4 -1
+
+        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);

...on this caller backend is always NULL...

Quoted 11 lines
exec.c +0 -6
     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

[...]

Quoted 9 lines
target/ppc/kvm.c +0 -1
index b329cd8173..0adcf18c9f 100644
@@ -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);

target/ppc/kvm.c static void kvm_fixup_page_sizes(PowerPCCPU *cpu) · line 497

Quoted 10 lines
target/ppc/kvm.c +1 -8
-    long pagesize;
-
-    if (mempath) {
-        pagesize = qemu_mempath_getpagesize(mempath);
-        g_free(mempath);
-    } else {
-        pagesize = getpagesize();
-    }
+    long pagesize = host_memory_backend_pagesize(MEMORY_BACKEND(mem_obj));
 

...and here backend is always non-NULL.

If there's no caller that relies on both code paths, why overload a single function for two different operations?

I would simply make qemu_mempath_getpagesize() work if path is NULL, use qemu_mempath_getpagesize(mem_path) at qemu_getrampagesize(), and make host_memory_backend_pagesize() assume require a non-NULL memdev.

target/ppc/kvm.c static void kvm_fixup_page_sizes(PowerPCCPU *cpu) · line 498

Quoted 1 line
target/ppc/kvm.c +1 -0
+long host_memory_backend_pagesize(HostMemoryBackend *memdev)

Why is the code duplicated in target/ppc/kvm.c?

Quoted 23 lines
target/ppc/kvm.c +18 -0
+{
+    const char *path = NULL;
+
+#ifdef __linux__
+    if (memdev) {
+        path = object_property_get_str(OBJECT(memdev), "mem-path", NULL);
+    } else {
+        path = mem_path;
+    }
+#endif
+
+    if (path) {
+        return qemu_mempath_getpagesize(path);
+    } else {
+        return getpagesize();
+    }
+}
+
     return pagesize >= max_cpu_page_size;
 }
Signature · 1 line
2.14.3
Signature · 1 line
Eduardo
#6 lore raw
Quoted 34 lines · Eduardo Habkost
Quoted 33 lines · David Gibson

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.

---
 backends/hostmem.c       | 20 ++++++++++++++++++++
 exec.c                   | 21 +++++----------------
 include/sysemu/hostmem.h |  2 ++
 target/ppc/kvm.c         | 10 +---------
 4 files changed, 28 insertions(+), 25 deletions(-)
backends/hostmem.c +1 -0
index f61093654e..b6a60cfc5d 100644
@@ -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,25 @@ bool host_memory_backend_is_mapped(HostMemoryBackend *backend)
     return backend->is_mapped;
 }
 
Quoted 4 lines

backends/hostmem.c bool host_memory_backend_is_mapped(HostMemoryBackend *backend) · line 266

Quoted 1 line
backends/hostmem.c +1 -0
+long host_memory_backend_pagesize(HostMemoryBackend *memdev)

qemu_mempath_getpagesize() returns size_t. Why are you using long here?

Because qemu_getrampagesize() returns long. But size_t is better, so I've changed it.

Quoted 10 lines
Quoted 10 lines
backends/hostmem.c +10 -0
+{
+    const char *path = NULL;
+
+#ifdef __linux__
+    if (memdev) {
+        path = object_property_get_str(OBJECT(memdev), "mem-path", NULL);
+    } else {
+        path = mem_path;
+    }
+#endif
Quoted 8 lines

backends/hostmem.c bool host_memory_backend_is_mapped(HostMemoryBackend *backend) · line 281

Quoted 5 lines
backends/hostmem.c +5 -0
+
+    if (path) {
+        return qemu_mempath_getpagesize(path);
+    } else {
+        return getpagesize();

Isn't it simpler to make qemu_mempath_getpagesize() handle path==NULL?

Uh.. possibly not, but things you bring up later kind of make it moot.

Quoted 80 lines
Quoted 17 lines
backends/hostmem.c +3 -0
+    }
+}
+
 static void
 host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
 {
exec.c +0 -1
index c09bd93df3..04856c2402 100644
@@ -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;
 

exec.c void ram_block_dump(Monitor *mon) · line 1494

Quoted 10 lines
exec.c +1 -8
     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);
-            if (hpsize < *hpsize_min) {
-                *hpsize_min = hpsize;
-            }
-        } else {
-            *hpsize_min = getpagesize();
+        long hpsize = host_memory_backend_pagesize(MEMORY_BACKEND(obj));

So in this caller, backend is always non-NULL...

exec.c static int find_max_supported_pagesize(Object *obj, void *opaque) · line 1507

Quoted 12 lines
exec.c +4 -1
+
+        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);

...on this caller backend is always NULL...

Quoted 11 lines
exec.c +0 -6
     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

[...]

Quoted 9 lines
target/ppc/kvm.c +0 -1
index b329cd8173..0adcf18c9f 100644
@@ -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);

target/ppc/kvm.c static void kvm_fixup_page_sizes(PowerPCCPU *cpu) · line 497

Quoted 10 lines
target/ppc/kvm.c +1 -8
-    long pagesize;
-
-    if (mempath) {
-        pagesize = qemu_mempath_getpagesize(mempath);
-        g_free(mempath);
-    } else {
-        pagesize = getpagesize();
-    }
+    long pagesize = host_memory_backend_pagesize(MEMORY_BACKEND(mem_obj));
 

...and here backend is always non-NULL.

Quoted 2 lines

If there's no caller that relies on both code paths, why overload a single function for two different operations?

Good point.

Quoted 4 lines

I would simply make qemu_mempath_getpagesize() work if path is NULL, use qemu_mempath_getpagesize(mem_path) at qemu_getrampagesize(), and make host_memory_backend_pagesize() assume require a non-NULL memdev.

Yeah, that makes sense. I thought I might have more need for a unified entry point in the code I have in the works, but looking at the latest draft, probably not.

I'll change it as you suggest.

Quoted 3 lines

target/ppc/kvm.c static void kvm_fixup_page_sizes(PowerPCCPU *cpu) · line 498

Quoted 1 line
target/ppc/kvm.c +1 -0
+long host_memory_backend_pagesize(HostMemoryBackend *memdev)

Why is the code duplicated in target/ppc/kvm.c?

Leftover from an early version, I think. I'll fix that.

Quoted 23 lines
Quoted 22 lines
target/ppc/kvm.c +18 -0
+{
+    const char *path = NULL;
+
+#ifdef __linux__
+    if (memdev) {
+        path = object_property_get_str(OBJECT(memdev), "mem-path", NULL);
+    } else {
+        path = mem_path;
+    }
+#endif
+
+    if (path) {
+        return qemu_mempath_getpagesize(path);
+    } else {
+        return getpagesize();
+    }
+}
+
     return pagesize >= max_cpu_page_size;
 }
Signature · 4 lines
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