2014-06-06 19:54:29 +04: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 12:36:01 +03:00
|
|
|
|
2016-01-29 20:49:54 +03:00
|
|
|
#include "qemu/osdep.h"
|
2014-06-06 19:54:29 +04:00
|
|
|
#include "sysemu/hostmem.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 23:29:12 +03: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 11:01:28 +03:00
|
|
|
#include "qapi/error.h"
|
2018-02-11 12:36:05 +03:00
|
|
|
#include "qapi/qapi-builtin-visit.h"
|
2014-06-06 19:54:29 +04:00
|
|
|
#include "qapi/visitor.h"
|
|
|
|
#include "qemu/config-file.h"
|
|
|
|
#include "qom/object_interfaces.h"
|
2018-04-03 08:05:45 +03:00
|
|
|
#include "qemu/mmap-alloc.h"
|
2022-02-08 23:08:52 +03:00
|
|
|
#include "qemu/madvise.h"
|
2024-01-31 19:53:27 +03:00
|
|
|
#include "hw/qdev-core.h"
|
2014-06-06 19:54:29 +04:00
|
|
|
|
2014-06-10 15:15:25 +04:00
|
|
|
#ifdef CONFIG_NUMA
|
|
|
|
#include <numaif.h>
|
hostmem: Honor multiple preferred nodes if possible
If a memory-backend is configured with mode
HOST_MEM_POLICY_PREFERRED then
host_memory_backend_memory_complete() calls mbind() as:
mbind(..., MPOL_PREFERRED, nodemask, ...);
Here, 'nodemask' is a bitmap of host NUMA nodes and corresponds
to the .host-nodes attribute. Therefore, there can be multiple
nodes specified. However, the documentation to MPOL_PREFERRED
says:
MPOL_PREFERRED
This mode sets the preferred node for allocation. ...
If nodemask specifies more than one node ID, the first node
in the mask will be selected as the preferred node.
Therefore, only the first node is honored and the rest is
silently ignored. Well, with recent changes to the kernel and
numactl we can do better.
The Linux kernel added in v5.15 via commit cfcaa66f8032
("mm/hugetlb: add support for mempolicy MPOL_PREFERRED_MANY")
support for MPOL_PREFERRED_MANY, which accepts multiple preferred
NUMA nodes instead.
Then, numa_has_preferred_many() API was introduced to numactl
(v2.0.15~26) allowing applications to query kernel support.
Wiring this all together, we can pass MPOL_PREFERRED_MANY to the
mbind() call instead and stop ignoring multiple nodes, silently.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Message-Id: <a0b4adce1af5bd2344c2218eb4a04b3ff7bcfdb4.1671097918.git.mprivozn@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
2022-12-15 12:55:03 +03:00
|
|
|
#include <numa.h>
|
2014-06-10 15:15:25 +04:00
|
|
|
QEMU_BUILD_BUG_ON(HOST_MEM_POLICY_DEFAULT != MPOL_DEFAULT);
|
hostmem: Honor multiple preferred nodes if possible
If a memory-backend is configured with mode
HOST_MEM_POLICY_PREFERRED then
host_memory_backend_memory_complete() calls mbind() as:
mbind(..., MPOL_PREFERRED, nodemask, ...);
Here, 'nodemask' is a bitmap of host NUMA nodes and corresponds
to the .host-nodes attribute. Therefore, there can be multiple
nodes specified. However, the documentation to MPOL_PREFERRED
says:
MPOL_PREFERRED
This mode sets the preferred node for allocation. ...
If nodemask specifies more than one node ID, the first node
in the mask will be selected as the preferred node.
Therefore, only the first node is honored and the rest is
silently ignored. Well, with recent changes to the kernel and
numactl we can do better.
The Linux kernel added in v5.15 via commit cfcaa66f8032
("mm/hugetlb: add support for mempolicy MPOL_PREFERRED_MANY")
support for MPOL_PREFERRED_MANY, which accepts multiple preferred
NUMA nodes instead.
Then, numa_has_preferred_many() API was introduced to numactl
(v2.0.15~26) allowing applications to query kernel support.
Wiring this all together, we can pass MPOL_PREFERRED_MANY to the
mbind() call instead and stop ignoring multiple nodes, silently.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Message-Id: <a0b4adce1af5bd2344c2218eb4a04b3ff7bcfdb4.1671097918.git.mprivozn@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
2022-12-15 12:55:03 +03:00
|
|
|
/*
|
|
|
|
* HOST_MEM_POLICY_PREFERRED may either translate to MPOL_PREFERRED or
|
|
|
|
* MPOL_PREFERRED_MANY, see comments further below.
|
|
|
|
*/
|
2014-06-10 15:15:25 +04:00
|
|
|
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 15:18:00 +03:00
|
|
|
char *
|
|
|
|
host_memory_backend_get_name(HostMemoryBackend *backend)
|
|
|
|
{
|
|
|
|
if (!backend->use_canonical_path) {
|
2020-07-14 19:02:00 +03:00
|
|
|
return g_strdup(object_get_canonical_path_component(OBJECT(backend)));
|
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 15:18:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return object_get_canonical_path(OBJECT(backend));
|
|
|
|
}
|
|
|
|
|
2014-06-06 19:54:29 +04: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 16:48:55 +03:00
|
|
|
host_memory_backend_get_size(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
2014-06-06 19:54:29 +04: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 16:48:54 +03:00
|
|
|
visit_type_size(v, name, &value, errp);
|
2014-06-06 19:54:29 +04: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 16:48:55 +03:00
|
|
|
host_memory_backend_set_size(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
2014-06-06 19:54:29 +04:00
|
|
|
{
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
|
|
|
|
uint64_t value;
|
|
|
|
|
2017-03-10 16:09:30 +03:00
|
|
|
if (host_memory_backend_mr_inited(backend)) {
|
error: Avoid unnecessary error_propagate() after error_setg()
Replace
error_setg(&err, ...);
error_propagate(errp, err);
by
error_setg(errp, ...);
Related pattern:
if (...) {
error_setg(&err, ...);
goto out;
}
...
out:
error_propagate(errp, err);
return;
When all paths to label out are that way, replace by
if (...) {
error_setg(errp, ...);
return;
}
and delete the label along with the error_propagate().
When we have at most one other path that actually needs to propagate,
and maybe one at the end that where propagation is unnecessary, e.g.
foo(..., &err);
if (err) {
goto out;
}
...
bar(..., &err);
out:
error_propagate(errp, err);
return;
move the error_propagate() to where it's needed, like
if (...) {
foo(..., &err);
error_propagate(errp, err);
return;
}
...
bar(..., errp);
return;
and transform the error_setg() as above.
In some places, the transformation results in obviously unnecessary
error_propagate(). The next few commits will eliminate them.
Bonus: the elimination of gotos will make later patches in this series
easier to review.
Candidates for conversion tracked down with this Coccinelle script:
@@
identifier err, errp;
expression list args;
@@
- error_setg(&err, args);
+ error_setg(errp, args);
... when != err
error_propagate(errp, err);
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-34-armbru@redhat.com>
2020-07-07 19:06:01 +03:00
|
|
|
error_setg(errp, "cannot change property %s of %s ", name,
|
|
|
|
object_get_typename(obj));
|
|
|
|
return;
|
2014-06-06 19:54:29 +04:00
|
|
|
}
|
|
|
|
|
error: Eliminate error_propagate() with Coccinelle, part 1
When all we do with an Error we receive into a local variable is
propagating to somewhere else, we can just as well receive it there
right away. Convert
if (!foo(..., &err)) {
...
error_propagate(errp, err);
...
return ...
}
to
if (!foo(..., errp)) {
...
...
return ...
}
where nothing else needs @err. Coccinelle script:
@rule1 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
binary operator op;
constant c1, c2;
symbol false;
@@
if (
(
- fun(args, &err, args2)
+ fun(args, errp, args2)
|
- !fun(args, &err, args2)
+ !fun(args, errp, args2)
|
- fun(args, &err, args2) op c1
+ fun(args, errp, args2) op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
)
}
@rule2 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
expression var;
binary operator op;
constant c1, c2;
symbol false;
@@
- var = fun(args, &err, args2);
+ var = fun(args, errp, args2);
... when != err
if (
(
var
|
!var
|
var op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
|
return var;
)
}
@depends on rule1 || rule2@
identifier err;
@@
- Error *err = NULL;
... when != err
Not exactly elegant, I'm afraid.
The "when != lbl:" is necessary to avoid transforming
if (fun(args, &err)) {
goto out
}
...
out:
error_propagate(errp, err);
even though other paths to label out still need the error_propagate().
For an actual example, see sclp_realize().
Without the "when strict", Coccinelle transforms vfio_msix_setup(),
incorrectly. I don't know what exactly "when strict" does, only that
it helps here.
The match of return is narrower than what I want, but I can't figure
out how to express "return where the operand doesn't use @err". For
an example where it's too narrow, see vfio_intx_enable().
Silently fails to convert hw/arm/armsse.c, because Coccinelle gets
confused by ARMSSE being used both as typedef and function-like macro
there. Converted manually.
Line breaks tidied up manually. One nested declaration of @local_err
deleted manually. Preexisting unwanted blank line dropped in
hw/riscv/sifive_e.c.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-35-armbru@redhat.com>
2020-07-07 19:06:02 +03:00
|
|
|
if (!visit_type_size(v, name, &value, errp)) {
|
error: Avoid unnecessary error_propagate() after error_setg()
Replace
error_setg(&err, ...);
error_propagate(errp, err);
by
error_setg(errp, ...);
Related pattern:
if (...) {
error_setg(&err, ...);
goto out;
}
...
out:
error_propagate(errp, err);
return;
When all paths to label out are that way, replace by
if (...) {
error_setg(errp, ...);
return;
}
and delete the label along with the error_propagate().
When we have at most one other path that actually needs to propagate,
and maybe one at the end that where propagation is unnecessary, e.g.
foo(..., &err);
if (err) {
goto out;
}
...
bar(..., &err);
out:
error_propagate(errp, err);
return;
move the error_propagate() to where it's needed, like
if (...) {
foo(..., &err);
error_propagate(errp, err);
return;
}
...
bar(..., errp);
return;
and transform the error_setg() as above.
In some places, the transformation results in obviously unnecessary
error_propagate(). The next few commits will eliminate them.
Bonus: the elimination of gotos will make later patches in this series
easier to review.
Candidates for conversion tracked down with this Coccinelle script:
@@
identifier err, errp;
expression list args;
@@
- error_setg(&err, args);
+ error_setg(errp, args);
... when != err
error_propagate(errp, err);
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-34-armbru@redhat.com>
2020-07-07 19:06:01 +03:00
|
|
|
return;
|
2014-06-06 19:54:29 +04:00
|
|
|
}
|
|
|
|
if (!value) {
|
error: Avoid unnecessary error_propagate() after error_setg()
Replace
error_setg(&err, ...);
error_propagate(errp, err);
by
error_setg(errp, ...);
Related pattern:
if (...) {
error_setg(&err, ...);
goto out;
}
...
out:
error_propagate(errp, err);
return;
When all paths to label out are that way, replace by
if (...) {
error_setg(errp, ...);
return;
}
and delete the label along with the error_propagate().
When we have at most one other path that actually needs to propagate,
and maybe one at the end that where propagation is unnecessary, e.g.
foo(..., &err);
if (err) {
goto out;
}
...
bar(..., &err);
out:
error_propagate(errp, err);
return;
move the error_propagate() to where it's needed, like
if (...) {
foo(..., &err);
error_propagate(errp, err);
return;
}
...
bar(..., errp);
return;
and transform the error_setg() as above.
In some places, the transformation results in obviously unnecessary
error_propagate(). The next few commits will eliminate them.
Bonus: the elimination of gotos will make later patches in this series
easier to review.
Candidates for conversion tracked down with this Coccinelle script:
@@
identifier err, errp;
expression list args;
@@
- error_setg(&err, args);
+ error_setg(errp, args);
... when != err
error_propagate(errp, err);
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-34-armbru@redhat.com>
2020-07-07 19:06:01 +03:00
|
|
|
error_setg(errp,
|
2019-01-02 08:26:24 +03:00
|
|
|
"property '%s' of %s doesn't take value '%" PRIu64 "'",
|
|
|
|
name, object_get_typename(obj), value);
|
error: Avoid unnecessary error_propagate() after error_setg()
Replace
error_setg(&err, ...);
error_propagate(errp, err);
by
error_setg(errp, ...);
Related pattern:
if (...) {
error_setg(&err, ...);
goto out;
}
...
out:
error_propagate(errp, err);
return;
When all paths to label out are that way, replace by
if (...) {
error_setg(errp, ...);
return;
}
and delete the label along with the error_propagate().
When we have at most one other path that actually needs to propagate,
and maybe one at the end that where propagation is unnecessary, e.g.
foo(..., &err);
if (err) {
goto out;
}
...
bar(..., &err);
out:
error_propagate(errp, err);
return;
move the error_propagate() to where it's needed, like
if (...) {
foo(..., &err);
error_propagate(errp, err);
return;
}
...
bar(..., errp);
return;
and transform the error_setg() as above.
In some places, the transformation results in obviously unnecessary
error_propagate(). The next few commits will eliminate them.
Bonus: the elimination of gotos will make later patches in this series
easier to review.
Candidates for conversion tracked down with this Coccinelle script:
@@
identifier err, errp;
expression list args;
@@
- error_setg(&err, args);
+ error_setg(errp, args);
... when != err
error_propagate(errp, err);
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-34-armbru@redhat.com>
2020-07-07 19:06:01 +03:00
|
|
|
return;
|
2014-06-06 19:54:29 +04:00
|
|
|
}
|
|
|
|
backend->size = value;
|
|
|
|
}
|
|
|
|
|
2014-06-10 15:15:25 +04: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 16:48:55 +03:00
|
|
|
host_memory_backend_get_host_nodes(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
2014-06-10 15:15:25 +04:00
|
|
|
{
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
|
|
|
|
uint16List *host_nodes = NULL;
|
2021-01-14 01:10:12 +03:00
|
|
|
uint16List **tail = &host_nodes;
|
2014-06-10 15:15:25 +04:00
|
|
|
unsigned long value;
|
|
|
|
|
|
|
|
value = find_first_bit(backend->host_nodes, MAX_NODES);
|
|
|
|
if (value == MAX_NODES) {
|
2019-02-14 13:57:33 +03:00
|
|
|
goto ret;
|
2014-06-10 15:15:25 +04:00
|
|
|
}
|
|
|
|
|
2021-01-14 01:10:12 +03:00
|
|
|
QAPI_LIST_APPEND(tail, value);
|
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 19:13:44 +03:00
|
|
|
|
2014-06-10 15:15:25 +04:00
|
|
|
do {
|
|
|
|
value = find_next_bit(backend->host_nodes, MAX_NODES, value + 1);
|
|
|
|
if (value == MAX_NODES) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-01-14 01:10:12 +03:00
|
|
|
QAPI_LIST_APPEND(tail, value);
|
2014-06-10 15:15:25 +04:00
|
|
|
} while (true);
|
|
|
|
|
2019-02-14 13:57:33 +03: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 16:48:54 +03:00
|
|
|
visit_type_uint16List(v, name, &host_nodes, errp);
|
2020-12-10 10:52:26 +03:00
|
|
|
qapi_free_uint16List(host_nodes);
|
2014-06-10 15:15:25 +04: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 16:48:55 +03:00
|
|
|
host_memory_backend_set_host_nodes(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
2014-06-10 15:15:25 +04:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_NUMA
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
|
2018-11-30 15:28:44 +03:00
|
|
|
uint16List *l, *host_nodes = NULL;
|
2014-06-10 15:15:25 +04:00
|
|
|
|
2018-11-30 15:28:44 +03: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 15:15:25 +04:00
|
|
|
|
2018-11-30 15:28:44 +03:00
|
|
|
for (l = host_nodes; l; l = l->next) {
|
2014-06-10 15:15:25 +04:00
|
|
|
bitmap_set(backend->host_nodes, l->value, 1);
|
|
|
|
}
|
2018-11-30 15:28:44 +03:00
|
|
|
|
|
|
|
out:
|
|
|
|
qapi_free_uint16List(host_nodes);
|
2014-06-10 15:15:25 +04:00
|
|
|
#else
|
|
|
|
error_setg(errp, "NUMA node binding are not supported by this QEMU");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-05-27 18:07:56 +03:00
|
|
|
static int
|
|
|
|
host_memory_backend_get_policy(Object *obj, Error **errp G_GNUC_UNUSED)
|
2014-06-10 15:15:25 +04:00
|
|
|
{
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
|
2015-05-27 18:07:56 +03:00
|
|
|
return backend->policy;
|
2014-06-10 15:15:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-05-27 18:07:56 +03:00
|
|
|
host_memory_backend_set_policy(Object *obj, int policy, Error **errp)
|
2014-06-10 15:15:25 +04: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 15:15:22 +04: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 16:09:30 +03:00
|
|
|
if (!host_memory_backend_mr_inited(backend)) {
|
2014-06-10 15:15:22 +04: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 16:09:30 +03:00
|
|
|
if (!host_memory_backend_mr_inited(backend)) {
|
2014-06-10 15:15:22 +04: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 15:15:23 +04:00
|
|
|
static bool host_memory_backend_get_prealloc(Object *obj, Error **errp)
|
|
|
|
{
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
|
|
|
|
|
2020-02-19 19:09:51 +03:00
|
|
|
return backend->prealloc;
|
2014-06-10 15:15:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void host_memory_backend_set_prealloc(Object *obj, bool value,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
|
|
|
|
|
2021-05-10 14:43:23 +03:00
|
|
|
if (!backend->reserve && value) {
|
|
|
|
error_setg(errp, "'prealloc=on' and 'reserve=off' are incompatible");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-10 16:09:30 +03:00
|
|
|
if (!host_memory_backend_mr_inited(backend)) {
|
2014-06-10 15:15:23 +04: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);
|
|
|
|
|
2023-11-20 17:32:57 +03:00
|
|
|
if (!qemu_prealloc_mem(fd, ptr, sz, backend->prealloc_threads,
|
2024-01-31 19:53:27 +03:00
|
|
|
backend->prealloc_context, false, errp)) {
|
2016-07-20 12:54:03 +03:00
|
|
|
return;
|
|
|
|
}
|
2014-06-10 15:15:23 +04:00
|
|
|
backend->prealloc = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-19 19:09:50 +03:00
|
|
|
static void host_memory_backend_get_prealloc_threads(Object *obj, Visitor *v,
|
|
|
|
const char *name, void *opaque, Error **errp)
|
|
|
|
{
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
|
|
|
|
visit_type_uint32(v, name, &backend->prealloc_threads, errp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void host_memory_backend_set_prealloc_threads(Object *obj, Visitor *v,
|
|
|
|
const char *name, void *opaque, Error **errp)
|
|
|
|
{
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
|
|
|
|
uint32_t value;
|
|
|
|
|
error: Eliminate error_propagate() with Coccinelle, part 1
When all we do with an Error we receive into a local variable is
propagating to somewhere else, we can just as well receive it there
right away. Convert
if (!foo(..., &err)) {
...
error_propagate(errp, err);
...
return ...
}
to
if (!foo(..., errp)) {
...
...
return ...
}
where nothing else needs @err. Coccinelle script:
@rule1 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
binary operator op;
constant c1, c2;
symbol false;
@@
if (
(
- fun(args, &err, args2)
+ fun(args, errp, args2)
|
- !fun(args, &err, args2)
+ !fun(args, errp, args2)
|
- fun(args, &err, args2) op c1
+ fun(args, errp, args2) op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
)
}
@rule2 forall@
identifier fun, err, errp, lbl;
expression list args, args2;
expression var;
binary operator op;
constant c1, c2;
symbol false;
@@
- var = fun(args, &err, args2);
+ var = fun(args, errp, args2);
... when != err
if (
(
var
|
!var
|
var op c1
)
)
{
... when != err
when != lbl:
when strict
- error_propagate(errp, err);
... when != err
(
return;
|
return c2;
|
return false;
|
return var;
)
}
@depends on rule1 || rule2@
identifier err;
@@
- Error *err = NULL;
... when != err
Not exactly elegant, I'm afraid.
The "when != lbl:" is necessary to avoid transforming
if (fun(args, &err)) {
goto out
}
...
out:
error_propagate(errp, err);
even though other paths to label out still need the error_propagate().
For an actual example, see sclp_realize().
Without the "when strict", Coccinelle transforms vfio_msix_setup(),
incorrectly. I don't know what exactly "when strict" does, only that
it helps here.
The match of return is narrower than what I want, but I can't figure
out how to express "return where the operand doesn't use @err". For
an example where it's too narrow, see vfio_intx_enable().
Silently fails to convert hw/arm/armsse.c, because Coccinelle gets
confused by ARMSSE being used both as typedef and function-like macro
there. Converted manually.
Line breaks tidied up manually. One nested declaration of @local_err
deleted manually. Preexisting unwanted blank line dropped in
hw/riscv/sifive_e.c.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-35-armbru@redhat.com>
2020-07-07 19:06:02 +03:00
|
|
|
if (!visit_type_uint32(v, name, &value, errp)) {
|
error: Avoid unnecessary error_propagate() after error_setg()
Replace
error_setg(&err, ...);
error_propagate(errp, err);
by
error_setg(errp, ...);
Related pattern:
if (...) {
error_setg(&err, ...);
goto out;
}
...
out:
error_propagate(errp, err);
return;
When all paths to label out are that way, replace by
if (...) {
error_setg(errp, ...);
return;
}
and delete the label along with the error_propagate().
When we have at most one other path that actually needs to propagate,
and maybe one at the end that where propagation is unnecessary, e.g.
foo(..., &err);
if (err) {
goto out;
}
...
bar(..., &err);
out:
error_propagate(errp, err);
return;
move the error_propagate() to where it's needed, like
if (...) {
foo(..., &err);
error_propagate(errp, err);
return;
}
...
bar(..., errp);
return;
and transform the error_setg() as above.
In some places, the transformation results in obviously unnecessary
error_propagate(). The next few commits will eliminate them.
Bonus: the elimination of gotos will make later patches in this series
easier to review.
Candidates for conversion tracked down with this Coccinelle script:
@@
identifier err, errp;
expression list args;
@@
- error_setg(&err, args);
+ error_setg(errp, args);
... when != err
error_propagate(errp, err);
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-34-armbru@redhat.com>
2020-07-07 19:06:01 +03:00
|
|
|
return;
|
2020-02-19 19:09:50 +03:00
|
|
|
}
|
|
|
|
if (value <= 0) {
|
error: Avoid unnecessary error_propagate() after error_setg()
Replace
error_setg(&err, ...);
error_propagate(errp, err);
by
error_setg(errp, ...);
Related pattern:
if (...) {
error_setg(&err, ...);
goto out;
}
...
out:
error_propagate(errp, err);
return;
When all paths to label out are that way, replace by
if (...) {
error_setg(errp, ...);
return;
}
and delete the label along with the error_propagate().
When we have at most one other path that actually needs to propagate,
and maybe one at the end that where propagation is unnecessary, e.g.
foo(..., &err);
if (err) {
goto out;
}
...
bar(..., &err);
out:
error_propagate(errp, err);
return;
move the error_propagate() to where it's needed, like
if (...) {
foo(..., &err);
error_propagate(errp, err);
return;
}
...
bar(..., errp);
return;
and transform the error_setg() as above.
In some places, the transformation results in obviously unnecessary
error_propagate(). The next few commits will eliminate them.
Bonus: the elimination of gotos will make later patches in this series
easier to review.
Candidates for conversion tracked down with this Coccinelle script:
@@
identifier err, errp;
expression list args;
@@
- error_setg(&err, args);
+ error_setg(errp, args);
... when != err
error_propagate(errp, err);
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-34-armbru@redhat.com>
2020-07-07 19:06:01 +03:00
|
|
|
error_setg(errp, "property '%s' of %s doesn't take value '%d'", name,
|
|
|
|
object_get_typename(obj), value);
|
|
|
|
return;
|
2020-02-19 19:09:50 +03:00
|
|
|
}
|
|
|
|
backend->prealloc_threads = value;
|
|
|
|
}
|
|
|
|
|
2014-06-10 15:15:18 +04:00
|
|
|
static void host_memory_backend_init(Object *obj)
|
2014-06-06 19:54:29 +04:00
|
|
|
{
|
2014-06-10 15:15:22 +04: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 23:29:12 +03:00
|
|
|
MachineState *machine = MACHINE(qdev_get_machine());
|
2014-06-10 15:15:22 +04:00
|
|
|
|
2020-02-19 19:09:50 +03:00
|
|
|
/* TODO: convert access to globals to compat properties */
|
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 23:29:12 +03:00
|
|
|
backend->merge = machine_mem_merge(machine);
|
|
|
|
backend->dump = machine_dump_guest_core(machine);
|
2021-05-10 14:43:23 +03:00
|
|
|
backend->reserve = true;
|
2022-05-17 15:38:58 +03:00
|
|
|
backend->prealloc_threads = machine->smp.cpus;
|
2014-06-06 19:54:29 +04: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 15:18:00 +03:00
|
|
|
static void host_memory_backend_post_init(Object *obj)
|
|
|
|
{
|
|
|
|
object_apply_compat_props(obj);
|
|
|
|
}
|
|
|
|
|
2017-03-10 16:09:29 +03: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 16:41:36 +03:00
|
|
|
MemoryRegion *host_memory_backend_get_memory(HostMemoryBackend *backend)
|
2014-06-06 19:54:29 +04:00
|
|
|
{
|
2017-03-10 16:09:30 +03:00
|
|
|
return host_memory_backend_mr_inited(backend) ? &backend->mr : NULL;
|
2014-06-06 19:54:29 +04:00
|
|
|
}
|
|
|
|
|
2016-07-13 07:18:06 +03: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 08:05:45 +03:00
|
|
|
size_t host_memory_backend_pagesize(HostMemoryBackend *memdev)
|
|
|
|
{
|
2022-08-10 15:57:18 +03:00
|
|
|
size_t pagesize = qemu_ram_pagesize(memdev->mr.ram_block);
|
|
|
|
g_assert(pagesize >= qemu_real_host_page_size());
|
2018-04-03 08:05:45 +03:00
|
|
|
return pagesize;
|
|
|
|
}
|
|
|
|
|
2014-06-10 15:15:19 +04:00
|
|
|
static void
|
|
|
|
host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
|
|
|
|
{
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(uc);
|
|
|
|
HostMemoryBackendClass *bc = MEMORY_BACKEND_GET_CLASS(uc);
|
2014-06-10 15:15:22 +04:00
|
|
|
void *ptr;
|
|
|
|
uint64_t sz;
|
2024-01-31 19:53:27 +03:00
|
|
|
bool async = !phase_check(PHASE_LATE_BACKENDS_CREATED);
|
2014-06-10 15:15:19 +04:00
|
|
|
|
2023-11-20 15:49:30 +03:00
|
|
|
if (!bc->alloc) {
|
|
|
|
return;
|
|
|
|
}
|
2023-11-20 15:50:52 +03:00
|
|
|
if (!bc->alloc(backend, errp)) {
|
|
|
|
return;
|
2023-11-20 15:49:30 +03:00
|
|
|
}
|
2014-06-10 15:15:22 +04:00
|
|
|
|
2023-11-20 15:49:30 +03:00
|
|
|
ptr = memory_region_get_ram_ptr(&backend->mr);
|
|
|
|
sz = memory_region_size(&backend->mr);
|
2014-06-10 15:15:22 +04:00
|
|
|
|
2023-11-20 15:49:30 +03:00
|
|
|
if (backend->merge) {
|
|
|
|
qemu_madvise(ptr, sz, QEMU_MADV_MERGEABLE);
|
|
|
|
}
|
|
|
|
if (!backend->dump) {
|
|
|
|
qemu_madvise(ptr, sz, QEMU_MADV_DONTDUMP);
|
|
|
|
}
|
2014-06-10 15:15:25 +04:00
|
|
|
#ifdef CONFIG_NUMA
|
2023-11-20 15:49:30 +03:00
|
|
|
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);
|
2024-01-29 21:31:30 +03:00
|
|
|
/*
|
|
|
|
* Ensure policy won't be ignored in case memory is preallocated
|
2023-11-20 15:49:30 +03:00
|
|
|
* before mbind(). note: MPOL_MF_STRICT is ignored on hugepages so
|
2024-01-29 21:31:30 +03:00
|
|
|
* this doesn't catch hugepage case.
|
|
|
|
*/
|
2023-11-20 15:49:30 +03:00
|
|
|
unsigned flags = MPOL_MF_STRICT | MPOL_MF_MOVE;
|
|
|
|
int mode = backend->policy;
|
|
|
|
|
|
|
|
/* 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",
|
|
|
|
HostMemPolicy_str(backend->policy));
|
|
|
|
return;
|
|
|
|
}
|
2014-06-10 15:15:25 +04:00
|
|
|
|
2024-01-29 21:31:30 +03:00
|
|
|
/*
|
|
|
|
* We can have up to MAX_NODES nodes, but we need to pass maxnode+1
|
2023-11-20 15:49:30 +03:00
|
|
|
* 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);
|
2020-04-30 18:46:06 +03:00
|
|
|
|
hostmem: Honor multiple preferred nodes if possible
If a memory-backend is configured with mode
HOST_MEM_POLICY_PREFERRED then
host_memory_backend_memory_complete() calls mbind() as:
mbind(..., MPOL_PREFERRED, nodemask, ...);
Here, 'nodemask' is a bitmap of host NUMA nodes and corresponds
to the .host-nodes attribute. Therefore, there can be multiple
nodes specified. However, the documentation to MPOL_PREFERRED
says:
MPOL_PREFERRED
This mode sets the preferred node for allocation. ...
If nodemask specifies more than one node ID, the first node
in the mask will be selected as the preferred node.
Therefore, only the first node is honored and the rest is
silently ignored. Well, with recent changes to the kernel and
numactl we can do better.
The Linux kernel added in v5.15 via commit cfcaa66f8032
("mm/hugetlb: add support for mempolicy MPOL_PREFERRED_MANY")
support for MPOL_PREFERRED_MANY, which accepts multiple preferred
NUMA nodes instead.
Then, numa_has_preferred_many() API was introduced to numactl
(v2.0.15~26) allowing applications to query kernel support.
Wiring this all together, we can pass MPOL_PREFERRED_MANY to the
mbind() call instead and stop ignoring multiple nodes, silently.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Message-Id: <a0b4adce1af5bd2344c2218eb4a04b3ff7bcfdb4.1671097918.git.mprivozn@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
2022-12-15 12:55:03 +03:00
|
|
|
#ifdef HAVE_NUMA_HAS_PREFERRED_MANY
|
2023-11-20 15:49:30 +03:00
|
|
|
if (mode == MPOL_PREFERRED && numa_has_preferred_many() > 0) {
|
|
|
|
/*
|
|
|
|
* Replace with MPOL_PREFERRED_MANY otherwise the mbind() below
|
|
|
|
* silently picks the first node.
|
|
|
|
*/
|
|
|
|
mode = MPOL_PREFERRED_MANY;
|
|
|
|
}
|
hostmem: Honor multiple preferred nodes if possible
If a memory-backend is configured with mode
HOST_MEM_POLICY_PREFERRED then
host_memory_backend_memory_complete() calls mbind() as:
mbind(..., MPOL_PREFERRED, nodemask, ...);
Here, 'nodemask' is a bitmap of host NUMA nodes and corresponds
to the .host-nodes attribute. Therefore, there can be multiple
nodes specified. However, the documentation to MPOL_PREFERRED
says:
MPOL_PREFERRED
This mode sets the preferred node for allocation. ...
If nodemask specifies more than one node ID, the first node
in the mask will be selected as the preferred node.
Therefore, only the first node is honored and the rest is
silently ignored. Well, with recent changes to the kernel and
numactl we can do better.
The Linux kernel added in v5.15 via commit cfcaa66f8032
("mm/hugetlb: add support for mempolicy MPOL_PREFERRED_MANY")
support for MPOL_PREFERRED_MANY, which accepts multiple preferred
NUMA nodes instead.
Then, numa_has_preferred_many() API was introduced to numactl
(v2.0.15~26) allowing applications to query kernel support.
Wiring this all together, we can pass MPOL_PREFERRED_MANY to the
mbind() call instead and stop ignoring multiple nodes, silently.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Message-Id: <a0b4adce1af5bd2344c2218eb4a04b3ff7bcfdb4.1671097918.git.mprivozn@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
2022-12-15 12:55:03 +03:00
|
|
|
#endif
|
|
|
|
|
2023-11-20 15:49:30 +03:00
|
|
|
if (maxnode &&
|
|
|
|
mbind(ptr, sz, mode, 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");
|
|
|
|
return;
|
2014-06-10 15:15:25 +04:00
|
|
|
}
|
2023-11-20 15:49:30 +03:00
|
|
|
}
|
2014-06-10 15:15:25 +04:00
|
|
|
#endif
|
2024-01-29 21:31:30 +03:00
|
|
|
/*
|
|
|
|
* Preallocate memory after the NUMA policy has been instantiated.
|
2023-11-20 15:49:30 +03:00
|
|
|
* This is necessary to guarantee memory is allocated with
|
|
|
|
* specified NUMA policy in place.
|
|
|
|
*/
|
2023-11-20 17:32:57 +03:00
|
|
|
if (backend->prealloc && !qemu_prealloc_mem(memory_region_get_fd(&backend->mr),
|
|
|
|
ptr, sz,
|
|
|
|
backend->prealloc_threads,
|
2024-01-31 19:53:27 +03:00
|
|
|
backend->prealloc_context,
|
|
|
|
async, errp)) {
|
2023-11-20 17:32:57 +03:00
|
|
|
return;
|
2014-06-10 15:15:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-30 11:36:29 +03:00
|
|
|
static bool
|
2017-08-30 01:03:37 +03:00
|
|
|
host_memory_backend_can_be_deleted(UserCreatable *uc)
|
2015-03-30 11:36:29 +03:00
|
|
|
{
|
2016-07-13 07:18:06 +03:00
|
|
|
if (host_memory_backend_is_mapped(MEMORY_BACKEND(uc))) {
|
2015-03-30 11:36:29 +03:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-13 17:37:37 +03: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;
|
|
|
|
}
|
|
|
|
|
2021-05-10 14:43:23 +03:00
|
|
|
#ifdef CONFIG_LINUX
|
|
|
|
static bool host_memory_backend_get_reserve(Object *o, Error **errp)
|
|
|
|
{
|
|
|
|
HostMemoryBackend *backend = MEMORY_BACKEND(o);
|
|
|
|
|
|
|
|
return backend->reserve;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void host_memory_backend_set_reserve(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;
|
|
|
|
}
|
|
|
|
if (backend->prealloc && !value) {
|
|
|
|
error_setg(errp, "'prealloc=on' and 'reserve=off' are incompatible");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
backend->reserve = value;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_LINUX */
|
|
|
|
|
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 15:18:00 +03: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 15:15:19 +04: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 11:36:29 +03:00
|
|
|
ucc->can_be_deleted = host_memory_backend_can_be_deleted;
|
2016-10-13 23:52:51 +03:00
|
|
|
|
|
|
|
object_class_property_add_bool(oc, "merge",
|
|
|
|
host_memory_backend_get_merge,
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 18:29:22 +03:00
|
|
|
host_memory_backend_set_merge);
|
2018-09-06 17:39:08 +03:00
|
|
|
object_class_property_set_description(oc, "merge",
|
2020-05-05 18:29:15 +03:00
|
|
|
"Mark memory as mergeable");
|
2016-10-13 23:52:51 +03:00
|
|
|
object_class_property_add_bool(oc, "dump",
|
|
|
|
host_memory_backend_get_dump,
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 18:29:22 +03:00
|
|
|
host_memory_backend_set_dump);
|
2018-09-06 17:39:08 +03:00
|
|
|
object_class_property_set_description(oc, "dump",
|
2020-05-05 18:29:15 +03:00
|
|
|
"Set to 'off' to exclude from core dump");
|
2016-10-13 23:52:51 +03:00
|
|
|
object_class_property_add_bool(oc, "prealloc",
|
|
|
|
host_memory_backend_get_prealloc,
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 18:29:22 +03:00
|
|
|
host_memory_backend_set_prealloc);
|
2018-09-06 17:39:08 +03:00
|
|
|
object_class_property_set_description(oc, "prealloc",
|
2020-05-05 18:29:15 +03:00
|
|
|
"Preallocate memory");
|
2020-02-19 19:09:50 +03:00
|
|
|
object_class_property_add(oc, "prealloc-threads", "int",
|
|
|
|
host_memory_backend_get_prealloc_threads,
|
|
|
|
host_memory_backend_set_prealloc_threads,
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 18:29:22 +03:00
|
|
|
NULL, NULL);
|
2020-02-19 19:09:50 +03:00
|
|
|
object_class_property_set_description(oc, "prealloc-threads",
|
2020-05-05 18:29:15 +03:00
|
|
|
"Number of CPU threads to use for prealloc");
|
2022-10-14 16:47:19 +03:00
|
|
|
object_class_property_add_link(oc, "prealloc-context",
|
|
|
|
TYPE_THREAD_CONTEXT, offsetof(HostMemoryBackend, prealloc_context),
|
|
|
|
object_property_allow_set_link, OBJ_PROP_LINK_STRONG);
|
|
|
|
object_class_property_set_description(oc, "prealloc-context",
|
|
|
|
"Context to use for creating CPU threads for preallocation");
|
2016-10-13 23:52:51 +03:00
|
|
|
object_class_property_add(oc, "size", "int",
|
|
|
|
host_memory_backend_get_size,
|
|
|
|
host_memory_backend_set_size,
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 18:29:22 +03:00
|
|
|
NULL, NULL);
|
2018-09-06 17:39:08 +03:00
|
|
|
object_class_property_set_description(oc, "size",
|
2020-05-05 18:29:15 +03:00
|
|
|
"Size of the memory region (ex: 500M)");
|
2016-10-13 23:52:51 +03:00
|
|
|
object_class_property_add(oc, "host-nodes", "int",
|
|
|
|
host_memory_backend_get_host_nodes,
|
|
|
|
host_memory_backend_set_host_nodes,
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 18:29:22 +03:00
|
|
|
NULL, NULL);
|
2018-09-06 17:39:08 +03:00
|
|
|
object_class_property_set_description(oc, "host-nodes",
|
2020-05-05 18:29:15 +03:00
|
|
|
"Binds memory to the list of NUMA host nodes");
|
2016-10-13 23:52:51 +03:00
|
|
|
object_class_property_add_enum(oc, "policy", "HostMemPolicy",
|
2017-08-24 11:46:10 +03:00
|
|
|
&HostMemPolicy_lookup,
|
2016-10-13 23:52:51 +03:00
|
|
|
host_memory_backend_get_policy,
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 18:29:22 +03:00
|
|
|
host_memory_backend_set_policy);
|
2018-09-06 17:39:08 +03:00
|
|
|
object_class_property_set_description(oc, "policy",
|
2020-05-05 18:29:15 +03:00
|
|
|
"Set the NUMA policy");
|
2017-12-13 17:37:37 +03:00
|
|
|
object_class_property_add_bool(oc, "share",
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 18:29:22 +03:00
|
|
|
host_memory_backend_get_share, host_memory_backend_set_share);
|
2018-09-06 17:39:08 +03:00
|
|
|
object_class_property_set_description(oc, "share",
|
2020-05-05 18:29:15 +03:00
|
|
|
"Mark the memory as private to QEMU or shared");
|
2021-05-10 14:43:23 +03:00
|
|
|
#ifdef CONFIG_LINUX
|
|
|
|
object_class_property_add_bool(oc, "reserve",
|
|
|
|
host_memory_backend_get_reserve, host_memory_backend_set_reserve);
|
|
|
|
object_class_property_set_description(oc, "reserve",
|
|
|
|
"Reserve swap space (or huge pages) if applicable");
|
|
|
|
#endif /* CONFIG_LINUX */
|
2021-01-21 19:15:04 +03:00
|
|
|
/*
|
|
|
|
* Do not delete/rename option. This option must be considered stable
|
|
|
|
* (as if it didn't have the 'x-' prefix including deprecation period) as
|
|
|
|
* long as 4.0 and older machine types exists.
|
|
|
|
* Option will be used by upper layers to override (disable) canonical path
|
|
|
|
* for ramblock-id set by compat properties on old machine types ( <= 4.0),
|
|
|
|
* to keep migration working when backend is used for main RAM with
|
|
|
|
* -machine memory-backend= option (main RAM historically used prefix-less
|
|
|
|
* ramblock-id).
|
|
|
|
*/
|
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 15:18:00 +03:00
|
|
|
object_class_property_add_bool(oc, "x-use-canonical-path-for-ramblock-id",
|
|
|
|
host_memory_backend_get_use_canonical_path,
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 18:29:22 +03:00
|
|
|
host_memory_backend_set_use_canonical_path);
|
2017-01-10 15:53:15 +03:00
|
|
|
}
|
|
|
|
|
2014-06-10 15:15:18 +04:00
|
|
|
static const TypeInfo host_memory_backend_info = {
|
2014-06-06 19:54:29 +04:00
|
|
|
.name = TYPE_MEMORY_BACKEND,
|
|
|
|
.parent = TYPE_OBJECT,
|
|
|
|
.abstract = true,
|
|
|
|
.class_size = sizeof(HostMemoryBackendClass),
|
2014-06-10 15:15:19 +04:00
|
|
|
.class_init = host_memory_backend_class_init,
|
2014-06-06 19:54:29 +04:00
|
|
|
.instance_size = sizeof(HostMemoryBackend),
|
2014-06-10 15:15:18 +04: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 15:18:00 +03:00
|
|
|
.instance_post_init = host_memory_backend_post_init,
|
2014-06-06 19:54:29 +04:00
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ TYPE_USER_CREATABLE },
|
|
|
|
{ }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void register_types(void)
|
|
|
|
{
|
2014-06-10 15:15:18 +04:00
|
|
|
type_register_static(&host_memory_backend_info);
|
2014-06-06 19:54:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
type_init(register_types);
|