xref: /qemu/hw/core/machine.c (revision 6402cbbb)
1 /*
2  * QEMU Machine
3  *
4  * Copyright (C) 2014 Red Hat Inc
5  *
6  * Authors:
7  *   Marcel Apfelbaum <marcel.a@redhat.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2 or later.
10  * See the COPYING file in the top-level directory.
11  */
12 
13 #include "qemu/osdep.h"
14 #include "hw/boards.h"
15 #include "qapi/error.h"
16 #include "qapi-visit.h"
17 #include "qapi/visitor.h"
18 #include "hw/sysbus.h"
19 #include "sysemu/sysemu.h"
20 #include "sysemu/numa.h"
21 #include "qemu/error-report.h"
22 #include "qemu/cutils.h"
23 #include "sysemu/numa.h"
24 #include "sysemu/qtest.h"
25 
26 static char *machine_get_accel(Object *obj, Error **errp)
27 {
28     MachineState *ms = MACHINE(obj);
29 
30     return g_strdup(ms->accel);
31 }
32 
33 static void machine_set_accel(Object *obj, const char *value, Error **errp)
34 {
35     MachineState *ms = MACHINE(obj);
36 
37     g_free(ms->accel);
38     ms->accel = g_strdup(value);
39 }
40 
41 static void machine_set_kernel_irqchip(Object *obj, Visitor *v,
42                                        const char *name, void *opaque,
43                                        Error **errp)
44 {
45     Error *err = NULL;
46     MachineState *ms = MACHINE(obj);
47     OnOffSplit mode;
48 
49     visit_type_OnOffSplit(v, name, &mode, &err);
50     if (err) {
51         error_propagate(errp, err);
52         return;
53     } else {
54         switch (mode) {
55         case ON_OFF_SPLIT_ON:
56             ms->kernel_irqchip_allowed = true;
57             ms->kernel_irqchip_required = true;
58             ms->kernel_irqchip_split = false;
59             break;
60         case ON_OFF_SPLIT_OFF:
61             ms->kernel_irqchip_allowed = false;
62             ms->kernel_irqchip_required = false;
63             ms->kernel_irqchip_split = false;
64             break;
65         case ON_OFF_SPLIT_SPLIT:
66             ms->kernel_irqchip_allowed = true;
67             ms->kernel_irqchip_required = true;
68             ms->kernel_irqchip_split = true;
69             break;
70         default:
71             /* The value was checked in visit_type_OnOffSplit() above. If
72              * we get here, then something is wrong in QEMU.
73              */
74             abort();
75         }
76     }
77 }
78 
79 static void machine_get_kvm_shadow_mem(Object *obj, Visitor *v,
80                                        const char *name, void *opaque,
81                                        Error **errp)
82 {
83     MachineState *ms = MACHINE(obj);
84     int64_t value = ms->kvm_shadow_mem;
85 
86     visit_type_int(v, name, &value, errp);
87 }
88 
89 static void machine_set_kvm_shadow_mem(Object *obj, Visitor *v,
90                                        const char *name, void *opaque,
91                                        Error **errp)
92 {
93     MachineState *ms = MACHINE(obj);
94     Error *error = NULL;
95     int64_t value;
96 
97     visit_type_int(v, name, &value, &error);
98     if (error) {
99         error_propagate(errp, error);
100         return;
101     }
102 
103     ms->kvm_shadow_mem = value;
104 }
105 
106 static char *machine_get_kernel(Object *obj, Error **errp)
107 {
108     MachineState *ms = MACHINE(obj);
109 
110     return g_strdup(ms->kernel_filename);
111 }
112 
113 static void machine_set_kernel(Object *obj, const char *value, Error **errp)
114 {
115     MachineState *ms = MACHINE(obj);
116 
117     g_free(ms->kernel_filename);
118     ms->kernel_filename = g_strdup(value);
119 }
120 
121 static char *machine_get_initrd(Object *obj, Error **errp)
122 {
123     MachineState *ms = MACHINE(obj);
124 
125     return g_strdup(ms->initrd_filename);
126 }
127 
128 static void machine_set_initrd(Object *obj, const char *value, Error **errp)
129 {
130     MachineState *ms = MACHINE(obj);
131 
132     g_free(ms->initrd_filename);
133     ms->initrd_filename = g_strdup(value);
134 }
135 
136 static char *machine_get_append(Object *obj, Error **errp)
137 {
138     MachineState *ms = MACHINE(obj);
139 
140     return g_strdup(ms->kernel_cmdline);
141 }
142 
143 static void machine_set_append(Object *obj, const char *value, Error **errp)
144 {
145     MachineState *ms = MACHINE(obj);
146 
147     g_free(ms->kernel_cmdline);
148     ms->kernel_cmdline = g_strdup(value);
149 }
150 
151 static char *machine_get_dtb(Object *obj, Error **errp)
152 {
153     MachineState *ms = MACHINE(obj);
154 
155     return g_strdup(ms->dtb);
156 }
157 
158 static void machine_set_dtb(Object *obj, const char *value, Error **errp)
159 {
160     MachineState *ms = MACHINE(obj);
161 
162     g_free(ms->dtb);
163     ms->dtb = g_strdup(value);
164 }
165 
166 static char *machine_get_dumpdtb(Object *obj, Error **errp)
167 {
168     MachineState *ms = MACHINE(obj);
169 
170     return g_strdup(ms->dumpdtb);
171 }
172 
173 static void machine_set_dumpdtb(Object *obj, const char *value, Error **errp)
174 {
175     MachineState *ms = MACHINE(obj);
176 
177     g_free(ms->dumpdtb);
178     ms->dumpdtb = g_strdup(value);
179 }
180 
181 static void machine_get_phandle_start(Object *obj, Visitor *v,
182                                       const char *name, void *opaque,
183                                       Error **errp)
184 {
185     MachineState *ms = MACHINE(obj);
186     int64_t value = ms->phandle_start;
187 
188     visit_type_int(v, name, &value, errp);
189 }
190 
191 static void machine_set_phandle_start(Object *obj, Visitor *v,
192                                       const char *name, void *opaque,
193                                       Error **errp)
194 {
195     MachineState *ms = MACHINE(obj);
196     Error *error = NULL;
197     int64_t value;
198 
199     visit_type_int(v, name, &value, &error);
200     if (error) {
201         error_propagate(errp, error);
202         return;
203     }
204 
205     ms->phandle_start = value;
206 }
207 
208 static char *machine_get_dt_compatible(Object *obj, Error **errp)
209 {
210     MachineState *ms = MACHINE(obj);
211 
212     return g_strdup(ms->dt_compatible);
213 }
214 
215 static void machine_set_dt_compatible(Object *obj, const char *value, Error **errp)
216 {
217     MachineState *ms = MACHINE(obj);
218 
219     g_free(ms->dt_compatible);
220     ms->dt_compatible = g_strdup(value);
221 }
222 
223 static bool machine_get_dump_guest_core(Object *obj, Error **errp)
224 {
225     MachineState *ms = MACHINE(obj);
226 
227     return ms->dump_guest_core;
228 }
229 
230 static void machine_set_dump_guest_core(Object *obj, bool value, Error **errp)
231 {
232     MachineState *ms = MACHINE(obj);
233 
234     ms->dump_guest_core = value;
235 }
236 
237 static bool machine_get_mem_merge(Object *obj, Error **errp)
238 {
239     MachineState *ms = MACHINE(obj);
240 
241     return ms->mem_merge;
242 }
243 
244 static void machine_set_mem_merge(Object *obj, bool value, Error **errp)
245 {
246     MachineState *ms = MACHINE(obj);
247 
248     ms->mem_merge = value;
249 }
250 
251 static bool machine_get_usb(Object *obj, Error **errp)
252 {
253     MachineState *ms = MACHINE(obj);
254 
255     return ms->usb;
256 }
257 
258 static void machine_set_usb(Object *obj, bool value, Error **errp)
259 {
260     MachineState *ms = MACHINE(obj);
261 
262     ms->usb = value;
263     ms->usb_disabled = !value;
264 }
265 
266 static bool machine_get_graphics(Object *obj, Error **errp)
267 {
268     MachineState *ms = MACHINE(obj);
269 
270     return ms->enable_graphics;
271 }
272 
273 static void machine_set_graphics(Object *obj, bool value, Error **errp)
274 {
275     MachineState *ms = MACHINE(obj);
276 
277     ms->enable_graphics = value;
278 }
279 
280 static bool machine_get_igd_gfx_passthru(Object *obj, Error **errp)
281 {
282     MachineState *ms = MACHINE(obj);
283 
284     return ms->igd_gfx_passthru;
285 }
286 
287 static void machine_set_igd_gfx_passthru(Object *obj, bool value, Error **errp)
288 {
289     MachineState *ms = MACHINE(obj);
290 
291     ms->igd_gfx_passthru = value;
292 }
293 
294 static char *machine_get_firmware(Object *obj, Error **errp)
295 {
296     MachineState *ms = MACHINE(obj);
297 
298     return g_strdup(ms->firmware);
299 }
300 
301 static void machine_set_firmware(Object *obj, const char *value, Error **errp)
302 {
303     MachineState *ms = MACHINE(obj);
304 
305     g_free(ms->firmware);
306     ms->firmware = g_strdup(value);
307 }
308 
309 static void machine_set_suppress_vmdesc(Object *obj, bool value, Error **errp)
310 {
311     MachineState *ms = MACHINE(obj);
312 
313     ms->suppress_vmdesc = value;
314 }
315 
316 static bool machine_get_suppress_vmdesc(Object *obj, Error **errp)
317 {
318     MachineState *ms = MACHINE(obj);
319 
320     return ms->suppress_vmdesc;
321 }
322 
323 static void machine_set_enforce_config_section(Object *obj, bool value,
324                                              Error **errp)
325 {
326     MachineState *ms = MACHINE(obj);
327 
328     ms->enforce_config_section = value;
329 }
330 
331 static bool machine_get_enforce_config_section(Object *obj, Error **errp)
332 {
333     MachineState *ms = MACHINE(obj);
334 
335     return ms->enforce_config_section;
336 }
337 
338 static void error_on_sysbus_device(SysBusDevice *sbdev, void *opaque)
339 {
340     error_report("Option '-device %s' cannot be handled by this machine",
341                  object_class_get_name(object_get_class(OBJECT(sbdev))));
342     exit(1);
343 }
344 
345 static void machine_init_notify(Notifier *notifier, void *data)
346 {
347     Object *machine = qdev_get_machine();
348     ObjectClass *oc = object_get_class(machine);
349     MachineClass *mc = MACHINE_CLASS(oc);
350 
351     if (mc->has_dynamic_sysbus) {
352         /* Our machine can handle dynamic sysbus devices, we're all good */
353         return;
354     }
355 
356     /*
357      * Loop through all dynamically created devices and check whether there
358      * are sysbus devices among them. If there are, error out.
359      */
360     foreach_dynamic_sysbus_device(error_on_sysbus_device, NULL);
361 }
362 
363 HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine)
364 {
365     int i;
366     Object *cpu;
367     HotpluggableCPUList *head = NULL;
368     const char *cpu_type;
369 
370     cpu = machine->possible_cpus->cpus[0].cpu;
371     assert(cpu); /* Boot cpu is always present */
372     cpu_type = object_get_typename(cpu);
373     for (i = 0; i < machine->possible_cpus->len; i++) {
374         HotpluggableCPUList *list_item = g_new0(typeof(*list_item), 1);
375         HotpluggableCPU *cpu_item = g_new0(typeof(*cpu_item), 1);
376 
377         cpu_item->type = g_strdup(cpu_type);
378         cpu_item->vcpus_count = machine->possible_cpus->cpus[i].vcpus_count;
379         cpu_item->props = g_memdup(&machine->possible_cpus->cpus[i].props,
380                                    sizeof(*cpu_item->props));
381 
382         cpu = machine->possible_cpus->cpus[i].cpu;
383         if (cpu) {
384             cpu_item->has_qom_path = true;
385             cpu_item->qom_path = object_get_canonical_path(cpu);
386         }
387         list_item->value = cpu_item;
388         list_item->next = head;
389         head = list_item;
390     }
391     return head;
392 }
393 
394 /**
395  * machine_set_cpu_numa_node:
396  * @machine: machine object to modify
397  * @props: specifies which cpu objects to assign to
398  *         numa node specified by @props.node_id
399  * @errp: if an error occurs, a pointer to an area to store the error
400  *
401  * Associate NUMA node specified by @props.node_id with cpu slots that
402  * match socket/core/thread-ids specified by @props. It's recommended to use
403  * query-hotpluggable-cpus.props values to specify affected cpu slots,
404  * which would lead to exact 1:1 mapping of cpu slots to NUMA node.
405  *
406  * However for CLI convenience it's possible to pass in subset of properties,
407  * which would affect all cpu slots that match it.
408  * Ex for pc machine:
409  *    -smp 4,cores=2,sockets=2 -numa node,nodeid=0 -numa node,nodeid=1 \
410  *    -numa cpu,node-id=0,socket_id=0 \
411  *    -numa cpu,node-id=1,socket_id=1
412  * will assign all child cores of socket 0 to node 0 and
413  * of socket 1 to node 1.
414  *
415  * On attempt of reassigning (already assigned) cpu slot to another NUMA node,
416  * return error.
417  * Empty subset is disallowed and function will return with error in this case.
418  */
419 void machine_set_cpu_numa_node(MachineState *machine,
420                                const CpuInstanceProperties *props, Error **errp)
421 {
422     MachineClass *mc = MACHINE_GET_CLASS(machine);
423     bool match = false;
424     int i;
425 
426     if (!mc->possible_cpu_arch_ids) {
427         error_setg(errp, "mapping of CPUs to NUMA node is not supported");
428         return;
429     }
430 
431     /* disabling node mapping is not supported, forbid it */
432     assert(props->has_node_id);
433 
434     /* force board to initialize possible_cpus if it hasn't been done yet */
435     mc->possible_cpu_arch_ids(machine);
436 
437     for (i = 0; i < machine->possible_cpus->len; i++) {
438         CPUArchId *slot = &machine->possible_cpus->cpus[i];
439 
440         /* reject unsupported by board properties */
441         if (props->has_thread_id && !slot->props.has_thread_id) {
442             error_setg(errp, "thread-id is not supported");
443             return;
444         }
445 
446         if (props->has_core_id && !slot->props.has_core_id) {
447             error_setg(errp, "core-id is not supported");
448             return;
449         }
450 
451         if (props->has_socket_id && !slot->props.has_socket_id) {
452             error_setg(errp, "socket-id is not supported");
453             return;
454         }
455 
456         /* skip slots with explicit mismatch */
457         if (props->has_thread_id && props->thread_id != slot->props.thread_id) {
458                 continue;
459         }
460 
461         if (props->has_core_id && props->core_id != slot->props.core_id) {
462                 continue;
463         }
464 
465         if (props->has_socket_id && props->socket_id != slot->props.socket_id) {
466                 continue;
467         }
468 
469         /* reject assignment if slot is already assigned, for compatibility
470          * of legacy cpu_index mapping with SPAPR core based mapping do not
471          * error out if cpu thread and matched core have the same node-id */
472         if (slot->props.has_node_id &&
473             slot->props.node_id != props->node_id) {
474             error_setg(errp, "CPU is already assigned to node-id: %" PRId64,
475                        slot->props.node_id);
476             return;
477         }
478 
479         /* assign slot to node as it's matched '-numa cpu' key */
480         match = true;
481         slot->props.node_id = props->node_id;
482         slot->props.has_node_id = props->has_node_id;
483     }
484 
485     if (!match) {
486         error_setg(errp, "no match found");
487     }
488 }
489 
490 static void machine_class_init(ObjectClass *oc, void *data)
491 {
492     MachineClass *mc = MACHINE_CLASS(oc);
493 
494     /* Default 128 MB as guest ram size */
495     mc->default_ram_size = 128 * M_BYTE;
496     mc->rom_file_has_mr = true;
497 
498     /* numa node memory size aligned on 8MB by default.
499      * On Linux, each node's border has to be 8MB aligned
500      */
501     mc->numa_mem_align_shift = 23;
502     mc->numa_auto_assign_ram = numa_default_auto_assign_ram;
503 
504     object_class_property_add_str(oc, "accel",
505         machine_get_accel, machine_set_accel, &error_abort);
506     object_class_property_set_description(oc, "accel",
507         "Accelerator list", &error_abort);
508 
509     object_class_property_add(oc, "kernel-irqchip", "OnOffSplit",
510         NULL, machine_set_kernel_irqchip,
511         NULL, NULL, &error_abort);
512     object_class_property_set_description(oc, "kernel-irqchip",
513         "Configure KVM in-kernel irqchip", &error_abort);
514 
515     object_class_property_add(oc, "kvm-shadow-mem", "int",
516         machine_get_kvm_shadow_mem, machine_set_kvm_shadow_mem,
517         NULL, NULL, &error_abort);
518     object_class_property_set_description(oc, "kvm-shadow-mem",
519         "KVM shadow MMU size", &error_abort);
520 
521     object_class_property_add_str(oc, "kernel",
522         machine_get_kernel, machine_set_kernel, &error_abort);
523     object_class_property_set_description(oc, "kernel",
524         "Linux kernel image file", &error_abort);
525 
526     object_class_property_add_str(oc, "initrd",
527         machine_get_initrd, machine_set_initrd, &error_abort);
528     object_class_property_set_description(oc, "initrd",
529         "Linux initial ramdisk file", &error_abort);
530 
531     object_class_property_add_str(oc, "append",
532         machine_get_append, machine_set_append, &error_abort);
533     object_class_property_set_description(oc, "append",
534         "Linux kernel command line", &error_abort);
535 
536     object_class_property_add_str(oc, "dtb",
537         machine_get_dtb, machine_set_dtb, &error_abort);
538     object_class_property_set_description(oc, "dtb",
539         "Linux kernel device tree file", &error_abort);
540 
541     object_class_property_add_str(oc, "dumpdtb",
542         machine_get_dumpdtb, machine_set_dumpdtb, &error_abort);
543     object_class_property_set_description(oc, "dumpdtb",
544         "Dump current dtb to a file and quit", &error_abort);
545 
546     object_class_property_add(oc, "phandle-start", "int",
547         machine_get_phandle_start, machine_set_phandle_start,
548         NULL, NULL, &error_abort);
549     object_class_property_set_description(oc, "phandle-start",
550             "The first phandle ID we may generate dynamically", &error_abort);
551 
552     object_class_property_add_str(oc, "dt-compatible",
553         machine_get_dt_compatible, machine_set_dt_compatible, &error_abort);
554     object_class_property_set_description(oc, "dt-compatible",
555         "Overrides the \"compatible\" property of the dt root node",
556         &error_abort);
557 
558     object_class_property_add_bool(oc, "dump-guest-core",
559         machine_get_dump_guest_core, machine_set_dump_guest_core, &error_abort);
560     object_class_property_set_description(oc, "dump-guest-core",
561         "Include guest memory in  a core dump", &error_abort);
562 
563     object_class_property_add_bool(oc, "mem-merge",
564         machine_get_mem_merge, machine_set_mem_merge, &error_abort);
565     object_class_property_set_description(oc, "mem-merge",
566         "Enable/disable memory merge support", &error_abort);
567 
568     object_class_property_add_bool(oc, "usb",
569         machine_get_usb, machine_set_usb, &error_abort);
570     object_class_property_set_description(oc, "usb",
571         "Set on/off to enable/disable usb", &error_abort);
572 
573     object_class_property_add_bool(oc, "graphics",
574         machine_get_graphics, machine_set_graphics, &error_abort);
575     object_class_property_set_description(oc, "graphics",
576         "Set on/off to enable/disable graphics emulation", &error_abort);
577 
578     object_class_property_add_bool(oc, "igd-passthru",
579         machine_get_igd_gfx_passthru, machine_set_igd_gfx_passthru,
580         &error_abort);
581     object_class_property_set_description(oc, "igd-passthru",
582         "Set on/off to enable/disable igd passthrou", &error_abort);
583 
584     object_class_property_add_str(oc, "firmware",
585         machine_get_firmware, machine_set_firmware,
586         &error_abort);
587     object_class_property_set_description(oc, "firmware",
588         "Firmware image", &error_abort);
589 
590     object_class_property_add_bool(oc, "suppress-vmdesc",
591         machine_get_suppress_vmdesc, machine_set_suppress_vmdesc,
592         &error_abort);
593     object_class_property_set_description(oc, "suppress-vmdesc",
594         "Set on to disable self-describing migration", &error_abort);
595 
596     object_class_property_add_bool(oc, "enforce-config-section",
597         machine_get_enforce_config_section, machine_set_enforce_config_section,
598         &error_abort);
599     object_class_property_set_description(oc, "enforce-config-section",
600         "Set on to enforce configuration section migration", &error_abort);
601 }
602 
603 static void machine_class_base_init(ObjectClass *oc, void *data)
604 {
605     if (!object_class_is_abstract(oc)) {
606         MachineClass *mc = MACHINE_CLASS(oc);
607         const char *cname = object_class_get_name(oc);
608         assert(g_str_has_suffix(cname, TYPE_MACHINE_SUFFIX));
609         mc->name = g_strndup(cname,
610                             strlen(cname) - strlen(TYPE_MACHINE_SUFFIX));
611     }
612 }
613 
614 static void machine_initfn(Object *obj)
615 {
616     MachineState *ms = MACHINE(obj);
617 
618     ms->kernel_irqchip_allowed = true;
619     ms->kvm_shadow_mem = -1;
620     ms->dump_guest_core = true;
621     ms->mem_merge = true;
622     ms->enable_graphics = true;
623 
624     /* Register notifier when init is done for sysbus sanity checks */
625     ms->sysbus_notifier.notify = machine_init_notify;
626     qemu_add_machine_init_done_notifier(&ms->sysbus_notifier);
627 }
628 
629 static void machine_finalize(Object *obj)
630 {
631     MachineState *ms = MACHINE(obj);
632 
633     g_free(ms->accel);
634     g_free(ms->kernel_filename);
635     g_free(ms->initrd_filename);
636     g_free(ms->kernel_cmdline);
637     g_free(ms->dtb);
638     g_free(ms->dumpdtb);
639     g_free(ms->dt_compatible);
640     g_free(ms->firmware);
641 }
642 
643 bool machine_usb(MachineState *machine)
644 {
645     return machine->usb;
646 }
647 
648 bool machine_kernel_irqchip_allowed(MachineState *machine)
649 {
650     return machine->kernel_irqchip_allowed;
651 }
652 
653 bool machine_kernel_irqchip_required(MachineState *machine)
654 {
655     return machine->kernel_irqchip_required;
656 }
657 
658 bool machine_kernel_irqchip_split(MachineState *machine)
659 {
660     return machine->kernel_irqchip_split;
661 }
662 
663 int machine_kvm_shadow_mem(MachineState *machine)
664 {
665     return machine->kvm_shadow_mem;
666 }
667 
668 int machine_phandle_start(MachineState *machine)
669 {
670     return machine->phandle_start;
671 }
672 
673 bool machine_dump_guest_core(MachineState *machine)
674 {
675     return machine->dump_guest_core;
676 }
677 
678 bool machine_mem_merge(MachineState *machine)
679 {
680     return machine->mem_merge;
681 }
682 
683 static char *cpu_slot_to_string(const CPUArchId *cpu)
684 {
685     GString *s = g_string_new(NULL);
686     if (cpu->props.has_socket_id) {
687         g_string_append_printf(s, "socket-id: %"PRId64, cpu->props.socket_id);
688     }
689     if (cpu->props.has_core_id) {
690         if (s->len) {
691             g_string_append_printf(s, ", ");
692         }
693         g_string_append_printf(s, "core-id: %"PRId64, cpu->props.core_id);
694     }
695     if (cpu->props.has_thread_id) {
696         if (s->len) {
697             g_string_append_printf(s, ", ");
698         }
699         g_string_append_printf(s, "thread-id: %"PRId64, cpu->props.thread_id);
700     }
701     return g_string_free(s, false);
702 }
703 
704 static void machine_numa_finish_init(MachineState *machine)
705 {
706     int i;
707     bool default_mapping;
708     GString *s = g_string_new(NULL);
709     MachineClass *mc = MACHINE_GET_CLASS(machine);
710     const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(machine);
711 
712     assert(nb_numa_nodes);
713     for (i = 0; i < possible_cpus->len; i++) {
714         if (possible_cpus->cpus[i].props.has_node_id) {
715             break;
716         }
717     }
718     default_mapping = (i == possible_cpus->len);
719 
720     for (i = 0; i < possible_cpus->len; i++) {
721         const CPUArchId *cpu_slot = &possible_cpus->cpus[i];
722 
723         if (!cpu_slot->props.has_node_id) {
724             /* fetch default mapping from board and enable it */
725             CpuInstanceProperties props = cpu_slot->props;
726 
727             if (!default_mapping) {
728                 /* record slots with not set mapping,
729                  * TODO: make it hard error in future */
730                 char *cpu_str = cpu_slot_to_string(cpu_slot);
731                 g_string_append_printf(s, "%sCPU %d [%s]",
732                                        s->len ? ", " : "", i, cpu_str);
733                 g_free(cpu_str);
734 
735                 /* non mapped cpus used to fallback to node 0 */
736                 props.node_id = 0;
737             }
738 
739             props.has_node_id = true;
740             machine_set_cpu_numa_node(machine, &props, &error_fatal);
741         }
742     }
743     if (s->len && !qtest_enabled()) {
744         warn_report("CPU(s) not present in any NUMA nodes: %s",
745                     s->str);
746         warn_report("All CPU(s) up to maxcpus should be described "
747                     "in NUMA config, ability to start up with partial NUMA "
748                     "mappings is obsoleted and will be removed in future");
749     }
750     g_string_free(s, true);
751 }
752 
753 void machine_run_board_init(MachineState *machine)
754 {
755     MachineClass *machine_class = MACHINE_GET_CLASS(machine);
756 
757     if (nb_numa_nodes) {
758         machine_numa_finish_init(machine);
759     }
760     machine_class->init(machine);
761 }
762 
763 static void machine_class_finalize(ObjectClass *klass, void *data)
764 {
765     MachineClass *mc = MACHINE_CLASS(klass);
766 
767     if (mc->compat_props) {
768         g_array_free(mc->compat_props, true);
769     }
770     g_free(mc->name);
771 }
772 
773 void machine_register_compat_props(MachineState *machine)
774 {
775     MachineClass *mc = MACHINE_GET_CLASS(machine);
776     int i;
777     GlobalProperty *p;
778 
779     if (!mc->compat_props) {
780         return;
781     }
782 
783     for (i = 0; i < mc->compat_props->len; i++) {
784         p = g_array_index(mc->compat_props, GlobalProperty *, i);
785         /* Machine compat_props must never cause errors: */
786         p->errp = &error_abort;
787         qdev_prop_register_global(p);
788     }
789 }
790 
791 static const TypeInfo machine_info = {
792     .name = TYPE_MACHINE,
793     .parent = TYPE_OBJECT,
794     .abstract = true,
795     .class_size = sizeof(MachineClass),
796     .class_init    = machine_class_init,
797     .class_base_init = machine_class_base_init,
798     .class_finalize = machine_class_finalize,
799     .instance_size = sizeof(MachineState),
800     .instance_init = machine_initfn,
801     .instance_finalize = machine_finalize,
802 };
803 
804 static void machine_register_types(void)
805 {
806     type_register_static(&machine_info);
807 }
808 
809 type_init(machine_register_types)
810