numa.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  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. #include "qemu/osdep.h"
  25. #include "sysemu/numa.h"
  26. #include "exec/cpu-common.h"
  27. #include "exec/ramlist.h"
  28. #include "qemu/bitmap.h"
  29. #include "qom/cpu.h"
  30. #include "qemu/error-report.h"
  31. #include "include/exec/cpu-common.h" /* for RAM_ADDR_FMT */
  32. #include "qapi-visit.h"
  33. #include "qapi/opts-visitor.h"
  34. #include "hw/boards.h"
  35. #include "sysemu/hostmem.h"
  36. #include "qmp-commands.h"
  37. #include "hw/mem/pc-dimm.h"
  38. #include "qemu/option.h"
  39. #include "qemu/config-file.h"
  40. QemuOptsList 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. static int have_memdevs = -1;
  47. static int max_numa_nodeid; /* Highest specified NUMA node ID, plus one.
  48. * For all nodes, nodeid < max_numa_nodeid
  49. */
  50. int nb_numa_nodes;
  51. bool have_numa_distance;
  52. NodeInfo numa_info[MAX_NODES];
  53. void numa_set_mem_node_id(ram_addr_t addr, uint64_t size, uint32_t node)
  54. {
  55. struct numa_addr_range *range;
  56. /*
  57. * Memory-less nodes can come here with 0 size in which case,
  58. * there is nothing to do.
  59. */
  60. if (!size) {
  61. return;
  62. }
  63. range = g_malloc0(sizeof(*range));
  64. range->mem_start = addr;
  65. range->mem_end = addr + size - 1;
  66. QLIST_INSERT_HEAD(&numa_info[node].addr, range, entry);
  67. }
  68. void numa_unset_mem_node_id(ram_addr_t addr, uint64_t size, uint32_t node)
  69. {
  70. struct numa_addr_range *range, *next;
  71. QLIST_FOREACH_SAFE(range, &numa_info[node].addr, entry, next) {
  72. if (addr == range->mem_start && (addr + size - 1) == range->mem_end) {
  73. QLIST_REMOVE(range, entry);
  74. g_free(range);
  75. return;
  76. }
  77. }
  78. }
  79. static void numa_set_mem_ranges(void)
  80. {
  81. int i;
  82. ram_addr_t mem_start = 0;
  83. /*
  84. * Deduce start address of each node and use it to store
  85. * the address range info in numa_info address range list
  86. */
  87. for (i = 0; i < nb_numa_nodes; i++) {
  88. numa_set_mem_node_id(mem_start, numa_info[i].node_mem, i);
  89. mem_start += numa_info[i].node_mem;
  90. }
  91. }
  92. /*
  93. * Check if @addr falls under NUMA @node.
  94. */
  95. static bool numa_addr_belongs_to_node(ram_addr_t addr, uint32_t node)
  96. {
  97. struct numa_addr_range *range;
  98. QLIST_FOREACH(range, &numa_info[node].addr, entry) {
  99. if (addr >= range->mem_start && addr <= range->mem_end) {
  100. return true;
  101. }
  102. }
  103. return false;
  104. }
  105. /*
  106. * Given an address, return the index of the NUMA node to which the
  107. * address belongs to.
  108. */
  109. uint32_t numa_get_node(ram_addr_t addr, Error **errp)
  110. {
  111. uint32_t i;
  112. /* For non NUMA configurations, check if the addr falls under node 0 */
  113. if (!nb_numa_nodes) {
  114. if (numa_addr_belongs_to_node(addr, 0)) {
  115. return 0;
  116. }
  117. }
  118. for (i = 0; i < nb_numa_nodes; i++) {
  119. if (numa_addr_belongs_to_node(addr, i)) {
  120. return i;
  121. }
  122. }
  123. error_setg(errp, "Address 0x" RAM_ADDR_FMT " doesn't belong to any "
  124. "NUMA node", addr);
  125. return -1;
  126. }
  127. static void parse_numa_node(MachineState *ms, NumaNodeOptions *node,
  128. QemuOpts *opts, Error **errp)
  129. {
  130. uint16_t nodenr;
  131. uint16List *cpus = NULL;
  132. MachineClass *mc = MACHINE_GET_CLASS(ms);
  133. if (node->has_nodeid) {
  134. nodenr = node->nodeid;
  135. } else {
  136. nodenr = nb_numa_nodes;
  137. }
  138. if (nodenr >= MAX_NODES) {
  139. error_setg(errp, "Max number of NUMA nodes reached: %"
  140. PRIu16 "", nodenr);
  141. return;
  142. }
  143. if (numa_info[nodenr].present) {
  144. error_setg(errp, "Duplicate NUMA nodeid: %" PRIu16, nodenr);
  145. return;
  146. }
  147. if (!mc->cpu_index_to_instance_props) {
  148. error_report("NUMA is not supported by this machine-type");
  149. exit(1);
  150. }
  151. for (cpus = node->cpus; cpus; cpus = cpus->next) {
  152. CpuInstanceProperties props;
  153. if (cpus->value >= max_cpus) {
  154. error_setg(errp,
  155. "CPU index (%" PRIu16 ")"
  156. " should be smaller than maxcpus (%d)",
  157. cpus->value, max_cpus);
  158. return;
  159. }
  160. props = mc->cpu_index_to_instance_props(ms, cpus->value);
  161. props.node_id = nodenr;
  162. props.has_node_id = true;
  163. machine_set_cpu_numa_node(ms, &props, &error_fatal);
  164. }
  165. if (node->has_mem && node->has_memdev) {
  166. error_setg(errp, "cannot specify both mem= and memdev=");
  167. return;
  168. }
  169. if (have_memdevs == -1) {
  170. have_memdevs = node->has_memdev;
  171. }
  172. if (node->has_memdev != have_memdevs) {
  173. error_setg(errp, "memdev option must be specified for either "
  174. "all or no nodes");
  175. return;
  176. }
  177. if (node->has_mem) {
  178. uint64_t mem_size = node->mem;
  179. const char *mem_str = qemu_opt_get(opts, "mem");
  180. /* Fix up legacy suffix-less format */
  181. if (g_ascii_isdigit(mem_str[strlen(mem_str) - 1])) {
  182. mem_size <<= 20;
  183. }
  184. numa_info[nodenr].node_mem = mem_size;
  185. }
  186. if (node->has_memdev) {
  187. Object *o;
  188. o = object_resolve_path_type(node->memdev, TYPE_MEMORY_BACKEND, NULL);
  189. if (!o) {
  190. error_setg(errp, "memdev=%s is ambiguous", node->memdev);
  191. return;
  192. }
  193. object_ref(o);
  194. numa_info[nodenr].node_mem = object_property_get_int(o, "size", NULL);
  195. numa_info[nodenr].node_memdev = MEMORY_BACKEND(o);
  196. }
  197. numa_info[nodenr].present = true;
  198. max_numa_nodeid = MAX(max_numa_nodeid, nodenr + 1);
  199. }
  200. static void parse_numa_distance(NumaDistOptions *dist, Error **errp)
  201. {
  202. uint16_t src = dist->src;
  203. uint16_t dst = dist->dst;
  204. uint8_t val = dist->val;
  205. if (src >= MAX_NODES || dst >= MAX_NODES) {
  206. error_setg(errp,
  207. "Invalid node %d, max possible could be %d",
  208. MAX(src, dst), MAX_NODES);
  209. return;
  210. }
  211. if (!numa_info[src].present || !numa_info[dst].present) {
  212. error_setg(errp, "Source/Destination NUMA node is missing. "
  213. "Please use '-numa node' option to declare it first.");
  214. return;
  215. }
  216. if (val < NUMA_DISTANCE_MIN) {
  217. error_setg(errp, "NUMA distance (%" PRIu8 ") is invalid, "
  218. "it shouldn't be less than %d.",
  219. val, NUMA_DISTANCE_MIN);
  220. return;
  221. }
  222. if (src == dst && val != NUMA_DISTANCE_MIN) {
  223. error_setg(errp, "Local distance of node %d should be %d.",
  224. src, NUMA_DISTANCE_MIN);
  225. return;
  226. }
  227. numa_info[src].distance[dst] = val;
  228. have_numa_distance = true;
  229. }
  230. static int parse_numa(void *opaque, QemuOpts *opts, Error **errp)
  231. {
  232. NumaOptions *object = NULL;
  233. MachineState *ms = opaque;
  234. Error *err = NULL;
  235. {
  236. Visitor *v = opts_visitor_new(opts);
  237. visit_type_NumaOptions(v, NULL, &object, &err);
  238. visit_free(v);
  239. }
  240. if (err) {
  241. goto end;
  242. }
  243. switch (object->type) {
  244. case NUMA_OPTIONS_TYPE_NODE:
  245. parse_numa_node(ms, &object->u.node, opts, &err);
  246. if (err) {
  247. goto end;
  248. }
  249. nb_numa_nodes++;
  250. break;
  251. case NUMA_OPTIONS_TYPE_DIST:
  252. parse_numa_distance(&object->u.dist, &err);
  253. if (err) {
  254. goto end;
  255. }
  256. break;
  257. case NUMA_OPTIONS_TYPE_CPU:
  258. if (!object->u.cpu.has_node_id) {
  259. error_setg(&err, "Missing mandatory node-id property");
  260. goto end;
  261. }
  262. if (!numa_info[object->u.cpu.node_id].present) {
  263. error_setg(&err, "Invalid node-id=%" PRId64 ", NUMA node must be "
  264. "defined with -numa node,nodeid=ID before it's used with "
  265. "-numa cpu,node-id=ID", object->u.cpu.node_id);
  266. goto end;
  267. }
  268. machine_set_cpu_numa_node(ms, qapi_NumaCpuOptions_base(&object->u.cpu),
  269. &err);
  270. break;
  271. default:
  272. abort();
  273. }
  274. end:
  275. qapi_free_NumaOptions(object);
  276. if (err) {
  277. error_report_err(err);
  278. return -1;
  279. }
  280. return 0;
  281. }
  282. /* If all node pair distances are symmetric, then only distances
  283. * in one direction are enough. If there is even one asymmetric
  284. * pair, though, then all distances must be provided. The
  285. * distance from a node to itself is always NUMA_DISTANCE_MIN,
  286. * so providing it is never necessary.
  287. */
  288. static void validate_numa_distance(void)
  289. {
  290. int src, dst;
  291. bool is_asymmetrical = false;
  292. for (src = 0; src < nb_numa_nodes; src++) {
  293. for (dst = src; dst < nb_numa_nodes; dst++) {
  294. if (numa_info[src].distance[dst] == 0 &&
  295. numa_info[dst].distance[src] == 0) {
  296. if (src != dst) {
  297. error_report("The distance between node %d and %d is "
  298. "missing, at least one distance value "
  299. "between each nodes should be provided.",
  300. src, dst);
  301. exit(EXIT_FAILURE);
  302. }
  303. }
  304. if (numa_info[src].distance[dst] != 0 &&
  305. numa_info[dst].distance[src] != 0 &&
  306. numa_info[src].distance[dst] !=
  307. numa_info[dst].distance[src]) {
  308. is_asymmetrical = true;
  309. }
  310. }
  311. }
  312. if (is_asymmetrical) {
  313. for (src = 0; src < nb_numa_nodes; src++) {
  314. for (dst = 0; dst < nb_numa_nodes; dst++) {
  315. if (src != dst && numa_info[src].distance[dst] == 0) {
  316. error_report("At least one asymmetrical pair of "
  317. "distances is given, please provide distances "
  318. "for both directions of all node pairs.");
  319. exit(EXIT_FAILURE);
  320. }
  321. }
  322. }
  323. }
  324. }
  325. static void complete_init_numa_distance(void)
  326. {
  327. int src, dst;
  328. /* Fixup NUMA distance by symmetric policy because if it is an
  329. * asymmetric distance table, it should be a complete table and
  330. * there would not be any missing distance except local node, which
  331. * is verified by validate_numa_distance above.
  332. */
  333. for (src = 0; src < nb_numa_nodes; src++) {
  334. for (dst = 0; dst < nb_numa_nodes; dst++) {
  335. if (numa_info[src].distance[dst] == 0) {
  336. if (src == dst) {
  337. numa_info[src].distance[dst] = NUMA_DISTANCE_MIN;
  338. } else {
  339. numa_info[src].distance[dst] = numa_info[dst].distance[src];
  340. }
  341. }
  342. }
  343. }
  344. }
  345. void numa_legacy_auto_assign_ram(MachineClass *mc, NodeInfo *nodes,
  346. int nb_nodes, ram_addr_t size)
  347. {
  348. int i;
  349. uint64_t usedmem = 0;
  350. /* Align each node according to the alignment
  351. * requirements of the machine class
  352. */
  353. for (i = 0; i < nb_nodes - 1; i++) {
  354. nodes[i].node_mem = (size / nb_nodes) &
  355. ~((1 << mc->numa_mem_align_shift) - 1);
  356. usedmem += nodes[i].node_mem;
  357. }
  358. nodes[i].node_mem = size - usedmem;
  359. }
  360. void numa_default_auto_assign_ram(MachineClass *mc, NodeInfo *nodes,
  361. int nb_nodes, ram_addr_t size)
  362. {
  363. int i;
  364. uint64_t usedmem = 0, node_mem;
  365. uint64_t granularity = size / nb_nodes;
  366. uint64_t propagate = 0;
  367. for (i = 0; i < nb_nodes - 1; i++) {
  368. node_mem = (granularity + propagate) &
  369. ~((1 << mc->numa_mem_align_shift) - 1);
  370. propagate = granularity + propagate - node_mem;
  371. nodes[i].node_mem = node_mem;
  372. usedmem += node_mem;
  373. }
  374. nodes[i].node_mem = size - usedmem;
  375. }
  376. void parse_numa_opts(MachineState *ms)
  377. {
  378. int i;
  379. MachineClass *mc = MACHINE_GET_CLASS(ms);
  380. if (qemu_opts_foreach(qemu_find_opts("numa"), parse_numa, ms, NULL)) {
  381. exit(1);
  382. }
  383. assert(max_numa_nodeid <= MAX_NODES);
  384. /* No support for sparse NUMA node IDs yet: */
  385. for (i = max_numa_nodeid - 1; i >= 0; i--) {
  386. /* Report large node IDs first, to make mistakes easier to spot */
  387. if (!numa_info[i].present) {
  388. error_report("numa: Node ID missing: %d", i);
  389. exit(1);
  390. }
  391. }
  392. /* This must be always true if all nodes are present: */
  393. assert(nb_numa_nodes == max_numa_nodeid);
  394. if (nb_numa_nodes > 0) {
  395. uint64_t numa_total;
  396. if (nb_numa_nodes > MAX_NODES) {
  397. nb_numa_nodes = MAX_NODES;
  398. }
  399. /* If no memory size is given for any node, assume the default case
  400. * and distribute the available memory equally across all nodes
  401. */
  402. for (i = 0; i < nb_numa_nodes; i++) {
  403. if (numa_info[i].node_mem != 0) {
  404. break;
  405. }
  406. }
  407. if (i == nb_numa_nodes) {
  408. assert(mc->numa_auto_assign_ram);
  409. mc->numa_auto_assign_ram(mc, numa_info, nb_numa_nodes, ram_size);
  410. }
  411. numa_total = 0;
  412. for (i = 0; i < nb_numa_nodes; i++) {
  413. numa_total += numa_info[i].node_mem;
  414. }
  415. if (numa_total != ram_size) {
  416. error_report("total memory for NUMA nodes (0x%" PRIx64 ")"
  417. " should equal RAM size (0x" RAM_ADDR_FMT ")",
  418. numa_total, ram_size);
  419. exit(1);
  420. }
  421. for (i = 0; i < nb_numa_nodes; i++) {
  422. QLIST_INIT(&numa_info[i].addr);
  423. }
  424. numa_set_mem_ranges();
  425. /* QEMU needs at least all unique node pair distances to build
  426. * the whole NUMA distance table. QEMU treats the distance table
  427. * as symmetric by default, i.e. distance A->B == distance B->A.
  428. * Thus, QEMU is able to complete the distance table
  429. * initialization even though only distance A->B is provided and
  430. * distance B->A is not. QEMU knows the distance of a node to
  431. * itself is always 10, so A->A distances may be omitted. When
  432. * the distances of two nodes of a pair differ, i.e. distance
  433. * A->B != distance B->A, then that means the distance table is
  434. * asymmetric. In this case, the distances for both directions
  435. * of all node pairs are required.
  436. */
  437. if (have_numa_distance) {
  438. /* Validate enough NUMA distance information was provided. */
  439. validate_numa_distance();
  440. /* Validation succeeded, now fill in any missing distances. */
  441. complete_init_numa_distance();
  442. }
  443. } else {
  444. numa_set_mem_node_id(0, ram_size, 0);
  445. }
  446. }
  447. void numa_cpu_pre_plug(const CPUArchId *slot, DeviceState *dev, Error **errp)
  448. {
  449. int node_id = object_property_get_int(OBJECT(dev), "node-id", &error_abort);
  450. if (node_id == CPU_UNSET_NUMA_NODE_ID) {
  451. /* due to bug in libvirt, it doesn't pass node-id from props on
  452. * device_add as expected, so we have to fix it up here */
  453. if (slot->props.has_node_id) {
  454. object_property_set_int(OBJECT(dev), slot->props.node_id,
  455. "node-id", errp);
  456. }
  457. } else if (node_id != slot->props.node_id) {
  458. error_setg(errp, "node-id=%d must match numa node specified "
  459. "with -numa option", node_id);
  460. }
  461. }
  462. static void allocate_system_memory_nonnuma(MemoryRegion *mr, Object *owner,
  463. const char *name,
  464. uint64_t ram_size)
  465. {
  466. if (mem_path) {
  467. #ifdef __linux__
  468. Error *err = NULL;
  469. memory_region_init_ram_from_file(mr, owner, name, ram_size, false,
  470. mem_path, &err);
  471. if (err) {
  472. error_report_err(err);
  473. if (mem_prealloc) {
  474. exit(1);
  475. }
  476. /* Legacy behavior: if allocation failed, fall back to
  477. * regular RAM allocation.
  478. */
  479. memory_region_init_ram(mr, owner, name, ram_size, &error_fatal);
  480. }
  481. #else
  482. fprintf(stderr, "-mem-path not supported on this host\n");
  483. exit(1);
  484. #endif
  485. } else {
  486. memory_region_init_ram(mr, owner, name, ram_size, &error_fatal);
  487. }
  488. vmstate_register_ram_global(mr);
  489. }
  490. void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
  491. const char *name,
  492. uint64_t ram_size)
  493. {
  494. uint64_t addr = 0;
  495. int i;
  496. if (nb_numa_nodes == 0 || !have_memdevs) {
  497. allocate_system_memory_nonnuma(mr, owner, name, ram_size);
  498. return;
  499. }
  500. memory_region_init(mr, owner, name, ram_size);
  501. for (i = 0; i < MAX_NODES; i++) {
  502. uint64_t size = numa_info[i].node_mem;
  503. HostMemoryBackend *backend = numa_info[i].node_memdev;
  504. if (!backend) {
  505. continue;
  506. }
  507. MemoryRegion *seg = host_memory_backend_get_memory(backend,
  508. &error_fatal);
  509. if (memory_region_is_mapped(seg)) {
  510. char *path = object_get_canonical_path_component(OBJECT(backend));
  511. error_report("memory backend %s is used multiple times. Each "
  512. "-numa option must use a different memdev value.",
  513. path);
  514. exit(1);
  515. }
  516. host_memory_backend_set_mapped(backend, true);
  517. memory_region_add_subregion(mr, addr, seg);
  518. vmstate_register_ram_global(seg);
  519. addr += size;
  520. }
  521. }
  522. static void numa_stat_memory_devices(uint64_t node_mem[])
  523. {
  524. MemoryDeviceInfoList *info_list = NULL;
  525. MemoryDeviceInfoList **prev = &info_list;
  526. MemoryDeviceInfoList *info;
  527. qmp_pc_dimm_device_list(qdev_get_machine(), &prev);
  528. for (info = info_list; info; info = info->next) {
  529. MemoryDeviceInfo *value = info->value;
  530. if (value) {
  531. switch (value->type) {
  532. case MEMORY_DEVICE_INFO_KIND_DIMM:
  533. node_mem[value->u.dimm.data->node] += value->u.dimm.data->size;
  534. break;
  535. default:
  536. break;
  537. }
  538. }
  539. }
  540. qapi_free_MemoryDeviceInfoList(info_list);
  541. }
  542. void query_numa_node_mem(uint64_t node_mem[])
  543. {
  544. int i;
  545. if (nb_numa_nodes <= 0) {
  546. return;
  547. }
  548. numa_stat_memory_devices(node_mem);
  549. for (i = 0; i < nb_numa_nodes; i++) {
  550. node_mem[i] += numa_info[i].node_mem;
  551. }
  552. }
  553. static int query_memdev(Object *obj, void *opaque)
  554. {
  555. MemdevList **list = opaque;
  556. MemdevList *m = NULL;
  557. if (object_dynamic_cast(obj, TYPE_MEMORY_BACKEND)) {
  558. m = g_malloc0(sizeof(*m));
  559. m->value = g_malloc0(sizeof(*m->value));
  560. m->value->id = object_property_get_str(obj, "id", NULL);
  561. m->value->has_id = !!m->value->id;
  562. m->value->size = object_property_get_int(obj, "size",
  563. &error_abort);
  564. m->value->merge = object_property_get_bool(obj, "merge",
  565. &error_abort);
  566. m->value->dump = object_property_get_bool(obj, "dump",
  567. &error_abort);
  568. m->value->prealloc = object_property_get_bool(obj,
  569. "prealloc",
  570. &error_abort);
  571. m->value->policy = object_property_get_enum(obj,
  572. "policy",
  573. "HostMemPolicy",
  574. &error_abort);
  575. object_property_get_uint16List(obj, "host-nodes",
  576. &m->value->host_nodes,
  577. &error_abort);
  578. m->next = *list;
  579. *list = m;
  580. }
  581. return 0;
  582. }
  583. MemdevList *qmp_query_memdev(Error **errp)
  584. {
  585. Object *obj = object_get_objects_root();
  586. MemdevList *list = NULL;
  587. object_child_foreach(obj, query_memdev, &list);
  588. return list;
  589. }
  590. void ram_block_notifier_add(RAMBlockNotifier *n)
  591. {
  592. QLIST_INSERT_HEAD(&ram_list.ramblock_notifiers, n, next);
  593. }
  594. void ram_block_notifier_remove(RAMBlockNotifier *n)
  595. {
  596. QLIST_REMOVE(n, next);
  597. }
  598. void ram_block_notify_add(void *host, size_t size)
  599. {
  600. RAMBlockNotifier *notifier;
  601. QLIST_FOREACH(notifier, &ram_list.ramblock_notifiers, next) {
  602. notifier->ram_block_added(notifier, host, size);
  603. }
  604. }
  605. void ram_block_notify_remove(void *host, size_t size)
  606. {
  607. RAMBlockNotifier *notifier;
  608. QLIST_FOREACH(notifier, &ram_list.ramblock_notifiers, next) {
  609. notifier->ram_block_removed(notifier, host, size);
  610. }
  611. }