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 static char *machine_get_accel(Object
*obj
, Error
**errp
)
27 MachineState
*ms
= MACHINE(obj
);
29 return g_strdup(ms
->accel
);
32 static void machine_set_accel(Object
*obj
, const char *value
, Error
**errp
)
34 MachineState
*ms
= MACHINE(obj
);
37 ms
->accel
= g_strdup(value
);
40 static void machine_set_kernel_irqchip(Object
*obj
, Visitor
*v
,
41 const char *name
, void *opaque
,
45 MachineState
*ms
= MACHINE(obj
);
48 visit_type_OnOffSplit(v
, name
, &mode
, &err
);
50 error_propagate(errp
, err
);
55 ms
->kernel_irqchip_allowed
= true;
56 ms
->kernel_irqchip_required
= true;
57 ms
->kernel_irqchip_split
= false;
59 case ON_OFF_SPLIT_OFF
:
60 ms
->kernel_irqchip_allowed
= false;
61 ms
->kernel_irqchip_required
= false;
62 ms
->kernel_irqchip_split
= false;
64 case ON_OFF_SPLIT_SPLIT
:
65 ms
->kernel_irqchip_allowed
= true;
66 ms
->kernel_irqchip_required
= true;
67 ms
->kernel_irqchip_split
= true;
70 /* The value was checked in visit_type_OnOffSplit() above. If
71 * we get here, then something is wrong in QEMU.
78 static void machine_get_kvm_shadow_mem(Object
*obj
, Visitor
*v
,
79 const char *name
, void *opaque
,
82 MachineState
*ms
= MACHINE(obj
);
83 int64_t value
= ms
->kvm_shadow_mem
;
85 visit_type_int(v
, name
, &value
, errp
);
88 static void machine_set_kvm_shadow_mem(Object
*obj
, Visitor
*v
,
89 const char *name
, void *opaque
,
92 MachineState
*ms
= MACHINE(obj
);
96 visit_type_int(v
, name
, &value
, &error
);
98 error_propagate(errp
, error
);
102 ms
->kvm_shadow_mem
= value
;
105 static char *machine_get_kernel(Object
*obj
, Error
**errp
)
107 MachineState
*ms
= MACHINE(obj
);
109 return g_strdup(ms
->kernel_filename
);
112 static void machine_set_kernel(Object
*obj
, const char *value
, Error
**errp
)
114 MachineState
*ms
= MACHINE(obj
);
116 g_free(ms
->kernel_filename
);
117 ms
->kernel_filename
= g_strdup(value
);
120 static char *machine_get_initrd(Object
*obj
, Error
**errp
)
122 MachineState
*ms
= MACHINE(obj
);
124 return g_strdup(ms
->initrd_filename
);
127 static void machine_set_initrd(Object
*obj
, const char *value
, Error
**errp
)
129 MachineState
*ms
= MACHINE(obj
);
131 g_free(ms
->initrd_filename
);
132 ms
->initrd_filename
= g_strdup(value
);
135 static char *machine_get_append(Object
*obj
, Error
**errp
)
137 MachineState
*ms
= MACHINE(obj
);
139 return g_strdup(ms
->kernel_cmdline
);
142 static void machine_set_append(Object
*obj
, const char *value
, Error
**errp
)
144 MachineState
*ms
= MACHINE(obj
);
146 g_free(ms
->kernel_cmdline
);
147 ms
->kernel_cmdline
= g_strdup(value
);
150 static char *machine_get_dtb(Object
*obj
, Error
**errp
)
152 MachineState
*ms
= MACHINE(obj
);
154 return g_strdup(ms
->dtb
);
157 static void machine_set_dtb(Object
*obj
, const char *value
, Error
**errp
)
159 MachineState
*ms
= MACHINE(obj
);
162 ms
->dtb
= g_strdup(value
);
165 static char *machine_get_dumpdtb(Object
*obj
, Error
**errp
)
167 MachineState
*ms
= MACHINE(obj
);
169 return g_strdup(ms
->dumpdtb
);
172 static void machine_set_dumpdtb(Object
*obj
, const char *value
, Error
**errp
)
174 MachineState
*ms
= MACHINE(obj
);
177 ms
->dumpdtb
= g_strdup(value
);
180 static void machine_get_phandle_start(Object
*obj
, Visitor
*v
,
181 const char *name
, void *opaque
,
184 MachineState
*ms
= MACHINE(obj
);
185 int64_t value
= ms
->phandle_start
;
187 visit_type_int(v
, name
, &value
, errp
);
190 static void machine_set_phandle_start(Object
*obj
, Visitor
*v
,
191 const char *name
, void *opaque
,
194 MachineState
*ms
= MACHINE(obj
);
198 visit_type_int(v
, name
, &value
, &error
);
200 error_propagate(errp
, error
);
204 ms
->phandle_start
= value
;
207 static char *machine_get_dt_compatible(Object
*obj
, Error
**errp
)
209 MachineState
*ms
= MACHINE(obj
);
211 return g_strdup(ms
->dt_compatible
);
214 static void machine_set_dt_compatible(Object
*obj
, const char *value
, Error
**errp
)
216 MachineState
*ms
= MACHINE(obj
);
218 g_free(ms
->dt_compatible
);
219 ms
->dt_compatible
= g_strdup(value
);
222 static bool machine_get_dump_guest_core(Object
*obj
, Error
**errp
)
224 MachineState
*ms
= MACHINE(obj
);
226 return ms
->dump_guest_core
;
229 static void machine_set_dump_guest_core(Object
*obj
, bool value
, Error
**errp
)
231 MachineState
*ms
= MACHINE(obj
);
233 ms
->dump_guest_core
= value
;
236 static bool machine_get_mem_merge(Object
*obj
, Error
**errp
)
238 MachineState
*ms
= MACHINE(obj
);
240 return ms
->mem_merge
;
243 static void machine_set_mem_merge(Object
*obj
, bool value
, Error
**errp
)
245 MachineState
*ms
= MACHINE(obj
);
247 ms
->mem_merge
= value
;
250 static bool machine_get_usb(Object
*obj
, Error
**errp
)
252 MachineState
*ms
= MACHINE(obj
);
257 static void machine_set_usb(Object
*obj
, bool value
, Error
**errp
)
259 MachineState
*ms
= MACHINE(obj
);
262 ms
->usb_disabled
= !value
;
265 static bool machine_get_graphics(Object
*obj
, Error
**errp
)
267 MachineState
*ms
= MACHINE(obj
);
269 return ms
->enable_graphics
;
272 static void machine_set_graphics(Object
*obj
, bool value
, Error
**errp
)
274 MachineState
*ms
= MACHINE(obj
);
276 ms
->enable_graphics
= value
;
279 static bool machine_get_igd_gfx_passthru(Object
*obj
, Error
**errp
)
281 MachineState
*ms
= MACHINE(obj
);
283 return ms
->igd_gfx_passthru
;
286 static void machine_set_igd_gfx_passthru(Object
*obj
, bool value
, Error
**errp
)
288 MachineState
*ms
= MACHINE(obj
);
290 ms
->igd_gfx_passthru
= value
;
293 static char *machine_get_firmware(Object
*obj
, Error
**errp
)
295 MachineState
*ms
= MACHINE(obj
);
297 return g_strdup(ms
->firmware
);
300 static void machine_set_firmware(Object
*obj
, const char *value
, Error
**errp
)
302 MachineState
*ms
= MACHINE(obj
);
304 g_free(ms
->firmware
);
305 ms
->firmware
= g_strdup(value
);
308 static void machine_set_suppress_vmdesc(Object
*obj
, bool value
, Error
**errp
)
310 MachineState
*ms
= MACHINE(obj
);
312 ms
->suppress_vmdesc
= value
;
315 static bool machine_get_suppress_vmdesc(Object
*obj
, Error
**errp
)
317 MachineState
*ms
= MACHINE(obj
);
319 return ms
->suppress_vmdesc
;
322 static void machine_set_enforce_config_section(Object
*obj
, bool value
,
325 MachineState
*ms
= MACHINE(obj
);
327 warn_report("enforce-config-section is deprecated, please use "
328 "-global migration.send-configuration=on|off instead");
330 ms
->enforce_config_section
= value
;
333 static bool machine_get_enforce_config_section(Object
*obj
, Error
**errp
)
335 MachineState
*ms
= MACHINE(obj
);
337 return ms
->enforce_config_section
;
340 static char *machine_get_memory_encryption(Object
*obj
, Error
**errp
)
342 MachineState
*ms
= MACHINE(obj
);
344 return g_strdup(ms
->memory_encryption
);
347 static void machine_set_memory_encryption(Object
*obj
, const char *value
,
350 MachineState
*ms
= MACHINE(obj
);
352 g_free(ms
->memory_encryption
);
353 ms
->memory_encryption
= g_strdup(value
);
356 void machine_class_allow_dynamic_sysbus_dev(MachineClass
*mc
, const char *type
)
358 strList
*item
= g_new0(strList
, 1);
360 item
->value
= g_strdup(type
);
361 item
->next
= mc
->allowed_dynamic_sysbus_devices
;
362 mc
->allowed_dynamic_sysbus_devices
= item
;
365 static void validate_sysbus_device(SysBusDevice
*sbdev
, void *opaque
)
367 MachineState
*machine
= opaque
;
368 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
369 bool allowed
= false;
372 for (wl
= mc
->allowed_dynamic_sysbus_devices
;
375 allowed
|= !!object_dynamic_cast(OBJECT(sbdev
), wl
->value
);
379 error_report("Option '-device %s' cannot be handled by this machine",
380 object_class_get_name(object_get_class(OBJECT(sbdev
))));
385 static void machine_init_notify(Notifier
*notifier
, void *data
)
387 MachineState
*machine
= MACHINE(qdev_get_machine());
390 * Loop through all dynamically created sysbus devices and check if they are
391 * all allowed. If a device is not allowed, error out.
393 foreach_dynamic_sysbus_device(validate_sysbus_device
, machine
);
396 HotpluggableCPUList
*machine_query_hotpluggable_cpus(MachineState
*machine
)
399 HotpluggableCPUList
*head
= NULL
;
400 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
402 /* force board to initialize possible_cpus if it hasn't been done yet */
403 mc
->possible_cpu_arch_ids(machine
);
405 for (i
= 0; i
< machine
->possible_cpus
->len
; i
++) {
407 HotpluggableCPUList
*list_item
= g_new0(typeof(*list_item
), 1);
408 HotpluggableCPU
*cpu_item
= g_new0(typeof(*cpu_item
), 1);
410 cpu_item
->type
= g_strdup(machine
->possible_cpus
->cpus
[i
].type
);
411 cpu_item
->vcpus_count
= machine
->possible_cpus
->cpus
[i
].vcpus_count
;
412 cpu_item
->props
= g_memdup(&machine
->possible_cpus
->cpus
[i
].props
,
413 sizeof(*cpu_item
->props
));
415 cpu
= machine
->possible_cpus
->cpus
[i
].cpu
;
417 cpu_item
->has_qom_path
= true;
418 cpu_item
->qom_path
= object_get_canonical_path(cpu
);
420 list_item
->value
= cpu_item
;
421 list_item
->next
= head
;
428 * machine_set_cpu_numa_node:
429 * @machine: machine object to modify
430 * @props: specifies which cpu objects to assign to
431 * numa node specified by @props.node_id
432 * @errp: if an error occurs, a pointer to an area to store the error
434 * Associate NUMA node specified by @props.node_id with cpu slots that
435 * match socket/core/thread-ids specified by @props. It's recommended to use
436 * query-hotpluggable-cpus.props values to specify affected cpu slots,
437 * which would lead to exact 1:1 mapping of cpu slots to NUMA node.
439 * However for CLI convenience it's possible to pass in subset of properties,
440 * which would affect all cpu slots that match it.
442 * -smp 4,cores=2,sockets=2 -numa node,nodeid=0 -numa node,nodeid=1 \
443 * -numa cpu,node-id=0,socket_id=0 \
444 * -numa cpu,node-id=1,socket_id=1
445 * will assign all child cores of socket 0 to node 0 and
446 * of socket 1 to node 1.
448 * On attempt of reassigning (already assigned) cpu slot to another NUMA node,
450 * Empty subset is disallowed and function will return with error in this case.
452 void machine_set_cpu_numa_node(MachineState
*machine
,
453 const CpuInstanceProperties
*props
, Error
**errp
)
455 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
459 if (!mc
->possible_cpu_arch_ids
) {
460 error_setg(errp
, "mapping of CPUs to NUMA node is not supported");
464 /* disabling node mapping is not supported, forbid it */
465 assert(props
->has_node_id
);
467 /* force board to initialize possible_cpus if it hasn't been done yet */
468 mc
->possible_cpu_arch_ids(machine
);
470 for (i
= 0; i
< machine
->possible_cpus
->len
; i
++) {
471 CPUArchId
*slot
= &machine
->possible_cpus
->cpus
[i
];
473 /* reject unsupported by board properties */
474 if (props
->has_thread_id
&& !slot
->props
.has_thread_id
) {
475 error_setg(errp
, "thread-id is not supported");
479 if (props
->has_core_id
&& !slot
->props
.has_core_id
) {
480 error_setg(errp
, "core-id is not supported");
484 if (props
->has_socket_id
&& !slot
->props
.has_socket_id
) {
485 error_setg(errp
, "socket-id is not supported");
489 /* skip slots with explicit mismatch */
490 if (props
->has_thread_id
&& props
->thread_id
!= slot
->props
.thread_id
) {
494 if (props
->has_core_id
&& props
->core_id
!= slot
->props
.core_id
) {
498 if (props
->has_socket_id
&& props
->socket_id
!= slot
->props
.socket_id
) {
502 /* reject assignment if slot is already assigned, for compatibility
503 * of legacy cpu_index mapping with SPAPR core based mapping do not
504 * error out if cpu thread and matched core have the same node-id */
505 if (slot
->props
.has_node_id
&&
506 slot
->props
.node_id
!= props
->node_id
) {
507 error_setg(errp
, "CPU is already assigned to node-id: %" PRId64
,
508 slot
->props
.node_id
);
512 /* assign slot to node as it's matched '-numa cpu' key */
514 slot
->props
.node_id
= props
->node_id
;
515 slot
->props
.has_node_id
= props
->has_node_id
;
519 error_setg(errp
, "no match found");
523 static void machine_class_init(ObjectClass
*oc
, void *data
)
525 MachineClass
*mc
= MACHINE_CLASS(oc
);
527 /* Default 128 MB as guest ram size */
528 mc
->default_ram_size
= 128 * MiB
;
529 mc
->rom_file_has_mr
= true;
531 /* numa node memory size aligned on 8MB by default.
532 * On Linux, each node's border has to be 8MB aligned
534 mc
->numa_mem_align_shift
= 23;
535 mc
->numa_auto_assign_ram
= numa_default_auto_assign_ram
;
537 object_class_property_add_str(oc
, "accel",
538 machine_get_accel
, machine_set_accel
, &error_abort
);
539 object_class_property_set_description(oc
, "accel",
540 "Accelerator list", &error_abort
);
542 object_class_property_add(oc
, "kernel-irqchip", "on|off|split",
543 NULL
, machine_set_kernel_irqchip
,
544 NULL
, NULL
, &error_abort
);
545 object_class_property_set_description(oc
, "kernel-irqchip",
546 "Configure KVM in-kernel irqchip", &error_abort
);
548 object_class_property_add(oc
, "kvm-shadow-mem", "int",
549 machine_get_kvm_shadow_mem
, machine_set_kvm_shadow_mem
,
550 NULL
, NULL
, &error_abort
);
551 object_class_property_set_description(oc
, "kvm-shadow-mem",
552 "KVM shadow MMU size", &error_abort
);
554 object_class_property_add_str(oc
, "kernel",
555 machine_get_kernel
, machine_set_kernel
, &error_abort
);
556 object_class_property_set_description(oc
, "kernel",
557 "Linux kernel image file", &error_abort
);
559 object_class_property_add_str(oc
, "initrd",
560 machine_get_initrd
, machine_set_initrd
, &error_abort
);
561 object_class_property_set_description(oc
, "initrd",
562 "Linux initial ramdisk file", &error_abort
);
564 object_class_property_add_str(oc
, "append",
565 machine_get_append
, machine_set_append
, &error_abort
);
566 object_class_property_set_description(oc
, "append",
567 "Linux kernel command line", &error_abort
);
569 object_class_property_add_str(oc
, "dtb",
570 machine_get_dtb
, machine_set_dtb
, &error_abort
);
571 object_class_property_set_description(oc
, "dtb",
572 "Linux kernel device tree file", &error_abort
);
574 object_class_property_add_str(oc
, "dumpdtb",
575 machine_get_dumpdtb
, machine_set_dumpdtb
, &error_abort
);
576 object_class_property_set_description(oc
, "dumpdtb",
577 "Dump current dtb to a file and quit", &error_abort
);
579 object_class_property_add(oc
, "phandle-start", "int",
580 machine_get_phandle_start
, machine_set_phandle_start
,
581 NULL
, NULL
, &error_abort
);
582 object_class_property_set_description(oc
, "phandle-start",
583 "The first phandle ID we may generate dynamically", &error_abort
);
585 object_class_property_add_str(oc
, "dt-compatible",
586 machine_get_dt_compatible
, machine_set_dt_compatible
, &error_abort
);
587 object_class_property_set_description(oc
, "dt-compatible",
588 "Overrides the \"compatible\" property of the dt root node",
591 object_class_property_add_bool(oc
, "dump-guest-core",
592 machine_get_dump_guest_core
, machine_set_dump_guest_core
, &error_abort
);
593 object_class_property_set_description(oc
, "dump-guest-core",
594 "Include guest memory in a core dump", &error_abort
);
596 object_class_property_add_bool(oc
, "mem-merge",
597 machine_get_mem_merge
, machine_set_mem_merge
, &error_abort
);
598 object_class_property_set_description(oc
, "mem-merge",
599 "Enable/disable memory merge support", &error_abort
);
601 object_class_property_add_bool(oc
, "usb",
602 machine_get_usb
, machine_set_usb
, &error_abort
);
603 object_class_property_set_description(oc
, "usb",
604 "Set on/off to enable/disable usb", &error_abort
);
606 object_class_property_add_bool(oc
, "graphics",
607 machine_get_graphics
, machine_set_graphics
, &error_abort
);
608 object_class_property_set_description(oc
, "graphics",
609 "Set on/off to enable/disable graphics emulation", &error_abort
);
611 object_class_property_add_bool(oc
, "igd-passthru",
612 machine_get_igd_gfx_passthru
, machine_set_igd_gfx_passthru
,
614 object_class_property_set_description(oc
, "igd-passthru",
615 "Set on/off to enable/disable igd passthrou", &error_abort
);
617 object_class_property_add_str(oc
, "firmware",
618 machine_get_firmware
, machine_set_firmware
,
620 object_class_property_set_description(oc
, "firmware",
621 "Firmware image", &error_abort
);
623 object_class_property_add_bool(oc
, "suppress-vmdesc",
624 machine_get_suppress_vmdesc
, machine_set_suppress_vmdesc
,
626 object_class_property_set_description(oc
, "suppress-vmdesc",
627 "Set on to disable self-describing migration", &error_abort
);
629 object_class_property_add_bool(oc
, "enforce-config-section",
630 machine_get_enforce_config_section
, machine_set_enforce_config_section
,
632 object_class_property_set_description(oc
, "enforce-config-section",
633 "Set on to enforce configuration section migration", &error_abort
);
635 object_class_property_add_str(oc
, "memory-encryption",
636 machine_get_memory_encryption
, machine_set_memory_encryption
,
638 object_class_property_set_description(oc
, "memory-encryption",
639 "Set memory encryption object to use", &error_abort
);
642 static void machine_class_base_init(ObjectClass
*oc
, void *data
)
644 if (!object_class_is_abstract(oc
)) {
645 MachineClass
*mc
= MACHINE_CLASS(oc
);
646 const char *cname
= object_class_get_name(oc
);
647 assert(g_str_has_suffix(cname
, TYPE_MACHINE_SUFFIX
));
648 mc
->name
= g_strndup(cname
,
649 strlen(cname
) - strlen(TYPE_MACHINE_SUFFIX
));
653 static void machine_initfn(Object
*obj
)
655 MachineState
*ms
= MACHINE(obj
);
656 MachineClass
*mc
= MACHINE_GET_CLASS(obj
);
658 ms
->kernel_irqchip_allowed
= true;
659 ms
->kernel_irqchip_split
= mc
->default_kernel_irqchip_split
;
660 ms
->kvm_shadow_mem
= -1;
661 ms
->dump_guest_core
= true;
662 ms
->mem_merge
= true;
663 ms
->enable_graphics
= true;
665 /* Register notifier when init is done for sysbus sanity checks */
666 ms
->sysbus_notifier
.notify
= machine_init_notify
;
667 qemu_add_machine_init_done_notifier(&ms
->sysbus_notifier
);
670 static void machine_finalize(Object
*obj
)
672 MachineState
*ms
= MACHINE(obj
);
675 g_free(ms
->kernel_filename
);
676 g_free(ms
->initrd_filename
);
677 g_free(ms
->kernel_cmdline
);
680 g_free(ms
->dt_compatible
);
681 g_free(ms
->firmware
);
682 g_free(ms
->device_memory
);
685 bool machine_usb(MachineState
*machine
)
690 bool machine_kernel_irqchip_allowed(MachineState
*machine
)
692 return machine
->kernel_irqchip_allowed
;
695 bool machine_kernel_irqchip_required(MachineState
*machine
)
697 return machine
->kernel_irqchip_required
;
700 bool machine_kernel_irqchip_split(MachineState
*machine
)
702 return machine
->kernel_irqchip_split
;
705 int machine_kvm_shadow_mem(MachineState
*machine
)
707 return machine
->kvm_shadow_mem
;
710 int machine_phandle_start(MachineState
*machine
)
712 return machine
->phandle_start
;
715 bool machine_dump_guest_core(MachineState
*machine
)
717 return machine
->dump_guest_core
;
720 bool machine_mem_merge(MachineState
*machine
)
722 return machine
->mem_merge
;
725 static char *cpu_slot_to_string(const CPUArchId
*cpu
)
727 GString
*s
= g_string_new(NULL
);
728 if (cpu
->props
.has_socket_id
) {
729 g_string_append_printf(s
, "socket-id: %"PRId64
, cpu
->props
.socket_id
);
731 if (cpu
->props
.has_core_id
) {
733 g_string_append_printf(s
, ", ");
735 g_string_append_printf(s
, "core-id: %"PRId64
, cpu
->props
.core_id
);
737 if (cpu
->props
.has_thread_id
) {
739 g_string_append_printf(s
, ", ");
741 g_string_append_printf(s
, "thread-id: %"PRId64
, cpu
->props
.thread_id
);
743 return g_string_free(s
, false);
746 static void machine_numa_finish_cpu_init(MachineState
*machine
)
749 bool default_mapping
;
750 GString
*s
= g_string_new(NULL
);
751 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
752 const CPUArchIdList
*possible_cpus
= mc
->possible_cpu_arch_ids(machine
);
754 assert(nb_numa_nodes
);
755 for (i
= 0; i
< possible_cpus
->len
; i
++) {
756 if (possible_cpus
->cpus
[i
].props
.has_node_id
) {
760 default_mapping
= (i
== possible_cpus
->len
);
762 for (i
= 0; i
< possible_cpus
->len
; i
++) {
763 const CPUArchId
*cpu_slot
= &possible_cpus
->cpus
[i
];
765 if (!cpu_slot
->props
.has_node_id
) {
766 /* fetch default mapping from board and enable it */
767 CpuInstanceProperties props
= cpu_slot
->props
;
769 props
.node_id
= mc
->get_default_cpu_node_id(machine
, i
);
770 if (!default_mapping
) {
771 /* record slots with not set mapping,
772 * TODO: make it hard error in future */
773 char *cpu_str
= cpu_slot_to_string(cpu_slot
);
774 g_string_append_printf(s
, "%sCPU %d [%s]",
775 s
->len
? ", " : "", i
, cpu_str
);
778 /* non mapped cpus used to fallback to node 0 */
782 props
.has_node_id
= true;
783 machine_set_cpu_numa_node(machine
, &props
, &error_fatal
);
786 if (s
->len
&& !qtest_enabled()) {
787 warn_report("CPU(s) not present in any NUMA nodes: %s",
789 warn_report("All CPU(s) up to maxcpus should be described "
790 "in NUMA config, ability to start up with partial NUMA "
791 "mappings is obsoleted and will be removed in future");
793 g_string_free(s
, true);
796 void machine_run_board_init(MachineState
*machine
)
798 MachineClass
*machine_class
= MACHINE_GET_CLASS(machine
);
800 numa_complete_configuration(machine
);
802 machine_numa_finish_cpu_init(machine
);
805 /* If the machine supports the valid_cpu_types check and the user
806 * specified a CPU with -cpu check here that the user CPU is supported.
808 if (machine_class
->valid_cpu_types
&& machine
->cpu_type
) {
809 ObjectClass
*class = object_class_by_name(machine
->cpu_type
);
812 for (i
= 0; machine_class
->valid_cpu_types
[i
]; i
++) {
813 if (object_class_dynamic_cast(class,
814 machine_class
->valid_cpu_types
[i
])) {
815 /* The user specificed CPU is in the valid field, we are
822 if (!machine_class
->valid_cpu_types
[i
]) {
823 /* The user specified CPU is not valid */
824 error_report("Invalid CPU type: %s", machine
->cpu_type
);
825 error_printf("The valid types are: %s",
826 machine_class
->valid_cpu_types
[0]);
827 for (i
= 1; machine_class
->valid_cpu_types
[i
]; i
++) {
828 error_printf(", %s", machine_class
->valid_cpu_types
[i
]);
836 machine_class
->init(machine
);
839 void machine_register_compat_props(MachineState
*machine
)
841 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
845 if (!mc
->compat_props
) {
849 for (i
= 0; i
< mc
->compat_props
->len
; i
++) {
850 p
= g_array_index(mc
->compat_props
, GlobalProperty
*, i
);
851 /* Machine compat_props must never cause errors: */
852 p
->errp
= &error_abort
;
853 qdev_prop_register_global(p
);
857 static const TypeInfo machine_info
= {
858 .name
= TYPE_MACHINE
,
859 .parent
= TYPE_OBJECT
,
861 .class_size
= sizeof(MachineClass
),
862 .class_init
= machine_class_init
,
863 .class_base_init
= machine_class_base_init
,
864 .instance_size
= sizeof(MachineState
),
865 .instance_init
= machine_initfn
,
866 .instance_finalize
= machine_finalize
,
869 static void machine_register_types(void)
871 type_register_static(&machine_info
);
874 type_init(machine_register_types
)