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