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