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