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/accel.h"
15 #include "sysemu/replay.h"
16 #include "hw/boards.h"
17 #include "hw/loader.h"
18 #include "qapi/error.h"
19 #include "qapi/qapi-visit-machine.h"
20 #include "qom/object_interfaces.h"
21 #include "sysemu/cpus.h"
22 #include "sysemu/sysemu.h"
23 #include "sysemu/reset.h"
24 #include "sysemu/runstate.h"
25 #include "sysemu/xen.h"
26 #include "sysemu/qtest.h"
27 #include "hw/pci/pci_bridge.h"
28 #include "hw/mem/nvdimm.h"
29 #include "migration/global_state.h"
30 #include "exec/confidential-guest-support.h"
31 #include "hw/virtio/virtio-pci.h"
32 #include "hw/virtio/virtio-net.h"
33 #include "audio/audio.h"
35 GlobalProperty hw_compat_8_2
[] = {
36 { "migration", "zero-page-detection", "legacy"},
38 const size_t hw_compat_8_2_len
= G_N_ELEMENTS(hw_compat_8_2
);
40 GlobalProperty hw_compat_8_1
[] = {
41 { TYPE_PCI_BRIDGE
, "x-pci-express-writeable-slt-bug", "true" },
42 { "ramfb", "x-migrate", "off" },
43 { "vfio-pci-nohotplug", "x-ramfb-migrate", "off" },
44 { "igb", "x-pcie-flr-init", "off" },
46 const size_t hw_compat_8_1_len
= G_N_ELEMENTS(hw_compat_8_1
);
48 GlobalProperty hw_compat_8_0
[] = {
49 { "migration", "multifd-flush-after-each-section", "on"},
50 { TYPE_PCI_DEVICE
, "x-pcie-ari-nextfn-1", "on" },
51 { TYPE_VIRTIO_NET
, "host_uso", "off"},
52 { TYPE_VIRTIO_NET
, "guest_uso4", "off"},
53 { TYPE_VIRTIO_NET
, "guest_uso6", "off"},
55 const size_t hw_compat_8_0_len
= G_N_ELEMENTS(hw_compat_8_0
);
57 GlobalProperty hw_compat_7_2
[] = {
58 { "e1000e", "migrate-timadj", "off" },
59 { "virtio-mem", "x-early-migration", "false" },
60 { "migration", "x-preempt-pre-7-2", "true" },
61 { TYPE_PCI_DEVICE
, "x-pcie-err-unc-mask", "off" },
63 const size_t hw_compat_7_2_len
= G_N_ELEMENTS(hw_compat_7_2
);
65 GlobalProperty hw_compat_7_1
[] = {
66 { "virtio-device", "queue_reset", "false" },
67 { "virtio-rng-pci", "vectors", "0" },
68 { "virtio-rng-pci-transitional", "vectors", "0" },
69 { "virtio-rng-pci-non-transitional", "vectors", "0" },
71 const size_t hw_compat_7_1_len
= G_N_ELEMENTS(hw_compat_7_1
);
73 GlobalProperty hw_compat_7_0
[] = {
74 { "arm-gicv3-common", "force-8-bit-prio", "on" },
75 { "nvme-ns", "eui64-default", "on"},
77 const size_t hw_compat_7_0_len
= G_N_ELEMENTS(hw_compat_7_0
);
79 GlobalProperty hw_compat_6_2
[] = {
80 { "PIIX4_PM", "x-not-migrate-acpi-index", "on"},
82 const size_t hw_compat_6_2_len
= G_N_ELEMENTS(hw_compat_6_2
);
84 GlobalProperty hw_compat_6_1
[] = {
85 { "vhost-user-vsock-device", "seqpacket", "off" },
86 { "nvme-ns", "shared", "off" },
88 const size_t hw_compat_6_1_len
= G_N_ELEMENTS(hw_compat_6_1
);
90 GlobalProperty hw_compat_6_0
[] = {
91 { "gpex-pcihost", "allow-unmapped-accesses", "false" },
92 { "i8042", "extended-state", "false"},
93 { "nvme-ns", "eui64-default", "off"},
94 { "e1000", "init-vet", "off" },
95 { "e1000e", "init-vet", "off" },
96 { "vhost-vsock-device", "seqpacket", "off" },
98 const size_t hw_compat_6_0_len
= G_N_ELEMENTS(hw_compat_6_0
);
100 GlobalProperty hw_compat_5_2
[] = {
101 { "ICH9-LPC", "smm-compat", "on"},
102 { "PIIX4_PM", "smm-compat", "on"},
103 { "virtio-blk-device", "report-discard-granularity", "off" },
104 { "virtio-net-pci-base", "vectors", "3"},
105 { "nvme", "msix-exclusive-bar", "on"},
107 const size_t hw_compat_5_2_len
= G_N_ELEMENTS(hw_compat_5_2
);
109 GlobalProperty hw_compat_5_1
[] = {
110 { "vhost-scsi", "num_queues", "1"},
111 { "vhost-user-blk", "num-queues", "1"},
112 { "vhost-user-scsi", "num_queues", "1"},
113 { "virtio-blk-device", "num-queues", "1"},
114 { "virtio-scsi-device", "num_queues", "1"},
115 { "nvme", "use-intel-id", "on"},
116 { "pvpanic", "events", "1"}, /* PVPANIC_PANICKED */
117 { "pl011", "migrate-clk", "off" },
118 { "virtio-pci", "x-ats-page-aligned", "off"},
120 const size_t hw_compat_5_1_len
= G_N_ELEMENTS(hw_compat_5_1
);
122 GlobalProperty hw_compat_5_0
[] = {
123 { "pci-host-bridge", "x-config-reg-migration-enabled", "off" },
124 { "virtio-balloon-device", "page-poison", "false" },
125 { "vmport", "x-read-set-eax", "off" },
126 { "vmport", "x-signal-unsupported-cmd", "off" },
127 { "vmport", "x-report-vmx-type", "off" },
128 { "vmport", "x-cmds-v2", "off" },
129 { "virtio-device", "x-disable-legacy-check", "true" },
131 const size_t hw_compat_5_0_len
= G_N_ELEMENTS(hw_compat_5_0
);
133 GlobalProperty hw_compat_4_2
[] = {
134 { "virtio-blk-device", "queue-size", "128"},
135 { "virtio-scsi-device", "virtqueue_size", "128"},
136 { "virtio-blk-device", "x-enable-wce-if-config-wce", "off" },
137 { "virtio-blk-device", "seg-max-adjust", "off"},
138 { "virtio-scsi-device", "seg_max_adjust", "off"},
139 { "vhost-blk-device", "seg_max_adjust", "off"},
140 { "usb-host", "suppress-remote-wake", "off" },
141 { "usb-redir", "suppress-remote-wake", "off" },
142 { "qxl", "revision", "4" },
143 { "qxl-vga", "revision", "4" },
144 { "fw_cfg", "acpi-mr-restore", "false" },
145 { "virtio-device", "use-disabled-flag", "false" },
147 const size_t hw_compat_4_2_len
= G_N_ELEMENTS(hw_compat_4_2
);
149 GlobalProperty hw_compat_4_1
[] = {
150 { "virtio-pci", "x-pcie-flr-init", "off" },
152 const size_t hw_compat_4_1_len
= G_N_ELEMENTS(hw_compat_4_1
);
154 GlobalProperty hw_compat_4_0
[] = {
155 { "VGA", "edid", "false" },
156 { "secondary-vga", "edid", "false" },
157 { "bochs-display", "edid", "false" },
158 { "virtio-vga", "edid", "false" },
159 { "virtio-gpu-device", "edid", "false" },
160 { "virtio-device", "use-started", "false" },
161 { "virtio-balloon-device", "qemu-4-0-config-size", "true" },
162 { "pl031", "migrate-tick-offset", "false" },
164 const size_t hw_compat_4_0_len
= G_N_ELEMENTS(hw_compat_4_0
);
166 GlobalProperty hw_compat_3_1
[] = {
167 { "pcie-root-port", "x-speed", "2_5" },
168 { "pcie-root-port", "x-width", "1" },
169 { "memory-backend-file", "x-use-canonical-path-for-ramblock-id", "true" },
170 { "memory-backend-memfd", "x-use-canonical-path-for-ramblock-id", "true" },
171 { "tpm-crb", "ppi", "false" },
172 { "tpm-tis", "ppi", "false" },
173 { "usb-kbd", "serial", "42" },
174 { "usb-mouse", "serial", "42" },
175 { "usb-tablet", "serial", "42" },
176 { "virtio-blk-device", "discard", "false" },
177 { "virtio-blk-device", "write-zeroes", "false" },
178 { "virtio-balloon-device", "qemu-4-0-config-size", "false" },
179 { "pcie-root-port-base", "disable-acs", "true" }, /* Added in 4.1 */
181 const size_t hw_compat_3_1_len
= G_N_ELEMENTS(hw_compat_3_1
);
183 GlobalProperty hw_compat_3_0
[] = {};
184 const size_t hw_compat_3_0_len
= G_N_ELEMENTS(hw_compat_3_0
);
186 GlobalProperty hw_compat_2_12
[] = {
187 { "migration", "decompress-error-check", "off" },
188 { "hda-audio", "use-timer", "false" },
189 { "cirrus-vga", "global-vmstate", "true" },
190 { "VGA", "global-vmstate", "true" },
191 { "vmware-svga", "global-vmstate", "true" },
192 { "qxl-vga", "global-vmstate", "true" },
194 const size_t hw_compat_2_12_len
= G_N_ELEMENTS(hw_compat_2_12
);
196 GlobalProperty hw_compat_2_11
[] = {
197 { "hpet", "hpet-offset-saved", "false" },
198 { "virtio-blk-pci", "vectors", "2" },
199 { "vhost-user-blk-pci", "vectors", "2" },
200 { "e1000", "migrate_tso_props", "off" },
202 const size_t hw_compat_2_11_len
= G_N_ELEMENTS(hw_compat_2_11
);
204 GlobalProperty hw_compat_2_10
[] = {
205 { "virtio-mouse-device", "wheel-axis", "false" },
206 { "virtio-tablet-device", "wheel-axis", "false" },
208 const size_t hw_compat_2_10_len
= G_N_ELEMENTS(hw_compat_2_10
);
210 GlobalProperty hw_compat_2_9
[] = {
211 { "pci-bridge", "shpc", "off" },
212 { "intel-iommu", "pt", "off" },
213 { "virtio-net-device", "x-mtu-bypass-backend", "off" },
214 { "pcie-root-port", "x-migrate-msix", "false" },
216 const size_t hw_compat_2_9_len
= G_N_ELEMENTS(hw_compat_2_9
);
218 GlobalProperty hw_compat_2_8
[] = {
219 { "fw_cfg_mem", "x-file-slots", "0x10" },
220 { "fw_cfg_io", "x-file-slots", "0x10" },
221 { "pflash_cfi01", "old-multiple-chip-handling", "on" },
222 { "pci-bridge", "shpc", "on" },
223 { TYPE_PCI_DEVICE
, "x-pcie-extcap-init", "off" },
224 { "virtio-pci", "x-pcie-deverr-init", "off" },
225 { "virtio-pci", "x-pcie-lnkctl-init", "off" },
226 { "virtio-pci", "x-pcie-pm-init", "off" },
227 { "cirrus-vga", "vgamem_mb", "8" },
228 { "isa-cirrus-vga", "vgamem_mb", "8" },
230 const size_t hw_compat_2_8_len
= G_N_ELEMENTS(hw_compat_2_8
);
232 GlobalProperty hw_compat_2_7
[] = {
233 { "virtio-pci", "page-per-vq", "on" },
234 { "virtio-serial-device", "emergency-write", "off" },
235 { "ioapic", "version", "0x11" },
236 { "intel-iommu", "x-buggy-eim", "true" },
237 { "virtio-pci", "x-ignore-backend-features", "on" },
239 const size_t hw_compat_2_7_len
= G_N_ELEMENTS(hw_compat_2_7
);
241 GlobalProperty hw_compat_2_6
[] = {
242 { "virtio-mmio", "format_transport_address", "off" },
243 /* Optional because not all virtio-pci devices support legacy mode */
244 { "virtio-pci", "disable-modern", "on", .optional
= true },
245 { "virtio-pci", "disable-legacy", "off", .optional
= true },
247 const size_t hw_compat_2_6_len
= G_N_ELEMENTS(hw_compat_2_6
);
249 GlobalProperty hw_compat_2_5
[] = {
250 { "isa-fdc", "fallback", "144" },
251 { "pvscsi", "x-old-pci-configuration", "on" },
252 { "pvscsi", "x-disable-pcie", "on" },
253 { "vmxnet3", "x-old-msi-offsets", "on" },
254 { "vmxnet3", "x-disable-pcie", "on" },
256 const size_t hw_compat_2_5_len
= G_N_ELEMENTS(hw_compat_2_5
);
258 GlobalProperty hw_compat_2_4
[] = {
259 /* Optional because the 'scsi' property is Linux-only */
260 { "virtio-blk-device", "scsi", "true", .optional
= true },
261 { "e1000", "extra_mac_registers", "off" },
262 { "virtio-pci", "x-disable-pcie", "on" },
263 { "virtio-pci", "migrate-extra", "off" },
264 { "fw_cfg_mem", "dma_enabled", "off" },
265 { "fw_cfg_io", "dma_enabled", "off" }
267 const size_t hw_compat_2_4_len
= G_N_ELEMENTS(hw_compat_2_4
);
269 GlobalProperty hw_compat_2_3
[] = {
270 { "virtio-blk-pci", "any_layout", "off" },
271 { "virtio-balloon-pci", "any_layout", "off" },
272 { "virtio-serial-pci", "any_layout", "off" },
273 { "virtio-9p-pci", "any_layout", "off" },
274 { "virtio-rng-pci", "any_layout", "off" },
275 { TYPE_PCI_DEVICE
, "x-pcie-lnksta-dllla", "off" },
276 { "migration", "send-configuration", "off" },
277 { "migration", "send-section-footer", "off" },
278 { "migration", "store-global-state", "off" },
280 const size_t hw_compat_2_3_len
= G_N_ELEMENTS(hw_compat_2_3
);
282 GlobalProperty hw_compat_2_2
[] = {};
283 const size_t hw_compat_2_2_len
= G_N_ELEMENTS(hw_compat_2_2
);
285 GlobalProperty hw_compat_2_1
[] = {
286 { "intel-hda", "old_msi_addr", "on" },
287 { "VGA", "qemu-extended-regs", "off" },
288 { "secondary-vga", "qemu-extended-regs", "off" },
289 { "virtio-scsi-pci", "any_layout", "off" },
290 { "usb-mouse", "usb_version", "1" },
291 { "usb-kbd", "usb_version", "1" },
292 { "virtio-pci", "virtio-pci-bus-master-bug-migration", "on" },
294 const size_t hw_compat_2_1_len
= G_N_ELEMENTS(hw_compat_2_1
);
296 MachineState
*current_machine
;
298 static char *machine_get_kernel(Object
*obj
, Error
**errp
)
300 MachineState
*ms
= MACHINE(obj
);
302 return g_strdup(ms
->kernel_filename
);
305 static void machine_set_kernel(Object
*obj
, const char *value
, Error
**errp
)
307 MachineState
*ms
= MACHINE(obj
);
309 g_free(ms
->kernel_filename
);
310 ms
->kernel_filename
= g_strdup(value
);
313 static char *machine_get_initrd(Object
*obj
, Error
**errp
)
315 MachineState
*ms
= MACHINE(obj
);
317 return g_strdup(ms
->initrd_filename
);
320 static void machine_set_initrd(Object
*obj
, const char *value
, Error
**errp
)
322 MachineState
*ms
= MACHINE(obj
);
324 g_free(ms
->initrd_filename
);
325 ms
->initrd_filename
= g_strdup(value
);
328 static char *machine_get_append(Object
*obj
, Error
**errp
)
330 MachineState
*ms
= MACHINE(obj
);
332 return g_strdup(ms
->kernel_cmdline
);
335 static void machine_set_append(Object
*obj
, const char *value
, Error
**errp
)
337 MachineState
*ms
= MACHINE(obj
);
339 g_free(ms
->kernel_cmdline
);
340 ms
->kernel_cmdline
= g_strdup(value
);
343 static char *machine_get_dtb(Object
*obj
, Error
**errp
)
345 MachineState
*ms
= MACHINE(obj
);
347 return g_strdup(ms
->dtb
);
350 static void machine_set_dtb(Object
*obj
, const char *value
, Error
**errp
)
352 MachineState
*ms
= MACHINE(obj
);
355 ms
->dtb
= g_strdup(value
);
358 static char *machine_get_dumpdtb(Object
*obj
, Error
**errp
)
360 MachineState
*ms
= MACHINE(obj
);
362 return g_strdup(ms
->dumpdtb
);
365 static void machine_set_dumpdtb(Object
*obj
, const char *value
, Error
**errp
)
367 MachineState
*ms
= MACHINE(obj
);
370 ms
->dumpdtb
= g_strdup(value
);
373 static void machine_get_phandle_start(Object
*obj
, Visitor
*v
,
374 const char *name
, void *opaque
,
377 MachineState
*ms
= MACHINE(obj
);
378 int64_t value
= ms
->phandle_start
;
380 visit_type_int(v
, name
, &value
, errp
);
383 static void machine_set_phandle_start(Object
*obj
, Visitor
*v
,
384 const char *name
, void *opaque
,
387 MachineState
*ms
= MACHINE(obj
);
390 if (!visit_type_int(v
, name
, &value
, errp
)) {
394 ms
->phandle_start
= value
;
397 static char *machine_get_dt_compatible(Object
*obj
, Error
**errp
)
399 MachineState
*ms
= MACHINE(obj
);
401 return g_strdup(ms
->dt_compatible
);
404 static void machine_set_dt_compatible(Object
*obj
, const char *value
, Error
**errp
)
406 MachineState
*ms
= MACHINE(obj
);
408 g_free(ms
->dt_compatible
);
409 ms
->dt_compatible
= g_strdup(value
);
412 static bool machine_get_dump_guest_core(Object
*obj
, Error
**errp
)
414 MachineState
*ms
= MACHINE(obj
);
416 return ms
->dump_guest_core
;
419 static void machine_set_dump_guest_core(Object
*obj
, bool value
, Error
**errp
)
421 MachineState
*ms
= MACHINE(obj
);
423 ms
->dump_guest_core
= value
;
426 static bool machine_get_mem_merge(Object
*obj
, Error
**errp
)
428 MachineState
*ms
= MACHINE(obj
);
430 return ms
->mem_merge
;
433 static void machine_set_mem_merge(Object
*obj
, bool value
, Error
**errp
)
435 MachineState
*ms
= MACHINE(obj
);
437 ms
->mem_merge
= value
;
440 static bool machine_get_usb(Object
*obj
, Error
**errp
)
442 MachineState
*ms
= MACHINE(obj
);
447 static void machine_set_usb(Object
*obj
, bool value
, Error
**errp
)
449 MachineState
*ms
= MACHINE(obj
);
452 ms
->usb_disabled
= !value
;
455 static bool machine_get_graphics(Object
*obj
, Error
**errp
)
457 MachineState
*ms
= MACHINE(obj
);
459 return ms
->enable_graphics
;
462 static void machine_set_graphics(Object
*obj
, bool value
, Error
**errp
)
464 MachineState
*ms
= MACHINE(obj
);
466 ms
->enable_graphics
= value
;
469 static char *machine_get_firmware(Object
*obj
, Error
**errp
)
471 MachineState
*ms
= MACHINE(obj
);
473 return g_strdup(ms
->firmware
);
476 static void machine_set_firmware(Object
*obj
, const char *value
, Error
**errp
)
478 MachineState
*ms
= MACHINE(obj
);
480 g_free(ms
->firmware
);
481 ms
->firmware
= g_strdup(value
);
484 static void machine_set_suppress_vmdesc(Object
*obj
, bool value
, Error
**errp
)
486 MachineState
*ms
= MACHINE(obj
);
488 ms
->suppress_vmdesc
= value
;
491 static bool machine_get_suppress_vmdesc(Object
*obj
, Error
**errp
)
493 MachineState
*ms
= MACHINE(obj
);
495 return ms
->suppress_vmdesc
;
498 static char *machine_get_memory_encryption(Object
*obj
, Error
**errp
)
500 MachineState
*ms
= MACHINE(obj
);
503 return g_strdup(object_get_canonical_path_component(OBJECT(ms
->cgs
)));
509 static void machine_set_memory_encryption(Object
*obj
, const char *value
,
513 object_resolve_path_component(object_get_objects_root(), value
);
516 error_setg(errp
, "No such memory encryption object '%s'", value
);
520 object_property_set_link(obj
, "confidential-guest-support", cgs
, errp
);
523 static void machine_check_confidential_guest_support(const Object
*obj
,
529 * So far the only constraint is that the target has the
530 * TYPE_CONFIDENTIAL_GUEST_SUPPORT interface, and that's checked
535 static bool machine_get_nvdimm(Object
*obj
, Error
**errp
)
537 MachineState
*ms
= MACHINE(obj
);
539 return ms
->nvdimms_state
->is_enabled
;
542 static void machine_set_nvdimm(Object
*obj
, bool value
, Error
**errp
)
544 MachineState
*ms
= MACHINE(obj
);
546 ms
->nvdimms_state
->is_enabled
= value
;
549 static bool machine_get_hmat(Object
*obj
, Error
**errp
)
551 MachineState
*ms
= MACHINE(obj
);
553 return ms
->numa_state
->hmat_enabled
;
556 static void machine_set_hmat(Object
*obj
, bool value
, Error
**errp
)
558 MachineState
*ms
= MACHINE(obj
);
560 ms
->numa_state
->hmat_enabled
= value
;
563 static void machine_get_mem(Object
*obj
, Visitor
*v
, const char *name
,
564 void *opaque
, Error
**errp
)
566 MachineState
*ms
= MACHINE(obj
);
567 MemorySizeConfiguration mem
= {
569 .size
= ms
->ram_size
,
570 .has_max_size
= !!ms
->ram_slots
,
571 .max_size
= ms
->maxram_size
,
572 .has_slots
= !!ms
->ram_slots
,
573 .slots
= ms
->ram_slots
,
575 MemorySizeConfiguration
*p_mem
= &mem
;
577 visit_type_MemorySizeConfiguration(v
, name
, &p_mem
, &error_abort
);
580 static void machine_set_mem(Object
*obj
, Visitor
*v
, const char *name
,
581 void *opaque
, Error
**errp
)
584 MachineState
*ms
= MACHINE(obj
);
585 MachineClass
*mc
= MACHINE_GET_CLASS(obj
);
586 MemorySizeConfiguration
*mem
;
588 if (!visit_type_MemorySizeConfiguration(v
, name
, &mem
, errp
)) {
592 if (!mem
->has_size
) {
593 mem
->has_size
= true;
594 mem
->size
= mc
->default_ram_size
;
596 mem
->size
= QEMU_ALIGN_UP(mem
->size
, 8192);
597 if (mc
->fixup_ram_size
) {
598 mem
->size
= mc
->fixup_ram_size(mem
->size
);
600 if ((ram_addr_t
)mem
->size
!= mem
->size
) {
601 error_setg(errp
, "ram size too large");
605 if (mem
->has_max_size
) {
606 if (mem
->max_size
< mem
->size
) {
607 error_setg(errp
, "invalid value of maxmem: "
608 "maximum memory size (0x%" PRIx64
") must be at least "
609 "the initial memory size (0x%" PRIx64
")",
610 mem
->max_size
, mem
->size
);
613 if (mem
->has_slots
&& mem
->slots
&& mem
->max_size
== mem
->size
) {
614 error_setg(errp
, "invalid value of maxmem: "
615 "memory slots were specified but maximum memory size "
616 "(0x%" PRIx64
") is equal to the initial memory size "
617 "(0x%" PRIx64
")", mem
->max_size
, mem
->size
);
620 ms
->maxram_size
= mem
->max_size
;
622 if (mem
->has_slots
) {
623 error_setg(errp
, "slots specified but no max-size");
626 ms
->maxram_size
= mem
->size
;
628 ms
->ram_size
= mem
->size
;
629 ms
->ram_slots
= mem
->has_slots
? mem
->slots
: 0;
631 qapi_free_MemorySizeConfiguration(mem
);
634 static char *machine_get_nvdimm_persistence(Object
*obj
, Error
**errp
)
636 MachineState
*ms
= MACHINE(obj
);
638 return g_strdup(ms
->nvdimms_state
->persistence_string
);
641 static void machine_set_nvdimm_persistence(Object
*obj
, const char *value
,
644 MachineState
*ms
= MACHINE(obj
);
645 NVDIMMState
*nvdimms_state
= ms
->nvdimms_state
;
647 if (strcmp(value
, "cpu") == 0) {
648 nvdimms_state
->persistence
= 3;
649 } else if (strcmp(value
, "mem-ctrl") == 0) {
650 nvdimms_state
->persistence
= 2;
652 error_setg(errp
, "-machine nvdimm-persistence=%s: unsupported option",
657 g_free(nvdimms_state
->persistence_string
);
658 nvdimms_state
->persistence_string
= g_strdup(value
);
661 void machine_class_allow_dynamic_sysbus_dev(MachineClass
*mc
, const char *type
)
663 QAPI_LIST_PREPEND(mc
->allowed_dynamic_sysbus_devices
, g_strdup(type
));
666 bool device_is_dynamic_sysbus(MachineClass
*mc
, DeviceState
*dev
)
668 Object
*obj
= OBJECT(dev
);
670 if (!object_dynamic_cast(obj
, TYPE_SYS_BUS_DEVICE
)) {
674 return device_type_is_dynamic_sysbus(mc
, object_get_typename(obj
));
677 bool device_type_is_dynamic_sysbus(MachineClass
*mc
, const char *type
)
679 bool allowed
= false;
681 ObjectClass
*klass
= object_class_by_name(type
);
683 for (wl
= mc
->allowed_dynamic_sysbus_devices
;
686 allowed
|= !!object_class_dynamic_cast(klass
, wl
->value
);
692 static char *machine_get_audiodev(Object
*obj
, Error
**errp
)
694 MachineState
*ms
= MACHINE(obj
);
696 return g_strdup(ms
->audiodev
);
699 static void machine_set_audiodev(Object
*obj
, const char *value
,
702 MachineState
*ms
= MACHINE(obj
);
704 if (!audio_state_by_name(value
, errp
)) {
708 g_free(ms
->audiodev
);
709 ms
->audiodev
= g_strdup(value
);
712 HotpluggableCPUList
*machine_query_hotpluggable_cpus(MachineState
*machine
)
715 HotpluggableCPUList
*head
= NULL
;
716 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
718 /* force board to initialize possible_cpus if it hasn't been done yet */
719 mc
->possible_cpu_arch_ids(machine
);
721 for (i
= 0; i
< machine
->possible_cpus
->len
; i
++) {
723 HotpluggableCPU
*cpu_item
= g_new0(typeof(*cpu_item
), 1);
725 cpu_item
->type
= g_strdup(machine
->possible_cpus
->cpus
[i
].type
);
726 cpu_item
->vcpus_count
= machine
->possible_cpus
->cpus
[i
].vcpus_count
;
727 cpu_item
->props
= g_memdup(&machine
->possible_cpus
->cpus
[i
].props
,
728 sizeof(*cpu_item
->props
));
730 cpu
= machine
->possible_cpus
->cpus
[i
].cpu
;
732 cpu_item
->qom_path
= object_get_canonical_path(OBJECT(cpu
));
734 QAPI_LIST_PREPEND(head
, cpu_item
);
740 * machine_set_cpu_numa_node:
741 * @machine: machine object to modify
742 * @props: specifies which cpu objects to assign to
743 * numa node specified by @props.node_id
744 * @errp: if an error occurs, a pointer to an area to store the error
746 * Associate NUMA node specified by @props.node_id with cpu slots that
747 * match socket/core/thread-ids specified by @props. It's recommended to use
748 * query-hotpluggable-cpus.props values to specify affected cpu slots,
749 * which would lead to exact 1:1 mapping of cpu slots to NUMA node.
751 * However for CLI convenience it's possible to pass in subset of properties,
752 * which would affect all cpu slots that match it.
754 * -smp 4,cores=2,sockets=2 -numa node,nodeid=0 -numa node,nodeid=1 \
755 * -numa cpu,node-id=0,socket_id=0 \
756 * -numa cpu,node-id=1,socket_id=1
757 * will assign all child cores of socket 0 to node 0 and
758 * of socket 1 to node 1.
760 * On attempt of reassigning (already assigned) cpu slot to another NUMA node,
762 * Empty subset is disallowed and function will return with error in this case.
764 void machine_set_cpu_numa_node(MachineState
*machine
,
765 const CpuInstanceProperties
*props
, Error
**errp
)
767 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
768 NodeInfo
*numa_info
= machine
->numa_state
->nodes
;
772 if (!mc
->possible_cpu_arch_ids
) {
773 error_setg(errp
, "mapping of CPUs to NUMA node is not supported");
777 /* disabling node mapping is not supported, forbid it */
778 assert(props
->has_node_id
);
780 /* force board to initialize possible_cpus if it hasn't been done yet */
781 mc
->possible_cpu_arch_ids(machine
);
783 for (i
= 0; i
< machine
->possible_cpus
->len
; i
++) {
784 CPUArchId
*slot
= &machine
->possible_cpus
->cpus
[i
];
786 /* reject unsupported by board properties */
787 if (props
->has_thread_id
&& !slot
->props
.has_thread_id
) {
788 error_setg(errp
, "thread-id is not supported");
792 if (props
->has_core_id
&& !slot
->props
.has_core_id
) {
793 error_setg(errp
, "core-id is not supported");
797 if (props
->has_cluster_id
&& !slot
->props
.has_cluster_id
) {
798 error_setg(errp
, "cluster-id is not supported");
802 if (props
->has_socket_id
&& !slot
->props
.has_socket_id
) {
803 error_setg(errp
, "socket-id is not supported");
807 if (props
->has_die_id
&& !slot
->props
.has_die_id
) {
808 error_setg(errp
, "die-id is not supported");
812 /* skip slots with explicit mismatch */
813 if (props
->has_thread_id
&& props
->thread_id
!= slot
->props
.thread_id
) {
817 if (props
->has_core_id
&& props
->core_id
!= slot
->props
.core_id
) {
821 if (props
->has_cluster_id
&&
822 props
->cluster_id
!= slot
->props
.cluster_id
) {
826 if (props
->has_die_id
&& props
->die_id
!= slot
->props
.die_id
) {
830 if (props
->has_socket_id
&& props
->socket_id
!= slot
->props
.socket_id
) {
834 /* reject assignment if slot is already assigned, for compatibility
835 * of legacy cpu_index mapping with SPAPR core based mapping do not
836 * error out if cpu thread and matched core have the same node-id */
837 if (slot
->props
.has_node_id
&&
838 slot
->props
.node_id
!= props
->node_id
) {
839 error_setg(errp
, "CPU is already assigned to node-id: %" PRId64
,
840 slot
->props
.node_id
);
844 /* assign slot to node as it's matched '-numa cpu' key */
846 slot
->props
.node_id
= props
->node_id
;
847 slot
->props
.has_node_id
= props
->has_node_id
;
849 if (machine
->numa_state
->hmat_enabled
) {
850 if ((numa_info
[props
->node_id
].initiator
< MAX_NODES
) &&
851 (props
->node_id
!= numa_info
[props
->node_id
].initiator
)) {
852 error_setg(errp
, "The initiator of CPU NUMA node %" PRId64
853 " should be itself (got %" PRIu16
")",
854 props
->node_id
, numa_info
[props
->node_id
].initiator
);
857 numa_info
[props
->node_id
].has_cpu
= true;
858 numa_info
[props
->node_id
].initiator
= props
->node_id
;
863 error_setg(errp
, "no match found");
867 static void machine_get_smp(Object
*obj
, Visitor
*v
, const char *name
,
868 void *opaque
, Error
**errp
)
870 MachineState
*ms
= MACHINE(obj
);
871 SMPConfiguration
*config
= &(SMPConfiguration
){
872 .has_cpus
= true, .cpus
= ms
->smp
.cpus
,
873 .has_drawers
= true, .drawers
= ms
->smp
.drawers
,
874 .has_books
= true, .books
= ms
->smp
.books
,
875 .has_sockets
= true, .sockets
= ms
->smp
.sockets
,
876 .has_dies
= true, .dies
= ms
->smp
.dies
,
877 .has_clusters
= true, .clusters
= ms
->smp
.clusters
,
878 .has_cores
= true, .cores
= ms
->smp
.cores
,
879 .has_threads
= true, .threads
= ms
->smp
.threads
,
880 .has_maxcpus
= true, .maxcpus
= ms
->smp
.max_cpus
,
883 if (!visit_type_SMPConfiguration(v
, name
, &config
, &error_abort
)) {
888 static void machine_set_smp(Object
*obj
, Visitor
*v
, const char *name
,
889 void *opaque
, Error
**errp
)
891 MachineState
*ms
= MACHINE(obj
);
892 g_autoptr(SMPConfiguration
) config
= NULL
;
894 if (!visit_type_SMPConfiguration(v
, name
, &config
, errp
)) {
898 machine_parse_smp_config(ms
, config
, errp
);
901 static void machine_get_boot(Object
*obj
, Visitor
*v
, const char *name
,
902 void *opaque
, Error
**errp
)
904 MachineState
*ms
= MACHINE(obj
);
905 BootConfiguration
*config
= &ms
->boot_config
;
906 visit_type_BootConfiguration(v
, name
, &config
, &error_abort
);
909 static void machine_free_boot_config(MachineState
*ms
)
911 g_free(ms
->boot_config
.order
);
912 g_free(ms
->boot_config
.once
);
913 g_free(ms
->boot_config
.splash
);
916 static void machine_copy_boot_config(MachineState
*ms
, BootConfiguration
*config
)
918 MachineClass
*machine_class
= MACHINE_GET_CLASS(ms
);
920 machine_free_boot_config(ms
);
921 ms
->boot_config
= *config
;
922 if (!config
->order
) {
923 ms
->boot_config
.order
= g_strdup(machine_class
->default_boot_order
);
927 static void machine_set_boot(Object
*obj
, Visitor
*v
, const char *name
,
928 void *opaque
, Error
**errp
)
931 MachineState
*ms
= MACHINE(obj
);
932 BootConfiguration
*config
= NULL
;
934 if (!visit_type_BootConfiguration(v
, name
, &config
, errp
)) {
938 validate_bootdevices(config
->order
, errp
);
944 validate_bootdevices(config
->once
, errp
);
950 machine_copy_boot_config(ms
, config
);
951 /* Strings live in ms->boot_config. */
956 qapi_free_BootConfiguration(config
);
959 void machine_add_audiodev_property(MachineClass
*mc
)
961 ObjectClass
*oc
= OBJECT_CLASS(mc
);
963 object_class_property_add_str(oc
, "audiodev",
964 machine_get_audiodev
,
965 machine_set_audiodev
);
966 object_class_property_set_description(oc
, "audiodev",
967 "Audiodev to use for default machine devices");
970 static void machine_class_init(ObjectClass
*oc
, void *data
)
972 MachineClass
*mc
= MACHINE_CLASS(oc
);
974 /* Default 128 MB as guest ram size */
975 mc
->default_ram_size
= 128 * MiB
;
976 mc
->rom_file_has_mr
= true;
978 /* numa node memory size aligned on 8MB by default.
979 * On Linux, each node's border has to be 8MB aligned
981 mc
->numa_mem_align_shift
= 23;
983 object_class_property_add_str(oc
, "kernel",
984 machine_get_kernel
, machine_set_kernel
);
985 object_class_property_set_description(oc
, "kernel",
986 "Linux kernel image file");
988 object_class_property_add_str(oc
, "initrd",
989 machine_get_initrd
, machine_set_initrd
);
990 object_class_property_set_description(oc
, "initrd",
991 "Linux initial ramdisk file");
993 object_class_property_add_str(oc
, "append",
994 machine_get_append
, machine_set_append
);
995 object_class_property_set_description(oc
, "append",
996 "Linux kernel command line");
998 object_class_property_add_str(oc
, "dtb",
999 machine_get_dtb
, machine_set_dtb
);
1000 object_class_property_set_description(oc
, "dtb",
1001 "Linux kernel device tree file");
1003 object_class_property_add_str(oc
, "dumpdtb",
1004 machine_get_dumpdtb
, machine_set_dumpdtb
);
1005 object_class_property_set_description(oc
, "dumpdtb",
1006 "Dump current dtb to a file and quit");
1008 object_class_property_add(oc
, "boot", "BootConfiguration",
1009 machine_get_boot
, machine_set_boot
,
1011 object_class_property_set_description(oc
, "boot",
1012 "Boot configuration");
1014 object_class_property_add(oc
, "smp", "SMPConfiguration",
1015 machine_get_smp
, machine_set_smp
,
1017 object_class_property_set_description(oc
, "smp",
1020 object_class_property_add(oc
, "phandle-start", "int",
1021 machine_get_phandle_start
, machine_set_phandle_start
,
1023 object_class_property_set_description(oc
, "phandle-start",
1024 "The first phandle ID we may generate dynamically");
1026 object_class_property_add_str(oc
, "dt-compatible",
1027 machine_get_dt_compatible
, machine_set_dt_compatible
);
1028 object_class_property_set_description(oc
, "dt-compatible",
1029 "Overrides the \"compatible\" property of the dt root node");
1031 object_class_property_add_bool(oc
, "dump-guest-core",
1032 machine_get_dump_guest_core
, machine_set_dump_guest_core
);
1033 object_class_property_set_description(oc
, "dump-guest-core",
1034 "Include guest memory in a core dump");
1036 object_class_property_add_bool(oc
, "mem-merge",
1037 machine_get_mem_merge
, machine_set_mem_merge
);
1038 object_class_property_set_description(oc
, "mem-merge",
1039 "Enable/disable memory merge support");
1041 object_class_property_add_bool(oc
, "usb",
1042 machine_get_usb
, machine_set_usb
);
1043 object_class_property_set_description(oc
, "usb",
1044 "Set on/off to enable/disable usb");
1046 object_class_property_add_bool(oc
, "graphics",
1047 machine_get_graphics
, machine_set_graphics
);
1048 object_class_property_set_description(oc
, "graphics",
1049 "Set on/off to enable/disable graphics emulation");
1051 object_class_property_add_str(oc
, "firmware",
1052 machine_get_firmware
, machine_set_firmware
);
1053 object_class_property_set_description(oc
, "firmware",
1056 object_class_property_add_bool(oc
, "suppress-vmdesc",
1057 machine_get_suppress_vmdesc
, machine_set_suppress_vmdesc
);
1058 object_class_property_set_description(oc
, "suppress-vmdesc",
1059 "Set on to disable self-describing migration");
1061 object_class_property_add_link(oc
, "confidential-guest-support",
1062 TYPE_CONFIDENTIAL_GUEST_SUPPORT
,
1063 offsetof(MachineState
, cgs
),
1064 machine_check_confidential_guest_support
,
1065 OBJ_PROP_LINK_STRONG
);
1066 object_class_property_set_description(oc
, "confidential-guest-support",
1067 "Set confidential guest scheme to support");
1069 /* For compatibility */
1070 object_class_property_add_str(oc
, "memory-encryption",
1071 machine_get_memory_encryption
, machine_set_memory_encryption
);
1072 object_class_property_set_description(oc
, "memory-encryption",
1073 "Set memory encryption object to use");
1075 object_class_property_add_link(oc
, "memory-backend", TYPE_MEMORY_BACKEND
,
1076 offsetof(MachineState
, memdev
), object_property_allow_set_link
,
1077 OBJ_PROP_LINK_STRONG
);
1078 object_class_property_set_description(oc
, "memory-backend",
1080 "Valid value is ID of hostmem based backend");
1082 object_class_property_add(oc
, "memory", "MemorySizeConfiguration",
1083 machine_get_mem
, machine_set_mem
,
1085 object_class_property_set_description(oc
, "memory",
1086 "Memory size configuration");
1089 static void machine_class_base_init(ObjectClass
*oc
, void *data
)
1091 MachineClass
*mc
= MACHINE_CLASS(oc
);
1092 mc
->max_cpus
= mc
->max_cpus
?: 1;
1093 mc
->min_cpus
= mc
->min_cpus
?: 1;
1094 mc
->default_cpus
= mc
->default_cpus
?: 1;
1096 if (!object_class_is_abstract(oc
)) {
1097 const char *cname
= object_class_get_name(oc
);
1098 assert(g_str_has_suffix(cname
, TYPE_MACHINE_SUFFIX
));
1099 mc
->name
= g_strndup(cname
,
1100 strlen(cname
) - strlen(TYPE_MACHINE_SUFFIX
));
1101 mc
->compat_props
= g_ptr_array_new();
1105 static void machine_initfn(Object
*obj
)
1107 MachineState
*ms
= MACHINE(obj
);
1108 MachineClass
*mc
= MACHINE_GET_CLASS(obj
);
1110 container_get(obj
, "/peripheral");
1111 container_get(obj
, "/peripheral-anon");
1113 ms
->dump_guest_core
= true;
1114 ms
->mem_merge
= true;
1115 ms
->enable_graphics
= true;
1116 ms
->kernel_cmdline
= g_strdup("");
1117 ms
->ram_size
= mc
->default_ram_size
;
1118 ms
->maxram_size
= mc
->default_ram_size
;
1120 if (mc
->nvdimm_supported
) {
1121 ms
->nvdimms_state
= g_new0(NVDIMMState
, 1);
1122 object_property_add_bool(obj
, "nvdimm",
1123 machine_get_nvdimm
, machine_set_nvdimm
);
1124 object_property_set_description(obj
, "nvdimm",
1125 "Set on/off to enable/disable "
1126 "NVDIMM instantiation");
1128 object_property_add_str(obj
, "nvdimm-persistence",
1129 machine_get_nvdimm_persistence
,
1130 machine_set_nvdimm_persistence
);
1131 object_property_set_description(obj
, "nvdimm-persistence",
1132 "Set NVDIMM persistence"
1133 "Valid values are cpu, mem-ctrl");
1136 if (mc
->cpu_index_to_instance_props
&& mc
->get_default_cpu_node_id
) {
1137 ms
->numa_state
= g_new0(NumaState
, 1);
1138 object_property_add_bool(obj
, "hmat",
1139 machine_get_hmat
, machine_set_hmat
);
1140 object_property_set_description(obj
, "hmat",
1141 "Set on/off to enable/disable "
1142 "ACPI Heterogeneous Memory Attribute "
1146 /* default to mc->default_cpus */
1147 ms
->smp
.cpus
= mc
->default_cpus
;
1148 ms
->smp
.max_cpus
= mc
->default_cpus
;
1149 ms
->smp
.drawers
= 1;
1151 ms
->smp
.sockets
= 1;
1153 ms
->smp
.clusters
= 1;
1155 ms
->smp
.threads
= 1;
1157 machine_copy_boot_config(ms
, &(BootConfiguration
){ 0 });
1160 static void machine_finalize(Object
*obj
)
1162 MachineState
*ms
= MACHINE(obj
);
1164 machine_free_boot_config(ms
);
1165 g_free(ms
->kernel_filename
);
1166 g_free(ms
->initrd_filename
);
1167 g_free(ms
->kernel_cmdline
);
1169 g_free(ms
->dumpdtb
);
1170 g_free(ms
->dt_compatible
);
1171 g_free(ms
->firmware
);
1172 g_free(ms
->device_memory
);
1173 g_free(ms
->nvdimms_state
);
1174 g_free(ms
->numa_state
);
1175 g_free(ms
->audiodev
);
1178 bool machine_usb(MachineState
*machine
)
1180 return machine
->usb
;
1183 int machine_phandle_start(MachineState
*machine
)
1185 return machine
->phandle_start
;
1188 bool machine_dump_guest_core(MachineState
*machine
)
1190 return machine
->dump_guest_core
;
1193 bool machine_mem_merge(MachineState
*machine
)
1195 return machine
->mem_merge
;
1198 static char *cpu_slot_to_string(const CPUArchId
*cpu
)
1200 GString
*s
= g_string_new(NULL
);
1201 if (cpu
->props
.has_socket_id
) {
1202 g_string_append_printf(s
, "socket-id: %"PRId64
, cpu
->props
.socket_id
);
1204 if (cpu
->props
.has_die_id
) {
1206 g_string_append_printf(s
, ", ");
1208 g_string_append_printf(s
, "die-id: %"PRId64
, cpu
->props
.die_id
);
1210 if (cpu
->props
.has_cluster_id
) {
1212 g_string_append_printf(s
, ", ");
1214 g_string_append_printf(s
, "cluster-id: %"PRId64
, cpu
->props
.cluster_id
);
1216 if (cpu
->props
.has_core_id
) {
1218 g_string_append_printf(s
, ", ");
1220 g_string_append_printf(s
, "core-id: %"PRId64
, cpu
->props
.core_id
);
1222 if (cpu
->props
.has_thread_id
) {
1224 g_string_append_printf(s
, ", ");
1226 g_string_append_printf(s
, "thread-id: %"PRId64
, cpu
->props
.thread_id
);
1228 return g_string_free(s
, false);
1231 static void numa_validate_initiator(NumaState
*numa_state
)
1234 NodeInfo
*numa_info
= numa_state
->nodes
;
1236 for (i
= 0; i
< numa_state
->num_nodes
; i
++) {
1237 if (numa_info
[i
].initiator
== MAX_NODES
) {
1241 if (!numa_info
[numa_info
[i
].initiator
].present
) {
1242 error_report("NUMA node %" PRIu16
" is missing, use "
1243 "'-numa node' option to declare it first",
1244 numa_info
[i
].initiator
);
1248 if (!numa_info
[numa_info
[i
].initiator
].has_cpu
) {
1249 error_report("The initiator of NUMA node %d is invalid", i
);
1255 static void machine_numa_finish_cpu_init(MachineState
*machine
)
1258 bool default_mapping
;
1259 GString
*s
= g_string_new(NULL
);
1260 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
1261 const CPUArchIdList
*possible_cpus
= mc
->possible_cpu_arch_ids(machine
);
1263 assert(machine
->numa_state
->num_nodes
);
1264 for (i
= 0; i
< possible_cpus
->len
; i
++) {
1265 if (possible_cpus
->cpus
[i
].props
.has_node_id
) {
1269 default_mapping
= (i
== possible_cpus
->len
);
1271 for (i
= 0; i
< possible_cpus
->len
; i
++) {
1272 const CPUArchId
*cpu_slot
= &possible_cpus
->cpus
[i
];
1274 if (!cpu_slot
->props
.has_node_id
) {
1275 /* fetch default mapping from board and enable it */
1276 CpuInstanceProperties props
= cpu_slot
->props
;
1278 props
.node_id
= mc
->get_default_cpu_node_id(machine
, i
);
1279 if (!default_mapping
) {
1280 /* record slots with not set mapping,
1281 * TODO: make it hard error in future */
1282 char *cpu_str
= cpu_slot_to_string(cpu_slot
);
1283 g_string_append_printf(s
, "%sCPU %d [%s]",
1284 s
->len
? ", " : "", i
, cpu_str
);
1287 /* non mapped cpus used to fallback to node 0 */
1291 props
.has_node_id
= true;
1292 machine_set_cpu_numa_node(machine
, &props
, &error_fatal
);
1296 if (machine
->numa_state
->hmat_enabled
) {
1297 numa_validate_initiator(machine
->numa_state
);
1300 if (s
->len
&& !qtest_enabled()) {
1301 warn_report("CPU(s) not present in any NUMA nodes: %s",
1303 warn_report("All CPU(s) up to maxcpus should be described "
1304 "in NUMA config, ability to start up with partial NUMA "
1305 "mappings is obsoleted and will be removed in future");
1307 g_string_free(s
, true);
1310 static void validate_cpu_cluster_to_numa_boundary(MachineState
*ms
)
1312 MachineClass
*mc
= MACHINE_GET_CLASS(ms
);
1313 NumaState
*state
= ms
->numa_state
;
1314 const CPUArchIdList
*possible_cpus
= mc
->possible_cpu_arch_ids(ms
);
1315 const CPUArchId
*cpus
= possible_cpus
->cpus
;
1318 if (qtest_enabled() || state
->num_nodes
<= 1 || possible_cpus
->len
<= 1) {
1323 * The Linux scheduling domain can't be parsed when the multiple CPUs
1324 * in one cluster have been associated with different NUMA nodes. However,
1325 * it's fine to associate one NUMA node with CPUs in different clusters.
1327 for (i
= 0; i
< possible_cpus
->len
; i
++) {
1328 for (j
= i
+ 1; j
< possible_cpus
->len
; j
++) {
1329 if (cpus
[i
].props
.has_socket_id
&&
1330 cpus
[i
].props
.has_cluster_id
&&
1331 cpus
[i
].props
.has_node_id
&&
1332 cpus
[j
].props
.has_socket_id
&&
1333 cpus
[j
].props
.has_cluster_id
&&
1334 cpus
[j
].props
.has_node_id
&&
1335 cpus
[i
].props
.socket_id
== cpus
[j
].props
.socket_id
&&
1336 cpus
[i
].props
.cluster_id
== cpus
[j
].props
.cluster_id
&&
1337 cpus
[i
].props
.node_id
!= cpus
[j
].props
.node_id
) {
1338 warn_report("CPU-%d and CPU-%d in socket-%" PRId64
"-cluster-%" PRId64
1339 " have been associated with node-%" PRId64
" and node-%" PRId64
1340 " respectively. It can cause OSes like Linux to"
1341 " misbehave", i
, j
, cpus
[i
].props
.socket_id
,
1342 cpus
[i
].props
.cluster_id
, cpus
[i
].props
.node_id
,
1343 cpus
[j
].props
.node_id
);
1349 MemoryRegion
*machine_consume_memdev(MachineState
*machine
,
1350 HostMemoryBackend
*backend
)
1352 MemoryRegion
*ret
= host_memory_backend_get_memory(backend
);
1354 if (host_memory_backend_is_mapped(backend
)) {
1355 error_report("memory backend %s can't be used multiple times.",
1356 object_get_canonical_path_component(OBJECT(backend
)));
1359 host_memory_backend_set_mapped(backend
, true);
1360 vmstate_register_ram_global(ret
);
1364 static bool create_default_memdev(MachineState
*ms
, const char *path
, Error
**errp
)
1367 MachineClass
*mc
= MACHINE_GET_CLASS(ms
);
1370 obj
= object_new(path
? TYPE_MEMORY_BACKEND_FILE
: TYPE_MEMORY_BACKEND_RAM
);
1372 if (!object_property_set_str(obj
, "mem-path", path
, errp
)) {
1376 if (!object_property_set_int(obj
, "size", ms
->ram_size
, errp
)) {
1379 object_property_add_child(object_get_objects_root(), mc
->default_ram_id
,
1381 /* Ensure backend's memory region name is equal to mc->default_ram_id */
1382 if (!object_property_set_bool(obj
, "x-use-canonical-path-for-ramblock-id",
1386 if (!user_creatable_complete(USER_CREATABLE(obj
), errp
)) {
1389 r
= object_property_set_link(OBJECT(ms
), "memory-backend", obj
, errp
);
1396 const char *machine_class_default_cpu_type(MachineClass
*mc
)
1398 if (mc
->valid_cpu_types
&& !mc
->valid_cpu_types
[1]) {
1399 /* Only a single CPU type allowed: use it as default. */
1400 return mc
->valid_cpu_types
[0];
1402 return mc
->default_cpu_type
;
1405 static bool is_cpu_type_supported(const MachineState
*machine
, Error
**errp
)
1407 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
1408 ObjectClass
*oc
= object_class_by_name(machine
->cpu_type
);
1413 * Check if the user specified CPU type is supported when the valid
1414 * CPU types have been determined. Note that the user specified CPU
1415 * type is provided through '-cpu' option.
1417 if (mc
->valid_cpu_types
) {
1418 assert(mc
->valid_cpu_types
[0] != NULL
);
1419 for (i
= 0; mc
->valid_cpu_types
[i
]; i
++) {
1420 if (object_class_dynamic_cast(oc
, mc
->valid_cpu_types
[i
])) {
1425 /* The user specified CPU type isn't valid */
1426 if (!mc
->valid_cpu_types
[i
]) {
1427 g_autofree
char *requested
= cpu_model_from_type(machine
->cpu_type
);
1428 error_setg(errp
, "Invalid CPU model: %s", requested
);
1429 if (!mc
->valid_cpu_types
[1]) {
1430 g_autofree
char *model
= cpu_model_from_type(
1431 mc
->valid_cpu_types
[0]);
1432 error_append_hint(errp
, "The only valid type is: %s\n", model
);
1434 error_append_hint(errp
, "The valid models are: ");
1435 for (i
= 0; mc
->valid_cpu_types
[i
]; i
++) {
1436 g_autofree
char *model
= cpu_model_from_type(
1437 mc
->valid_cpu_types
[i
]);
1438 error_append_hint(errp
, "%s%s",
1440 mc
->valid_cpu_types
[i
+ 1] ? ", " : "");
1442 error_append_hint(errp
, "\n");
1449 /* Check if CPU type is deprecated and warn if so */
1452 if (cc
->deprecation_note
) {
1453 warn_report("CPU model %s is deprecated -- %s",
1454 machine
->cpu_type
, cc
->deprecation_note
);
1460 void machine_run_board_init(MachineState
*machine
, const char *mem_path
, Error
**errp
)
1463 MachineClass
*machine_class
= MACHINE_GET_CLASS(machine
);
1465 /* This checkpoint is required by replay to separate prior clock
1466 reading from the other reads, because timer polling functions query
1467 clock values from the log. */
1468 replay_checkpoint(CHECKPOINT_INIT
);
1470 if (!xen_enabled()) {
1471 /* On 32-bit hosts, QEMU is limited by virtual address space */
1472 if (machine
->ram_size
> (2047 << 20) && HOST_LONG_BITS
== 32) {
1473 error_setg(errp
, "at most 2047 MB RAM can be simulated");
1478 if (machine
->memdev
) {
1479 ram_addr_t backend_size
= object_property_get_uint(OBJECT(machine
->memdev
),
1480 "size", &error_abort
);
1481 if (backend_size
!= machine
->ram_size
) {
1482 error_setg(errp
, "Machine memory size does not match the size of the memory backend");
1485 } else if (machine_class
->default_ram_id
&& machine
->ram_size
&&
1486 numa_uses_legacy_mem()) {
1487 if (object_property_find(object_get_objects_root(),
1488 machine_class
->default_ram_id
)) {
1489 error_setg(errp
, "object's id '%s' is reserved for the default"
1490 " RAM backend, it can't be used for any other purposes",
1491 machine_class
->default_ram_id
);
1492 error_append_hint(errp
,
1493 "Change the object's 'id' to something else or disable"
1494 " automatic creation of the default RAM backend by setting"
1495 " 'memory-backend=%s' with '-machine'.\n",
1496 machine_class
->default_ram_id
);
1499 if (!create_default_memdev(current_machine
, mem_path
, errp
)) {
1504 if (machine
->numa_state
) {
1505 numa_complete_configuration(machine
);
1506 if (machine
->numa_state
->num_nodes
) {
1507 machine_numa_finish_cpu_init(machine
);
1508 if (machine_class
->cpu_cluster_has_numa_boundary
) {
1509 validate_cpu_cluster_to_numa_boundary(machine
);
1514 if (!machine
->ram
&& machine
->memdev
) {
1515 machine
->ram
= machine_consume_memdev(machine
, machine
->memdev
);
1518 /* Check if the CPU type is supported */
1519 if (machine
->cpu_type
&& !is_cpu_type_supported(machine
, errp
)) {
1525 * With confidential guests, the host can't see the real
1526 * contents of RAM, so there's no point in it trying to merge
1529 machine_set_mem_merge(OBJECT(machine
), false, &error_abort
);
1532 * Virtio devices can't count on directly accessing guest
1533 * memory, so they need iommu_platform=on to use normal DMA
1534 * mechanisms. That requires also disabling legacy virtio
1535 * support for those virtio pci devices which allow it.
1537 object_register_sugar_prop(TYPE_VIRTIO_PCI
, "disable-legacy",
1539 object_register_sugar_prop(TYPE_VIRTIO_DEVICE
, "iommu_platform",
1543 accel_init_interfaces(ACCEL_GET_CLASS(machine
->accelerator
));
1544 machine_class
->init(machine
);
1545 phase_advance(PHASE_MACHINE_INITIALIZED
);
1548 static NotifierList machine_init_done_notifiers
=
1549 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers
);
1551 void qemu_add_machine_init_done_notifier(Notifier
*notify
)
1553 notifier_list_add(&machine_init_done_notifiers
, notify
);
1554 if (phase_check(PHASE_MACHINE_READY
)) {
1555 notify
->notify(notify
, NULL
);
1559 void qemu_remove_machine_init_done_notifier(Notifier
*notify
)
1561 notifier_remove(notify
);
1564 void qdev_machine_creation_done(void)
1566 cpu_synchronize_all_post_init();
1568 if (current_machine
->boot_config
.once
) {
1569 qemu_boot_set(current_machine
->boot_config
.once
, &error_fatal
);
1570 qemu_register_reset(restore_boot_order
, g_strdup(current_machine
->boot_config
.order
));
1574 * ok, initial machine setup is done, starting from now we can
1575 * only create hotpluggable devices
1577 phase_advance(PHASE_MACHINE_READY
);
1578 qdev_assert_realized_properly();
1580 /* TODO: once all bus devices are qdevified, this should be done
1581 * when bus is created by qdev.c */
1583 * This is where we arrange for the sysbus to be reset when the
1584 * whole simulation is reset. In turn, resetting the sysbus will cause
1585 * all devices hanging off it (and all their child buses, recursively)
1586 * to be reset. Note that this will *not* reset any Device objects
1587 * which are not attached to some part of the qbus tree!
1589 qemu_register_resettable(OBJECT(sysbus_get_default()));
1591 notifier_list_notify(&machine_init_done_notifiers
, NULL
);
1593 if (rom_check_and_register_reset() != 0) {
1599 /* This checkpoint is required by replay to separate prior clock
1600 reading from the other reads, because timer polling functions query
1601 clock values from the log. */
1602 replay_checkpoint(CHECKPOINT_RESET
);
1603 qemu_system_reset(SHUTDOWN_CAUSE_NONE
);
1604 register_global_state();
1607 static const TypeInfo machine_info
= {
1608 .name
= TYPE_MACHINE
,
1609 .parent
= TYPE_OBJECT
,
1611 .class_size
= sizeof(MachineClass
),
1612 .class_init
= machine_class_init
,
1613 .class_base_init
= machine_class_base_init
,
1614 .instance_size
= sizeof(MachineState
),
1615 .instance_init
= machine_initfn
,
1616 .instance_finalize
= machine_finalize
,
1619 static void machine_register_types(void)
1621 type_register_static(&machine_info
);
1624 type_init(machine_register_types
)