From: zhanghailiang <zhang.zhanghailiang@huawei.com>
To: qemu-devel@nongnu.org
Cc: zhanghailiang <zhang.zhanghailiang@huawei.com>,
mst@redhat.com, hutao@cn.fujitsu.com, luonengjun@huawei.com,
peter.huangpeng@huawei.com, xiexiangyou <xiexiangyou@huawei.com>,
aliguori@amazon.com, pbonzini@redhat.com,
gaowanlong@cn.fujitsu.com
Subject: [Qemu-devel] [PATCH] mlock: fix bug when mlockall called before mbind
Date: Wed, 13 Aug 2014 19:21:57 +0800 [thread overview]
Message-ID: <1407928917-16220-1-git-send-email-zhang.zhanghailiang@huawei.com> (raw)
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
next reply other threads:[~2014-08-13 11:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-13 11:21 zhanghailiang [this message]
2014-08-13 11:50 ` [Qemu-devel] [PATCH] mlock: fix bug when mlockall called before mbind 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
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=1407928917-16220-1-git-send-email-zhang.zhanghailiang@huawei.com \
--to=zhang.zhanghailiang@huawei.com \
--cc=aliguori@amazon.com \
--cc=gaowanlong@cn.fujitsu.com \
--cc=hutao@cn.fujitsu.com \
--cc=luonengjun@huawei.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.huangpeng@huawei.com \
--cc=qemu-devel@nongnu.org \
--cc=xiexiangyou@huawei.com \
/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).