4 * Copyright (C) 2014 Red Hat Inc
7 * Marcel Apfelbaum <marcel.a@redhat.com>
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.
13 #include "qemu/osdep.h"
14 #include "qemu/option.h"
15 #include "qemu/accel.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/qapi-visit-machine.h"
23 #include "qapi/visitor.h"
24 #include "qom/object_interfaces.h"
25 #include "hw/sysbus.h"
26 #include "sysemu/cpus.h"
27 #include "sysemu/sysemu.h"
28 #include "sysemu/reset.h"
29 #include "sysemu/runstate.h"
30 #include "sysemu/numa.h"
31 #include "sysemu/xen.h"
32 #include "qemu/error-report.h"
33 #include "sysemu/qtest.h"
34 #include "hw/pci/pci.h"
35 #include "hw/mem/nvdimm.h"
36 #include "migration/global_state.h"
37 #include "migration/vmstate.h"
38 #include "exec/confidential-guest-support.h"
39 #include "hw/virtio/virtio.h"
40 #include "hw/virtio/virtio-pci.h"
42 GlobalProperty hw_compat_7_2
[] = {
43 { "virtio-mem", "x-early-migration", "false" },
45 const size_t hw_compat_7_2_len
= G_N_ELEMENTS(hw_compat_7_2
);
47 GlobalProperty hw_compat_7_1
[] = {
48 { "virtio-device", "queue_reset", "false" },
49 { "virtio-rng-pci", "vectors", "0" },
51 const size_t hw_compat_7_1_len
= G_N_ELEMENTS(hw_compat_7_1
);
53 GlobalProperty hw_compat_7_0
[] = {
54 { "arm-gicv3-common", "force-8-bit-prio", "on" },
55 { "nvme-ns", "eui64-default", "on"},
57 const size_t hw_compat_7_0_len
= G_N_ELEMENTS(hw_compat_7_0
);
59 GlobalProperty hw_compat_6_2
[] = {
60 { "PIIX4_PM", "x-not-migrate-acpi-index", "on"},
62 const size_t hw_compat_6_2_len
= G_N_ELEMENTS(hw_compat_6_2
);
64 GlobalProperty hw_compat_6_1
[] = {
65 { "vhost-user-vsock-device", "seqpacket", "off" },
66 { "nvme-ns", "shared", "off" },
68 const size_t hw_compat_6_1_len
= G_N_ELEMENTS(hw_compat_6_1
);
70 GlobalProperty hw_compat_6_0
[] = {
71 { "gpex-pcihost", "allow-unmapped-accesses", "false" },
72 { "i8042", "extended-state", "false"},
73 { "nvme-ns", "eui64-default", "off"},
74 { "e1000", "init-vet", "off" },
75 { "e1000e", "init-vet", "off" },
76 { "vhost-vsock-device", "seqpacket", "off" },
78 const size_t hw_compat_6_0_len
= G_N_ELEMENTS(hw_compat_6_0
);
80 GlobalProperty hw_compat_5_2
[] = {
81 { "ICH9-LPC", "smm-compat", "on"},
82 { "PIIX4_PM", "smm-compat", "on"},
83 { "virtio-blk-device", "report-discard-granularity", "off" },
84 { "virtio-net-pci-base", "vectors", "3"},
86 const size_t hw_compat_5_2_len
= G_N_ELEMENTS(hw_compat_5_2
);
88 GlobalProperty hw_compat_5_1
[] = {
89 { "vhost-scsi", "num_queues", "1"},
90 { "vhost-user-blk", "num-queues", "1"},
91 { "vhost-user-scsi", "num_queues", "1"},
92 { "virtio-blk-device", "num-queues", "1"},
93 { "virtio-scsi-device", "num_queues", "1"},
94 { "nvme", "use-intel-id", "on"},
95 { "pvpanic", "events", "1"}, /* PVPANIC_PANICKED */
96 { "pl011", "migrate-clk", "off" },
97 { "virtio-pci", "x-ats-page-aligned", "off"},
99 const size_t hw_compat_5_1_len
= G_N_ELEMENTS(hw_compat_5_1
);
101 GlobalProperty hw_compat_5_0
[] = {
102 { "pci-host-bridge", "x-config-reg-migration-enabled", "off" },
103 { "virtio-balloon-device", "page-poison", "false" },
104 { "vmport", "x-read-set-eax", "off" },
105 { "vmport", "x-signal-unsupported-cmd", "off" },
106 { "vmport", "x-report-vmx-type", "off" },
107 { "vmport", "x-cmds-v2", "off" },
108 { "virtio-device", "x-disable-legacy-check", "true" },
110 const size_t hw_compat_5_0_len
= G_N_ELEMENTS(hw_compat_5_0
);
112 GlobalProperty hw_compat_4_2
[] = {
113 { "virtio-blk-device", "queue-size", "128"},
114 { "virtio-scsi-device", "virtqueue_size", "128"},
115 { "virtio-blk-device", "x-enable-wce-if-config-wce", "off" },
116 { "virtio-blk-device", "seg-max-adjust", "off"},
117 { "virtio-scsi-device", "seg_max_adjust", "off"},
118 { "vhost-blk-device", "seg_max_adjust", "off"},
119 { "usb-host", "suppress-remote-wake", "off" },
120 { "usb-redir", "suppress-remote-wake", "off" },
121 { "qxl", "revision", "4" },
122 { "qxl-vga", "revision", "4" },
123 { "fw_cfg", "acpi-mr-restore", "false" },
124 { "virtio-device", "use-disabled-flag", "false" },
126 const size_t hw_compat_4_2_len
= G_N_ELEMENTS(hw_compat_4_2
);
128 GlobalProperty hw_compat_4_1
[] = {
129 { "virtio-pci", "x-pcie-flr-init", "off" },
131 const size_t hw_compat_4_1_len
= G_N_ELEMENTS(hw_compat_4_1
);
133 GlobalProperty hw_compat_4_0
[] = {
134 { "VGA", "edid", "false" },
135 { "secondary-vga", "edid", "false" },
136 { "bochs-display", "edid", "false" },
137 { "virtio-vga", "edid", "false" },
138 { "virtio-gpu-device", "edid", "false" },
139 { "virtio-device", "use-started", "false" },
140 { "virtio-balloon-device", "qemu-4-0-config-size", "true" },
141 { "pl031", "migrate-tick-offset", "false" },
143 const size_t hw_compat_4_0_len
= G_N_ELEMENTS(hw_compat_4_0
);
145 GlobalProperty hw_compat_3_1
[] = {
146 { "pcie-root-port", "x-speed", "2_5" },
147 { "pcie-root-port", "x-width", "1" },
148 { "memory-backend-file", "x-use-canonical-path-for-ramblock-id", "true" },
149 { "memory-backend-memfd", "x-use-canonical-path-for-ramblock-id", "true" },
150 { "tpm-crb", "ppi", "false" },
151 { "tpm-tis", "ppi", "false" },
152 { "usb-kbd", "serial", "42" },
153 { "usb-mouse", "serial", "42" },
154 { "usb-tablet", "serial", "42" },
155 { "virtio-blk-device", "discard", "false" },
156 { "virtio-blk-device", "write-zeroes", "false" },
157 { "virtio-balloon-device", "qemu-4-0-config-size", "false" },
158 { "pcie-root-port-base", "disable-acs", "true" }, /* Added in 4.1 */
160 const size_t hw_compat_3_1_len
= G_N_ELEMENTS(hw_compat_3_1
);
162 GlobalProperty hw_compat_3_0
[] = {};
163 const size_t hw_compat_3_0_len
= G_N_ELEMENTS(hw_compat_3_0
);
165 GlobalProperty hw_compat_2_12
[] = {
166 { "migration", "decompress-error-check", "off" },
167 { "hda-audio", "use-timer", "false" },
168 { "cirrus-vga", "global-vmstate", "true" },
169 { "VGA", "global-vmstate", "true" },
170 { "vmware-svga", "global-vmstate", "true" },
171 { "qxl-vga", "global-vmstate", "true" },
173 const size_t hw_compat_2_12_len
= G_N_ELEMENTS(hw_compat_2_12
);
175 GlobalProperty hw_compat_2_11
[] = {
176 { "hpet", "hpet-offset-saved", "false" },
177 { "virtio-blk-pci", "vectors", "2" },
178 { "vhost-user-blk-pci", "vectors", "2" },
179 { "e1000", "migrate_tso_props", "off" },
181 const size_t hw_compat_2_11_len
= G_N_ELEMENTS(hw_compat_2_11
);
183 GlobalProperty hw_compat_2_10
[] = {
184 { "virtio-mouse-device", "wheel-axis", "false" },
185 { "virtio-tablet-device", "wheel-axis", "false" },
187 const size_t hw_compat_2_10_len
= G_N_ELEMENTS(hw_compat_2_10
);
189 GlobalProperty hw_compat_2_9
[] = {
190 { "pci-bridge", "shpc", "off" },
191 { "intel-iommu", "pt", "off" },
192 { "virtio-net-device", "x-mtu-bypass-backend", "off" },
193 { "pcie-root-port", "x-migrate-msix", "false" },
195 const size_t hw_compat_2_9_len
= G_N_ELEMENTS(hw_compat_2_9
);
197 GlobalProperty hw_compat_2_8
[] = {
198 { "fw_cfg_mem", "x-file-slots", "0x10" },
199 { "fw_cfg_io", "x-file-slots", "0x10" },
200 { "pflash_cfi01", "old-multiple-chip-handling", "on" },
201 { "pci-bridge", "shpc", "on" },
202 { TYPE_PCI_DEVICE
, "x-pcie-extcap-init", "off" },
203 { "virtio-pci", "x-pcie-deverr-init", "off" },
204 { "virtio-pci", "x-pcie-lnkctl-init", "off" },
205 { "virtio-pci", "x-pcie-pm-init", "off" },
206 { "cirrus-vga", "vgamem_mb", "8" },
207 { "isa-cirrus-vga", "vgamem_mb", "8" },
209 const size_t hw_compat_2_8_len
= G_N_ELEMENTS(hw_compat_2_8
);
211 GlobalProperty hw_compat_2_7
[] = {
212 { "virtio-pci", "page-per-vq", "on" },
213 { "virtio-serial-device", "emergency-write", "off" },
214 { "ioapic", "version", "0x11" },
215 { "intel-iommu", "x-buggy-eim", "true" },
216 { "virtio-pci", "x-ignore-backend-features", "on" },
218 const size_t hw_compat_2_7_len
= G_N_ELEMENTS(hw_compat_2_7
);
220 GlobalProperty hw_compat_2_6
[] = {
221 { "virtio-mmio", "format_transport_address", "off" },
222 /* Optional because not all virtio-pci devices support legacy mode */
223 { "virtio-pci", "disable-modern", "on", .optional
= true },
224 { "virtio-pci", "disable-legacy", "off", .optional
= true },
226 const size_t hw_compat_2_6_len
= G_N_ELEMENTS(hw_compat_2_6
);
228 GlobalProperty hw_compat_2_5
[] = {
229 { "isa-fdc", "fallback", "144" },
230 { "pvscsi", "x-old-pci-configuration", "on" },
231 { "pvscsi", "x-disable-pcie", "on" },
232 { "vmxnet3", "x-old-msi-offsets", "on" },
233 { "vmxnet3", "x-disable-pcie", "on" },
235 const size_t hw_compat_2_5_len
= G_N_ELEMENTS(hw_compat_2_5
);
237 GlobalProperty hw_compat_2_4
[] = {
238 /* Optional because the 'scsi' property is Linux-only */
239 { "virtio-blk-device", "scsi", "true", .optional
= true },
240 { "e1000", "extra_mac_registers", "off" },
241 { "virtio-pci", "x-disable-pcie", "on" },
242 { "virtio-pci", "migrate-extra", "off" },
243 { "fw_cfg_mem", "dma_enabled", "off" },
244 { "fw_cfg_io", "dma_enabled", "off" }
246 const size_t hw_compat_2_4_len
= G_N_ELEMENTS(hw_compat_2_4
);
248 GlobalProperty hw_compat_2_3
[] = {
249 { "virtio-blk-pci", "any_layout", "off" },
250 { "virtio-balloon-pci", "any_layout", "off" },
251 { "virtio-serial-pci", "any_layout", "off" },
252 { "virtio-9p-pci", "any_layout", "off" },
253 { "virtio-rng-pci", "any_layout", "off" },
254 { TYPE_PCI_DEVICE
, "x-pcie-lnksta-dllla", "off" },
255 { "migration", "send-configuration", "off" },
256 { "migration", "send-section-footer", "off" },
257 { "migration", "store-global-state", "off" },
259 const size_t hw_compat_2_3_len
= G_N_ELEMENTS(hw_compat_2_3
);
261 GlobalProperty hw_compat_2_2
[] = {};
262 const size_t hw_compat_2_2_len
= G_N_ELEMENTS(hw_compat_2_2
);
264 GlobalProperty hw_compat_2_1
[] = {
265 { "intel-hda", "old_msi_addr", "on" },
266 { "VGA", "qemu-extended-regs", "off" },
267 { "secondary-vga", "qemu-extended-regs", "off" },
268 { "virtio-scsi-pci", "any_layout", "off" },
269 { "usb-mouse", "usb_version", "1" },
270 { "usb-kbd", "usb_version", "1" },
271 { "virtio-pci", "virtio-pci-bus-master-bug-migration", "on" },
273 const size_t hw_compat_2_1_len
= G_N_ELEMENTS(hw_compat_2_1
);
275 MachineState
*current_machine
;
277 static char *machine_get_kernel(Object
*obj
, Error
**errp
)
279 MachineState
*ms
= MACHINE(obj
);
281 return g_strdup(ms
->kernel_filename
);
284 static void machine_set_kernel(Object
*obj
, const char *value
, Error
**errp
)
286 MachineState
*ms
= MACHINE(obj
);
288 g_free(ms
->kernel_filename
);
289 ms
->kernel_filename
= g_strdup(value
);
292 static char *machine_get_initrd(Object
*obj
, Error
**errp
)
294 MachineState
*ms
= MACHINE(obj
);
296 return g_strdup(ms
->initrd_filename
);
299 static void machine_set_initrd(Object
*obj
, const char *value
, Error
**errp
)
301 MachineState
*ms
= MACHINE(obj
);
303 g_free(ms
->initrd_filename
);
304 ms
->initrd_filename
= g_strdup(value
);
307 static char *machine_get_append(Object
*obj
, Error
**errp
)
309 MachineState
*ms
= MACHINE(obj
);
311 return g_strdup(ms
->kernel_cmdline
);
314 static void machine_set_append(Object
*obj
, const char *value
, Error
**errp
)
316 MachineState
*ms
= MACHINE(obj
);
318 g_free(ms
->kernel_cmdline
);
319 ms
->kernel_cmdline
= g_strdup(value
);
322 static char *machine_get_dtb(Object
*obj
, Error
**errp
)
324 MachineState
*ms
= MACHINE(obj
);
326 return g_strdup(ms
->dtb
);
329 static void machine_set_dtb(Object
*obj
, const char *value
, Error
**errp
)
331 MachineState
*ms
= MACHINE(obj
);
334 ms
->dtb
= g_strdup(value
);
337 static char *machine_get_dumpdtb(Object
*obj
, Error
**errp
)
339 MachineState
*ms
= MACHINE(obj
);
341 return g_strdup(ms
->dumpdtb
);
344 static void machine_set_dumpdtb(Object
*obj
, const char *value
, Error
**errp
)
346 MachineState
*ms
= MACHINE(obj
);
349 ms
->dumpdtb
= g_strdup(value
);
352 static void machine_get_phandle_start(Object
*obj
, Visitor
*v
,
353 const char *name
, void *opaque
,
356 MachineState
*ms
= MACHINE(obj
);
357 int64_t value
= ms
->phandle_start
;
359 visit_type_int(v
, name
, &value
, errp
);
362 static void machine_set_phandle_start(Object
*obj
, Visitor
*v
,
363 const char *name
, void *opaque
,
366 MachineState
*ms
= MACHINE(obj
);
369 if (!visit_type_int(v
, name
, &value
, errp
)) {
373 ms
->phandle_start
= value
;
376 static char *machine_get_dt_compatible(Object
*obj
, Error
**errp
)
378 MachineState
*ms
= MACHINE(obj
);
380 return g_strdup(ms
->dt_compatible
);
383 static void machine_set_dt_compatible(Object
*obj
, const char *value
, Error
**errp
)
385 MachineState
*ms
= MACHINE(obj
);
387 g_free(ms
->dt_compatible
);
388 ms
->dt_compatible
= g_strdup(value
);
391 static bool machine_get_dump_guest_core(Object
*obj
, Error
**errp
)
393 MachineState
*ms
= MACHINE(obj
);
395 return ms
->dump_guest_core
;
398 static void machine_set_dump_guest_core(Object
*obj
, bool value
, Error
**errp
)
400 MachineState
*ms
= MACHINE(obj
);
402 ms
->dump_guest_core
= value
;
405 static bool machine_get_mem_merge(Object
*obj
, Error
**errp
)
407 MachineState
*ms
= MACHINE(obj
);
409 return ms
->mem_merge
;
412 static void machine_set_mem_merge(Object
*obj
, bool value
, Error
**errp
)
414 MachineState
*ms
= MACHINE(obj
);
416 ms
->mem_merge
= value
;
419 static bool machine_get_usb(Object
*obj
, Error
**errp
)
421 MachineState
*ms
= MACHINE(obj
);
426 static void machine_set_usb(Object
*obj
, bool value
, Error
**errp
)
428 MachineState
*ms
= MACHINE(obj
);
431 ms
->usb_disabled
= !value
;
434 static bool machine_get_graphics(Object
*obj
, Error
**errp
)
436 MachineState
*ms
= MACHINE(obj
);
438 return ms
->enable_graphics
;
441 static void machine_set_graphics(Object
*obj
, bool value
, Error
**errp
)
443 MachineState
*ms
= MACHINE(obj
);
445 ms
->enable_graphics
= value
;
448 static char *machine_get_firmware(Object
*obj
, Error
**errp
)
450 MachineState
*ms
= MACHINE(obj
);
452 return g_strdup(ms
->firmware
);
455 static void machine_set_firmware(Object
*obj
, const char *value
, Error
**errp
)
457 MachineState
*ms
= MACHINE(obj
);
459 g_free(ms
->firmware
);
460 ms
->firmware
= g_strdup(value
);
463 static void machine_set_suppress_vmdesc(Object
*obj
, bool value
, Error
**errp
)
465 MachineState
*ms
= MACHINE(obj
);
467 ms
->suppress_vmdesc
= value
;
470 static bool machine_get_suppress_vmdesc(Object
*obj
, Error
**errp
)
472 MachineState
*ms
= MACHINE(obj
);
474 return ms
->suppress_vmdesc
;
477 static char *machine_get_memory_encryption(Object
*obj
, Error
**errp
)
479 MachineState
*ms
= MACHINE(obj
);
482 return g_strdup(object_get_canonical_path_component(OBJECT(ms
->cgs
)));
488 static void machine_set_memory_encryption(Object
*obj
, const char *value
,
492 object_resolve_path_component(object_get_objects_root(), value
);
495 error_setg(errp
, "No such memory encryption object '%s'", value
);
499 object_property_set_link(obj
, "confidential-guest-support", cgs
, errp
);
502 static void machine_check_confidential_guest_support(const Object
*obj
,
508 * So far the only constraint is that the target has the
509 * TYPE_CONFIDENTIAL_GUEST_SUPPORT interface, and that's checked
514 static bool machine_get_nvdimm(Object
*obj
, Error
**errp
)
516 MachineState
*ms
= MACHINE(obj
);
518 return ms
->nvdimms_state
->is_enabled
;
521 static void machine_set_nvdimm(Object
*obj
, bool value
, Error
**errp
)
523 MachineState
*ms
= MACHINE(obj
);
525 ms
->nvdimms_state
->is_enabled
= value
;
528 static bool machine_get_hmat(Object
*obj
, Error
**errp
)
530 MachineState
*ms
= MACHINE(obj
);
532 return ms
->numa_state
->hmat_enabled
;
535 static void machine_set_hmat(Object
*obj
, bool value
, Error
**errp
)
537 MachineState
*ms
= MACHINE(obj
);
539 ms
->numa_state
->hmat_enabled
= value
;
542 static void machine_get_mem(Object
*obj
, Visitor
*v
, const char *name
,
543 void *opaque
, Error
**errp
)
545 MachineState
*ms
= MACHINE(obj
);
546 MemorySizeConfiguration mem
= {
548 .size
= ms
->ram_size
,
549 .has_max_size
= !!ms
->ram_slots
,
550 .max_size
= ms
->maxram_size
,
551 .has_slots
= !!ms
->ram_slots
,
552 .slots
= ms
->ram_slots
,
554 MemorySizeConfiguration
*p_mem
= &mem
;
556 visit_type_MemorySizeConfiguration(v
, name
, &p_mem
, &error_abort
);
559 static void machine_set_mem(Object
*obj
, Visitor
*v
, const char *name
,
560 void *opaque
, Error
**errp
)
563 MachineState
*ms
= MACHINE(obj
);
564 MachineClass
*mc
= MACHINE_GET_CLASS(obj
);
565 MemorySizeConfiguration
*mem
;
567 if (!visit_type_MemorySizeConfiguration(v
, name
, &mem
, errp
)) {
571 if (!mem
->has_size
) {
572 mem
->has_size
= true;
573 mem
->size
= mc
->default_ram_size
;
575 mem
->size
= QEMU_ALIGN_UP(mem
->size
, 8192);
576 if (mc
->fixup_ram_size
) {
577 mem
->size
= mc
->fixup_ram_size(mem
->size
);
579 if ((ram_addr_t
)mem
->size
!= mem
->size
) {
580 error_setg(errp
, "ram size too large");
584 if (mem
->has_max_size
) {
585 if (mem
->max_size
< mem
->size
) {
586 error_setg(errp
, "invalid value of maxmem: "
587 "maximum memory size (0x%" PRIx64
") must be at least "
588 "the initial memory size (0x%" PRIx64
")",
589 mem
->max_size
, mem
->size
);
592 if (mem
->has_slots
&& mem
->slots
&& mem
->max_size
== mem
->size
) {
593 error_setg(errp
, "invalid value of maxmem: "
594 "memory slots were specified but maximum memory size "
595 "(0x%" PRIx64
") is equal to the initial memory size "
596 "(0x%" PRIx64
")", mem
->max_size
, mem
->size
);
599 ms
->maxram_size
= mem
->max_size
;
601 if (mem
->has_slots
) {
602 error_setg(errp
, "slots specified but no max-size");
605 ms
->maxram_size
= mem
->size
;
607 ms
->ram_size
= mem
->size
;
608 ms
->ram_slots
= mem
->has_slots
? mem
->slots
: 0;
610 qapi_free_MemorySizeConfiguration(mem
);
613 static char *machine_get_nvdimm_persistence(Object
*obj
, Error
**errp
)
615 MachineState
*ms
= MACHINE(obj
);
617 return g_strdup(ms
->nvdimms_state
->persistence_string
);
620 static void machine_set_nvdimm_persistence(Object
*obj
, const char *value
,
623 MachineState
*ms
= MACHINE(obj
);
624 NVDIMMState
*nvdimms_state
= ms
->nvdimms_state
;
626 if (strcmp(value
, "cpu") == 0) {
627 nvdimms_state
->persistence
= 3;
628 } else if (strcmp(value
, "mem-ctrl") == 0) {
629 nvdimms_state
->persistence
= 2;
631 error_setg(errp
, "-machine nvdimm-persistence=%s: unsupported option",
636 g_free(nvdimms_state
->persistence_string
);
637 nvdimms_state
->persistence_string
= g_strdup(value
);
640 void machine_class_allow_dynamic_sysbus_dev(MachineClass
*mc
, const char *type
)
642 QAPI_LIST_PREPEND(mc
->allowed_dynamic_sysbus_devices
, g_strdup(type
));
645 bool device_is_dynamic_sysbus(MachineClass
*mc
, DeviceState
*dev
)
647 Object
*obj
= OBJECT(dev
);
649 if (!object_dynamic_cast(obj
, TYPE_SYS_BUS_DEVICE
)) {
653 return device_type_is_dynamic_sysbus(mc
, object_get_typename(obj
));
656 bool device_type_is_dynamic_sysbus(MachineClass
*mc
, const char *type
)
658 bool allowed
= false;
660 ObjectClass
*klass
= object_class_by_name(type
);
662 for (wl
= mc
->allowed_dynamic_sysbus_devices
;
665 allowed
|= !!object_class_dynamic_cast(klass
, wl
->value
);
671 HotpluggableCPUList
*machine_query_hotpluggable_cpus(MachineState
*machine
)
674 HotpluggableCPUList
*head
= NULL
;
675 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
677 /* force board to initialize possible_cpus if it hasn't been done yet */
678 mc
->possible_cpu_arch_ids(machine
);
680 for (i
= 0; i
< machine
->possible_cpus
->len
; i
++) {
682 HotpluggableCPU
*cpu_item
= g_new0(typeof(*cpu_item
), 1);
684 cpu_item
->type
= g_strdup(machine
->possible_cpus
->cpus
[i
].type
);
685 cpu_item
->vcpus_count
= machine
->possible_cpus
->cpus
[i
].vcpus_count
;
686 cpu_item
->props
= g_memdup(&machine
->possible_cpus
->cpus
[i
].props
,
687 sizeof(*cpu_item
->props
));
689 cpu
= machine
->possible_cpus
->cpus
[i
].cpu
;
691 cpu_item
->qom_path
= object_get_canonical_path(cpu
);
693 QAPI_LIST_PREPEND(head
, cpu_item
);
699 * machine_set_cpu_numa_node:
700 * @machine: machine object to modify
701 * @props: specifies which cpu objects to assign to
702 * numa node specified by @props.node_id
703 * @errp: if an error occurs, a pointer to an area to store the error
705 * Associate NUMA node specified by @props.node_id with cpu slots that
706 * match socket/core/thread-ids specified by @props. It's recommended to use
707 * query-hotpluggable-cpus.props values to specify affected cpu slots,
708 * which would lead to exact 1:1 mapping of cpu slots to NUMA node.
710 * However for CLI convenience it's possible to pass in subset of properties,
711 * which would affect all cpu slots that match it.
713 * -smp 4,cores=2,sockets=2 -numa node,nodeid=0 -numa node,nodeid=1 \
714 * -numa cpu,node-id=0,socket_id=0 \
715 * -numa cpu,node-id=1,socket_id=1
716 * will assign all child cores of socket 0 to node 0 and
717 * of socket 1 to node 1.
719 * On attempt of reassigning (already assigned) cpu slot to another NUMA node,
721 * Empty subset is disallowed and function will return with error in this case.
723 void machine_set_cpu_numa_node(MachineState
*machine
,
724 const CpuInstanceProperties
*props
, Error
**errp
)
726 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
727 NodeInfo
*numa_info
= machine
->numa_state
->nodes
;
731 if (!mc
->possible_cpu_arch_ids
) {
732 error_setg(errp
, "mapping of CPUs to NUMA node is not supported");
736 /* disabling node mapping is not supported, forbid it */
737 assert(props
->has_node_id
);
739 /* force board to initialize possible_cpus if it hasn't been done yet */
740 mc
->possible_cpu_arch_ids(machine
);
742 for (i
= 0; i
< machine
->possible_cpus
->len
; i
++) {
743 CPUArchId
*slot
= &machine
->possible_cpus
->cpus
[i
];
745 /* reject unsupported by board properties */
746 if (props
->has_thread_id
&& !slot
->props
.has_thread_id
) {
747 error_setg(errp
, "thread-id is not supported");
751 if (props
->has_core_id
&& !slot
->props
.has_core_id
) {
752 error_setg(errp
, "core-id is not supported");
756 if (props
->has_cluster_id
&& !slot
->props
.has_cluster_id
) {
757 error_setg(errp
, "cluster-id is not supported");
761 if (props
->has_socket_id
&& !slot
->props
.has_socket_id
) {
762 error_setg(errp
, "socket-id is not supported");
766 if (props
->has_die_id
&& !slot
->props
.has_die_id
) {
767 error_setg(errp
, "die-id is not supported");
771 /* skip slots with explicit mismatch */
772 if (props
->has_thread_id
&& props
->thread_id
!= slot
->props
.thread_id
) {
776 if (props
->has_core_id
&& props
->core_id
!= slot
->props
.core_id
) {
780 if (props
->has_cluster_id
&&
781 props
->cluster_id
!= slot
->props
.cluster_id
) {
785 if (props
->has_die_id
&& props
->die_id
!= slot
->props
.die_id
) {
789 if (props
->has_socket_id
&& props
->socket_id
!= slot
->props
.socket_id
) {
793 /* reject assignment if slot is already assigned, for compatibility
794 * of legacy cpu_index mapping with SPAPR core based mapping do not
795 * error out if cpu thread and matched core have the same node-id */
796 if (slot
->props
.has_node_id
&&
797 slot
->props
.node_id
!= props
->node_id
) {
798 error_setg(errp
, "CPU is already assigned to node-id: %" PRId64
,
799 slot
->props
.node_id
);
803 /* assign slot to node as it's matched '-numa cpu' key */
805 slot
->props
.node_id
= props
->node_id
;
806 slot
->props
.has_node_id
= props
->has_node_id
;
808 if (machine
->numa_state
->hmat_enabled
) {
809 if ((numa_info
[props
->node_id
].initiator
< MAX_NODES
) &&
810 (props
->node_id
!= numa_info
[props
->node_id
].initiator
)) {
811 error_setg(errp
, "The initiator of CPU NUMA node %" PRId64
812 " should be itself (got %" PRIu16
")",
813 props
->node_id
, numa_info
[props
->node_id
].initiator
);
816 numa_info
[props
->node_id
].has_cpu
= true;
817 numa_info
[props
->node_id
].initiator
= props
->node_id
;
822 error_setg(errp
, "no match found");
826 static void machine_get_smp(Object
*obj
, Visitor
*v
, const char *name
,
827 void *opaque
, Error
**errp
)
829 MachineState
*ms
= MACHINE(obj
);
830 SMPConfiguration
*config
= &(SMPConfiguration
){
831 .has_cpus
= true, .cpus
= ms
->smp
.cpus
,
832 .has_sockets
= true, .sockets
= ms
->smp
.sockets
,
833 .has_dies
= true, .dies
= ms
->smp
.dies
,
834 .has_clusters
= true, .clusters
= ms
->smp
.clusters
,
835 .has_cores
= true, .cores
= ms
->smp
.cores
,
836 .has_threads
= true, .threads
= ms
->smp
.threads
,
837 .has_maxcpus
= true, .maxcpus
= ms
->smp
.max_cpus
,
840 if (!visit_type_SMPConfiguration(v
, name
, &config
, &error_abort
)) {
845 static void machine_set_smp(Object
*obj
, Visitor
*v
, const char *name
,
846 void *opaque
, Error
**errp
)
848 MachineState
*ms
= MACHINE(obj
);
849 g_autoptr(SMPConfiguration
) config
= NULL
;
851 if (!visit_type_SMPConfiguration(v
, name
, &config
, errp
)) {
855 machine_parse_smp_config(ms
, config
, errp
);
858 static void machine_get_boot(Object
*obj
, Visitor
*v
, const char *name
,
859 void *opaque
, Error
**errp
)
861 MachineState
*ms
= MACHINE(obj
);
862 BootConfiguration
*config
= &ms
->boot_config
;
863 visit_type_BootConfiguration(v
, name
, &config
, &error_abort
);
866 static void machine_free_boot_config(MachineState
*ms
)
868 g_free(ms
->boot_config
.order
);
869 g_free(ms
->boot_config
.once
);
870 g_free(ms
->boot_config
.splash
);
873 static void machine_copy_boot_config(MachineState
*ms
, BootConfiguration
*config
)
875 MachineClass
*machine_class
= MACHINE_GET_CLASS(ms
);
877 machine_free_boot_config(ms
);
878 ms
->boot_config
= *config
;
879 if (!config
->order
) {
880 ms
->boot_config
.order
= g_strdup(machine_class
->default_boot_order
);
884 static void machine_set_boot(Object
*obj
, Visitor
*v
, const char *name
,
885 void *opaque
, Error
**errp
)
888 MachineState
*ms
= MACHINE(obj
);
889 BootConfiguration
*config
= NULL
;
891 if (!visit_type_BootConfiguration(v
, name
, &config
, errp
)) {
895 validate_bootdevices(config
->order
, errp
);
901 validate_bootdevices(config
->once
, errp
);
907 machine_copy_boot_config(ms
, config
);
908 /* Strings live in ms->boot_config. */
913 qapi_free_BootConfiguration(config
);
916 static void machine_class_init(ObjectClass
*oc
, void *data
)
918 MachineClass
*mc
= MACHINE_CLASS(oc
);
920 /* Default 128 MB as guest ram size */
921 mc
->default_ram_size
= 128 * MiB
;
922 mc
->rom_file_has_mr
= true;
924 /* numa node memory size aligned on 8MB by default.
925 * On Linux, each node's border has to be 8MB aligned
927 mc
->numa_mem_align_shift
= 23;
929 object_class_property_add_str(oc
, "kernel",
930 machine_get_kernel
, machine_set_kernel
);
931 object_class_property_set_description(oc
, "kernel",
932 "Linux kernel image file");
934 object_class_property_add_str(oc
, "initrd",
935 machine_get_initrd
, machine_set_initrd
);
936 object_class_property_set_description(oc
, "initrd",
937 "Linux initial ramdisk file");
939 object_class_property_add_str(oc
, "append",
940 machine_get_append
, machine_set_append
);
941 object_class_property_set_description(oc
, "append",
942 "Linux kernel command line");
944 object_class_property_add_str(oc
, "dtb",
945 machine_get_dtb
, machine_set_dtb
);
946 object_class_property_set_description(oc
, "dtb",
947 "Linux kernel device tree file");
949 object_class_property_add_str(oc
, "dumpdtb",
950 machine_get_dumpdtb
, machine_set_dumpdtb
);
951 object_class_property_set_description(oc
, "dumpdtb",
952 "Dump current dtb to a file and quit");
954 object_class_property_add(oc
, "boot", "BootConfiguration",
955 machine_get_boot
, machine_set_boot
,
957 object_class_property_set_description(oc
, "boot",
958 "Boot configuration");
960 object_class_property_add(oc
, "smp", "SMPConfiguration",
961 machine_get_smp
, machine_set_smp
,
963 object_class_property_set_description(oc
, "smp",
966 object_class_property_add(oc
, "phandle-start", "int",
967 machine_get_phandle_start
, machine_set_phandle_start
,
969 object_class_property_set_description(oc
, "phandle-start",
970 "The first phandle ID we may generate dynamically");
972 object_class_property_add_str(oc
, "dt-compatible",
973 machine_get_dt_compatible
, machine_set_dt_compatible
);
974 object_class_property_set_description(oc
, "dt-compatible",
975 "Overrides the \"compatible\" property of the dt root node");
977 object_class_property_add_bool(oc
, "dump-guest-core",
978 machine_get_dump_guest_core
, machine_set_dump_guest_core
);
979 object_class_property_set_description(oc
, "dump-guest-core",
980 "Include guest memory in a core dump");
982 object_class_property_add_bool(oc
, "mem-merge",
983 machine_get_mem_merge
, machine_set_mem_merge
);
984 object_class_property_set_description(oc
, "mem-merge",
985 "Enable/disable memory merge support");
987 object_class_property_add_bool(oc
, "usb",
988 machine_get_usb
, machine_set_usb
);
989 object_class_property_set_description(oc
, "usb",
990 "Set on/off to enable/disable usb");
992 object_class_property_add_bool(oc
, "graphics",
993 machine_get_graphics
, machine_set_graphics
);
994 object_class_property_set_description(oc
, "graphics",
995 "Set on/off to enable/disable graphics emulation");
997 object_class_property_add_str(oc
, "firmware",
998 machine_get_firmware
, machine_set_firmware
);
999 object_class_property_set_description(oc
, "firmware",
1002 object_class_property_add_bool(oc
, "suppress-vmdesc",
1003 machine_get_suppress_vmdesc
, machine_set_suppress_vmdesc
);
1004 object_class_property_set_description(oc
, "suppress-vmdesc",
1005 "Set on to disable self-describing migration");
1007 object_class_property_add_link(oc
, "confidential-guest-support",
1008 TYPE_CONFIDENTIAL_GUEST_SUPPORT
,
1009 offsetof(MachineState
, cgs
),
1010 machine_check_confidential_guest_support
,
1011 OBJ_PROP_LINK_STRONG
);
1012 object_class_property_set_description(oc
, "confidential-guest-support",
1013 "Set confidential guest scheme to support");
1015 /* For compatibility */
1016 object_class_property_add_str(oc
, "memory-encryption",
1017 machine_get_memory_encryption
, machine_set_memory_encryption
);
1018 object_class_property_set_description(oc
, "memory-encryption",
1019 "Set memory encryption object to use");
1021 object_class_property_add_link(oc
, "memory-backend", TYPE_MEMORY_BACKEND
,
1022 offsetof(MachineState
, memdev
), object_property_allow_set_link
,
1023 OBJ_PROP_LINK_STRONG
);
1024 object_class_property_set_description(oc
, "memory-backend",
1026 "Valid value is ID of hostmem based backend");
1028 object_class_property_add(oc
, "memory", "MemorySizeConfiguration",
1029 machine_get_mem
, machine_set_mem
,
1031 object_class_property_set_description(oc
, "memory",
1032 "Memory size configuration");
1035 static void machine_class_base_init(ObjectClass
*oc
, void *data
)
1037 MachineClass
*mc
= MACHINE_CLASS(oc
);
1038 mc
->max_cpus
= mc
->max_cpus
?: 1;
1039 mc
->min_cpus
= mc
->min_cpus
?: 1;
1040 mc
->default_cpus
= mc
->default_cpus
?: 1;
1042 if (!object_class_is_abstract(oc
)) {
1043 const char *cname
= object_class_get_name(oc
);
1044 assert(g_str_has_suffix(cname
, TYPE_MACHINE_SUFFIX
));
1045 mc
->name
= g_strndup(cname
,
1046 strlen(cname
) - strlen(TYPE_MACHINE_SUFFIX
));
1047 mc
->compat_props
= g_ptr_array_new();
1051 static void machine_initfn(Object
*obj
)
1053 MachineState
*ms
= MACHINE(obj
);
1054 MachineClass
*mc
= MACHINE_GET_CLASS(obj
);
1056 container_get(obj
, "/peripheral");
1057 container_get(obj
, "/peripheral-anon");
1059 ms
->dump_guest_core
= true;
1060 ms
->mem_merge
= true;
1061 ms
->enable_graphics
= true;
1062 ms
->kernel_cmdline
= g_strdup("");
1063 ms
->ram_size
= mc
->default_ram_size
;
1064 ms
->maxram_size
= mc
->default_ram_size
;
1066 if (mc
->nvdimm_supported
) {
1067 Object
*obj
= OBJECT(ms
);
1069 ms
->nvdimms_state
= g_new0(NVDIMMState
, 1);
1070 object_property_add_bool(obj
, "nvdimm",
1071 machine_get_nvdimm
, machine_set_nvdimm
);
1072 object_property_set_description(obj
, "nvdimm",
1073 "Set on/off to enable/disable "
1074 "NVDIMM instantiation");
1076 object_property_add_str(obj
, "nvdimm-persistence",
1077 machine_get_nvdimm_persistence
,
1078 machine_set_nvdimm_persistence
);
1079 object_property_set_description(obj
, "nvdimm-persistence",
1080 "Set NVDIMM persistence"
1081 "Valid values are cpu, mem-ctrl");
1084 if (mc
->cpu_index_to_instance_props
&& mc
->get_default_cpu_node_id
) {
1085 ms
->numa_state
= g_new0(NumaState
, 1);
1086 object_property_add_bool(obj
, "hmat",
1087 machine_get_hmat
, machine_set_hmat
);
1088 object_property_set_description(obj
, "hmat",
1089 "Set on/off to enable/disable "
1090 "ACPI Heterogeneous Memory Attribute "
1094 /* default to mc->default_cpus */
1095 ms
->smp
.cpus
= mc
->default_cpus
;
1096 ms
->smp
.max_cpus
= mc
->default_cpus
;
1097 ms
->smp
.sockets
= 1;
1099 ms
->smp
.clusters
= 1;
1101 ms
->smp
.threads
= 1;
1103 machine_copy_boot_config(ms
, &(BootConfiguration
){ 0 });
1106 static void machine_finalize(Object
*obj
)
1108 MachineState
*ms
= MACHINE(obj
);
1110 machine_free_boot_config(ms
);
1111 g_free(ms
->kernel_filename
);
1112 g_free(ms
->initrd_filename
);
1113 g_free(ms
->kernel_cmdline
);
1115 g_free(ms
->dumpdtb
);
1116 g_free(ms
->dt_compatible
);
1117 g_free(ms
->firmware
);
1118 g_free(ms
->device_memory
);
1119 g_free(ms
->nvdimms_state
);
1120 g_free(ms
->numa_state
);
1123 bool machine_usb(MachineState
*machine
)
1125 return machine
->usb
;
1128 int machine_phandle_start(MachineState
*machine
)
1130 return machine
->phandle_start
;
1133 bool machine_dump_guest_core(MachineState
*machine
)
1135 return machine
->dump_guest_core
;
1138 bool machine_mem_merge(MachineState
*machine
)
1140 return machine
->mem_merge
;
1143 static char *cpu_slot_to_string(const CPUArchId
*cpu
)
1145 GString
*s
= g_string_new(NULL
);
1146 if (cpu
->props
.has_socket_id
) {
1147 g_string_append_printf(s
, "socket-id: %"PRId64
, cpu
->props
.socket_id
);
1149 if (cpu
->props
.has_die_id
) {
1151 g_string_append_printf(s
, ", ");
1153 g_string_append_printf(s
, "die-id: %"PRId64
, cpu
->props
.die_id
);
1155 if (cpu
->props
.has_cluster_id
) {
1157 g_string_append_printf(s
, ", ");
1159 g_string_append_printf(s
, "cluster-id: %"PRId64
, cpu
->props
.cluster_id
);
1161 if (cpu
->props
.has_core_id
) {
1163 g_string_append_printf(s
, ", ");
1165 g_string_append_printf(s
, "core-id: %"PRId64
, cpu
->props
.core_id
);
1167 if (cpu
->props
.has_thread_id
) {
1169 g_string_append_printf(s
, ", ");
1171 g_string_append_printf(s
, "thread-id: %"PRId64
, cpu
->props
.thread_id
);
1173 return g_string_free(s
, false);
1176 static void numa_validate_initiator(NumaState
*numa_state
)
1179 NodeInfo
*numa_info
= numa_state
->nodes
;
1181 for (i
= 0; i
< numa_state
->num_nodes
; i
++) {
1182 if (numa_info
[i
].initiator
== MAX_NODES
) {
1186 if (!numa_info
[numa_info
[i
].initiator
].present
) {
1187 error_report("NUMA node %" PRIu16
" is missing, use "
1188 "'-numa node' option to declare it first",
1189 numa_info
[i
].initiator
);
1193 if (!numa_info
[numa_info
[i
].initiator
].has_cpu
) {
1194 error_report("The initiator of NUMA node %d is invalid", i
);
1200 static void machine_numa_finish_cpu_init(MachineState
*machine
)
1203 bool default_mapping
;
1204 GString
*s
= g_string_new(NULL
);
1205 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
1206 const CPUArchIdList
*possible_cpus
= mc
->possible_cpu_arch_ids(machine
);
1208 assert(machine
->numa_state
->num_nodes
);
1209 for (i
= 0; i
< possible_cpus
->len
; i
++) {
1210 if (possible_cpus
->cpus
[i
].props
.has_node_id
) {
1214 default_mapping
= (i
== possible_cpus
->len
);
1216 for (i
= 0; i
< possible_cpus
->len
; i
++) {
1217 const CPUArchId
*cpu_slot
= &possible_cpus
->cpus
[i
];
1219 if (!cpu_slot
->props
.has_node_id
) {
1220 /* fetch default mapping from board and enable it */
1221 CpuInstanceProperties props
= cpu_slot
->props
;
1223 props
.node_id
= mc
->get_default_cpu_node_id(machine
, i
);
1224 if (!default_mapping
) {
1225 /* record slots with not set mapping,
1226 * TODO: make it hard error in future */
1227 char *cpu_str
= cpu_slot_to_string(cpu_slot
);
1228 g_string_append_printf(s
, "%sCPU %d [%s]",
1229 s
->len
? ", " : "", i
, cpu_str
);
1232 /* non mapped cpus used to fallback to node 0 */
1236 props
.has_node_id
= true;
1237 machine_set_cpu_numa_node(machine
, &props
, &error_fatal
);
1241 if (machine
->numa_state
->hmat_enabled
) {
1242 numa_validate_initiator(machine
->numa_state
);
1245 if (s
->len
&& !qtest_enabled()) {
1246 warn_report("CPU(s) not present in any NUMA nodes: %s",
1248 warn_report("All CPU(s) up to maxcpus should be described "
1249 "in NUMA config, ability to start up with partial NUMA "
1250 "mappings is obsoleted and will be removed in future");
1252 g_string_free(s
, true);
1255 MemoryRegion
*machine_consume_memdev(MachineState
*machine
,
1256 HostMemoryBackend
*backend
)
1258 MemoryRegion
*ret
= host_memory_backend_get_memory(backend
);
1260 if (host_memory_backend_is_mapped(backend
)) {
1261 error_report("memory backend %s can't be used multiple times.",
1262 object_get_canonical_path_component(OBJECT(backend
)));
1265 host_memory_backend_set_mapped(backend
, true);
1266 vmstate_register_ram_global(ret
);
1270 static bool create_default_memdev(MachineState
*ms
, const char *path
, Error
**errp
)
1273 MachineClass
*mc
= MACHINE_GET_CLASS(ms
);
1276 obj
= object_new(path
? TYPE_MEMORY_BACKEND_FILE
: TYPE_MEMORY_BACKEND_RAM
);
1278 if (!object_property_set_str(obj
, "mem-path", path
, errp
)) {
1282 if (!object_property_set_int(obj
, "size", ms
->ram_size
, errp
)) {
1285 object_property_add_child(object_get_objects_root(), mc
->default_ram_id
,
1287 /* Ensure backend's memory region name is equal to mc->default_ram_id */
1288 if (!object_property_set_bool(obj
, "x-use-canonical-path-for-ramblock-id",
1292 if (!user_creatable_complete(USER_CREATABLE(obj
), errp
)) {
1295 r
= object_property_set_link(OBJECT(ms
), "memory-backend", obj
, errp
);
1303 void machine_run_board_init(MachineState
*machine
, const char *mem_path
, Error
**errp
)
1305 MachineClass
*machine_class
= MACHINE_GET_CLASS(machine
);
1306 ObjectClass
*oc
= object_class_by_name(machine
->cpu_type
);
1309 /* This checkpoint is required by replay to separate prior clock
1310 reading from the other reads, because timer polling functions query
1311 clock values from the log. */
1312 replay_checkpoint(CHECKPOINT_INIT
);
1314 if (!xen_enabled()) {
1315 /* On 32-bit hosts, QEMU is limited by virtual address space */
1316 if (machine
->ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
1317 error_setg(errp
, "at most 2047 MB RAM can be simulated");
1322 if (machine
->memdev
) {
1323 ram_addr_t backend_size
= object_property_get_uint(OBJECT(machine
->memdev
),
1324 "size", &error_abort
);
1325 if (backend_size
!= machine
->ram_size
) {
1326 error_setg(errp
, "Machine memory size does not match the size of the memory backend");
1329 } else if (machine_class
->default_ram_id
&& machine
->ram_size
&&
1330 numa_uses_legacy_mem()) {
1331 if (!create_default_memdev(current_machine
, mem_path
, errp
)) {
1336 if (machine
->numa_state
) {
1337 numa_complete_configuration(machine
);
1338 if (machine
->numa_state
->num_nodes
) {
1339 machine_numa_finish_cpu_init(machine
);
1343 if (!machine
->ram
&& machine
->memdev
) {
1344 machine
->ram
= machine_consume_memdev(machine
, machine
->memdev
);
1347 /* If the machine supports the valid_cpu_types check and the user
1348 * specified a CPU with -cpu check here that the user CPU is supported.
1350 if (machine_class
->valid_cpu_types
&& machine
->cpu_type
) {
1353 for (i
= 0; machine_class
->valid_cpu_types
[i
]; i
++) {
1354 if (object_class_dynamic_cast(oc
,
1355 machine_class
->valid_cpu_types
[i
])) {
1356 /* The user specificed CPU is in the valid field, we are
1363 if (!machine_class
->valid_cpu_types
[i
]) {
1364 /* The user specified CPU is not valid */
1365 error_report("Invalid CPU type: %s", machine
->cpu_type
);
1366 error_printf("The valid types are: %s",
1367 machine_class
->valid_cpu_types
[0]);
1368 for (i
= 1; machine_class
->valid_cpu_types
[i
]; i
++) {
1369 error_printf(", %s", machine_class
->valid_cpu_types
[i
]);
1377 /* Check if CPU type is deprecated and warn if so */
1379 if (cc
&& cc
->deprecation_note
) {
1380 warn_report("CPU model %s is deprecated -- %s", machine
->cpu_type
,
1381 cc
->deprecation_note
);
1386 * With confidential guests, the host can't see the real
1387 * contents of RAM, so there's no point in it trying to merge
1390 machine_set_mem_merge(OBJECT(machine
), false, &error_abort
);
1393 * Virtio devices can't count on directly accessing guest
1394 * memory, so they need iommu_platform=on to use normal DMA
1395 * mechanisms. That requires also disabling legacy virtio
1396 * support for those virtio pci devices which allow it.
1398 object_register_sugar_prop(TYPE_VIRTIO_PCI
, "disable-legacy",
1400 object_register_sugar_prop(TYPE_VIRTIO_DEVICE
, "iommu_platform",
1404 accel_init_interfaces(ACCEL_GET_CLASS(machine
->accelerator
));
1405 machine_class
->init(machine
);
1406 phase_advance(PHASE_MACHINE_INITIALIZED
);
1409 static NotifierList machine_init_done_notifiers
=
1410 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
1412 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
1414 notifier_list_add(&machine_init_done_notifiers
, notify
);
1415 if (phase_check(PHASE_MACHINE_READY
)) {
1416 notify
->notify(notify
, NULL
);
1420 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
1422 notifier_remove(notify
);
1425 void qdev_machine_creation_done(void)
1427 cpu_synchronize_all_post_init();
1429 if (current_machine
->boot_config
.once
) {
1430 qemu_boot_set(current_machine
->boot_config
.once
, &error_fatal
);
1431 qemu_register_reset(restore_boot_order
, g_strdup(current_machine
->boot_config
.order
));
1435 * ok, initial machine setup is done, starting from now we can
1436 * only create hotpluggable devices
1438 phase_advance(PHASE_MACHINE_READY
);
1439 qdev_assert_realized_properly();
1441 /* TODO: once all bus devices are qdevified, this should be done
1442 * when bus is created by qdev.c */
1444 * TODO: If we had a main 'reset container' that the whole system
1445 * lived in, we could reset that using the multi-phase reset
1446 * APIs. For the moment, we just reset the sysbus, which will cause
1447 * all devices hanging off it (and all their child buses, recursively)
1448 * to be reset. Note that this will *not* reset any Device objects
1449 * which are not attached to some part of the qbus tree!
1451 qemu_register_reset(resettable_cold_reset_fn
, sysbus_get_default());
1453 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
1455 if (rom_check_and_register_reset() != 0) {
1461 /* This checkpoint is required by replay to separate prior clock
1462 reading from the other reads, because timer polling functions query
1463 clock values from the log. */
1464 replay_checkpoint(CHECKPOINT_RESET
);
1465 qemu_system_reset(SHUTDOWN_CAUSE_NONE
);
1466 register_global_state();
1469 static const TypeInfo machine_info
= {
1470 .name
= TYPE_MACHINE
,
1471 .parent
= TYPE_OBJECT
,
1473 .class_size
= sizeof(MachineClass
),
1474 .class_init
= machine_class_init
,
1475 .class_base_init
= machine_class_base_init
,
1476 .instance_size
= sizeof(MachineState
),
1477 .instance_init
= machine_initfn
,
1478 .instance_finalize
= machine_finalize
,
1481 static void machine_register_types(void)
1483 type_register_static(&machine_info
);
1486 type_init(machine_register_types
)