qemu-stable
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] hostmem: don't use mbind() if host-nodes is epmty


From: Philippe Mathieu-Daudé
Subject: Re: [PATCH] hostmem: don't use mbind() if host-nodes is epmty
Date: Mon, 4 May 2020 16:31:07 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0

On 5/1/20 10:57 AM, Daniel P. Berrangé wrote:
On Thu, Apr 30, 2020 at 11:46:06AM -0400, Igor Mammedov wrote:
Since 5.0 QEMU uses hostmem backend for allocating main guest RAM.
The backend however calls mbind() which is typically NOP
in case of default policy/absent host-nodes bitmap.
However when runing in container with black-listed mbind()
syscall, QEMU fails to start with error
  "cannot bind memory to host NUMA nodes: Operation not permitted"
even when user hasn't provided host-nodes to pin to explictly
(which is the case with -m option)

To fix issue, call mbind() only in case when user has provided
host-nodes explicitly (i.e. host_nodes bitmap is not empty).
That should allow to run QEMU in containers with black-listed
mbind() without memory pinning. If QEMU provided memory-pinning
is required user still has to white-list mbind() in container
configuration.

Reported-by: Manuel Hohmann <address@hidden>
Signed-off-by: Igor Mammedov <address@hidden>
---
CC: address@hidden
CC: address@hidden
CC: address@hidden
CC: address@hidden
CC: address@hidden
---
  backends/hostmem.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/backends/hostmem.c b/backends/hostmem.c
index 327f9eebc3..0efd7b7bd6 100644
--- a/backends/hostmem.c
+++ b/backends/hostmem.c
@@ -383,8 +383,10 @@ host_memory_backend_memory_complete(UserCreatable *uc, 
Error **errp)
          assert(sizeof(backend->host_nodes) >=
                 BITS_TO_LONGS(MAX_NODES + 1) * sizeof(unsigned long));
          assert(maxnode <= MAX_NODES);
-        if (mbind(ptr, sz, backend->policy,
-                  maxnode ? backend->host_nodes : NULL, maxnode + 1, flags)) {
+
+        if (maxnode &&
+            mbind(ptr, sz, backend->policy, backend->host_nodes, maxnode + 1,
+                  flags)) {
              if (backend->policy != MPOL_DEFAULT || errno != ENOSYS) {
                  error_setg_errno(errp, errno,
                                   "cannot bind memory to host NUMA nodes");

personally I would have found this code clearer if the
check had been  "if (backend->policy != MPOL_DEFAULT && ..."
as I had to read quite a few lines to understand that the
'maxnode' is zero if-and-only-if  policy == MPOL_DEFAULT

Regardless though, this is functionally correct so

    Reviewed-by: Daniel P. Berrangé <address@hidden>

I could reproduce running 'make check-qtest-hppa' on the qemu:fedora image:

  TEST    check-qtest-hppa: tests/qtest/boot-serial-test
qemu-system-hppa: cannot bind memory to host NUMA nodes: Operation not permitted
Broken pipe
tests/qtest/libqtest.c:166: kill_qemu() tried to terminate QEMU process but encountered exit status 1 (expected 0)
ERROR - too few tests run (expected 1, got 0)
make: *** [tests/Makefile.include:637: check-qtest-hppa] Error 1

Tested-by: Philippe Mathieu-Daudé <address@hidden>


Regards,
Daniel





reply via email to

[Prev in Thread] Current Thread [Next in Thread]