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/units.h"
15 #include "hw/boards.h"
16 #include "qapi/error.h"
17 #include "qapi/qapi-visit-common.h"
18 #include "qapi/visitor.h"
19 #include "hw/sysbus.h"
20 #include "sysemu/sysemu.h"
21 #include "sysemu/numa.h"
22 #include "qemu/error-report.h"
23 #include "sysemu/qtest.h"
25 GlobalProperty hw_compat_3_1
[] = {
27 .driver
= "pcie-root-port",
28 .property
= "x-speed",
31 .driver
= "pcie-root-port",
32 .property
= "x-width",
36 const size_t hw_compat_3_1_len
= G_N_ELEMENTS(hw_compat_3_1
);
38 GlobalProperty hw_compat_3_0
[] = {};
39 const size_t hw_compat_3_0_len
= G_N_ELEMENTS(hw_compat_3_0
);
41 GlobalProperty hw_compat_2_12
[] = {
43 .driver
= "migration",
44 .property
= "decompress-error-check",
47 .driver
= "hda-audio",
48 .property
= "use-timer",
51 .driver
= "cirrus-vga",
52 .property
= "global-vmstate",
56 .property
= "global-vmstate",
59 .driver
= "vmware-svga",
60 .property
= "global-vmstate",
64 .property
= "global-vmstate",
68 const size_t hw_compat_2_12_len
= G_N_ELEMENTS(hw_compat_2_12
);
70 GlobalProperty hw_compat_2_11
[] = {
73 .property
= "hpet-offset-saved",
76 .driver
= "virtio-blk-pci",
77 .property
= "vectors",
80 .driver
= "vhost-user-blk-pci",
81 .property
= "vectors",
85 .property
= "migrate_tso_props",
89 const size_t hw_compat_2_11_len
= G_N_ELEMENTS(hw_compat_2_11
);
91 GlobalProperty hw_compat_2_10
[] = {
93 .driver
= "virtio-mouse-device",
94 .property
= "wheel-axis",
97 .driver
= "virtio-tablet-device",
98 .property
= "wheel-axis",
102 const size_t hw_compat_2_10_len
= G_N_ELEMENTS(hw_compat_2_10
);
104 GlobalProperty hw_compat_2_9
[] = {
106 .driver
= "pci-bridge",
110 .driver
= "intel-iommu",
114 .driver
= "virtio-net-device",
115 .property
= "x-mtu-bypass-backend",
118 .driver
= "pcie-root-port",
119 .property
= "x-migrate-msix",
123 const size_t hw_compat_2_9_len
= G_N_ELEMENTS(hw_compat_2_9
);
125 static char *machine_get_accel(Object
*obj
, Error
**errp
)
127 MachineState
*ms
= MACHINE(obj
);
129 return g_strdup(ms
->accel
);
132 static void machine_set_accel(Object
*obj
, const char *value
, Error
**errp
)
134 MachineState
*ms
= MACHINE(obj
);
137 ms
->accel
= g_strdup(value
);
140 static void machine_set_kernel_irqchip(Object
*obj
, Visitor
*v
,
141 const char *name
, void *opaque
,
145 MachineState
*ms
= MACHINE(obj
);
148 visit_type_OnOffSplit(v
, name
, &mode
, &err
);
150 error_propagate(errp
, err
);
154 case ON_OFF_SPLIT_ON
:
155 ms
->kernel_irqchip_allowed
= true;
156 ms
->kernel_irqchip_required
= true;
157 ms
->kernel_irqchip_split
= false;
159 case ON_OFF_SPLIT_OFF
:
160 ms
->kernel_irqchip_allowed
= false;
161 ms
->kernel_irqchip_required
= false;
162 ms
->kernel_irqchip_split
= false;
164 case ON_OFF_SPLIT_SPLIT
:
165 ms
->kernel_irqchip_allowed
= true;
166 ms
->kernel_irqchip_required
= true;
167 ms
->kernel_irqchip_split
= true;
170 /* The value was checked in visit_type_OnOffSplit() above. If
171 * we get here, then something is wrong in QEMU.
178 static void machine_get_kvm_shadow_mem(Object
*obj
, Visitor
*v
,
179 const char *name
, void *opaque
,
182 MachineState
*ms
= MACHINE(obj
);
183 int64_t value
= ms
->kvm_shadow_mem
;
185 visit_type_int(v
, name
, &value
, errp
);
188 static void machine_set_kvm_shadow_mem(Object
*obj
, Visitor
*v
,
189 const char *name
, void *opaque
,
192 MachineState
*ms
= MACHINE(obj
);
196 visit_type_int(v
, name
, &value
, &error
);
198 error_propagate(errp
, error
);
202 ms
->kvm_shadow_mem
= value
;
205 static char *machine_get_kernel(Object
*obj
, Error
**errp
)
207 MachineState
*ms
= MACHINE(obj
);
209 return g_strdup(ms
->kernel_filename
);
212 static void machine_set_kernel(Object
*obj
, const char *value
, Error
**errp
)
214 MachineState
*ms
= MACHINE(obj
);
216 g_free(ms
->kernel_filename
);
217 ms
->kernel_filename
= g_strdup(value
);
220 static char *machine_get_initrd(Object
*obj
, Error
**errp
)
222 MachineState
*ms
= MACHINE(obj
);
224 return g_strdup(ms
->initrd_filename
);
227 static void machine_set_initrd(Object
*obj
, const char *value
, Error
**errp
)
229 MachineState
*ms
= MACHINE(obj
);
231 g_free(ms
->initrd_filename
);
232 ms
->initrd_filename
= g_strdup(value
);
235 static char *machine_get_append(Object
*obj
, Error
**errp
)
237 MachineState
*ms
= MACHINE(obj
);
239 return g_strdup(ms
->kernel_cmdline
);
242 static void machine_set_append(Object
*obj
, const char *value
, Error
**errp
)
244 MachineState
*ms
= MACHINE(obj
);
246 g_free(ms
->kernel_cmdline
);
247 ms
->kernel_cmdline
= g_strdup(value
);
250 static char *machine_get_dtb(Object
*obj
, Error
**errp
)
252 MachineState
*ms
= MACHINE(obj
);
254 return g_strdup(ms
->dtb
);
257 static void machine_set_dtb(Object
*obj
, const char *value
, Error
**errp
)
259 MachineState
*ms
= MACHINE(obj
);
262 ms
->dtb
= g_strdup(value
);
265 static char *machine_get_dumpdtb(Object
*obj
, Error
**errp
)
267 MachineState
*ms
= MACHINE(obj
);
269 return g_strdup(ms
->dumpdtb
);
272 static void machine_set_dumpdtb(Object
*obj
, const char *value
, Error
**errp
)
274 MachineState
*ms
= MACHINE(obj
);
277 ms
->dumpdtb
= g_strdup(value
);
280 static void machine_get_phandle_start(Object
*obj
, Visitor
*v
,
281 const char *name
, void *opaque
,
284 MachineState
*ms
= MACHINE(obj
);
285 int64_t value
= ms
->phandle_start
;
287 visit_type_int(v
, name
, &value
, errp
);
290 static void machine_set_phandle_start(Object
*obj
, Visitor
*v
,
291 const char *name
, void *opaque
,
294 MachineState
*ms
= MACHINE(obj
);
298 visit_type_int(v
, name
, &value
, &error
);
300 error_propagate(errp
, error
);
304 ms
->phandle_start
= value
;
307 static char *machine_get_dt_compatible(Object
*obj
, Error
**errp
)
309 MachineState
*ms
= MACHINE(obj
);
311 return g_strdup(ms
->dt_compatible
);
314 static void machine_set_dt_compatible(Object
*obj
, const char *value
, Error
**errp
)
316 MachineState
*ms
= MACHINE(obj
);
318 g_free(ms
->dt_compatible
);
319 ms
->dt_compatible
= g_strdup(value
);
322 static bool machine_get_dump_guest_core(Object
*obj
, Error
**errp
)
324 MachineState
*ms
= MACHINE(obj
);
326 return ms
->dump_guest_core
;
329 static void machine_set_dump_guest_core(Object
*obj
, bool value
, Error
**errp
)
331 MachineState
*ms
= MACHINE(obj
);
333 ms
->dump_guest_core
= value
;
336 static bool machine_get_mem_merge(Object
*obj
, Error
**errp
)
338 MachineState
*ms
= MACHINE(obj
);
340 return ms
->mem_merge
;
343 static void machine_set_mem_merge(Object
*obj
, bool value
, Error
**errp
)
345 MachineState
*ms
= MACHINE(obj
);
347 ms
->mem_merge
= value
;
350 static bool machine_get_usb(Object
*obj
, Error
**errp
)
352 MachineState
*ms
= MACHINE(obj
);
357 static void machine_set_usb(Object
*obj
, bool value
, Error
**errp
)
359 MachineState
*ms
= MACHINE(obj
);
362 ms
->usb_disabled
= !value
;
365 static bool machine_get_graphics(Object
*obj
, Error
**errp
)
367 MachineState
*ms
= MACHINE(obj
);
369 return ms
->enable_graphics
;
372 static void machine_set_graphics(Object
*obj
, bool value
, Error
**errp
)
374 MachineState
*ms
= MACHINE(obj
);
376 ms
->enable_graphics
= value
;
379 static bool machine_get_igd_gfx_passthru(Object
*obj
, Error
**errp
)
381 MachineState
*ms
= MACHINE(obj
);
383 return ms
->igd_gfx_passthru
;
386 static void machine_set_igd_gfx_passthru(Object
*obj
, bool value
, Error
**errp
)
388 MachineState
*ms
= MACHINE(obj
);
390 ms
->igd_gfx_passthru
= value
;
393 static char *machine_get_firmware(Object
*obj
, Error
**errp
)
395 MachineState
*ms
= MACHINE(obj
);
397 return g_strdup(ms
->firmware
);
400 static void machine_set_firmware(Object
*obj
, const char *value
, Error
**errp
)
402 MachineState
*ms
= MACHINE(obj
);
404 g_free(ms
->firmware
);
405 ms
->firmware
= g_strdup(value
);
408 static void machine_set_suppress_vmdesc(Object
*obj
, bool value
, Error
**errp
)
410 MachineState
*ms
= MACHINE(obj
);
412 ms
->suppress_vmdesc
= value
;
415 static bool machine_get_suppress_vmdesc(Object
*obj
, Error
**errp
)
417 MachineState
*ms
= MACHINE(obj
);
419 return ms
->suppress_vmdesc
;
422 static void machine_set_enforce_config_section(Object
*obj
, bool value
,
425 MachineState
*ms
= MACHINE(obj
);
427 warn_report("enforce-config-section is deprecated, please use "
428 "-global migration.send-configuration=on|off instead");
430 ms
->enforce_config_section
= value
;
433 static bool machine_get_enforce_config_section(Object
*obj
, Error
**errp
)
435 MachineState
*ms
= MACHINE(obj
);
437 return ms
->enforce_config_section
;
440 static char *machine_get_memory_encryption(Object
*obj
, Error
**errp
)
442 MachineState
*ms
= MACHINE(obj
);
444 return g_strdup(ms
->memory_encryption
);
447 static void machine_set_memory_encryption(Object
*obj
, const char *value
,
450 MachineState
*ms
= MACHINE(obj
);
452 g_free(ms
->memory_encryption
);
453 ms
->memory_encryption
= g_strdup(value
);
456 void machine_class_allow_dynamic_sysbus_dev(MachineClass
*mc
, const char *type
)
458 strList
*item
= g_new0(strList
, 1);
460 item
->value
= g_strdup(type
);
461 item
->next
= mc
->allowed_dynamic_sysbus_devices
;
462 mc
->allowed_dynamic_sysbus_devices
= item
;
465 static void validate_sysbus_device(SysBusDevice
*sbdev
, void *opaque
)
467 MachineState
*machine
= opaque
;
468 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
469 bool allowed
= false;
472 for (wl
= mc
->allowed_dynamic_sysbus_devices
;
475 allowed
|= !!object_dynamic_cast(OBJECT(sbdev
), wl
->value
);
479 error_report("Option '-device %s' cannot be handled by this machine",
480 object_class_get_name(object_get_class(OBJECT(sbdev
))));
485 static void machine_init_notify(Notifier
*notifier
, void *data
)
487 MachineState
*machine
= MACHINE(qdev_get_machine());
490 * Loop through all dynamically created sysbus devices and check if they are
491 * all allowed. If a device is not allowed, error out.
493 foreach_dynamic_sysbus_device(validate_sysbus_device
, machine
);
496 HotpluggableCPUList
*machine_query_hotpluggable_cpus(MachineState
*machine
)
499 HotpluggableCPUList
*head
= NULL
;
500 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
502 /* force board to initialize possible_cpus if it hasn't been done yet */
503 mc
->possible_cpu_arch_ids(machine
);
505 for (i
= 0; i
< machine
->possible_cpus
->len
; i
++) {
507 HotpluggableCPUList
*list_item
= g_new0(typeof(*list_item
), 1);
508 HotpluggableCPU
*cpu_item
= g_new0(typeof(*cpu_item
), 1);
510 cpu_item
->type
= g_strdup(machine
->possible_cpus
->cpus
[i
].type
);
511 cpu_item
->vcpus_count
= machine
->possible_cpus
->cpus
[i
].vcpus_count
;
512 cpu_item
->props
= g_memdup(&machine
->possible_cpus
->cpus
[i
].props
,
513 sizeof(*cpu_item
->props
));
515 cpu
= machine
->possible_cpus
->cpus
[i
].cpu
;
517 cpu_item
->has_qom_path
= true;
518 cpu_item
->qom_path
= object_get_canonical_path(cpu
);
520 list_item
->value
= cpu_item
;
521 list_item
->next
= head
;
528 * machine_set_cpu_numa_node:
529 * @machine: machine object to modify
530 * @props: specifies which cpu objects to assign to
531 * numa node specified by @props.node_id
532 * @errp: if an error occurs, a pointer to an area to store the error
534 * Associate NUMA node specified by @props.node_id with cpu slots that
535 * match socket/core/thread-ids specified by @props. It's recommended to use
536 * query-hotpluggable-cpus.props values to specify affected cpu slots,
537 * which would lead to exact 1:1 mapping of cpu slots to NUMA node.
539 * However for CLI convenience it's possible to pass in subset of properties,
540 * which would affect all cpu slots that match it.
542 * -smp 4,cores=2,sockets=2 -numa node,nodeid=0 -numa node,nodeid=1 \
543 * -numa cpu,node-id=0,socket_id=0 \
544 * -numa cpu,node-id=1,socket_id=1
545 * will assign all child cores of socket 0 to node 0 and
546 * of socket 1 to node 1.
548 * On attempt of reassigning (already assigned) cpu slot to another NUMA node,
550 * Empty subset is disallowed and function will return with error in this case.
552 void machine_set_cpu_numa_node(MachineState
*machine
,
553 const CpuInstanceProperties
*props
, Error
**errp
)
555 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
559 if (!mc
->possible_cpu_arch_ids
) {
560 error_setg(errp
, "mapping of CPUs to NUMA node is not supported");
564 /* disabling node mapping is not supported, forbid it */
565 assert(props
->has_node_id
);
567 /* force board to initialize possible_cpus if it hasn't been done yet */
568 mc
->possible_cpu_arch_ids(machine
);
570 for (i
= 0; i
< machine
->possible_cpus
->len
; i
++) {
571 CPUArchId
*slot
= &machine
->possible_cpus
->cpus
[i
];
573 /* reject unsupported by board properties */
574 if (props
->has_thread_id
&& !slot
->props
.has_thread_id
) {
575 error_setg(errp
, "thread-id is not supported");
579 if (props
->has_core_id
&& !slot
->props
.has_core_id
) {
580 error_setg(errp
, "core-id is not supported");
584 if (props
->has_socket_id
&& !slot
->props
.has_socket_id
) {
585 error_setg(errp
, "socket-id is not supported");
589 /* skip slots with explicit mismatch */
590 if (props
->has_thread_id
&& props
->thread_id
!= slot
->props
.thread_id
) {
594 if (props
->has_core_id
&& props
->core_id
!= slot
->props
.core_id
) {
598 if (props
->has_socket_id
&& props
->socket_id
!= slot
->props
.socket_id
) {
602 /* reject assignment if slot is already assigned, for compatibility
603 * of legacy cpu_index mapping with SPAPR core based mapping do not
604 * error out if cpu thread and matched core have the same node-id */
605 if (slot
->props
.has_node_id
&&
606 slot
->props
.node_id
!= props
->node_id
) {
607 error_setg(errp
, "CPU is already assigned to node-id: %" PRId64
,
608 slot
->props
.node_id
);
612 /* assign slot to node as it's matched '-numa cpu' key */
614 slot
->props
.node_id
= props
->node_id
;
615 slot
->props
.has_node_id
= props
->has_node_id
;
619 error_setg(errp
, "no match found");
623 static void machine_class_init(ObjectClass
*oc
, void *data
)
625 MachineClass
*mc
= MACHINE_CLASS(oc
);
627 /* Default 128 MB as guest ram size */
628 mc
->default_ram_size
= 128 * MiB
;
629 mc
->rom_file_has_mr
= true;
631 /* numa node memory size aligned on 8MB by default.
632 * On Linux, each node's border has to be 8MB aligned
634 mc
->numa_mem_align_shift
= 23;
635 mc
->numa_auto_assign_ram
= numa_default_auto_assign_ram
;
637 object_class_property_add_str(oc
, "accel",
638 machine_get_accel
, machine_set_accel
, &error_abort
);
639 object_class_property_set_description(oc
, "accel",
640 "Accelerator list", &error_abort
);
642 object_class_property_add(oc
, "kernel-irqchip", "on|off|split",
643 NULL
, machine_set_kernel_irqchip
,
644 NULL
, NULL
, &error_abort
);
645 object_class_property_set_description(oc
, "kernel-irqchip",
646 "Configure KVM in-kernel irqchip", &error_abort
);
648 object_class_property_add(oc
, "kvm-shadow-mem", "int",
649 machine_get_kvm_shadow_mem
, machine_set_kvm_shadow_mem
,
650 NULL
, NULL
, &error_abort
);
651 object_class_property_set_description(oc
, "kvm-shadow-mem",
652 "KVM shadow MMU size", &error_abort
);
654 object_class_property_add_str(oc
, "kernel",
655 machine_get_kernel
, machine_set_kernel
, &error_abort
);
656 object_class_property_set_description(oc
, "kernel",
657 "Linux kernel image file", &error_abort
);
659 object_class_property_add_str(oc
, "initrd",
660 machine_get_initrd
, machine_set_initrd
, &error_abort
);
661 object_class_property_set_description(oc
, "initrd",
662 "Linux initial ramdisk file", &error_abort
);
664 object_class_property_add_str(oc
, "append",
665 machine_get_append
, machine_set_append
, &error_abort
);
666 object_class_property_set_description(oc
, "append",
667 "Linux kernel command line", &error_abort
);
669 object_class_property_add_str(oc
, "dtb",
670 machine_get_dtb
, machine_set_dtb
, &error_abort
);
671 object_class_property_set_description(oc
, "dtb",
672 "Linux kernel device tree file", &error_abort
);
674 object_class_property_add_str(oc
, "dumpdtb",
675 machine_get_dumpdtb
, machine_set_dumpdtb
, &error_abort
);
676 object_class_property_set_description(oc
, "dumpdtb",
677 "Dump current dtb to a file and quit", &error_abort
);
679 object_class_property_add(oc
, "phandle-start", "int",
680 machine_get_phandle_start
, machine_set_phandle_start
,
681 NULL
, NULL
, &error_abort
);
682 object_class_property_set_description(oc
, "phandle-start",
683 "The first phandle ID we may generate dynamically", &error_abort
);
685 object_class_property_add_str(oc
, "dt-compatible",
686 machine_get_dt_compatible
, machine_set_dt_compatible
, &error_abort
);
687 object_class_property_set_description(oc
, "dt-compatible",
688 "Overrides the \"compatible\" property of the dt root node",
691 object_class_property_add_bool(oc
, "dump-guest-core",
692 machine_get_dump_guest_core
, machine_set_dump_guest_core
, &error_abort
);
693 object_class_property_set_description(oc
, "dump-guest-core",
694 "Include guest memory in a core dump", &error_abort
);
696 object_class_property_add_bool(oc
, "mem-merge",
697 machine_get_mem_merge
, machine_set_mem_merge
, &error_abort
);
698 object_class_property_set_description(oc
, "mem-merge",
699 "Enable/disable memory merge support", &error_abort
);
701 object_class_property_add_bool(oc
, "usb",
702 machine_get_usb
, machine_set_usb
, &error_abort
);
703 object_class_property_set_description(oc
, "usb",
704 "Set on/off to enable/disable usb", &error_abort
);
706 object_class_property_add_bool(oc
, "graphics",
707 machine_get_graphics
, machine_set_graphics
, &error_abort
);
708 object_class_property_set_description(oc
, "graphics",
709 "Set on/off to enable/disable graphics emulation", &error_abort
);
711 object_class_property_add_bool(oc
, "igd-passthru",
712 machine_get_igd_gfx_passthru
, machine_set_igd_gfx_passthru
,
714 object_class_property_set_description(oc
, "igd-passthru",
715 "Set on/off to enable/disable igd passthrou", &error_abort
);
717 object_class_property_add_str(oc
, "firmware",
718 machine_get_firmware
, machine_set_firmware
,
720 object_class_property_set_description(oc
, "firmware",
721 "Firmware image", &error_abort
);
723 object_class_property_add_bool(oc
, "suppress-vmdesc",
724 machine_get_suppress_vmdesc
, machine_set_suppress_vmdesc
,
726 object_class_property_set_description(oc
, "suppress-vmdesc",
727 "Set on to disable self-describing migration", &error_abort
);
729 object_class_property_add_bool(oc
, "enforce-config-section",
730 machine_get_enforce_config_section
, machine_set_enforce_config_section
,
732 object_class_property_set_description(oc
, "enforce-config-section",
733 "Set on to enforce configuration section migration", &error_abort
);
735 object_class_property_add_str(oc
, "memory-encryption",
736 machine_get_memory_encryption
, machine_set_memory_encryption
,
738 object_class_property_set_description(oc
, "memory-encryption",
739 "Set memory encryption object to use", &error_abort
);
742 static void machine_class_base_init(ObjectClass
*oc
, void *data
)
744 if (!object_class_is_abstract(oc
)) {
745 MachineClass
*mc
= MACHINE_CLASS(oc
);
746 const char *cname
= object_class_get_name(oc
);
747 assert(g_str_has_suffix(cname
, TYPE_MACHINE_SUFFIX
));
748 mc
->name
= g_strndup(cname
,
749 strlen(cname
) - strlen(TYPE_MACHINE_SUFFIX
));
750 mc
->compat_props
= g_ptr_array_new();
754 static void machine_initfn(Object
*obj
)
756 MachineState
*ms
= MACHINE(obj
);
757 MachineClass
*mc
= MACHINE_GET_CLASS(obj
);
759 ms
->kernel_irqchip_allowed
= true;
760 ms
->kernel_irqchip_split
= mc
->default_kernel_irqchip_split
;
761 ms
->kvm_shadow_mem
= -1;
762 ms
->dump_guest_core
= true;
763 ms
->mem_merge
= true;
764 ms
->enable_graphics
= true;
766 /* Register notifier when init is done for sysbus sanity checks */
767 ms
->sysbus_notifier
.notify
= machine_init_notify
;
768 qemu_add_machine_init_done_notifier(&ms
->sysbus_notifier
);
771 static void machine_finalize(Object
*obj
)
773 MachineState
*ms
= MACHINE(obj
);
776 g_free(ms
->kernel_filename
);
777 g_free(ms
->initrd_filename
);
778 g_free(ms
->kernel_cmdline
);
781 g_free(ms
->dt_compatible
);
782 g_free(ms
->firmware
);
783 g_free(ms
->device_memory
);
786 bool machine_usb(MachineState
*machine
)
791 bool machine_kernel_irqchip_allowed(MachineState
*machine
)
793 return machine
->kernel_irqchip_allowed
;
796 bool machine_kernel_irqchip_required(MachineState
*machine
)
798 return machine
->kernel_irqchip_required
;
801 bool machine_kernel_irqchip_split(MachineState
*machine
)
803 return machine
->kernel_irqchip_split
;
806 int machine_kvm_shadow_mem(MachineState
*machine
)
808 return machine
->kvm_shadow_mem
;
811 int machine_phandle_start(MachineState
*machine
)
813 return machine
->phandle_start
;
816 bool machine_dump_guest_core(MachineState
*machine
)
818 return machine
->dump_guest_core
;
821 bool machine_mem_merge(MachineState
*machine
)
823 return machine
->mem_merge
;
826 static char *cpu_slot_to_string(const CPUArchId
*cpu
)
828 GString
*s
= g_string_new(NULL
);
829 if (cpu
->props
.has_socket_id
) {
830 g_string_append_printf(s
, "socket-id: %"PRId64
, cpu
->props
.socket_id
);
832 if (cpu
->props
.has_core_id
) {
834 g_string_append_printf(s
, ", ");
836 g_string_append_printf(s
, "core-id: %"PRId64
, cpu
->props
.core_id
);
838 if (cpu
->props
.has_thread_id
) {
840 g_string_append_printf(s
, ", ");
842 g_string_append_printf(s
, "thread-id: %"PRId64
, cpu
->props
.thread_id
);
844 return g_string_free(s
, false);
847 static void machine_numa_finish_cpu_init(MachineState
*machine
)
850 bool default_mapping
;
851 GString
*s
= g_string_new(NULL
);
852 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
853 const CPUArchIdList
*possible_cpus
= mc
->possible_cpu_arch_ids(machine
);
855 assert(nb_numa_nodes
);
856 for (i
= 0; i
< possible_cpus
->len
; i
++) {
857 if (possible_cpus
->cpus
[i
].props
.has_node_id
) {
861 default_mapping
= (i
== possible_cpus
->len
);
863 for (i
= 0; i
< possible_cpus
->len
; i
++) {
864 const CPUArchId
*cpu_slot
= &possible_cpus
->cpus
[i
];
866 if (!cpu_slot
->props
.has_node_id
) {
867 /* fetch default mapping from board and enable it */
868 CpuInstanceProperties props
= cpu_slot
->props
;
870 props
.node_id
= mc
->get_default_cpu_node_id(machine
, i
);
871 if (!default_mapping
) {
872 /* record slots with not set mapping,
873 * TODO: make it hard error in future */
874 char *cpu_str
= cpu_slot_to_string(cpu_slot
);
875 g_string_append_printf(s
, "%sCPU %d [%s]",
876 s
->len
? ", " : "", i
, cpu_str
);
879 /* non mapped cpus used to fallback to node 0 */
883 props
.has_node_id
= true;
884 machine_set_cpu_numa_node(machine
, &props
, &error_fatal
);
887 if (s
->len
&& !qtest_enabled()) {
888 warn_report("CPU(s) not present in any NUMA nodes: %s",
890 warn_report("All CPU(s) up to maxcpus should be described "
891 "in NUMA config, ability to start up with partial NUMA "
892 "mappings is obsoleted and will be removed in future");
894 g_string_free(s
, true);
897 void machine_run_board_init(MachineState
*machine
)
899 MachineClass
*machine_class
= MACHINE_GET_CLASS(machine
);
901 numa_complete_configuration(machine
);
903 machine_numa_finish_cpu_init(machine
);
906 /* If the machine supports the valid_cpu_types check and the user
907 * specified a CPU with -cpu check here that the user CPU is supported.
909 if (machine_class
->valid_cpu_types
&& machine
->cpu_type
) {
910 ObjectClass
*class = object_class_by_name(machine
->cpu_type
);
913 for (i
= 0; machine_class
->valid_cpu_types
[i
]; i
++) {
914 if (object_class_dynamic_cast(class,
915 machine_class
->valid_cpu_types
[i
])) {
916 /* The user specificed CPU is in the valid field, we are
923 if (!machine_class
->valid_cpu_types
[i
]) {
924 /* The user specified CPU is not valid */
925 error_report("Invalid CPU type: %s", machine
->cpu_type
);
926 error_printf("The valid types are: %s",
927 machine_class
->valid_cpu_types
[0]);
928 for (i
= 1; machine_class
->valid_cpu_types
[i
]; i
++) {
929 error_printf(", %s", machine_class
->valid_cpu_types
[i
]);
937 machine_class
->init(machine
);
940 static const TypeInfo machine_info
= {
941 .name
= TYPE_MACHINE
,
942 .parent
= TYPE_OBJECT
,
944 .class_size
= sizeof(MachineClass
),
945 .class_init
= machine_class_init
,
946 .class_base_init
= machine_class_base_init
,
947 .instance_size
= sizeof(MachineState
),
948 .instance_init
= machine_initfn
,
949 .instance_finalize
= machine_finalize
,
952 static void machine_register_types(void)
954 type_register_static(&machine_info
);
957 type_init(machine_register_types
)