]> git.proxmox.com Git - mirror_qemu.git/blame - numa.c
numa: report all DIMM/NVDIMMs as plugged memory
[mirror_qemu.git] / numa.c
CommitLineData
96d0e26c
WG
1/*
2 * NUMA parameter parsing routines
3 *
4 * Copyright (c) 2014 Fujitsu Ltd.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
d38ea87a 25#include "qemu/osdep.h"
e35704ba 26#include "sysemu/numa.h"
96d0e26c 27#include "exec/cpu-common.h"
0987d735 28#include "exec/ramlist.h"
96d0e26c
WG
29#include "qemu/bitmap.h"
30#include "qom/cpu.h"
2b631ec2 31#include "qemu/error-report.h"
e688df6b 32#include "qapi/error.h"
0042109a 33#include "qapi/opts-visitor.h"
112ed241
MA
34#include "qapi/qapi-commands-misc.h"
35#include "qapi/qapi-visit-misc.h"
dfabb8b9 36#include "hw/boards.h"
7febe36f 37#include "sysemu/hostmem.h"
5b009e40 38#include "hw/mem/pc-dimm.h"
2cc0e2e8 39#include "hw/mem/memory-device.h"
7dcd1d70
EH
40#include "qemu/option.h"
41#include "qemu/config-file.h"
cc001888 42#include "qemu/cutils.h"
0042109a
WG
43
44QemuOptsList qemu_numa_opts = {
45 .name = "numa",
46 .implied_opt_name = "type",
47 .head = QTAILQ_HEAD_INITIALIZER(qemu_numa_opts.head),
48 .desc = { { 0 } } /* validated with OptsVisitor */
49};
50
7febe36f 51static int have_memdevs = -1;
25712ffe
EH
52static int max_numa_nodeid; /* Highest specified NUMA node ID, plus one.
53 * For all nodes, nodeid < max_numa_nodeid
54 */
de1a7c84 55int nb_numa_nodes;
0f203430 56bool have_numa_distance;
de1a7c84 57NodeInfo numa_info[MAX_NODES];
7febe36f 58
e75e2a14 59
64c2a8f6 60static void parse_numa_node(MachineState *ms, NumaNodeOptions *node,
cc001888 61 Error **errp)
96d0e26c 62{
0042109a
WG
63 uint16_t nodenr;
64 uint16List *cpus = NULL;
64c2a8f6 65 MachineClass *mc = MACHINE_GET_CLASS(ms);
96d0e26c 66
0042109a
WG
67 if (node->has_nodeid) {
68 nodenr = node->nodeid;
96d0e26c 69 } else {
0042109a 70 nodenr = nb_numa_nodes;
96d0e26c
WG
71 }
72
0042109a
WG
73 if (nodenr >= MAX_NODES) {
74 error_setg(errp, "Max number of NUMA nodes reached: %"
01bbbcf4 75 PRIu16 "", nodenr);
0042109a 76 return;
96d0e26c
WG
77 }
78
1945b9d8
EH
79 if (numa_info[nodenr].present) {
80 error_setg(errp, "Duplicate NUMA nodeid: %" PRIu16, nodenr);
81 return;
82 }
83
81ce6aa5 84 if (!mc->cpu_index_to_instance_props || !mc->get_default_cpu_node_id) {
64c2a8f6
IM
85 error_report("NUMA is not supported by this machine-type");
86 exit(1);
87 }
0042109a 88 for (cpus = node->cpus; cpus; cpus = cpus->next) {
7c88e65d 89 CpuInstanceProperties props;
8979c945
EH
90 if (cpus->value >= max_cpus) {
91 error_setg(errp,
92 "CPU index (%" PRIu16 ")"
93 " should be smaller than maxcpus (%d)",
94 cpus->value, max_cpus);
0042109a
WG
95 return;
96 }
7c88e65d
IM
97 props = mc->cpu_index_to_instance_props(ms, cpus->value);
98 props.node_id = nodenr;
99 props.has_node_id = true;
100 machine_set_cpu_numa_node(ms, &props, &error_fatal);
96d0e26c
WG
101 }
102
7febe36f 103 if (node->has_mem && node->has_memdev) {
d0e31a10 104 error_setg(errp, "cannot specify both mem= and memdev=");
7febe36f
PB
105 return;
106 }
107
108 if (have_memdevs == -1) {
109 have_memdevs = node->has_memdev;
110 }
111 if (node->has_memdev != have_memdevs) {
d0e31a10 112 error_setg(errp, "memdev option must be specified for either "
01bbbcf4 113 "all or no nodes");
7febe36f
PB
114 return;
115 }
116
0042109a 117 if (node->has_mem) {
cc001888 118 numa_info[nodenr].node_mem = node->mem;
0042109a 119 }
7febe36f
PB
120 if (node->has_memdev) {
121 Object *o;
122 o = object_resolve_path_type(node->memdev, TYPE_MEMORY_BACKEND, NULL);
123 if (!o) {
124 error_setg(errp, "memdev=%s is ambiguous", node->memdev);
125 return;
126 }
127
128 object_ref(o);
61d7c144 129 numa_info[nodenr].node_mem = object_property_get_uint(o, "size", NULL);
7febe36f
PB
130 numa_info[nodenr].node_memdev = MEMORY_BACKEND(o);
131 }
1af878e0
EH
132 numa_info[nodenr].present = true;
133 max_numa_nodeid = MAX(max_numa_nodeid, nodenr + 1);
7b8be49d 134 nb_numa_nodes++;
96d0e26c
WG
135}
136
0f203430
HC
137static void parse_numa_distance(NumaDistOptions *dist, Error **errp)
138{
139 uint16_t src = dist->src;
140 uint16_t dst = dist->dst;
141 uint8_t val = dist->val;
142
143 if (src >= MAX_NODES || dst >= MAX_NODES) {
74f38e96
IM
144 error_setg(errp, "Parameter '%s' expects an integer between 0 and %d",
145 src >= MAX_NODES ? "src" : "dst", MAX_NODES - 1);
0f203430
HC
146 return;
147 }
148
149 if (!numa_info[src].present || !numa_info[dst].present) {
150 error_setg(errp, "Source/Destination NUMA node is missing. "
151 "Please use '-numa node' option to declare it first.");
152 return;
153 }
154
155 if (val < NUMA_DISTANCE_MIN) {
156 error_setg(errp, "NUMA distance (%" PRIu8 ") is invalid, "
157 "it shouldn't be less than %d.",
158 val, NUMA_DISTANCE_MIN);
159 return;
160 }
161
162 if (src == dst && val != NUMA_DISTANCE_MIN) {
163 error_setg(errp, "Local distance of node %d should be %d.",
164 src, NUMA_DISTANCE_MIN);
165 return;
166 }
167
168 numa_info[src].distance[dst] = val;
169 have_numa_distance = true;
170}
171
3319b4ef
IM
172static
173void set_numa_options(MachineState *ms, NumaOptions *object, Error **errp)
96d0e26c 174{
0042109a 175 Error *err = NULL;
96d0e26c 176
1fd5d4fe 177 switch (object->type) {
d081a49a 178 case NUMA_OPTIONS_TYPE_NODE:
cc001888 179 parse_numa_node(ms, &object->u.node, &err);
0042109a 180 if (err) {
157e94e8 181 goto end;
96d0e26c 182 }
0042109a 183 break;
0f203430
HC
184 case NUMA_OPTIONS_TYPE_DIST:
185 parse_numa_distance(&object->u.dist, &err);
186 if (err) {
187 goto end;
188 }
189 break;
419fcdec
IM
190 case NUMA_OPTIONS_TYPE_CPU:
191 if (!object->u.cpu.has_node_id) {
192 error_setg(&err, "Missing mandatory node-id property");
193 goto end;
194 }
195 if (!numa_info[object->u.cpu.node_id].present) {
196 error_setg(&err, "Invalid node-id=%" PRId64 ", NUMA node must be "
197 "defined with -numa node,nodeid=ID before it's used with "
198 "-numa cpu,node-id=ID", object->u.cpu.node_id);
199 goto end;
200 }
201
202 machine_set_cpu_numa_node(ms, qapi_NumaCpuOptions_base(&object->u.cpu),
203 &err);
204 break;
0042109a
WG
205 default:
206 abort();
207 }
96d0e26c 208
3319b4ef
IM
209end:
210 error_propagate(errp, err);
211}
212
213int parse_numa(void *opaque, QemuOpts *opts, Error **errp)
214{
215 NumaOptions *object = NULL;
216 MachineState *ms = MACHINE(opaque);
217 Error *err = NULL;
218 Visitor *v = opts_visitor_new(opts);
219
220 visit_type_NumaOptions(v, NULL, &object, &err);
221 visit_free(v);
222 if (err) {
223 goto end;
224 }
225
226 /* Fix up legacy suffix-less format */
227 if ((object->type == NUMA_OPTIONS_TYPE_NODE) && object->u.node.has_mem) {
228 const char *mem_str = qemu_opt_get(opts, "mem");
229 qemu_strtosz_MiB(mem_str, NULL, &object->u.node.mem);
230 }
231
232 set_numa_options(ms, object, &err);
233
157e94e8 234end:
96a1616c 235 qapi_free_NumaOptions(object);
157e94e8
MAL
236 if (err) {
237 error_report_err(err);
238 return -1;
239 }
0042109a 240
157e94e8 241 return 0;
96d0e26c
WG
242}
243
0f203430
HC
244/* If all node pair distances are symmetric, then only distances
245 * in one direction are enough. If there is even one asymmetric
246 * pair, though, then all distances must be provided. The
247 * distance from a node to itself is always NUMA_DISTANCE_MIN,
248 * so providing it is never necessary.
249 */
250static void validate_numa_distance(void)
3ef71975 251{
0f203430
HC
252 int src, dst;
253 bool is_asymmetrical = false;
254
255 for (src = 0; src < nb_numa_nodes; src++) {
256 for (dst = src; dst < nb_numa_nodes; dst++) {
257 if (numa_info[src].distance[dst] == 0 &&
258 numa_info[dst].distance[src] == 0) {
259 if (src != dst) {
260 error_report("The distance between node %d and %d is "
261 "missing, at least one distance value "
262 "between each nodes should be provided.",
263 src, dst);
264 exit(EXIT_FAILURE);
265 }
266 }
3ef71975 267
0f203430
HC
268 if (numa_info[src].distance[dst] != 0 &&
269 numa_info[dst].distance[src] != 0 &&
270 numa_info[src].distance[dst] !=
271 numa_info[dst].distance[src]) {
272 is_asymmetrical = true;
273 }
274 }
275 }
276
277 if (is_asymmetrical) {
278 for (src = 0; src < nb_numa_nodes; src++) {
279 for (dst = 0; dst < nb_numa_nodes; dst++) {
280 if (src != dst && numa_info[src].distance[dst] == 0) {
281 error_report("At least one asymmetrical pair of "
282 "distances is given, please provide distances "
283 "for both directions of all node pairs.");
284 exit(EXIT_FAILURE);
285 }
286 }
287 }
3ef71975 288 }
3ef71975
EH
289}
290
0f203430 291static void complete_init_numa_distance(void)
3ef71975 292{
0f203430 293 int src, dst;
3ef71975 294
0f203430
HC
295 /* Fixup NUMA distance by symmetric policy because if it is an
296 * asymmetric distance table, it should be a complete table and
297 * there would not be any missing distance except local node, which
298 * is verified by validate_numa_distance above.
299 */
300 for (src = 0; src < nb_numa_nodes; src++) {
301 for (dst = 0; dst < nb_numa_nodes; dst++) {
302 if (numa_info[src].distance[dst] == 0) {
303 if (src == dst) {
304 numa_info[src].distance[dst] = NUMA_DISTANCE_MIN;
305 } else {
306 numa_info[src].distance[dst] = numa_info[dst].distance[src];
307 }
308 }
3ef71975 309 }
3ef71975 310 }
0f203430 311}
549fc54b 312
3bfe5716
LV
313void numa_legacy_auto_assign_ram(MachineClass *mc, NodeInfo *nodes,
314 int nb_nodes, ram_addr_t size)
315{
316 int i;
317 uint64_t usedmem = 0;
318
319 /* Align each node according to the alignment
320 * requirements of the machine class
321 */
322
323 for (i = 0; i < nb_nodes - 1; i++) {
324 nodes[i].node_mem = (size / nb_nodes) &
325 ~((1 << mc->numa_mem_align_shift) - 1);
326 usedmem += nodes[i].node_mem;
549fc54b 327 }
3bfe5716 328 nodes[i].node_mem = size - usedmem;
3ef71975
EH
329}
330
3bfe5716
LV
331void numa_default_auto_assign_ram(MachineClass *mc, NodeInfo *nodes,
332 int nb_nodes, ram_addr_t size)
96d0e26c 333{
12d6e464 334 int i;
3bfe5716
LV
335 uint64_t usedmem = 0, node_mem;
336 uint64_t granularity = size / nb_nodes;
337 uint64_t propagate = 0;
338
339 for (i = 0; i < nb_nodes - 1; i++) {
340 node_mem = (granularity + propagate) &
341 ~((1 << mc->numa_mem_align_shift) - 1);
342 propagate = granularity + propagate - node_mem;
343 nodes[i].node_mem = node_mem;
344 usedmem += node_mem;
345 }
346 nodes[i].node_mem = size - usedmem;
347}
12d6e464 348
7a3099fc 349void numa_complete_configuration(MachineState *ms)
96d0e26c 350{
12d6e464 351 int i;
ea089eeb 352 MachineClass *mc = MACHINE_GET_CLASS(ms);
cdda2018 353
7b8be49d
DL
354 /*
355 * If memory hotplug is enabled (slots > 0) but without '-numa'
356 * options explicitly on CLI, guestes will break.
357 *
358 * Windows: won't enable memory hotplug without SRAT table at all
359 *
360 * Linux: if QEMU is started with initial memory all below 4Gb
361 * and no SRAT table present, guest kernel will use nommu DMA ops,
362 * which breaks 32bit hw drivers when memory is hotplugged and
363 * guest tries to use it with that drivers.
364 *
365 * Enable NUMA implicitly by adding a new NUMA node automatically.
366 */
367 if (ms->ram_slots > 0 && nb_numa_nodes == 0 &&
368 mc->auto_enable_numa_with_memhp) {
369 NumaNodeOptions node = { };
370 parse_numa_node(ms, &node, NULL);
371 }
372
12d6e464
EH
373 assert(max_numa_nodeid <= MAX_NODES);
374
375 /* No support for sparse NUMA node IDs yet: */
376 for (i = max_numa_nodeid - 1; i >= 0; i--) {
377 /* Report large node IDs first, to make mistakes easier to spot */
378 if (!numa_info[i].present) {
379 error_report("numa: Node ID missing: %d", i);
380 exit(1);
381 }
382 }
383
384 /* This must be always true if all nodes are present: */
385 assert(nb_numa_nodes == max_numa_nodeid);
386
96d0e26c 387 if (nb_numa_nodes > 0) {
2b631ec2 388 uint64_t numa_total;
96d0e26c
WG
389
390 if (nb_numa_nodes > MAX_NODES) {
391 nb_numa_nodes = MAX_NODES;
392 }
393
9851d0fe 394 /* If no memory size is given for any node, assume the default case
96d0e26c
WG
395 * and distribute the available memory equally across all nodes
396 */
397 for (i = 0; i < nb_numa_nodes; i++) {
8c85901e 398 if (numa_info[i].node_mem != 0) {
96d0e26c
WG
399 break;
400 }
401 }
402 if (i == nb_numa_nodes) {
3bfe5716
LV
403 assert(mc->numa_auto_assign_ram);
404 mc->numa_auto_assign_ram(mc, numa_info, nb_numa_nodes, ram_size);
96d0e26c
WG
405 }
406
2b631ec2
WG
407 numa_total = 0;
408 for (i = 0; i < nb_numa_nodes; i++) {
8c85901e 409 numa_total += numa_info[i].node_mem;
2b631ec2
WG
410 }
411 if (numa_total != ram_size) {
c68233ae
HT
412 error_report("total memory for NUMA nodes (0x%" PRIx64 ")"
413 " should equal RAM size (0x" RAM_ADDR_FMT ")",
2b631ec2
WG
414 numa_total, ram_size);
415 exit(1);
416 }
417
0f203430
HC
418 /* QEMU needs at least all unique node pair distances to build
419 * the whole NUMA distance table. QEMU treats the distance table
420 * as symmetric by default, i.e. distance A->B == distance B->A.
421 * Thus, QEMU is able to complete the distance table
422 * initialization even though only distance A->B is provided and
423 * distance B->A is not. QEMU knows the distance of a node to
424 * itself is always 10, so A->A distances may be omitted. When
425 * the distances of two nodes of a pair differ, i.e. distance
426 * A->B != distance B->A, then that means the distance table is
427 * asymmetric. In this case, the distances for both directions
428 * of all node pairs are required.
429 */
430 if (have_numa_distance) {
431 /* Validate enough NUMA distance information was provided. */
432 validate_numa_distance();
96d0e26c 433
0f203430
HC
434 /* Validation succeeded, now fill in any missing distances. */
435 complete_init_numa_distance();
96d0e26c
WG
436 }
437 }
438}
dfabb8b9 439
7a3099fc
IM
440void parse_numa_opts(MachineState *ms)
441{
442 if (qemu_opts_foreach(qemu_find_opts("numa"), parse_numa, ms, NULL)) {
443 exit(1);
444 }
445}
446
f3be6781
IM
447void qmp_set_numa_node(NumaOptions *cmd, Error **errp)
448{
449 if (!runstate_check(RUN_STATE_PRECONFIG)) {
450 error_setg(errp, "The command is permitted only in '%s' state",
451 RunState_str(RUN_STATE_PRECONFIG));
452 return;
453 }
454
455 set_numa_options(MACHINE(qdev_get_machine()), cmd, errp);
456}
457
a0ceb640
IM
458void numa_cpu_pre_plug(const CPUArchId *slot, DeviceState *dev, Error **errp)
459{
a0ceb640
IM
460 int node_id = object_property_get_int(OBJECT(dev), "node-id", &error_abort);
461
a0ceb640
IM
462 if (node_id == CPU_UNSET_NUMA_NODE_ID) {
463 /* due to bug in libvirt, it doesn't pass node-id from props on
464 * device_add as expected, so we have to fix it up here */
d41f3e75
IM
465 if (slot->props.has_node_id) {
466 object_property_set_int(OBJECT(dev), slot->props.node_id,
467 "node-id", errp);
468 }
469 } else if (node_id != slot->props.node_id) {
a0ceb640
IM
470 error_setg(errp, "node-id=%d must match numa node specified "
471 "with -numa option", node_id);
472 }
473}
474
7febe36f
PB
475static void allocate_system_memory_nonnuma(MemoryRegion *mr, Object *owner,
476 const char *name,
477 uint64_t ram_size)
478{
0b183fc8
PB
479 if (mem_path) {
480#ifdef __linux__
7f56e740 481 Error *err = NULL;
98376843 482 memory_region_init_ram_from_file(mr, owner, name, ram_size, 0, false,
7f56e740 483 mem_path, &err);
c3ba3095 484 if (err) {
29b762f5 485 error_report_err(err);
fae947b0
LC
486 if (mem_prealloc) {
487 exit(1);
488 }
e85687ff 489 error_report("falling back to regular RAM allocation.");
fae947b0
LC
490
491 /* Legacy behavior: if allocation failed, fall back to
492 * regular RAM allocation.
493 */
6233b679 494 mem_path = NULL;
1cfe48c1 495 memory_region_init_ram_nomigrate(mr, owner, name, ram_size, &error_fatal);
7f56e740 496 }
0b183fc8
PB
497#else
498 fprintf(stderr, "-mem-path not supported on this host\n");
499 exit(1);
500#endif
501 } else {
1cfe48c1 502 memory_region_init_ram_nomigrate(mr, owner, name, ram_size, &error_fatal);
0b183fc8 503 }
7febe36f
PB
504 vmstate_register_ram_global(mr);
505}
506
dfabb8b9
PB
507void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
508 const char *name,
509 uint64_t ram_size)
510{
7febe36f
PB
511 uint64_t addr = 0;
512 int i;
513
514 if (nb_numa_nodes == 0 || !have_memdevs) {
515 allocate_system_memory_nonnuma(mr, owner, name, ram_size);
516 return;
517 }
518
519 memory_region_init(mr, owner, name, ram_size);
f51878ba 520 for (i = 0; i < nb_numa_nodes; i++) {
7febe36f
PB
521 uint64_t size = numa_info[i].node_mem;
522 HostMemoryBackend *backend = numa_info[i].node_memdev;
523 if (!backend) {
524 continue;
525 }
7943e97b 526 MemoryRegion *seg = host_memory_backend_get_memory(backend);
7febe36f 527
0462faee
HT
528 if (memory_region_is_mapped(seg)) {
529 char *path = object_get_canonical_path_component(OBJECT(backend));
530 error_report("memory backend %s is used multiple times. Each "
531 "-numa option must use a different memdev value.",
532 path);
533 exit(1);
534 }
535
0b217571 536 host_memory_backend_set_mapped(backend, true);
7febe36f
PB
537 memory_region_add_subregion(mr, addr, seg);
538 vmstate_register_ram_global(seg);
539 addr += size;
540 }
dfabb8b9 541}
76b5d850 542
31959e82 543static void numa_stat_memory_devices(NumaNodeMem node_mem[])
5b009e40 544{
2cc0e2e8 545 MemoryDeviceInfoList *info_list = qmp_memory_device_list();
5b009e40 546 MemoryDeviceInfoList *info;
31959e82 547 PCDIMMDeviceInfo *pcdimm_info;
5b009e40 548
5b009e40
HZ
549 for (info = info_list; info; info = info->next) {
550 MemoryDeviceInfo *value = info->value;
551
552 if (value) {
1fd5d4fe 553 switch (value->type) {
6388e18d 554 case MEMORY_DEVICE_INFO_KIND_DIMM:
31959e82 555 pcdimm_info = value->u.dimm.data;
6388e18d
HZ
556 break;
557
558 case MEMORY_DEVICE_INFO_KIND_NVDIMM:
559 pcdimm_info = value->u.nvdimm.data;
560 break;
561
562 default:
563 pcdimm_info = NULL;
564 break;
565 }
566
567 if (pcdimm_info) {
31959e82 568 node_mem[pcdimm_info->node].node_mem += pcdimm_info->size;
178003ea
DH
569 node_mem[pcdimm_info->node].node_plugged_mem +=
570 pcdimm_info->size;
5b009e40
HZ
571 }
572 }
573 }
574 qapi_free_MemoryDeviceInfoList(info_list);
575}
576
31959e82 577void query_numa_node_mem(NumaNodeMem node_mem[])
5b009e40
HZ
578{
579 int i;
580
581 if (nb_numa_nodes <= 0) {
582 return;
583 }
584
585 numa_stat_memory_devices(node_mem);
586 for (i = 0; i < nb_numa_nodes; i++) {
31959e82 587 node_mem[i].node_mem += numa_info[i].node_mem;
5b009e40
HZ
588 }
589}
590
76b5d850
HT
591static int query_memdev(Object *obj, void *opaque)
592{
593 MemdevList **list = opaque;
b0e90181 594 MemdevList *m = NULL;
76b5d850
HT
595
596 if (object_dynamic_cast(obj, TYPE_MEMORY_BACKEND)) {
b0e90181 597 m = g_malloc0(sizeof(*m));
76b5d850
HT
598
599 m->value = g_malloc0(sizeof(*m->value));
600
29de4ec1 601 m->value->id = object_get_canonical_path_component(obj);
e1ff3c67
IM
602 m->value->has_id = !!m->value->id;
603
61d7c144
MAL
604 m->value->size = object_property_get_uint(obj, "size",
605 &error_abort);
76b5d850 606 m->value->merge = object_property_get_bool(obj, "merge",
2f6f826e 607 &error_abort);
76b5d850 608 m->value->dump = object_property_get_bool(obj, "dump",
2f6f826e 609 &error_abort);
76b5d850 610 m->value->prealloc = object_property_get_bool(obj,
2f6f826e
MA
611 "prealloc",
612 &error_abort);
76b5d850
HT
613 m->value->policy = object_property_get_enum(obj,
614 "policy",
a3590dac 615 "HostMemPolicy",
2f6f826e 616 &error_abort);
76b5d850 617 object_property_get_uint16List(obj, "host-nodes",
2f6f826e
MA
618 &m->value->host_nodes,
619 &error_abort);
76b5d850
HT
620
621 m->next = *list;
622 *list = m;
623 }
624
625 return 0;
76b5d850
HT
626}
627
628MemdevList *qmp_query_memdev(Error **errp)
629{
2f6f826e 630 Object *obj = object_get_objects_root();
ecaf54a0 631 MemdevList *list = NULL;
76b5d850 632
2f6f826e 633 object_child_foreach(obj, query_memdev, &list);
76b5d850 634 return list;
76b5d850 635}
6bea1ddf 636
0987d735
PB
637void ram_block_notifier_add(RAMBlockNotifier *n)
638{
639 QLIST_INSERT_HEAD(&ram_list.ramblock_notifiers, n, next);
640}
641
642void ram_block_notifier_remove(RAMBlockNotifier *n)
643{
644 QLIST_REMOVE(n, next);
645}
646
647void ram_block_notify_add(void *host, size_t size)
648{
649 RAMBlockNotifier *notifier;
650
651 QLIST_FOREACH(notifier, &ram_list.ramblock_notifiers, next) {
652 notifier->ram_block_added(notifier, host, size);
653 }
654}
655
656void ram_block_notify_remove(void *host, size_t size)
657{
658 RAMBlockNotifier *notifier;
659
660 QLIST_FOREACH(notifier, &ram_list.ramblock_notifiers, next) {
661 notifier->ram_block_removed(notifier, host, size);
662 }
663}