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