xref: /qemu/hw/core/machine.c (revision dc293f60)
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 "qemu/option.h"
15 #include "qapi/qmp/qerror.h"
16 #include "sysemu/replay.h"
17 #include "qemu/units.h"
18 #include "hw/boards.h"
19 #include "hw/loader.h"
20 #include "qapi/error.h"
21 #include "qapi/qapi-visit-common.h"
22 #include "qapi/visitor.h"
23 #include "hw/sysbus.h"
24 #include "sysemu/cpus.h"
25 #include "sysemu/sysemu.h"
26 #include "sysemu/reset.h"
27 #include "sysemu/runstate.h"
28 #include "sysemu/numa.h"
29 #include "qemu/error-report.h"
30 #include "sysemu/qtest.h"
31 #include "hw/pci/pci.h"
32 #include "hw/mem/nvdimm.h"
33 #include "migration/global_state.h"
34 #include "migration/vmstate.h"
35 #include "exec/confidential-guest-support.h"
36 #include "hw/virtio/virtio.h"
37 #include "hw/virtio/virtio-pci.h"
38 
39 GlobalProperty hw_compat_5_2[] = {
40     { "ICH9-LPC", "smm-compat", "on"},
41     { "PIIX4_PM", "smm-compat", "on"},
42     { "virtio-blk-device", "report-discard-granularity", "off" },
43     { "virtio-net-pci", "vectors", "3"},
44 };
45 const size_t hw_compat_5_2_len = G_N_ELEMENTS(hw_compat_5_2);
46 
47 GlobalProperty hw_compat_5_1[] = {
48     { "vhost-scsi", "num_queues", "1"},
49     { "vhost-user-blk", "num-queues", "1"},
50     { "vhost-user-scsi", "num_queues", "1"},
51     { "virtio-blk-device", "num-queues", "1"},
52     { "virtio-scsi-device", "num_queues", "1"},
53     { "nvme", "use-intel-id", "on"},
54     { "pvpanic", "events", "1"}, /* PVPANIC_PANICKED */
55 };
56 const size_t hw_compat_5_1_len = G_N_ELEMENTS(hw_compat_5_1);
57 
58 GlobalProperty hw_compat_5_0[] = {
59     { "pci-host-bridge", "x-config-reg-migration-enabled", "off" },
60     { "virtio-balloon-device", "page-poison", "false" },
61     { "vmport", "x-read-set-eax", "off" },
62     { "vmport", "x-signal-unsupported-cmd", "off" },
63     { "vmport", "x-report-vmx-type", "off" },
64     { "vmport", "x-cmds-v2", "off" },
65     { "virtio-device", "x-disable-legacy-check", "true" },
66 };
67 const size_t hw_compat_5_0_len = G_N_ELEMENTS(hw_compat_5_0);
68 
69 GlobalProperty hw_compat_4_2[] = {
70     { "virtio-blk-device", "queue-size", "128"},
71     { "virtio-scsi-device", "virtqueue_size", "128"},
72     { "virtio-blk-device", "x-enable-wce-if-config-wce", "off" },
73     { "virtio-blk-device", "seg-max-adjust", "off"},
74     { "virtio-scsi-device", "seg_max_adjust", "off"},
75     { "vhost-blk-device", "seg_max_adjust", "off"},
76     { "usb-host", "suppress-remote-wake", "off" },
77     { "usb-redir", "suppress-remote-wake", "off" },
78     { "qxl", "revision", "4" },
79     { "qxl-vga", "revision", "4" },
80     { "fw_cfg", "acpi-mr-restore", "false" },
81     { "virtio-device", "use-disabled-flag", "false" },
82 };
83 const size_t hw_compat_4_2_len = G_N_ELEMENTS(hw_compat_4_2);
84 
85 GlobalProperty hw_compat_4_1[] = {
86     { "virtio-pci", "x-pcie-flr-init", "off" },
87 };
88 const size_t hw_compat_4_1_len = G_N_ELEMENTS(hw_compat_4_1);
89 
90 GlobalProperty hw_compat_4_0[] = {
91     { "VGA",            "edid", "false" },
92     { "secondary-vga",  "edid", "false" },
93     { "bochs-display",  "edid", "false" },
94     { "virtio-vga",     "edid", "false" },
95     { "virtio-gpu-device", "edid", "false" },
96     { "virtio-device", "use-started", "false" },
97     { "virtio-balloon-device", "qemu-4-0-config-size", "true" },
98     { "pl031", "migrate-tick-offset", "false" },
99 };
100 const size_t hw_compat_4_0_len = G_N_ELEMENTS(hw_compat_4_0);
101 
102 GlobalProperty hw_compat_3_1[] = {
103     { "pcie-root-port", "x-speed", "2_5" },
104     { "pcie-root-port", "x-width", "1" },
105     { "memory-backend-file", "x-use-canonical-path-for-ramblock-id", "true" },
106     { "memory-backend-memfd", "x-use-canonical-path-for-ramblock-id", "true" },
107     { "tpm-crb", "ppi", "false" },
108     { "tpm-tis", "ppi", "false" },
109     { "usb-kbd", "serial", "42" },
110     { "usb-mouse", "serial", "42" },
111     { "usb-tablet", "serial", "42" },
112     { "virtio-blk-device", "discard", "false" },
113     { "virtio-blk-device", "write-zeroes", "false" },
114     { "virtio-balloon-device", "qemu-4-0-config-size", "false" },
115     { "pcie-root-port-base", "disable-acs", "true" }, /* Added in 4.1 */
116 };
117 const size_t hw_compat_3_1_len = G_N_ELEMENTS(hw_compat_3_1);
118 
119 GlobalProperty hw_compat_3_0[] = {};
120 const size_t hw_compat_3_0_len = G_N_ELEMENTS(hw_compat_3_0);
121 
122 GlobalProperty hw_compat_2_12[] = {
123     { "migration", "decompress-error-check", "off" },
124     { "hda-audio", "use-timer", "false" },
125     { "cirrus-vga", "global-vmstate", "true" },
126     { "VGA", "global-vmstate", "true" },
127     { "vmware-svga", "global-vmstate", "true" },
128     { "qxl-vga", "global-vmstate", "true" },
129 };
130 const size_t hw_compat_2_12_len = G_N_ELEMENTS(hw_compat_2_12);
131 
132 GlobalProperty hw_compat_2_11[] = {
133     { "hpet", "hpet-offset-saved", "false" },
134     { "virtio-blk-pci", "vectors", "2" },
135     { "vhost-user-blk-pci", "vectors", "2" },
136     { "e1000", "migrate_tso_props", "off" },
137 };
138 const size_t hw_compat_2_11_len = G_N_ELEMENTS(hw_compat_2_11);
139 
140 GlobalProperty hw_compat_2_10[] = {
141     { "virtio-mouse-device", "wheel-axis", "false" },
142     { "virtio-tablet-device", "wheel-axis", "false" },
143 };
144 const size_t hw_compat_2_10_len = G_N_ELEMENTS(hw_compat_2_10);
145 
146 GlobalProperty hw_compat_2_9[] = {
147     { "pci-bridge", "shpc", "off" },
148     { "intel-iommu", "pt", "off" },
149     { "virtio-net-device", "x-mtu-bypass-backend", "off" },
150     { "pcie-root-port", "x-migrate-msix", "false" },
151 };
152 const size_t hw_compat_2_9_len = G_N_ELEMENTS(hw_compat_2_9);
153 
154 GlobalProperty hw_compat_2_8[] = {
155     { "fw_cfg_mem", "x-file-slots", "0x10" },
156     { "fw_cfg_io", "x-file-slots", "0x10" },
157     { "pflash_cfi01", "old-multiple-chip-handling", "on" },
158     { "pci-bridge", "shpc", "on" },
159     { TYPE_PCI_DEVICE, "x-pcie-extcap-init", "off" },
160     { "virtio-pci", "x-pcie-deverr-init", "off" },
161     { "virtio-pci", "x-pcie-lnkctl-init", "off" },
162     { "virtio-pci", "x-pcie-pm-init", "off" },
163     { "cirrus-vga", "vgamem_mb", "8" },
164     { "isa-cirrus-vga", "vgamem_mb", "8" },
165 };
166 const size_t hw_compat_2_8_len = G_N_ELEMENTS(hw_compat_2_8);
167 
168 GlobalProperty hw_compat_2_7[] = {
169     { "virtio-pci", "page-per-vq", "on" },
170     { "virtio-serial-device", "emergency-write", "off" },
171     { "ioapic", "version", "0x11" },
172     { "intel-iommu", "x-buggy-eim", "true" },
173     { "virtio-pci", "x-ignore-backend-features", "on" },
174 };
175 const size_t hw_compat_2_7_len = G_N_ELEMENTS(hw_compat_2_7);
176 
177 GlobalProperty hw_compat_2_6[] = {
178     { "virtio-mmio", "format_transport_address", "off" },
179     /* Optional because not all virtio-pci devices support legacy mode */
180     { "virtio-pci", "disable-modern", "on",  .optional = true },
181     { "virtio-pci", "disable-legacy", "off", .optional = true },
182 };
183 const size_t hw_compat_2_6_len = G_N_ELEMENTS(hw_compat_2_6);
184 
185 GlobalProperty hw_compat_2_5[] = {
186     { "isa-fdc", "fallback", "144" },
187     { "pvscsi", "x-old-pci-configuration", "on" },
188     { "pvscsi", "x-disable-pcie", "on" },
189     { "vmxnet3", "x-old-msi-offsets", "on" },
190     { "vmxnet3", "x-disable-pcie", "on" },
191 };
192 const size_t hw_compat_2_5_len = G_N_ELEMENTS(hw_compat_2_5);
193 
194 GlobalProperty hw_compat_2_4[] = {
195     /* Optional because the 'scsi' property is Linux-only */
196     { "virtio-blk-device", "scsi", "true", .optional = true },
197     { "e1000", "extra_mac_registers", "off" },
198     { "virtio-pci", "x-disable-pcie", "on" },
199     { "virtio-pci", "migrate-extra", "off" },
200     { "fw_cfg_mem", "dma_enabled", "off" },
201     { "fw_cfg_io", "dma_enabled", "off" }
202 };
203 const size_t hw_compat_2_4_len = G_N_ELEMENTS(hw_compat_2_4);
204 
205 GlobalProperty hw_compat_2_3[] = {
206     { "virtio-blk-pci", "any_layout", "off" },
207     { "virtio-balloon-pci", "any_layout", "off" },
208     { "virtio-serial-pci", "any_layout", "off" },
209     { "virtio-9p-pci", "any_layout", "off" },
210     { "virtio-rng-pci", "any_layout", "off" },
211     { TYPE_PCI_DEVICE, "x-pcie-lnksta-dllla", "off" },
212     { "migration", "send-configuration", "off" },
213     { "migration", "send-section-footer", "off" },
214     { "migration", "store-global-state", "off" },
215 };
216 const size_t hw_compat_2_3_len = G_N_ELEMENTS(hw_compat_2_3);
217 
218 GlobalProperty hw_compat_2_2[] = {};
219 const size_t hw_compat_2_2_len = G_N_ELEMENTS(hw_compat_2_2);
220 
221 GlobalProperty hw_compat_2_1[] = {
222     { "intel-hda", "old_msi_addr", "on" },
223     { "VGA", "qemu-extended-regs", "off" },
224     { "secondary-vga", "qemu-extended-regs", "off" },
225     { "virtio-scsi-pci", "any_layout", "off" },
226     { "usb-mouse", "usb_version", "1" },
227     { "usb-kbd", "usb_version", "1" },
228     { "virtio-pci", "virtio-pci-bus-master-bug-migration", "on" },
229 };
230 const size_t hw_compat_2_1_len = G_N_ELEMENTS(hw_compat_2_1);
231 
232 MachineState *current_machine;
233 
234 static char *machine_get_kernel(Object *obj, Error **errp)
235 {
236     MachineState *ms = MACHINE(obj);
237 
238     return g_strdup(ms->kernel_filename);
239 }
240 
241 static void machine_set_kernel(Object *obj, const char *value, Error **errp)
242 {
243     MachineState *ms = MACHINE(obj);
244 
245     g_free(ms->kernel_filename);
246     ms->kernel_filename = g_strdup(value);
247 }
248 
249 static char *machine_get_initrd(Object *obj, Error **errp)
250 {
251     MachineState *ms = MACHINE(obj);
252 
253     return g_strdup(ms->initrd_filename);
254 }
255 
256 static void machine_set_initrd(Object *obj, const char *value, Error **errp)
257 {
258     MachineState *ms = MACHINE(obj);
259 
260     g_free(ms->initrd_filename);
261     ms->initrd_filename = g_strdup(value);
262 }
263 
264 static char *machine_get_append(Object *obj, Error **errp)
265 {
266     MachineState *ms = MACHINE(obj);
267 
268     return g_strdup(ms->kernel_cmdline);
269 }
270 
271 static void machine_set_append(Object *obj, const char *value, Error **errp)
272 {
273     MachineState *ms = MACHINE(obj);
274 
275     g_free(ms->kernel_cmdline);
276     ms->kernel_cmdline = g_strdup(value);
277 }
278 
279 static char *machine_get_dtb(Object *obj, Error **errp)
280 {
281     MachineState *ms = MACHINE(obj);
282 
283     return g_strdup(ms->dtb);
284 }
285 
286 static void machine_set_dtb(Object *obj, const char *value, Error **errp)
287 {
288     MachineState *ms = MACHINE(obj);
289 
290     g_free(ms->dtb);
291     ms->dtb = g_strdup(value);
292 }
293 
294 static char *machine_get_dumpdtb(Object *obj, Error **errp)
295 {
296     MachineState *ms = MACHINE(obj);
297 
298     return g_strdup(ms->dumpdtb);
299 }
300 
301 static void machine_set_dumpdtb(Object *obj, const char *value, Error **errp)
302 {
303     MachineState *ms = MACHINE(obj);
304 
305     g_free(ms->dumpdtb);
306     ms->dumpdtb = g_strdup(value);
307 }
308 
309 static void machine_get_phandle_start(Object *obj, Visitor *v,
310                                       const char *name, void *opaque,
311                                       Error **errp)
312 {
313     MachineState *ms = MACHINE(obj);
314     int64_t value = ms->phandle_start;
315 
316     visit_type_int(v, name, &value, errp);
317 }
318 
319 static void machine_set_phandle_start(Object *obj, Visitor *v,
320                                       const char *name, void *opaque,
321                                       Error **errp)
322 {
323     MachineState *ms = MACHINE(obj);
324     int64_t value;
325 
326     if (!visit_type_int(v, name, &value, errp)) {
327         return;
328     }
329 
330     ms->phandle_start = value;
331 }
332 
333 static char *machine_get_dt_compatible(Object *obj, Error **errp)
334 {
335     MachineState *ms = MACHINE(obj);
336 
337     return g_strdup(ms->dt_compatible);
338 }
339 
340 static void machine_set_dt_compatible(Object *obj, const char *value, Error **errp)
341 {
342     MachineState *ms = MACHINE(obj);
343 
344     g_free(ms->dt_compatible);
345     ms->dt_compatible = g_strdup(value);
346 }
347 
348 static bool machine_get_dump_guest_core(Object *obj, Error **errp)
349 {
350     MachineState *ms = MACHINE(obj);
351 
352     return ms->dump_guest_core;
353 }
354 
355 static void machine_set_dump_guest_core(Object *obj, bool value, Error **errp)
356 {
357     MachineState *ms = MACHINE(obj);
358 
359     ms->dump_guest_core = value;
360 }
361 
362 static bool machine_get_mem_merge(Object *obj, Error **errp)
363 {
364     MachineState *ms = MACHINE(obj);
365 
366     return ms->mem_merge;
367 }
368 
369 static void machine_set_mem_merge(Object *obj, bool value, Error **errp)
370 {
371     MachineState *ms = MACHINE(obj);
372 
373     ms->mem_merge = value;
374 }
375 
376 static bool machine_get_usb(Object *obj, Error **errp)
377 {
378     MachineState *ms = MACHINE(obj);
379 
380     return ms->usb;
381 }
382 
383 static void machine_set_usb(Object *obj, bool value, Error **errp)
384 {
385     MachineState *ms = MACHINE(obj);
386 
387     ms->usb = value;
388     ms->usb_disabled = !value;
389 }
390 
391 static bool machine_get_graphics(Object *obj, Error **errp)
392 {
393     MachineState *ms = MACHINE(obj);
394 
395     return ms->enable_graphics;
396 }
397 
398 static void machine_set_graphics(Object *obj, bool value, Error **errp)
399 {
400     MachineState *ms = MACHINE(obj);
401 
402     ms->enable_graphics = value;
403 }
404 
405 static char *machine_get_firmware(Object *obj, Error **errp)
406 {
407     MachineState *ms = MACHINE(obj);
408 
409     return g_strdup(ms->firmware);
410 }
411 
412 static void machine_set_firmware(Object *obj, const char *value, Error **errp)
413 {
414     MachineState *ms = MACHINE(obj);
415 
416     g_free(ms->firmware);
417     ms->firmware = g_strdup(value);
418 }
419 
420 static void machine_set_suppress_vmdesc(Object *obj, bool value, Error **errp)
421 {
422     MachineState *ms = MACHINE(obj);
423 
424     ms->suppress_vmdesc = value;
425 }
426 
427 static bool machine_get_suppress_vmdesc(Object *obj, Error **errp)
428 {
429     MachineState *ms = MACHINE(obj);
430 
431     return ms->suppress_vmdesc;
432 }
433 
434 static char *machine_get_memory_encryption(Object *obj, Error **errp)
435 {
436     MachineState *ms = MACHINE(obj);
437 
438     if (ms->cgs) {
439         return g_strdup(object_get_canonical_path_component(OBJECT(ms->cgs)));
440     }
441 
442     return NULL;
443 }
444 
445 static void machine_set_memory_encryption(Object *obj, const char *value,
446                                         Error **errp)
447 {
448     Object *cgs =
449         object_resolve_path_component(object_get_objects_root(), value);
450 
451     if (!cgs) {
452         error_setg(errp, "No such memory encryption object '%s'", value);
453         return;
454     }
455 
456     object_property_set_link(obj, "confidential-guest-support", cgs, errp);
457 }
458 
459 static void machine_check_confidential_guest_support(const Object *obj,
460                                                      const char *name,
461                                                      Object *new_target,
462                                                      Error **errp)
463 {
464     /*
465      * So far the only constraint is that the target has the
466      * TYPE_CONFIDENTIAL_GUEST_SUPPORT interface, and that's checked
467      * by the QOM core
468      */
469 }
470 
471 static bool machine_get_nvdimm(Object *obj, Error **errp)
472 {
473     MachineState *ms = MACHINE(obj);
474 
475     return ms->nvdimms_state->is_enabled;
476 }
477 
478 static void machine_set_nvdimm(Object *obj, bool value, Error **errp)
479 {
480     MachineState *ms = MACHINE(obj);
481 
482     ms->nvdimms_state->is_enabled = value;
483 }
484 
485 static bool machine_get_hmat(Object *obj, Error **errp)
486 {
487     MachineState *ms = MACHINE(obj);
488 
489     return ms->numa_state->hmat_enabled;
490 }
491 
492 static void machine_set_hmat(Object *obj, bool value, Error **errp)
493 {
494     MachineState *ms = MACHINE(obj);
495 
496     ms->numa_state->hmat_enabled = value;
497 }
498 
499 static char *machine_get_nvdimm_persistence(Object *obj, Error **errp)
500 {
501     MachineState *ms = MACHINE(obj);
502 
503     return g_strdup(ms->nvdimms_state->persistence_string);
504 }
505 
506 static void machine_set_nvdimm_persistence(Object *obj, const char *value,
507                                            Error **errp)
508 {
509     MachineState *ms = MACHINE(obj);
510     NVDIMMState *nvdimms_state = ms->nvdimms_state;
511 
512     if (strcmp(value, "cpu") == 0) {
513         nvdimms_state->persistence = 3;
514     } else if (strcmp(value, "mem-ctrl") == 0) {
515         nvdimms_state->persistence = 2;
516     } else {
517         error_setg(errp, "-machine nvdimm-persistence=%s: unsupported option",
518                    value);
519         return;
520     }
521 
522     g_free(nvdimms_state->persistence_string);
523     nvdimms_state->persistence_string = g_strdup(value);
524 }
525 
526 void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type)
527 {
528     QAPI_LIST_PREPEND(mc->allowed_dynamic_sysbus_devices, g_strdup(type));
529 }
530 
531 static void validate_sysbus_device(SysBusDevice *sbdev, void *opaque)
532 {
533     MachineState *machine = opaque;
534     MachineClass *mc = MACHINE_GET_CLASS(machine);
535     bool allowed = false;
536     strList *wl;
537 
538     for (wl = mc->allowed_dynamic_sysbus_devices;
539          !allowed && wl;
540          wl = wl->next) {
541         allowed |= !!object_dynamic_cast(OBJECT(sbdev), wl->value);
542     }
543 
544     if (!allowed) {
545         error_report("Option '-device %s' cannot be handled by this machine",
546                      object_class_get_name(object_get_class(OBJECT(sbdev))));
547         exit(1);
548     }
549 }
550 
551 static char *machine_get_memdev(Object *obj, Error **errp)
552 {
553     MachineState *ms = MACHINE(obj);
554 
555     return g_strdup(ms->ram_memdev_id);
556 }
557 
558 static void machine_set_memdev(Object *obj, const char *value, Error **errp)
559 {
560     MachineState *ms = MACHINE(obj);
561 
562     g_free(ms->ram_memdev_id);
563     ms->ram_memdev_id = g_strdup(value);
564 }
565 
566 
567 static void machine_init_notify(Notifier *notifier, void *data)
568 {
569     MachineState *machine = MACHINE(qdev_get_machine());
570 
571     /*
572      * Loop through all dynamically created sysbus devices and check if they are
573      * all allowed.  If a device is not allowed, error out.
574      */
575     foreach_dynamic_sysbus_device(validate_sysbus_device, machine);
576 }
577 
578 HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine)
579 {
580     int i;
581     HotpluggableCPUList *head = NULL;
582     MachineClass *mc = MACHINE_GET_CLASS(machine);
583 
584     /* force board to initialize possible_cpus if it hasn't been done yet */
585     mc->possible_cpu_arch_ids(machine);
586 
587     for (i = 0; i < machine->possible_cpus->len; i++) {
588         Object *cpu;
589         HotpluggableCPU *cpu_item = g_new0(typeof(*cpu_item), 1);
590 
591         cpu_item->type = g_strdup(machine->possible_cpus->cpus[i].type);
592         cpu_item->vcpus_count = machine->possible_cpus->cpus[i].vcpus_count;
593         cpu_item->props = g_memdup(&machine->possible_cpus->cpus[i].props,
594                                    sizeof(*cpu_item->props));
595 
596         cpu = machine->possible_cpus->cpus[i].cpu;
597         if (cpu) {
598             cpu_item->has_qom_path = true;
599             cpu_item->qom_path = object_get_canonical_path(cpu);
600         }
601         QAPI_LIST_PREPEND(head, cpu_item);
602     }
603     return head;
604 }
605 
606 /**
607  * machine_set_cpu_numa_node:
608  * @machine: machine object to modify
609  * @props: specifies which cpu objects to assign to
610  *         numa node specified by @props.node_id
611  * @errp: if an error occurs, a pointer to an area to store the error
612  *
613  * Associate NUMA node specified by @props.node_id with cpu slots that
614  * match socket/core/thread-ids specified by @props. It's recommended to use
615  * query-hotpluggable-cpus.props values to specify affected cpu slots,
616  * which would lead to exact 1:1 mapping of cpu slots to NUMA node.
617  *
618  * However for CLI convenience it's possible to pass in subset of properties,
619  * which would affect all cpu slots that match it.
620  * Ex for pc machine:
621  *    -smp 4,cores=2,sockets=2 -numa node,nodeid=0 -numa node,nodeid=1 \
622  *    -numa cpu,node-id=0,socket_id=0 \
623  *    -numa cpu,node-id=1,socket_id=1
624  * will assign all child cores of socket 0 to node 0 and
625  * of socket 1 to node 1.
626  *
627  * On attempt of reassigning (already assigned) cpu slot to another NUMA node,
628  * return error.
629  * Empty subset is disallowed and function will return with error in this case.
630  */
631 void machine_set_cpu_numa_node(MachineState *machine,
632                                const CpuInstanceProperties *props, Error **errp)
633 {
634     MachineClass *mc = MACHINE_GET_CLASS(machine);
635     NodeInfo *numa_info = machine->numa_state->nodes;
636     bool match = false;
637     int i;
638 
639     if (!mc->possible_cpu_arch_ids) {
640         error_setg(errp, "mapping of CPUs to NUMA node is not supported");
641         return;
642     }
643 
644     /* disabling node mapping is not supported, forbid it */
645     assert(props->has_node_id);
646 
647     /* force board to initialize possible_cpus if it hasn't been done yet */
648     mc->possible_cpu_arch_ids(machine);
649 
650     for (i = 0; i < machine->possible_cpus->len; i++) {
651         CPUArchId *slot = &machine->possible_cpus->cpus[i];
652 
653         /* reject unsupported by board properties */
654         if (props->has_thread_id && !slot->props.has_thread_id) {
655             error_setg(errp, "thread-id is not supported");
656             return;
657         }
658 
659         if (props->has_core_id && !slot->props.has_core_id) {
660             error_setg(errp, "core-id is not supported");
661             return;
662         }
663 
664         if (props->has_socket_id && !slot->props.has_socket_id) {
665             error_setg(errp, "socket-id is not supported");
666             return;
667         }
668 
669         if (props->has_die_id && !slot->props.has_die_id) {
670             error_setg(errp, "die-id is not supported");
671             return;
672         }
673 
674         /* skip slots with explicit mismatch */
675         if (props->has_thread_id && props->thread_id != slot->props.thread_id) {
676                 continue;
677         }
678 
679         if (props->has_core_id && props->core_id != slot->props.core_id) {
680                 continue;
681         }
682 
683         if (props->has_die_id && props->die_id != slot->props.die_id) {
684                 continue;
685         }
686 
687         if (props->has_socket_id && props->socket_id != slot->props.socket_id) {
688                 continue;
689         }
690 
691         /* reject assignment if slot is already assigned, for compatibility
692          * of legacy cpu_index mapping with SPAPR core based mapping do not
693          * error out if cpu thread and matched core have the same node-id */
694         if (slot->props.has_node_id &&
695             slot->props.node_id != props->node_id) {
696             error_setg(errp, "CPU is already assigned to node-id: %" PRId64,
697                        slot->props.node_id);
698             return;
699         }
700 
701         /* assign slot to node as it's matched '-numa cpu' key */
702         match = true;
703         slot->props.node_id = props->node_id;
704         slot->props.has_node_id = props->has_node_id;
705 
706         if (machine->numa_state->hmat_enabled) {
707             if ((numa_info[props->node_id].initiator < MAX_NODES) &&
708                 (props->node_id != numa_info[props->node_id].initiator)) {
709                 error_setg(errp, "The initiator of CPU NUMA node %" PRId64
710                         " should be itself", props->node_id);
711                 return;
712             }
713             numa_info[props->node_id].has_cpu = true;
714             numa_info[props->node_id].initiator = props->node_id;
715         }
716     }
717 
718     if (!match) {
719         error_setg(errp, "no match found");
720     }
721 }
722 
723 static void smp_parse(MachineState *ms, QemuOpts *opts)
724 {
725     if (opts) {
726         unsigned cpus    = qemu_opt_get_number(opts, "cpus", 0);
727         unsigned sockets = qemu_opt_get_number(opts, "sockets", 0);
728         unsigned cores   = qemu_opt_get_number(opts, "cores", 0);
729         unsigned threads = qemu_opt_get_number(opts, "threads", 0);
730 
731         /* compute missing values, prefer sockets over cores over threads */
732         if (cpus == 0 || sockets == 0) {
733             cores = cores > 0 ? cores : 1;
734             threads = threads > 0 ? threads : 1;
735             if (cpus == 0) {
736                 sockets = sockets > 0 ? sockets : 1;
737                 cpus = cores * threads * sockets;
738             } else {
739                 ms->smp.max_cpus =
740                         qemu_opt_get_number(opts, "maxcpus", cpus);
741                 sockets = ms->smp.max_cpus / (cores * threads);
742             }
743         } else if (cores == 0) {
744             threads = threads > 0 ? threads : 1;
745             cores = cpus / (sockets * threads);
746             cores = cores > 0 ? cores : 1;
747         } else if (threads == 0) {
748             threads = cpus / (cores * sockets);
749             threads = threads > 0 ? threads : 1;
750         } else if (sockets * cores * threads < cpus) {
751             error_report("cpu topology: "
752                          "sockets (%u) * cores (%u) * threads (%u) < "
753                          "smp_cpus (%u)",
754                          sockets, cores, threads, cpus);
755             exit(1);
756         }
757 
758         ms->smp.max_cpus =
759                 qemu_opt_get_number(opts, "maxcpus", cpus);
760 
761         if (ms->smp.max_cpus < cpus) {
762             error_report("maxcpus must be equal to or greater than smp");
763             exit(1);
764         }
765 
766         if (sockets * cores * threads != ms->smp.max_cpus) {
767             error_report("Invalid CPU topology: "
768                          "sockets (%u) * cores (%u) * threads (%u) "
769                          "!= maxcpus (%u)",
770                          sockets, cores, threads,
771                          ms->smp.max_cpus);
772             exit(1);
773         }
774 
775         ms->smp.cpus = cpus;
776         ms->smp.cores = cores;
777         ms->smp.threads = threads;
778         ms->smp.sockets = sockets;
779     }
780 
781     if (ms->smp.cpus > 1) {
782         Error *blocker = NULL;
783         error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp");
784         replay_add_blocker(blocker);
785     }
786 }
787 
788 static void machine_class_init(ObjectClass *oc, void *data)
789 {
790     MachineClass *mc = MACHINE_CLASS(oc);
791 
792     /* Default 128 MB as guest ram size */
793     mc->default_ram_size = 128 * MiB;
794     mc->rom_file_has_mr = true;
795     mc->smp_parse = smp_parse;
796 
797     /* numa node memory size aligned on 8MB by default.
798      * On Linux, each node's border has to be 8MB aligned
799      */
800     mc->numa_mem_align_shift = 23;
801 
802     object_class_property_add_str(oc, "kernel",
803         machine_get_kernel, machine_set_kernel);
804     object_class_property_set_description(oc, "kernel",
805         "Linux kernel image file");
806 
807     object_class_property_add_str(oc, "initrd",
808         machine_get_initrd, machine_set_initrd);
809     object_class_property_set_description(oc, "initrd",
810         "Linux initial ramdisk file");
811 
812     object_class_property_add_str(oc, "append",
813         machine_get_append, machine_set_append);
814     object_class_property_set_description(oc, "append",
815         "Linux kernel command line");
816 
817     object_class_property_add_str(oc, "dtb",
818         machine_get_dtb, machine_set_dtb);
819     object_class_property_set_description(oc, "dtb",
820         "Linux kernel device tree file");
821 
822     object_class_property_add_str(oc, "dumpdtb",
823         machine_get_dumpdtb, machine_set_dumpdtb);
824     object_class_property_set_description(oc, "dumpdtb",
825         "Dump current dtb to a file and quit");
826 
827     object_class_property_add(oc, "phandle-start", "int",
828         machine_get_phandle_start, machine_set_phandle_start,
829         NULL, NULL);
830     object_class_property_set_description(oc, "phandle-start",
831         "The first phandle ID we may generate dynamically");
832 
833     object_class_property_add_str(oc, "dt-compatible",
834         machine_get_dt_compatible, machine_set_dt_compatible);
835     object_class_property_set_description(oc, "dt-compatible",
836         "Overrides the \"compatible\" property of the dt root node");
837 
838     object_class_property_add_bool(oc, "dump-guest-core",
839         machine_get_dump_guest_core, machine_set_dump_guest_core);
840     object_class_property_set_description(oc, "dump-guest-core",
841         "Include guest memory in a core dump");
842 
843     object_class_property_add_bool(oc, "mem-merge",
844         machine_get_mem_merge, machine_set_mem_merge);
845     object_class_property_set_description(oc, "mem-merge",
846         "Enable/disable memory merge support");
847 
848     object_class_property_add_bool(oc, "usb",
849         machine_get_usb, machine_set_usb);
850     object_class_property_set_description(oc, "usb",
851         "Set on/off to enable/disable usb");
852 
853     object_class_property_add_bool(oc, "graphics",
854         machine_get_graphics, machine_set_graphics);
855     object_class_property_set_description(oc, "graphics",
856         "Set on/off to enable/disable graphics emulation");
857 
858     object_class_property_add_str(oc, "firmware",
859         machine_get_firmware, machine_set_firmware);
860     object_class_property_set_description(oc, "firmware",
861         "Firmware image");
862 
863     object_class_property_add_bool(oc, "suppress-vmdesc",
864         machine_get_suppress_vmdesc, machine_set_suppress_vmdesc);
865     object_class_property_set_description(oc, "suppress-vmdesc",
866         "Set on to disable self-describing migration");
867 
868     object_class_property_add_link(oc, "confidential-guest-support",
869                                    TYPE_CONFIDENTIAL_GUEST_SUPPORT,
870                                    offsetof(MachineState, cgs),
871                                    machine_check_confidential_guest_support,
872                                    OBJ_PROP_LINK_STRONG);
873     object_class_property_set_description(oc, "confidential-guest-support",
874                                           "Set confidential guest scheme to support");
875 
876     /* For compatibility */
877     object_class_property_add_str(oc, "memory-encryption",
878         machine_get_memory_encryption, machine_set_memory_encryption);
879     object_class_property_set_description(oc, "memory-encryption",
880         "Set memory encryption object to use");
881 
882     object_class_property_add_str(oc, "memory-backend",
883                                   machine_get_memdev, machine_set_memdev);
884     object_class_property_set_description(oc, "memory-backend",
885                                           "Set RAM backend"
886                                           "Valid value is ID of hostmem based backend");
887 }
888 
889 static void machine_class_base_init(ObjectClass *oc, void *data)
890 {
891     MachineClass *mc = MACHINE_CLASS(oc);
892     mc->max_cpus = mc->max_cpus ?: 1;
893     mc->min_cpus = mc->min_cpus ?: 1;
894     mc->default_cpus = mc->default_cpus ?: 1;
895 
896     if (!object_class_is_abstract(oc)) {
897         const char *cname = object_class_get_name(oc);
898         assert(g_str_has_suffix(cname, TYPE_MACHINE_SUFFIX));
899         mc->name = g_strndup(cname,
900                             strlen(cname) - strlen(TYPE_MACHINE_SUFFIX));
901         mc->compat_props = g_ptr_array_new();
902     }
903 }
904 
905 static void machine_initfn(Object *obj)
906 {
907     MachineState *ms = MACHINE(obj);
908     MachineClass *mc = MACHINE_GET_CLASS(obj);
909 
910     container_get(obj, "/peripheral");
911     container_get(obj, "/peripheral-anon");
912 
913     ms->dump_guest_core = true;
914     ms->mem_merge = true;
915     ms->enable_graphics = true;
916     ms->kernel_cmdline = g_strdup("");
917 
918     if (mc->nvdimm_supported) {
919         Object *obj = OBJECT(ms);
920 
921         ms->nvdimms_state = g_new0(NVDIMMState, 1);
922         object_property_add_bool(obj, "nvdimm",
923                                  machine_get_nvdimm, machine_set_nvdimm);
924         object_property_set_description(obj, "nvdimm",
925                                         "Set on/off to enable/disable "
926                                         "NVDIMM instantiation");
927 
928         object_property_add_str(obj, "nvdimm-persistence",
929                                 machine_get_nvdimm_persistence,
930                                 machine_set_nvdimm_persistence);
931         object_property_set_description(obj, "nvdimm-persistence",
932                                         "Set NVDIMM persistence"
933                                         "Valid values are cpu, mem-ctrl");
934     }
935 
936     if (mc->cpu_index_to_instance_props && mc->get_default_cpu_node_id) {
937         ms->numa_state = g_new0(NumaState, 1);
938         object_property_add_bool(obj, "hmat",
939                                  machine_get_hmat, machine_set_hmat);
940         object_property_set_description(obj, "hmat",
941                                         "Set on/off to enable/disable "
942                                         "ACPI Heterogeneous Memory Attribute "
943                                         "Table (HMAT)");
944     }
945 
946     /* Register notifier when init is done for sysbus sanity checks */
947     ms->sysbus_notifier.notify = machine_init_notify;
948     qemu_add_machine_init_done_notifier(&ms->sysbus_notifier);
949 
950     /* default to mc->default_cpus */
951     ms->smp.cpus = mc->default_cpus;
952     ms->smp.max_cpus = mc->default_cpus;
953     ms->smp.cores = 1;
954     ms->smp.threads = 1;
955     ms->smp.sockets = 1;
956 }
957 
958 static void machine_finalize(Object *obj)
959 {
960     MachineState *ms = MACHINE(obj);
961 
962     g_free(ms->kernel_filename);
963     g_free(ms->initrd_filename);
964     g_free(ms->kernel_cmdline);
965     g_free(ms->dtb);
966     g_free(ms->dumpdtb);
967     g_free(ms->dt_compatible);
968     g_free(ms->firmware);
969     g_free(ms->device_memory);
970     g_free(ms->nvdimms_state);
971     g_free(ms->numa_state);
972 }
973 
974 bool machine_usb(MachineState *machine)
975 {
976     return machine->usb;
977 }
978 
979 int machine_phandle_start(MachineState *machine)
980 {
981     return machine->phandle_start;
982 }
983 
984 bool machine_dump_guest_core(MachineState *machine)
985 {
986     return machine->dump_guest_core;
987 }
988 
989 bool machine_mem_merge(MachineState *machine)
990 {
991     return machine->mem_merge;
992 }
993 
994 static char *cpu_slot_to_string(const CPUArchId *cpu)
995 {
996     GString *s = g_string_new(NULL);
997     if (cpu->props.has_socket_id) {
998         g_string_append_printf(s, "socket-id: %"PRId64, cpu->props.socket_id);
999     }
1000     if (cpu->props.has_die_id) {
1001         g_string_append_printf(s, "die-id: %"PRId64, cpu->props.die_id);
1002     }
1003     if (cpu->props.has_core_id) {
1004         if (s->len) {
1005             g_string_append_printf(s, ", ");
1006         }
1007         g_string_append_printf(s, "core-id: %"PRId64, cpu->props.core_id);
1008     }
1009     if (cpu->props.has_thread_id) {
1010         if (s->len) {
1011             g_string_append_printf(s, ", ");
1012         }
1013         g_string_append_printf(s, "thread-id: %"PRId64, cpu->props.thread_id);
1014     }
1015     return g_string_free(s, false);
1016 }
1017 
1018 static void numa_validate_initiator(NumaState *numa_state)
1019 {
1020     int i;
1021     NodeInfo *numa_info = numa_state->nodes;
1022 
1023     for (i = 0; i < numa_state->num_nodes; i++) {
1024         if (numa_info[i].initiator == MAX_NODES) {
1025             error_report("The initiator of NUMA node %d is missing, use "
1026                          "'-numa node,initiator' option to declare it", i);
1027             exit(1);
1028         }
1029 
1030         if (!numa_info[numa_info[i].initiator].present) {
1031             error_report("NUMA node %" PRIu16 " is missing, use "
1032                          "'-numa node' option to declare it first",
1033                          numa_info[i].initiator);
1034             exit(1);
1035         }
1036 
1037         if (!numa_info[numa_info[i].initiator].has_cpu) {
1038             error_report("The initiator of NUMA node %d is invalid", i);
1039             exit(1);
1040         }
1041     }
1042 }
1043 
1044 static void machine_numa_finish_cpu_init(MachineState *machine)
1045 {
1046     int i;
1047     bool default_mapping;
1048     GString *s = g_string_new(NULL);
1049     MachineClass *mc = MACHINE_GET_CLASS(machine);
1050     const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(machine);
1051 
1052     assert(machine->numa_state->num_nodes);
1053     for (i = 0; i < possible_cpus->len; i++) {
1054         if (possible_cpus->cpus[i].props.has_node_id) {
1055             break;
1056         }
1057     }
1058     default_mapping = (i == possible_cpus->len);
1059 
1060     for (i = 0; i < possible_cpus->len; i++) {
1061         const CPUArchId *cpu_slot = &possible_cpus->cpus[i];
1062 
1063         if (!cpu_slot->props.has_node_id) {
1064             /* fetch default mapping from board and enable it */
1065             CpuInstanceProperties props = cpu_slot->props;
1066 
1067             props.node_id = mc->get_default_cpu_node_id(machine, i);
1068             if (!default_mapping) {
1069                 /* record slots with not set mapping,
1070                  * TODO: make it hard error in future */
1071                 char *cpu_str = cpu_slot_to_string(cpu_slot);
1072                 g_string_append_printf(s, "%sCPU %d [%s]",
1073                                        s->len ? ", " : "", i, cpu_str);
1074                 g_free(cpu_str);
1075 
1076                 /* non mapped cpus used to fallback to node 0 */
1077                 props.node_id = 0;
1078             }
1079 
1080             props.has_node_id = true;
1081             machine_set_cpu_numa_node(machine, &props, &error_fatal);
1082         }
1083     }
1084 
1085     if (machine->numa_state->hmat_enabled) {
1086         numa_validate_initiator(machine->numa_state);
1087     }
1088 
1089     if (s->len && !qtest_enabled()) {
1090         warn_report("CPU(s) not present in any NUMA nodes: %s",
1091                     s->str);
1092         warn_report("All CPU(s) up to maxcpus should be described "
1093                     "in NUMA config, ability to start up with partial NUMA "
1094                     "mappings is obsoleted and will be removed in future");
1095     }
1096     g_string_free(s, true);
1097 }
1098 
1099 MemoryRegion *machine_consume_memdev(MachineState *machine,
1100                                      HostMemoryBackend *backend)
1101 {
1102     MemoryRegion *ret = host_memory_backend_get_memory(backend);
1103 
1104     if (memory_region_is_mapped(ret)) {
1105         error_report("memory backend %s can't be used multiple times.",
1106                      object_get_canonical_path_component(OBJECT(backend)));
1107         exit(EXIT_FAILURE);
1108     }
1109     host_memory_backend_set_mapped(backend, true);
1110     vmstate_register_ram_global(ret);
1111     return ret;
1112 }
1113 
1114 bool machine_smp_parse(MachineState *ms, QemuOpts *opts, Error **errp)
1115 {
1116     MachineClass *mc = MACHINE_GET_CLASS(ms);
1117 
1118     mc->smp_parse(ms, opts);
1119 
1120     /* sanity-check smp_cpus and max_cpus against mc */
1121     if (ms->smp.cpus < mc->min_cpus) {
1122         error_setg(errp, "Invalid SMP CPUs %d. The min CPUs "
1123                    "supported by machine '%s' is %d",
1124                    ms->smp.cpus,
1125                    mc->name, mc->min_cpus);
1126         return false;
1127     } else if (ms->smp.max_cpus > mc->max_cpus) {
1128         error_setg(errp, "Invalid SMP CPUs %d. The max CPUs "
1129                    "supported by machine '%s' is %d",
1130                    current_machine->smp.max_cpus,
1131                    mc->name, mc->max_cpus);
1132         return false;
1133     }
1134     return true;
1135 }
1136 
1137 void machine_run_board_init(MachineState *machine)
1138 {
1139     MachineClass *machine_class = MACHINE_GET_CLASS(machine);
1140     ObjectClass *oc = object_class_by_name(machine->cpu_type);
1141     CPUClass *cc;
1142 
1143     /* This checkpoint is required by replay to separate prior clock
1144        reading from the other reads, because timer polling functions query
1145        clock values from the log. */
1146     replay_checkpoint(CHECKPOINT_INIT);
1147 
1148     if (machine->ram_memdev_id) {
1149         Object *o;
1150         o = object_resolve_path_type(machine->ram_memdev_id,
1151                                      TYPE_MEMORY_BACKEND, NULL);
1152         machine->ram = machine_consume_memdev(machine, MEMORY_BACKEND(o));
1153     }
1154 
1155     if (machine->numa_state) {
1156         numa_complete_configuration(machine);
1157         if (machine->numa_state->num_nodes) {
1158             machine_numa_finish_cpu_init(machine);
1159         }
1160     }
1161 
1162     /* If the machine supports the valid_cpu_types check and the user
1163      * specified a CPU with -cpu check here that the user CPU is supported.
1164      */
1165     if (machine_class->valid_cpu_types && machine->cpu_type) {
1166         int i;
1167 
1168         for (i = 0; machine_class->valid_cpu_types[i]; i++) {
1169             if (object_class_dynamic_cast(oc,
1170                                           machine_class->valid_cpu_types[i])) {
1171                 /* The user specificed CPU is in the valid field, we are
1172                  * good to go.
1173                  */
1174                 break;
1175             }
1176         }
1177 
1178         if (!machine_class->valid_cpu_types[i]) {
1179             /* The user specified CPU is not valid */
1180             error_report("Invalid CPU type: %s", machine->cpu_type);
1181             error_printf("The valid types are: %s",
1182                          machine_class->valid_cpu_types[0]);
1183             for (i = 1; machine_class->valid_cpu_types[i]; i++) {
1184                 error_printf(", %s", machine_class->valid_cpu_types[i]);
1185             }
1186             error_printf("\n");
1187 
1188             exit(1);
1189         }
1190     }
1191 
1192     /* Check if CPU type is deprecated and warn if so */
1193     cc = CPU_CLASS(oc);
1194     if (cc && cc->deprecation_note) {
1195         warn_report("CPU model %s is deprecated -- %s", machine->cpu_type,
1196                     cc->deprecation_note);
1197     }
1198 
1199     if (machine->cgs) {
1200         /*
1201          * With confidential guests, the host can't see the real
1202          * contents of RAM, so there's no point in it trying to merge
1203          * areas.
1204          */
1205         machine_set_mem_merge(OBJECT(machine), false, &error_abort);
1206 
1207         /*
1208          * Virtio devices can't count on directly accessing guest
1209          * memory, so they need iommu_platform=on to use normal DMA
1210          * mechanisms.  That requires also disabling legacy virtio
1211          * support for those virtio pci devices which allow it.
1212          */
1213         object_register_sugar_prop(TYPE_VIRTIO_PCI, "disable-legacy",
1214                                    "on", true);
1215         object_register_sugar_prop(TYPE_VIRTIO_DEVICE, "iommu_platform",
1216                                    "on", false);
1217     }
1218 
1219     machine_class->init(machine);
1220     phase_advance(PHASE_MACHINE_INITIALIZED);
1221 }
1222 
1223 static NotifierList machine_init_done_notifiers =
1224     NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers);
1225 
1226 void qemu_add_machine_init_done_notifier(Notifier *notify)
1227 {
1228     notifier_list_add(&machine_init_done_notifiers, notify);
1229     if (phase_check(PHASE_MACHINE_READY)) {
1230         notify->notify(notify, NULL);
1231     }
1232 }
1233 
1234 void qemu_remove_machine_init_done_notifier(Notifier *notify)
1235 {
1236     notifier_remove(notify);
1237 }
1238 
1239 void qdev_machine_creation_done(void)
1240 {
1241     cpu_synchronize_all_post_init();
1242 
1243     if (current_machine->boot_once) {
1244         qemu_boot_set(current_machine->boot_once, &error_fatal);
1245         qemu_register_reset(restore_boot_order, g_strdup(current_machine->boot_order));
1246     }
1247 
1248     /*
1249      * ok, initial machine setup is done, starting from now we can
1250      * only create hotpluggable devices
1251      */
1252     phase_advance(PHASE_MACHINE_READY);
1253     qdev_assert_realized_properly();
1254 
1255     /* TODO: once all bus devices are qdevified, this should be done
1256      * when bus is created by qdev.c */
1257     /*
1258      * TODO: If we had a main 'reset container' that the whole system
1259      * lived in, we could reset that using the multi-phase reset
1260      * APIs. For the moment, we just reset the sysbus, which will cause
1261      * all devices hanging off it (and all their child buses, recursively)
1262      * to be reset. Note that this will *not* reset any Device objects
1263      * which are not attached to some part of the qbus tree!
1264      */
1265     qemu_register_reset(resettable_cold_reset_fn, sysbus_get_default());
1266 
1267     notifier_list_notify(&machine_init_done_notifiers, NULL);
1268 
1269     if (rom_check_and_register_reset() != 0) {
1270         exit(1);
1271     }
1272 
1273     replay_start();
1274 
1275     /* This checkpoint is required by replay to separate prior clock
1276        reading from the other reads, because timer polling functions query
1277        clock values from the log. */
1278     replay_checkpoint(CHECKPOINT_RESET);
1279     qemu_system_reset(SHUTDOWN_CAUSE_NONE);
1280     register_global_state();
1281 }
1282 
1283 static const TypeInfo machine_info = {
1284     .name = TYPE_MACHINE,
1285     .parent = TYPE_OBJECT,
1286     .abstract = true,
1287     .class_size = sizeof(MachineClass),
1288     .class_init    = machine_class_init,
1289     .class_base_init = machine_class_base_init,
1290     .instance_size = sizeof(MachineState),
1291     .instance_init = machine_initfn,
1292     .instance_finalize = machine_finalize,
1293 };
1294 
1295 static void machine_register_types(void)
1296 {
1297     type_register_static(&machine_info);
1298 }
1299 
1300 type_init(machine_register_types)
1301