qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] mlock: fix bug when mlockall called before mbind
@ 2014-08-13 11:21 zhanghailiang
  2014-08-13 11:50 ` Michael S. Tsirkin
  0 siblings, 1 reply; 7+ messages in thread
From: zhanghailiang @ 2014-08-13 11:21 UTC (permalink / raw)
  To: qemu-devel
  Cc: zhanghailiang, mst, hutao, luonengjun, peter.huangpeng,
	xiexiangyou, aliguori, pbonzini, gaowanlong

If we configure qemu with realtime-mlock-on and memory-node-bind at the same time,
Qemu will fail to start, and mbind() fails with message "Input/output error".

>From man page:
int mbind(void *addr, unsigned long len, int mode,
                 unsigned long *nodemask, unsigned long maxnode,
                 unsigned flags);
The *MPOL_BIND* mode specifies a strict policy that restricts memory allocation
to the nodes specified in nodemask.
If *MPOL_MF_STRICT* is passed in flags and policy is not MPOL_DEFAULT(In qemu
here is MPOL_BIND), then the call will fail with the error EIO if the existing
pages in  the memory range don't follow the policy.

The memory locked ahead by mlockall can not guarantee to follow the policy above,
And if that happens, it will result in an EIO error.

So we should call mlock after mbind, here we adjust the place where called mlock,
Move it to function pc_memory_init.

Signed-off-by: xiexiangyou <xiexiangyou@huawei.com>
Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
---
 hw/i386/pc.c            |  8 ++++++++
 include/sysemu/sysemu.h |  1 +
 vl.c                    | 10 +---------
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 9e58982..08a03c2 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1321,6 +1321,14 @@ FWCfgState *pc_memory_init(MachineState *machine,
     for (i = 0; i < nb_option_roms; i++) {
         rom_add_option(option_rom[i].name, option_rom[i].bootindex);
     }
+
+    if (enable_mlock) {
+        if (os_mlock() < 0) {
+            error_report("qemu: locking memory failed\n");
+            exit(EXIT_FAILURE);
+        }
+    }
+
     guest_info->fw_cfg = fw_cfg;
     return fw_cfg;
 }
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index d8539fd..b61e78f 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -136,6 +136,7 @@ extern uint8_t qemu_extra_params_fw[2];
 extern QEMUClockType rtc_clock;
 extern const char *mem_path;
 extern int mem_prealloc;
+extern bool enable_mlock;
 
 #define MAX_NODES 128
 
diff --git a/vl.c b/vl.c
index a8029d5..9a19d97 100644
--- a/vl.c
+++ b/vl.c
@@ -134,6 +134,7 @@ const char* keyboard_layout = NULL;
 ram_addr_t ram_size;
 const char *mem_path = NULL;
 int mem_prealloc = 0; /* force preallocation of physical target memory */
+bool enable_mlock = false;
 int nb_nics;
 NICInfo nd_table[MAX_NICS];
 int autostart;
@@ -1419,16 +1420,7 @@ static void smp_parse(QemuOpts *opts)
 
 static void configure_realtime(QemuOpts *opts)
 {
-    bool enable_mlock;
-
     enable_mlock = qemu_opt_get_bool(opts, "mlock", true);
-
-    if (enable_mlock) {
-        if (os_mlock() < 0) {
-            fprintf(stderr, "qemu: locking memory failed\n");
-            exit(1);
-        }
-    }
 }
 
 
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-08-18  0:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-13 11:21 [Qemu-devel] [PATCH] mlock: fix bug when mlockall called before mbind zhanghailiang
2014-08-13 11:50 ` Michael S. Tsirkin
2014-08-14  6:31   ` zhanghailiang
2014-08-14  7:15     ` Hu Tao
2014-08-14  9:09       ` zhanghailiang
2014-08-14  9:56         ` Michael S. Tsirkin
2014-08-18  0:36           ` zhanghailiang

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).