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