2014-06-06 17:54:29 +02:00
|
|
|
/*
|
|
|
|
* QEMU Host Memory Backend
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013-2014 Red Hat Inc
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Igor Mammedov <imammedo@redhat.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*/
|
2018-02-11 10:36:01 +01:00
|
|
|
|
2016-01-29 18:49:54 +01:00
|
|
|
#include "qemu/osdep.h"
|
2014-06-06 17:54:29 +02:00
|
|
|
#include "sysemu/hostmem.h"
|
2019-08-12 07:23:57 +02:00
|
|
|
#include "sysemu/sysemu.h"
|
hostmem: Fix qemu_opt_get_bool() crash in host_memory_backend_init()
This fixes the following crash, introduced by commit
49d2e648e8087d154d8bf8b91f27c8e05e79d5a6:
$ gdb --args qemu-system-x86_64 -machine pc,mem-merge=off -object memory-backend-ram,id=ram-node0,size=1024
[...]
Program received signal SIGABRT, Aborted.
(gdb) bt
#0 0x00007ffff253b8c7 in raise () at /lib64/libc.so.6
#1 0x00007ffff253d52a in abort () at /lib64/libc.so.6
#2 0x00007ffff253446d in __assert_fail_base () at /lib64/libc.so.6
#3 0x00007ffff2534522 in () at /lib64/libc.so.6
#4 0x00005555558bb80a in qemu_opt_get_bool_helper (opts=0x55555621b650, name=name@entry=0x5555558ec922 "mem-merge", defval=defval@entry=true, del=del@entry=false) at qemu/util/qemu-option.c:388
#5 0x00005555558bbb5a in qemu_opt_get_bool (opts=<optimized out>, name=name@entry=0x5555558ec922 "mem-merge", defval=defval@entry=true) at qemu/util/qemu-option.c:398
#6 0x0000555555720a24 in host_memory_backend_init (obj=0x5555562ac970) at qemu/backends/hostmem.c:226
Instead of using qemu_opt_get_bool(), that didn't work with
qemu_machine_opts for a long time, we can use the corresponding
MachineState fields.
Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2015-07-16 22:29:12 +02:00
|
|
|
#include "hw/boards.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 09:01:28 +01:00
|
|
|
#include "qapi/error.h"
|
2018-02-11 10:36:05 +01:00
|
|
|
#include "qapi/qapi-builtin-visit.h"
|
2014-06-06 17:54:29 +02:00
|
|
|
#include "qapi/visitor.h"
|
|
|
|
#include "qemu/config-file.h"
|
|
|
|
#include "qom/object_interfaces.h"
|
2018-04-03 07:05:45 +02:00
|
|
|
#include "qemu/mmap-alloc.h"
|
2014-06-06 17:54:29 +02:00
|
|
|
|
2014-06-10 13:15:25 +02:00
|
|
|
#ifdef CONFIG_NUMA
|
|
|
|
#include <numaif.h>
|
|
|
|
QEMU_BUILD_BUG_ON(HOST_MEM_POLICY_DEFAULT != MPOL_DEFAULT);
|
|
|
|
QEMU_BUILD_BUG_ON(HOST_MEM_POLICY_PREFERRED != MPOL_PREFERRED);
|
|
|
|
QEMU_BUILD_BUG_ON(HOST_MEM_POLICY_BIND != MPOL_BIND);
|
|
|
|
QEMU_BUILD_BUG_ON(HOST_MEM_POLICY_INTERLEAVE != MPOL_INTERLEAVE);
|
|
|
|
#endif
|
|
|
|
|
hostmem: use object id for memory region name with >= 4.0
hostmem-file and hostmem-memfd use the whole object path for the
memory region name, and hostname-ram uses only the path component (the
object id, or canonical path basename):
qemu -m 1024 -object memory-backend-file,id=mem,size=1G,mem-path=/tmp/foo -numa node,memdev=mem -monitor stdio
(qemu) info ramblock
Block Name PSize Offset Used Total
/objects/mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000
qemu -m 1024 -object memory-backend-memfd,id=mem,size=1G -numa node,memdev=mem -monitor stdio
(qemu) info ramblock
Block Name PSize Offset Used Total
/objects/mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000
qemu -m 1024 -object memory-backend-ram,id=mem,size=1G -numa node,memdev=mem -monitor stdio
(qemu) info ramblock
Block Name PSize Offset Used Total
mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000
For consistency, change to use object id for -file and -memfd as well
with >= 4.0.
Having a consistent naming allows to migrate to different hostmem
backends.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Acked-by: Eduardo Habkost <ehabkost@redhat.com>
2018-09-12 14:18:00 +02:00
|
|
|
char *
|
|
|
|
host_memory_backend_get_name(HostMemoryBackend *backend)
|
|
|
|
{
|
|
|
|
if (!backend->use_canonical_path) {
|
|
|
|
return object_get_canonical_path_component(OBJECT(backend));
|
|
|
|
}
|
|
|
|
|
|
|
|
return object_get_canonical_path(OBJECT(backend));
|
|
|
|
}
|
|
|
|
|
2014-06-06 17:54:29 +02:00
|
|
|
static void
|
qom: Swap 'name' next to visitor in ObjectPropertyAccessor
Similar to the previous patch, it's nice to have all functions
in the tree that involve a visitor and a name for conversion to
or from QAPI to consistently stick the 'name' parameter next
to the Visitor parameter.
Done by manually changing include/qom/object.h and qom/object.c,
then running this Coccinelle script and touching up the fallout
(Coccinelle insisted on adding some trailing whitespace).
@ rule1 @
identifier fn;
typedef Object, Visitor, Error;
identifier obj, v, opaque, name, errp;
@@
void fn
- (Object *obj, Visitor *v, void *opaque, const char *name,
+ (Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp) { ... }
@@
identifier rule1.fn;
expression obj, v, opaque, name, errp;
@@
fn(obj, v,
- opaque, name,
+ name, opaque,
errp)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-20-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:55 +01:00
|
|
|
host_memory_backend_get_size(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
2014-06-06 17:54:29 +02:00
|
|
|
{
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
|
|
|
|
uint64_t value = backend->size;
|
|
|
|
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:54 +01:00
|
|
|
visit_type_size(v, name, &value, errp);
|
2014-06-06 17:54:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
qom: Swap 'name' next to visitor in ObjectPropertyAccessor
Similar to the previous patch, it's nice to have all functions
in the tree that involve a visitor and a name for conversion to
or from QAPI to consistently stick the 'name' parameter next
to the Visitor parameter.
Done by manually changing include/qom/object.h and qom/object.c,
then running this Coccinelle script and touching up the fallout
(Coccinelle insisted on adding some trailing whitespace).
@ rule1 @
identifier fn;
typedef Object, Visitor, Error;
identifier obj, v, opaque, name, errp;
@@
void fn
- (Object *obj, Visitor *v, void *opaque, const char *name,
+ (Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp) { ... }
@@
identifier rule1.fn;
expression obj, v, opaque, name, errp;
@@
fn(obj, v,
- opaque, name,
+ name, opaque,
errp)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-20-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:55 +01:00
|
|
|
host_memory_backend_set_size(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
2014-06-06 17:54:29 +02:00
|
|
|
{
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
|
|
|
|
Error *local_err = NULL;
|
|
|
|
uint64_t value;
|
|
|
|
|
2017-03-10 14:09:30 +01:00
|
|
|
if (host_memory_backend_mr_inited(backend)) {
|
2019-01-02 06:26:24 +01:00
|
|
|
error_setg(&local_err, "cannot change property %s of %s ",
|
|
|
|
name, object_get_typename(obj));
|
2014-06-06 17:54:29 +02:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:54 +01:00
|
|
|
visit_type_size(v, name, &value, &local_err);
|
2014-06-06 17:54:29 +02:00
|
|
|
if (local_err) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (!value) {
|
2019-01-02 06:26:24 +01:00
|
|
|
error_setg(&local_err,
|
|
|
|
"property '%s' of %s doesn't take value '%" PRIu64 "'",
|
|
|
|
name, object_get_typename(obj), value);
|
2014-06-06 17:54:29 +02:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
backend->size = value;
|
|
|
|
out:
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
}
|
|
|
|
|
2014-06-10 13:15:25 +02:00
|
|
|
static void
|
qom: Swap 'name' next to visitor in ObjectPropertyAccessor
Similar to the previous patch, it's nice to have all functions
in the tree that involve a visitor and a name for conversion to
or from QAPI to consistently stick the 'name' parameter next
to the Visitor parameter.
Done by manually changing include/qom/object.h and qom/object.c,
then running this Coccinelle script and touching up the fallout
(Coccinelle insisted on adding some trailing whitespace).
@ rule1 @
identifier fn;
typedef Object, Visitor, Error;
identifier obj, v, opaque, name, errp;
@@
void fn
- (Object *obj, Visitor *v, void *opaque, const char *name,
+ (Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp) { ... }
@@
identifier rule1.fn;
expression obj, v, opaque, name, errp;
@@
fn(obj, v,
- opaque, name,
+ name, opaque,
errp)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-20-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:55 +01:00
|
|
|
host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
2014-06-10 13:15:25 +02:00
|
|
|
{
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
|
|
|
|
uint16List *host_nodes = NULL;
|
|
|
|
uint16List **node = &host_nodes;
|
|
|
|
unsigned long value;
|
|
|
|
|
|
|
|
value = find_first_bit(backend->host_nodes, MAX_NODES);
|
|
|
|
if (value == MAX_NODES) {
|
2019-02-14 11:57:33 +01:00
|
|
|
goto ret;
|
2014-06-10 13:15:25 +02:00
|
|
|
}
|
|
|
|
|
Revert "hostmem: fix QEMU crash by 'info memdev'"
This reverts commit 1454d33f0507cb54d62ed80f494884157c9e7130.
The string input visitor regression fixed in the previous commit made
visit_type_uint16List() fail on empty input. query_memdev() calls it
via object_property_get_uint16List(). Because it doesn't expect it to
fail, it passes &error_abort, and duly crashes.
Commit 1454d33 "fixes" this crash by making
host_memory_backend_get_host_nodes() return a list containing just
MAX_NODES instead of the empty list. Papers over the regression, and
leads to bogus "info memdev" output, as shown below; revert.
I suspect that if we had bisected the crash back then, we would have
found and fixed the actual bug instead of papering over it.
To reproduce, run HMP command "info memdev" with
$ qemu-system-x86_64 --nodefaults -S -display none -monitor stdio -object memory-backend-ram,id=mem1,size=4k
With this commit, "info memdev" prints
memory backend: mem1
size: 4096
merge: true
dump: true
prealloc: false
policy: default
host nodes:
exactly like before commit 74f24cb.
Between commit 1454d33 and this commit, it prints
memory backend: mem1
size: 4096
merge: true
dump: true
prealloc: false
policy: default
host nodes: 128
The last line is bogus.
Between commit 74f24cb and 1454d33, it crashes like this:
Unexpected error in parse_str() at /work/armbru/tmp/qemu/qapi/string-input-visitor.c:126:
Parameter 'null' expects an int64 value or range
Aborted (core dumped)
Cc: Xiao Guangrong <guangrong.xiao@linux.intel.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1490026424-11330-3-git-send-email-armbru@redhat.com>
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
2017-03-20 17:13:44 +01:00
|
|
|
*node = g_malloc0(sizeof(**node));
|
|
|
|
(*node)->value = value;
|
|
|
|
node = &(*node)->next;
|
|
|
|
|
2014-06-10 13:15:25 +02:00
|
|
|
do {
|
|
|
|
value = find_next_bit(backend->host_nodes, MAX_NODES, value + 1);
|
|
|
|
if (value == MAX_NODES) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
Revert "hostmem: fix QEMU crash by 'info memdev'"
This reverts commit 1454d33f0507cb54d62ed80f494884157c9e7130.
The string input visitor regression fixed in the previous commit made
visit_type_uint16List() fail on empty input. query_memdev() calls it
via object_property_get_uint16List(). Because it doesn't expect it to
fail, it passes &error_abort, and duly crashes.
Commit 1454d33 "fixes" this crash by making
host_memory_backend_get_host_nodes() return a list containing just
MAX_NODES instead of the empty list. Papers over the regression, and
leads to bogus "info memdev" output, as shown below; revert.
I suspect that if we had bisected the crash back then, we would have
found and fixed the actual bug instead of papering over it.
To reproduce, run HMP command "info memdev" with
$ qemu-system-x86_64 --nodefaults -S -display none -monitor stdio -object memory-backend-ram,id=mem1,size=4k
With this commit, "info memdev" prints
memory backend: mem1
size: 4096
merge: true
dump: true
prealloc: false
policy: default
host nodes:
exactly like before commit 74f24cb.
Between commit 1454d33 and this commit, it prints
memory backend: mem1
size: 4096
merge: true
dump: true
prealloc: false
policy: default
host nodes: 128
The last line is bogus.
Between commit 74f24cb and 1454d33, it crashes like this:
Unexpected error in parse_str() at /work/armbru/tmp/qemu/qapi/string-input-visitor.c:126:
Parameter 'null' expects an int64 value or range
Aborted (core dumped)
Cc: Xiao Guangrong <guangrong.xiao@linux.intel.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1490026424-11330-3-git-send-email-armbru@redhat.com>
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
2017-03-20 17:13:44 +01:00
|
|
|
*node = g_malloc0(sizeof(**node));
|
|
|
|
(*node)->value = value;
|
|
|
|
node = &(*node)->next;
|
2014-06-10 13:15:25 +02:00
|
|
|
} while (true);
|
|
|
|
|
2019-02-14 11:57:33 +01:00
|
|
|
ret:
|
qapi: Swap visit_* arguments for consistent 'name' placement
JSON uses "name":value, but many of our visitor interfaces were
called with visit_type_FOO(v, &value, name, errp). This can be
a bit confusing to have to mentally swap the parameter order to
match JSON order. It's particularly bad for visit_start_struct(),
where the 'name' parameter is smack in the middle of the
otherwise-related group of 'obj, kind, size' parameters! It's
time to do a global swap of the parameter ordering, so that the
'name' parameter is always immediately after the Visitor argument.
Additional reason in favor of the swap: the existing include/qjson.h
prefers listing 'name' first in json_prop_*(), and I have plans to
unify that file with the qapi visitors; listing 'name' first in
qapi will minimize churn to the (admittedly few) qjson.h clients.
Later patches will then fix docs, object.h, visitor-impl.h, and
those clients to match.
Done by first patching scripts/qapi*.py by hand to make generated
files do what I want, then by running the following Coccinelle
script to affect the rest of the code base:
$ spatch --sp-file script `git grep -l '\bvisit_' -- '**/*.[ch]'`
I then had to apply some touchups (Coccinelle insisted on TAB
indentation in visitor.h, and botched the signature of
visit_type_enum() by rewriting 'const char *const strings[]' to
the syntactically invalid 'const char*const[] strings'). The
movement of parameters is sufficient to provoke compiler errors
if any callers were missed.
// Part 1: Swap declaration order
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_start_struct
-(TV v, TObj OBJ, T1 ARG1, const char *name, T2 ARG2, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type bool, TV, T1;
identifier ARG1;
@@
bool visit_optional
-(TV v, T1 ARG1, const char *name)
+(TV v, const char *name, T1 ARG1)
{ ... }
@@
type TV, TErr, TObj, T1;
identifier OBJ, ARG1;
@@
void visit_get_next_type
-(TV v, TObj OBJ, T1 ARG1, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, TErr errp)
{ ... }
@@
type TV, TErr, TObj, T1, T2;
identifier OBJ, ARG1, ARG2;
@@
void visit_type_enum
-(TV v, TObj OBJ, T1 ARG1, T2 ARG2, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, T1 ARG1, T2 ARG2, TErr errp)
{ ... }
@@
type TV, TErr, TObj;
identifier OBJ;
identifier VISIT_TYPE =~ "^visit_type_";
@@
void VISIT_TYPE
-(TV v, TObj OBJ, const char *name, TErr errp)
+(TV v, const char *name, TObj OBJ, TErr errp)
{ ... }
// Part 2: swap caller order
@@
expression V, NAME, OBJ, ARG1, ARG2, ERR;
identifier VISIT_TYPE =~ "^visit_type_";
@@
(
-visit_start_struct(V, OBJ, ARG1, NAME, ARG2, ERR)
+visit_start_struct(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-visit_optional(V, ARG1, NAME)
+visit_optional(V, NAME, ARG1)
|
-visit_get_next_type(V, OBJ, ARG1, NAME, ERR)
+visit_get_next_type(V, NAME, OBJ, ARG1, ERR)
|
-visit_type_enum(V, OBJ, ARG1, ARG2, NAME, ERR)
+visit_type_enum(V, NAME, OBJ, ARG1, ARG2, ERR)
|
-VISIT_TYPE(V, OBJ, NAME, ERR)
+VISIT_TYPE(V, NAME, OBJ, ERR)
)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-19-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:54 +01:00
|
|
|
visit_type_uint16List(v, name, &host_nodes, errp);
|
2014-06-10 13:15:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
qom: Swap 'name' next to visitor in ObjectPropertyAccessor
Similar to the previous patch, it's nice to have all functions
in the tree that involve a visitor and a name for conversion to
or from QAPI to consistently stick the 'name' parameter next
to the Visitor parameter.
Done by manually changing include/qom/object.h and qom/object.c,
then running this Coccinelle script and touching up the fallout
(Coccinelle insisted on adding some trailing whitespace).
@ rule1 @
identifier fn;
typedef Object, Visitor, Error;
identifier obj, v, opaque, name, errp;
@@
void fn
- (Object *obj, Visitor *v, void *opaque, const char *name,
+ (Object *obj, Visitor *v, const char *name, void *opaque,
Error **errp) { ... }
@@
identifier rule1.fn;
expression obj, v, opaque, name, errp;
@@
fn(obj, v,
- opaque, name,
+ name, opaque,
errp)
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <1454075341-13658-20-git-send-email-eblake@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-01-29 14:48:55 +01:00
|
|
|
host_memory_backend_set_host_nodes(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
2014-06-10 13:15:25 +02:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_NUMA
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
|
2018-11-30 13:28:44 +01:00
|
|
|
uint16List *l, *host_nodes = NULL;
|
2014-06-10 13:15:25 +02:00
|
|
|
|
2018-11-30 13:28:44 +01:00
|
|
|
visit_type_uint16List(v, name, &host_nodes, errp);
|
|
|
|
|
|
|
|
for (l = host_nodes; l; l = l->next) {
|
|
|
|
if (l->value >= MAX_NODES) {
|
|
|
|
error_setg(errp, "Invalid host-nodes value: %d", l->value);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
2014-06-10 13:15:25 +02:00
|
|
|
|
2018-11-30 13:28:44 +01:00
|
|
|
for (l = host_nodes; l; l = l->next) {
|
2014-06-10 13:15:25 +02:00
|
|
|
bitmap_set(backend->host_nodes, l->value, 1);
|
|
|
|
}
|
2018-11-30 13:28:44 +01:00
|
|
|
|
|
|
|
out:
|
|
|
|
qapi_free_uint16List(host_nodes);
|
2014-06-10 13:15:25 +02:00
|
|
|
#else
|
|
|
|
error_setg(errp, "NUMA node binding are not supported by this QEMU");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-05-27 17:07:56 +02:00
|
|
|
static int
|
|
|
|
host_memory_backend_get_policy(Object *obj, Error **errp G_GNUC_UNUSED)
|
2014-06-10 13:15:25 +02:00
|
|
|
{
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
|
2015-05-27 17:07:56 +02:00
|
|
|
return backend->policy;
|
2014-06-10 13:15:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-05-27 17:07:56 +02:00
|
|
|
host_memory_backend_set_policy(Object *obj, int policy, Error **errp)
|
2014-06-10 13:15:25 +02:00
|
|
|
{
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
|
|
|
|
backend->policy = policy;
|
|
|
|
|
|
|
|
#ifndef CONFIG_NUMA
|
|
|
|
if (policy != HOST_MEM_POLICY_DEFAULT) {
|
|
|
|
error_setg(errp, "NUMA policies are not supported by this QEMU");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-06-10 13:15:22 +02:00
|
|
|
static bool host_memory_backend_get_merge(Object *obj, Error **errp)
|
|
|
|
{
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
|
|
|
|
|
|
|
|
return backend->merge;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void host_memory_backend_set_merge(Object *obj, bool value, Error **errp)
|
|
|
|
{
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
|
|
|
|
|
2017-03-10 14:09:30 +01:00
|
|
|
if (!host_memory_backend_mr_inited(backend)) {
|
2014-06-10 13:15:22 +02:00
|
|
|
backend->merge = value;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value != backend->merge) {
|
|
|
|
void *ptr = memory_region_get_ram_ptr(&backend->mr);
|
|
|
|
uint64_t sz = memory_region_size(&backend->mr);
|
|
|
|
|
|
|
|
qemu_madvise(ptr, sz,
|
|
|
|
value ? QEMU_MADV_MERGEABLE : QEMU_MADV_UNMERGEABLE);
|
|
|
|
backend->merge = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool host_memory_backend_get_dump(Object *obj, Error **errp)
|
|
|
|
{
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
|
|
|
|
|
|
|
|
return backend->dump;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void host_memory_backend_set_dump(Object *obj, bool value, Error **errp)
|
|
|
|
{
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
|
|
|
|
|
2017-03-10 14:09:30 +01:00
|
|
|
if (!host_memory_backend_mr_inited(backend)) {
|
2014-06-10 13:15:22 +02:00
|
|
|
backend->dump = value;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value != backend->dump) {
|
|
|
|
void *ptr = memory_region_get_ram_ptr(&backend->mr);
|
|
|
|
uint64_t sz = memory_region_size(&backend->mr);
|
|
|
|
|
|
|
|
qemu_madvise(ptr, sz,
|
|
|
|
value ? QEMU_MADV_DODUMP : QEMU_MADV_DONTDUMP);
|
|
|
|
backend->dump = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-10 13:15:23 +02:00
|
|
|
static bool host_memory_backend_get_prealloc(Object *obj, Error **errp)
|
|
|
|
{
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
|
|
|
|
|
|
|
|
return backend->prealloc || backend->force_prealloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void host_memory_backend_set_prealloc(Object *obj, bool value,
|
|
|
|
Error **errp)
|
|
|
|
{
|
2016-07-20 11:54:03 +02:00
|
|
|
Error *local_err = NULL;
|
2014-06-10 13:15:23 +02:00
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
|
2019-05-18 22:54:21 +02:00
|
|
|
MachineState *ms = MACHINE(qdev_get_machine());
|
2014-06-10 13:15:23 +02:00
|
|
|
|
|
|
|
if (backend->force_prealloc) {
|
|
|
|
if (value) {
|
|
|
|
error_setg(errp,
|
|
|
|
"remove -mem-prealloc to use the prealloc property");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-10 14:09:30 +01:00
|
|
|
if (!host_memory_backend_mr_inited(backend)) {
|
2014-06-10 13:15:23 +02:00
|
|
|
backend->prealloc = value;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value && !backend->prealloc) {
|
|
|
|
int fd = memory_region_get_fd(&backend->mr);
|
|
|
|
void *ptr = memory_region_get_ram_ptr(&backend->mr);
|
|
|
|
uint64_t sz = memory_region_size(&backend->mr);
|
|
|
|
|
2019-05-18 22:54:21 +02:00
|
|
|
os_mem_prealloc(fd, ptr, sz, ms->smp.cpus, &local_err);
|
2016-07-20 11:54:03 +02:00
|
|
|
if (local_err) {
|
|
|
|
error_propagate(errp, local_err);
|
|
|
|
return;
|
|
|
|
}
|
2014-06-10 13:15:23 +02:00
|
|
|
backend->prealloc = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-10 13:15:18 +02:00
|
|
|
static void host_memory_backend_init(Object *obj)
|
2014-06-06 17:54:29 +02:00
|
|
|
{
|
2014-06-10 13:15:22 +02:00
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
|
hostmem: Fix qemu_opt_get_bool() crash in host_memory_backend_init()
This fixes the following crash, introduced by commit
49d2e648e8087d154d8bf8b91f27c8e05e79d5a6:
$ gdb --args qemu-system-x86_64 -machine pc,mem-merge=off -object memory-backend-ram,id=ram-node0,size=1024
[...]
Program received signal SIGABRT, Aborted.
(gdb) bt
#0 0x00007ffff253b8c7 in raise () at /lib64/libc.so.6
#1 0x00007ffff253d52a in abort () at /lib64/libc.so.6
#2 0x00007ffff253446d in __assert_fail_base () at /lib64/libc.so.6
#3 0x00007ffff2534522 in () at /lib64/libc.so.6
#4 0x00005555558bb80a in qemu_opt_get_bool_helper (opts=0x55555621b650, name=name@entry=0x5555558ec922 "mem-merge", defval=defval@entry=true, del=del@entry=false) at qemu/util/qemu-option.c:388
#5 0x00005555558bbb5a in qemu_opt_get_bool (opts=<optimized out>, name=name@entry=0x5555558ec922 "mem-merge", defval=defval@entry=true) at qemu/util/qemu-option.c:398
#6 0x0000555555720a24 in host_memory_backend_init (obj=0x5555562ac970) at qemu/backends/hostmem.c:226
Instead of using qemu_opt_get_bool(), that didn't work with
qemu_machine_opts for a long time, we can use the corresponding
MachineState fields.
Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2015-07-16 22:29:12 +02:00
|
|
|
MachineState *machine = MACHINE(qdev_get_machine());
|
2014-06-10 13:15:22 +02:00
|
|
|
|
hostmem: Fix qemu_opt_get_bool() crash in host_memory_backend_init()
This fixes the following crash, introduced by commit
49d2e648e8087d154d8bf8b91f27c8e05e79d5a6:
$ gdb --args qemu-system-x86_64 -machine pc,mem-merge=off -object memory-backend-ram,id=ram-node0,size=1024
[...]
Program received signal SIGABRT, Aborted.
(gdb) bt
#0 0x00007ffff253b8c7 in raise () at /lib64/libc.so.6
#1 0x00007ffff253d52a in abort () at /lib64/libc.so.6
#2 0x00007ffff253446d in __assert_fail_base () at /lib64/libc.so.6
#3 0x00007ffff2534522 in () at /lib64/libc.so.6
#4 0x00005555558bb80a in qemu_opt_get_bool_helper (opts=0x55555621b650, name=name@entry=0x5555558ec922 "mem-merge", defval=defval@entry=true, del=del@entry=false) at qemu/util/qemu-option.c:388
#5 0x00005555558bbb5a in qemu_opt_get_bool (opts=<optimized out>, name=name@entry=0x5555558ec922 "mem-merge", defval=defval@entry=true) at qemu/util/qemu-option.c:398
#6 0x0000555555720a24 in host_memory_backend_init (obj=0x5555562ac970) at qemu/backends/hostmem.c:226
Instead of using qemu_opt_get_bool(), that didn't work with
qemu_machine_opts for a long time, we can use the corresponding
MachineState fields.
Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2015-07-16 22:29:12 +02:00
|
|
|
backend->merge = machine_mem_merge(machine);
|
|
|
|
backend->dump = machine_dump_guest_core(machine);
|
2014-06-10 13:15:23 +02:00
|
|
|
backend->prealloc = mem_prealloc;
|
2014-06-06 17:54:29 +02:00
|
|
|
}
|
|
|
|
|
hostmem: use object id for memory region name with >= 4.0
hostmem-file and hostmem-memfd use the whole object path for the
memory region name, and hostname-ram uses only the path component (the
object id, or canonical path basename):
qemu -m 1024 -object memory-backend-file,id=mem,size=1G,mem-path=/tmp/foo -numa node,memdev=mem -monitor stdio
(qemu) info ramblock
Block Name PSize Offset Used Total
/objects/mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000
qemu -m 1024 -object memory-backend-memfd,id=mem,size=1G -numa node,memdev=mem -monitor stdio
(qemu) info ramblock
Block Name PSize Offset Used Total
/objects/mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000
qemu -m 1024 -object memory-backend-ram,id=mem,size=1G -numa node,memdev=mem -monitor stdio
(qemu) info ramblock
Block Name PSize Offset Used Total
mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000
For consistency, change to use object id for -file and -memfd as well
with >= 4.0.
Having a consistent naming allows to migrate to different hostmem
backends.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Acked-by: Eduardo Habkost <ehabkost@redhat.com>
2018-09-12 14:18:00 +02:00
|
|
|
static void host_memory_backend_post_init(Object *obj)
|
|
|
|
{
|
|
|
|
object_apply_compat_props(obj);
|
|
|
|
}
|
|
|
|
|
2017-03-10 14:09:29 +01:00
|
|
|
bool host_memory_backend_mr_inited(HostMemoryBackend *backend)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* NOTE: We forbid zero-length memory backend, so here zero means
|
|
|
|
* "we haven't inited the backend memory region yet".
|
|
|
|
*/
|
|
|
|
return memory_region_size(&backend->mr) != 0;
|
|
|
|
}
|
|
|
|
|
2018-06-19 15:41:36 +02:00
|
|
|
MemoryRegion *host_memory_backend_get_memory(HostMemoryBackend *backend)
|
2014-06-06 17:54:29 +02:00
|
|
|
{
|
2017-03-10 14:09:30 +01:00
|
|
|
return host_memory_backend_mr_inited(backend) ? &backend->mr : NULL;
|
2014-06-06 17:54:29 +02:00
|
|
|
}
|
|
|
|
|
2016-07-13 06:18:06 +02:00
|
|
|
void host_memory_backend_set_mapped(HostMemoryBackend *backend, bool mapped)
|
|
|
|
{
|
|
|
|
backend->is_mapped = mapped;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool host_memory_backend_is_mapped(HostMemoryBackend *backend)
|
|
|
|
{
|
|
|
|
return backend->is_mapped;
|
|
|
|
}
|
|
|
|
|
2018-04-03 07:05:45 +02:00
|
|
|
#ifdef __linux__
|
|
|
|
size_t host_memory_backend_pagesize(HostMemoryBackend *memdev)
|
|
|
|
{
|
|
|
|
Object *obj = OBJECT(memdev);
|
|
|
|
char *path = object_property_get_str(obj, "mem-path", NULL);
|
|
|
|
size_t pagesize = qemu_mempath_getpagesize(path);
|
|
|
|
|
|
|
|
g_free(path);
|
|
|
|
return pagesize;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
size_t host_memory_backend_pagesize(HostMemoryBackend *memdev)
|
|
|
|
{
|
2019-10-13 04:11:45 +02:00
|
|
|
return qemu_real_host_page_size;
|
2018-04-03 07:05:45 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-06-10 13:15:19 +02:00
|
|
|
static void
|
|
|
|
host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
|
|
|
|
{
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(uc);
|
|
|
|
HostMemoryBackendClass *bc = MEMORY_BACKEND_GET_CLASS(uc);
|
2019-05-18 22:54:21 +02:00
|
|
|
MachineState *ms = MACHINE(qdev_get_machine());
|
2014-06-10 13:15:22 +02:00
|
|
|
Error *local_err = NULL;
|
|
|
|
void *ptr;
|
|
|
|
uint64_t sz;
|
2014-06-10 13:15:19 +02:00
|
|
|
|
|
|
|
if (bc->alloc) {
|
2014-06-10 13:15:22 +02:00
|
|
|
bc->alloc(backend, &local_err);
|
|
|
|
if (local_err) {
|
2016-07-20 11:54:03 +02:00
|
|
|
goto out;
|
2014-06-10 13:15:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ptr = memory_region_get_ram_ptr(&backend->mr);
|
|
|
|
sz = memory_region_size(&backend->mr);
|
|
|
|
|
|
|
|
if (backend->merge) {
|
|
|
|
qemu_madvise(ptr, sz, QEMU_MADV_MERGEABLE);
|
|
|
|
}
|
|
|
|
if (!backend->dump) {
|
|
|
|
qemu_madvise(ptr, sz, QEMU_MADV_DONTDUMP);
|
|
|
|
}
|
2014-06-10 13:15:25 +02:00
|
|
|
#ifdef CONFIG_NUMA
|
|
|
|
unsigned long lastbit = find_last_bit(backend->host_nodes, MAX_NODES);
|
|
|
|
/* lastbit == MAX_NODES means maxnode = 0 */
|
|
|
|
unsigned long maxnode = (lastbit + 1) % (MAX_NODES + 1);
|
|
|
|
/* ensure policy won't be ignored in case memory is preallocated
|
|
|
|
* before mbind(). note: MPOL_MF_STRICT is ignored on hugepages so
|
|
|
|
* this doesn't catch hugepage case. */
|
2014-08-13 13:50:24 +02:00
|
|
|
unsigned flags = MPOL_MF_STRICT | MPOL_MF_MOVE;
|
2014-06-10 13:15:25 +02:00
|
|
|
|
|
|
|
/* check for invalid host-nodes and policies and give more verbose
|
|
|
|
* error messages than mbind(). */
|
|
|
|
if (maxnode && backend->policy == MPOL_DEFAULT) {
|
|
|
|
error_setg(errp, "host-nodes must be empty for policy default,"
|
|
|
|
" or you should explicitly specify a policy other"
|
|
|
|
" than default");
|
|
|
|
return;
|
|
|
|
} else if (maxnode == 0 && backend->policy != MPOL_DEFAULT) {
|
|
|
|
error_setg(errp, "host-nodes must be set for policy %s",
|
2017-08-24 10:46:08 +02:00
|
|
|
HostMemPolicy_str(backend->policy));
|
2014-06-10 13:15:25 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We can have up to MAX_NODES nodes, but we need to pass maxnode+1
|
|
|
|
* as argument to mbind() due to an old Linux bug (feature?) which
|
|
|
|
* cuts off the last specified node. This means backend->host_nodes
|
|
|
|
* must have MAX_NODES+1 bits available.
|
|
|
|
*/
|
|
|
|
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)) {
|
2015-10-27 13:51:31 +01:00
|
|
|
if (backend->policy != MPOL_DEFAULT || errno != ENOSYS) {
|
|
|
|
error_setg_errno(errp, errno,
|
|
|
|
"cannot bind memory to host NUMA nodes");
|
|
|
|
return;
|
|
|
|
}
|
2014-06-10 13:15:25 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* Preallocate memory after the NUMA policy has been instantiated.
|
|
|
|
* This is necessary to guarantee memory is allocated with
|
|
|
|
* specified NUMA policy in place.
|
|
|
|
*/
|
2014-06-10 13:15:23 +02:00
|
|
|
if (backend->prealloc) {
|
2016-07-20 11:54:03 +02:00
|
|
|
os_mem_prealloc(memory_region_get_fd(&backend->mr), ptr, sz,
|
2019-05-18 22:54:21 +02:00
|
|
|
ms->smp.cpus, &local_err);
|
2016-07-20 11:54:03 +02:00
|
|
|
if (local_err) {
|
|
|
|
goto out;
|
|
|
|
}
|
2014-06-10 13:15:23 +02:00
|
|
|
}
|
2014-06-10 13:15:19 +02:00
|
|
|
}
|
2016-07-20 11:54:03 +02:00
|
|
|
out:
|
|
|
|
error_propagate(errp, local_err);
|
2014-06-10 13:15:19 +02:00
|
|
|
}
|
|
|
|
|
2015-03-30 10:36:29 +02:00
|
|
|
static bool
|
2017-08-30 00:03:37 +02:00
|
|
|
host_memory_backend_can_be_deleted(UserCreatable *uc)
|
2015-03-30 10:36:29 +02:00
|
|
|
{
|
2016-07-13 06:18:06 +02:00
|
|
|
if (host_memory_backend_is_mapped(MEMORY_BACKEND(uc))) {
|
2015-03-30 10:36:29 +02:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-13 15:37:37 +01:00
|
|
|
static bool host_memory_backend_get_share(Object *o, Error **errp)
|
|
|
|
{
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(o);
|
|
|
|
|
|
|
|
return backend->share;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void host_memory_backend_set_share(Object *o, bool value, Error **errp)
|
|
|
|
{
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(o);
|
|
|
|
|
|
|
|
if (host_memory_backend_mr_inited(backend)) {
|
|
|
|
error_setg(errp, "cannot change property value");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
backend->share = value;
|
|
|
|
}
|
|
|
|
|
hostmem: use object id for memory region name with >= 4.0
hostmem-file and hostmem-memfd use the whole object path for the
memory region name, and hostname-ram uses only the path component (the
object id, or canonical path basename):
qemu -m 1024 -object memory-backend-file,id=mem,size=1G,mem-path=/tmp/foo -numa node,memdev=mem -monitor stdio
(qemu) info ramblock
Block Name PSize Offset Used Total
/objects/mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000
qemu -m 1024 -object memory-backend-memfd,id=mem,size=1G -numa node,memdev=mem -monitor stdio
(qemu) info ramblock
Block Name PSize Offset Used Total
/objects/mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000
qemu -m 1024 -object memory-backend-ram,id=mem,size=1G -numa node,memdev=mem -monitor stdio
(qemu) info ramblock
Block Name PSize Offset Used Total
mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000
For consistency, change to use object id for -file and -memfd as well
with >= 4.0.
Having a consistent naming allows to migrate to different hostmem
backends.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Acked-by: Eduardo Habkost <ehabkost@redhat.com>
2018-09-12 14:18:00 +02:00
|
|
|
static bool
|
|
|
|
host_memory_backend_get_use_canonical_path(Object *obj, Error **errp)
|
|
|
|
{
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
|
|
|
|
|
|
|
|
return backend->use_canonical_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
host_memory_backend_set_use_canonical_path(Object *obj, bool value,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
|
|
|
|
|
|
|
|
backend->use_canonical_path = value;
|
|
|
|
}
|
|
|
|
|
2014-06-10 13:15:19 +02:00
|
|
|
static void
|
|
|
|
host_memory_backend_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
|
|
|
UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
|
|
|
|
|
|
|
|
ucc->complete = host_memory_backend_memory_complete;
|
2015-03-30 10:36:29 +02:00
|
|
|
ucc->can_be_deleted = host_memory_backend_can_be_deleted;
|
2016-10-13 22:52:51 +02:00
|
|
|
|
|
|
|
object_class_property_add_bool(oc, "merge",
|
|
|
|
host_memory_backend_get_merge,
|
|
|
|
host_memory_backend_set_merge, &error_abort);
|
2018-09-06 16:39:08 +02:00
|
|
|
object_class_property_set_description(oc, "merge",
|
|
|
|
"Mark memory as mergeable", &error_abort);
|
2016-10-13 22:52:51 +02:00
|
|
|
object_class_property_add_bool(oc, "dump",
|
|
|
|
host_memory_backend_get_dump,
|
|
|
|
host_memory_backend_set_dump, &error_abort);
|
2018-09-06 16:39:08 +02:00
|
|
|
object_class_property_set_description(oc, "dump",
|
|
|
|
"Set to 'off' to exclude from core dump", &error_abort);
|
2016-10-13 22:52:51 +02:00
|
|
|
object_class_property_add_bool(oc, "prealloc",
|
|
|
|
host_memory_backend_get_prealloc,
|
|
|
|
host_memory_backend_set_prealloc, &error_abort);
|
2018-09-06 16:39:08 +02:00
|
|
|
object_class_property_set_description(oc, "prealloc",
|
|
|
|
"Preallocate memory", &error_abort);
|
2016-10-13 22:52:51 +02:00
|
|
|
object_class_property_add(oc, "size", "int",
|
|
|
|
host_memory_backend_get_size,
|
|
|
|
host_memory_backend_set_size,
|
|
|
|
NULL, NULL, &error_abort);
|
2018-09-06 16:39:08 +02:00
|
|
|
object_class_property_set_description(oc, "size",
|
|
|
|
"Size of the memory region (ex: 500M)", &error_abort);
|
2016-10-13 22:52:51 +02:00
|
|
|
object_class_property_add(oc, "host-nodes", "int",
|
|
|
|
host_memory_backend_get_host_nodes,
|
|
|
|
host_memory_backend_set_host_nodes,
|
|
|
|
NULL, NULL, &error_abort);
|
2018-09-06 16:39:08 +02:00
|
|
|
object_class_property_set_description(oc, "host-nodes",
|
|
|
|
"Binds memory to the list of NUMA host nodes", &error_abort);
|
2016-10-13 22:52:51 +02:00
|
|
|
object_class_property_add_enum(oc, "policy", "HostMemPolicy",
|
2017-08-24 10:46:10 +02:00
|
|
|
&HostMemPolicy_lookup,
|
2016-10-13 22:52:51 +02:00
|
|
|
host_memory_backend_get_policy,
|
|
|
|
host_memory_backend_set_policy, &error_abort);
|
2018-09-06 16:39:08 +02:00
|
|
|
object_class_property_set_description(oc, "policy",
|
|
|
|
"Set the NUMA policy", &error_abort);
|
2017-12-13 15:37:37 +01:00
|
|
|
object_class_property_add_bool(oc, "share",
|
|
|
|
host_memory_backend_get_share, host_memory_backend_set_share,
|
|
|
|
&error_abort);
|
2018-09-06 16:39:08 +02:00
|
|
|
object_class_property_set_description(oc, "share",
|
|
|
|
"Mark the memory as private to QEMU or shared", &error_abort);
|
hostmem: use object id for memory region name with >= 4.0
hostmem-file and hostmem-memfd use the whole object path for the
memory region name, and hostname-ram uses only the path component (the
object id, or canonical path basename):
qemu -m 1024 -object memory-backend-file,id=mem,size=1G,mem-path=/tmp/foo -numa node,memdev=mem -monitor stdio
(qemu) info ramblock
Block Name PSize Offset Used Total
/objects/mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000
qemu -m 1024 -object memory-backend-memfd,id=mem,size=1G -numa node,memdev=mem -monitor stdio
(qemu) info ramblock
Block Name PSize Offset Used Total
/objects/mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000
qemu -m 1024 -object memory-backend-ram,id=mem,size=1G -numa node,memdev=mem -monitor stdio
(qemu) info ramblock
Block Name PSize Offset Used Total
mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000
For consistency, change to use object id for -file and -memfd as well
with >= 4.0.
Having a consistent naming allows to migrate to different hostmem
backends.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Acked-by: Eduardo Habkost <ehabkost@redhat.com>
2018-09-12 14:18:00 +02:00
|
|
|
object_class_property_add_bool(oc, "x-use-canonical-path-for-ramblock-id",
|
|
|
|
host_memory_backend_get_use_canonical_path,
|
|
|
|
host_memory_backend_set_use_canonical_path, &error_abort);
|
2017-01-10 13:53:15 +01:00
|
|
|
}
|
|
|
|
|
2014-06-10 13:15:18 +02:00
|
|
|
static const TypeInfo host_memory_backend_info = {
|
2014-06-06 17:54:29 +02:00
|
|
|
.name = TYPE_MEMORY_BACKEND,
|
|
|
|
.parent = TYPE_OBJECT,
|
|
|
|
.abstract = true,
|
|
|
|
.class_size = sizeof(HostMemoryBackendClass),
|
2014-06-10 13:15:19 +02:00
|
|
|
.class_init = host_memory_backend_class_init,
|
2014-06-06 17:54:29 +02:00
|
|
|
.instance_size = sizeof(HostMemoryBackend),
|
2014-06-10 13:15:18 +02:00
|
|
|
.instance_init = host_memory_backend_init,
|
hostmem: use object id for memory region name with >= 4.0
hostmem-file and hostmem-memfd use the whole object path for the
memory region name, and hostname-ram uses only the path component (the
object id, or canonical path basename):
qemu -m 1024 -object memory-backend-file,id=mem,size=1G,mem-path=/tmp/foo -numa node,memdev=mem -monitor stdio
(qemu) info ramblock
Block Name PSize Offset Used Total
/objects/mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000
qemu -m 1024 -object memory-backend-memfd,id=mem,size=1G -numa node,memdev=mem -monitor stdio
(qemu) info ramblock
Block Name PSize Offset Used Total
/objects/mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000
qemu -m 1024 -object memory-backend-ram,id=mem,size=1G -numa node,memdev=mem -monitor stdio
(qemu) info ramblock
Block Name PSize Offset Used Total
mem 4 KiB 0x0000000000000000 0x0000000040000000 0x0000000040000000
For consistency, change to use object id for -file and -memfd as well
with >= 4.0.
Having a consistent naming allows to migrate to different hostmem
backends.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Acked-by: Eduardo Habkost <ehabkost@redhat.com>
2018-09-12 14:18:00 +02:00
|
|
|
.instance_post_init = host_memory_backend_post_init,
|
2014-06-06 17:54:29 +02:00
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ TYPE_USER_CREATABLE },
|
|
|
|
{ }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void register_types(void)
|
|
|
|
{
|
2014-06-10 13:15:18 +02:00
|
|
|
type_register_static(&host_memory_backend_info);
|
2014-06-06 17:54:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type_init(register_types);
|