]> git.proxmox.com Git - mirror_qemu.git/blob - hw/core/machine.c
virtio-blk: add "discard" and "write-zeroes" properties
[mirror_qemu.git] / hw / core / machine.c
1 /*
2 * QEMU Machine
3 *
4 * Copyright (C) 2014 Red Hat Inc
5 *
6 * Authors:
7 * Marcel Apfelbaum <marcel.a@redhat.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
11 */
12
13 #include "qemu/osdep.h"
14 #include "qemu/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"
24 #include "hw/pci/pci.h"
25
26 GlobalProperty hw_compat_3_1[] = {
27 { "pcie-root-port", "x-speed", "2_5" },
28 { "pcie-root-port", "x-width", "1" },
29 { "memory-backend-file", "x-use-canonical-path-for-ramblock-id", "true" },
30 { "memory-backend-memfd", "x-use-canonical-path-for-ramblock-id", "true" },
31 { "tpm-crb", "ppi", "false" },
32 { "tpm-tis", "ppi", "false" },
33 { "usb-kbd", "serial", "42" },
34 { "usb-mouse", "serial", "42" },
35 { "usb-kbd", "serial", "42" },
36 { "virtio-blk-device", "discard", "false" },
37 { "virtio-blk-device", "write-zeroes", "false" },
38 };
39 const size_t hw_compat_3_1_len = G_N_ELEMENTS(hw_compat_3_1);
40
41 GlobalProperty hw_compat_3_0[] = {};
42 const size_t hw_compat_3_0_len = G_N_ELEMENTS(hw_compat_3_0);
43
44 GlobalProperty hw_compat_2_12[] = {
45 { "migration", "decompress-error-check", "off" },
46 { "hda-audio", "use-timer", "false" },
47 { "cirrus-vga", "global-vmstate", "true" },
48 { "VGA", "global-vmstate", "true" },
49 { "vmware-svga", "global-vmstate", "true" },
50 { "qxl-vga", "global-vmstate", "true" },
51 };
52 const size_t hw_compat_2_12_len = G_N_ELEMENTS(hw_compat_2_12);
53
54 GlobalProperty hw_compat_2_11[] = {
55 { "hpet", "hpet-offset-saved", "false" },
56 { "virtio-blk-pci", "vectors", "2" },
57 { "vhost-user-blk-pci", "vectors", "2" },
58 { "e1000", "migrate_tso_props", "off" },
59 };
60 const size_t hw_compat_2_11_len = G_N_ELEMENTS(hw_compat_2_11);
61
62 GlobalProperty hw_compat_2_10[] = {
63 { "virtio-mouse-device", "wheel-axis", "false" },
64 { "virtio-tablet-device", "wheel-axis", "false" },
65 };
66 const size_t hw_compat_2_10_len = G_N_ELEMENTS(hw_compat_2_10);
67
68 GlobalProperty hw_compat_2_9[] = {
69 { "pci-bridge", "shpc", "off" },
70 { "intel-iommu", "pt", "off" },
71 { "virtio-net-device", "x-mtu-bypass-backend", "off" },
72 { "pcie-root-port", "x-migrate-msix", "false" },
73 };
74 const size_t hw_compat_2_9_len = G_N_ELEMENTS(hw_compat_2_9);
75
76 GlobalProperty hw_compat_2_8[] = {
77 { "fw_cfg_mem", "x-file-slots", "0x10" },
78 { "fw_cfg_io", "x-file-slots", "0x10" },
79 { "pflash_cfi01", "old-multiple-chip-handling", "on" },
80 { "pci-bridge", "shpc", "on" },
81 { TYPE_PCI_DEVICE, "x-pcie-extcap-init", "off" },
82 { "virtio-pci", "x-pcie-deverr-init", "off" },
83 { "virtio-pci", "x-pcie-lnkctl-init", "off" },
84 { "virtio-pci", "x-pcie-pm-init", "off" },
85 { "cirrus-vga", "vgamem_mb", "8" },
86 { "isa-cirrus-vga", "vgamem_mb", "8" },
87 };
88 const size_t hw_compat_2_8_len = G_N_ELEMENTS(hw_compat_2_8);
89
90 GlobalProperty hw_compat_2_7[] = {
91 { "virtio-pci", "page-per-vq", "on" },
92 { "virtio-serial-device", "emergency-write", "off" },
93 { "ioapic", "version", "0x11" },
94 { "intel-iommu", "x-buggy-eim", "true" },
95 { "virtio-pci", "x-ignore-backend-features", "on" },
96 };
97 const size_t hw_compat_2_7_len = G_N_ELEMENTS(hw_compat_2_7);
98
99 GlobalProperty hw_compat_2_6[] = {
100 { "virtio-mmio", "format_transport_address", "off" },
101 /* Optional because not all virtio-pci devices support legacy mode */
102 { "virtio-pci", "disable-modern", "on", .optional = true },
103 { "virtio-pci", "disable-legacy", "off", .optional = true },
104 };
105 const size_t hw_compat_2_6_len = G_N_ELEMENTS(hw_compat_2_6);
106
107 GlobalProperty hw_compat_2_5[] = {
108 { "isa-fdc", "fallback", "144" },
109 { "pvscsi", "x-old-pci-configuration", "on" },
110 { "pvscsi", "x-disable-pcie", "on" },
111 { "vmxnet3", "x-old-msi-offsets", "on" },
112 { "vmxnet3", "x-disable-pcie", "on" },
113 };
114 const size_t hw_compat_2_5_len = G_N_ELEMENTS(hw_compat_2_5);
115
116 GlobalProperty hw_compat_2_4[] = {
117 { "virtio-blk-device", "scsi", "true" },
118 { "e1000", "extra_mac_registers", "off" },
119 { "virtio-pci", "x-disable-pcie", "on" },
120 { "virtio-pci", "migrate-extra", "off" },
121 { "fw_cfg_mem", "dma_enabled", "off" },
122 { "fw_cfg_io", "dma_enabled", "off" }
123 };
124 const size_t hw_compat_2_4_len = G_N_ELEMENTS(hw_compat_2_4);
125
126 GlobalProperty hw_compat_2_3[] = {
127 { "virtio-blk-pci", "any_layout", "off" },
128 { "virtio-balloon-pci", "any_layout", "off" },
129 { "virtio-serial-pci", "any_layout", "off" },
130 { "virtio-9p-pci", "any_layout", "off" },
131 { "virtio-rng-pci", "any_layout", "off" },
132 { TYPE_PCI_DEVICE, "x-pcie-lnksta-dllla", "off" },
133 { "migration", "send-configuration", "off" },
134 { "migration", "send-section-footer", "off" },
135 { "migration", "store-global-state", "off" },
136 };
137 const size_t hw_compat_2_3_len = G_N_ELEMENTS(hw_compat_2_3);
138
139 GlobalProperty hw_compat_2_2[] = {};
140 const size_t hw_compat_2_2_len = G_N_ELEMENTS(hw_compat_2_2);
141
142 GlobalProperty hw_compat_2_1[] = {
143 { "intel-hda", "old_msi_addr", "on" },
144 { "VGA", "qemu-extended-regs", "off" },
145 { "secondary-vga", "qemu-extended-regs", "off" },
146 { "virtio-scsi-pci", "any_layout", "off" },
147 { "usb-mouse", "usb_version", "1" },
148 { "usb-kbd", "usb_version", "1" },
149 { "virtio-pci", "virtio-pci-bus-master-bug-migration", "on" },
150 };
151 const size_t hw_compat_2_1_len = G_N_ELEMENTS(hw_compat_2_1);
152
153 static char *machine_get_accel(Object *obj, Error **errp)
154 {
155 MachineState *ms = MACHINE(obj);
156
157 return g_strdup(ms->accel);
158 }
159
160 static void machine_set_accel(Object *obj, const char *value, Error **errp)
161 {
162 MachineState *ms = MACHINE(obj);
163
164 g_free(ms->accel);
165 ms->accel = g_strdup(value);
166 }
167
168 static void machine_set_kernel_irqchip(Object *obj, Visitor *v,
169 const char *name, void *opaque,
170 Error **errp)
171 {
172 Error *err = NULL;
173 MachineState *ms = MACHINE(obj);
174 OnOffSplit mode;
175
176 visit_type_OnOffSplit(v, name, &mode, &err);
177 if (err) {
178 error_propagate(errp, err);
179 return;
180 } else {
181 switch (mode) {
182 case ON_OFF_SPLIT_ON:
183 ms->kernel_irqchip_allowed = true;
184 ms->kernel_irqchip_required = true;
185 ms->kernel_irqchip_split = false;
186 break;
187 case ON_OFF_SPLIT_OFF:
188 ms->kernel_irqchip_allowed = false;
189 ms->kernel_irqchip_required = false;
190 ms->kernel_irqchip_split = false;
191 break;
192 case ON_OFF_SPLIT_SPLIT:
193 ms->kernel_irqchip_allowed = true;
194 ms->kernel_irqchip_required = true;
195 ms->kernel_irqchip_split = true;
196 break;
197 default:
198 /* The value was checked in visit_type_OnOffSplit() above. If
199 * we get here, then something is wrong in QEMU.
200 */
201 abort();
202 }
203 }
204 }
205
206 static void machine_get_kvm_shadow_mem(Object *obj, Visitor *v,
207 const char *name, void *opaque,
208 Error **errp)
209 {
210 MachineState *ms = MACHINE(obj);
211 int64_t value = ms->kvm_shadow_mem;
212
213 visit_type_int(v, name, &value, errp);
214 }
215
216 static void machine_set_kvm_shadow_mem(Object *obj, Visitor *v,
217 const char *name, void *opaque,
218 Error **errp)
219 {
220 MachineState *ms = MACHINE(obj);
221 Error *error = NULL;
222 int64_t value;
223
224 visit_type_int(v, name, &value, &error);
225 if (error) {
226 error_propagate(errp, error);
227 return;
228 }
229
230 ms->kvm_shadow_mem = value;
231 }
232
233 static char *machine_get_kernel(Object *obj, Error **errp)
234 {
235 MachineState *ms = MACHINE(obj);
236
237 return g_strdup(ms->kernel_filename);
238 }
239
240 static void machine_set_kernel(Object *obj, const char *value, Error **errp)
241 {
242 MachineState *ms = MACHINE(obj);
243
244 g_free(ms->kernel_filename);
245 ms->kernel_filename = g_strdup(value);
246 }
247
248 static char *machine_get_initrd(Object *obj, Error **errp)
249 {
250 MachineState *ms = MACHINE(obj);
251
252 return g_strdup(ms->initrd_filename);
253 }
254
255 static void machine_set_initrd(Object *obj, const char *value, Error **errp)
256 {
257 MachineState *ms = MACHINE(obj);
258
259 g_free(ms->initrd_filename);
260 ms->initrd_filename = g_strdup(value);
261 }
262
263 static char *machine_get_append(Object *obj, Error **errp)
264 {
265 MachineState *ms = MACHINE(obj);
266
267 return g_strdup(ms->kernel_cmdline);
268 }
269
270 static void machine_set_append(Object *obj, const char *value, Error **errp)
271 {
272 MachineState *ms = MACHINE(obj);
273
274 g_free(ms->kernel_cmdline);
275 ms->kernel_cmdline = g_strdup(value);
276 }
277
278 static char *machine_get_dtb(Object *obj, Error **errp)
279 {
280 MachineState *ms = MACHINE(obj);
281
282 return g_strdup(ms->dtb);
283 }
284
285 static void machine_set_dtb(Object *obj, const char *value, Error **errp)
286 {
287 MachineState *ms = MACHINE(obj);
288
289 g_free(ms->dtb);
290 ms->dtb = g_strdup(value);
291 }
292
293 static char *machine_get_dumpdtb(Object *obj, Error **errp)
294 {
295 MachineState *ms = MACHINE(obj);
296
297 return g_strdup(ms->dumpdtb);
298 }
299
300 static void machine_set_dumpdtb(Object *obj, const char *value, Error **errp)
301 {
302 MachineState *ms = MACHINE(obj);
303
304 g_free(ms->dumpdtb);
305 ms->dumpdtb = g_strdup(value);
306 }
307
308 static void machine_get_phandle_start(Object *obj, Visitor *v,
309 const char *name, void *opaque,
310 Error **errp)
311 {
312 MachineState *ms = MACHINE(obj);
313 int64_t value = ms->phandle_start;
314
315 visit_type_int(v, name, &value, errp);
316 }
317
318 static void machine_set_phandle_start(Object *obj, Visitor *v,
319 const char *name, void *opaque,
320 Error **errp)
321 {
322 MachineState *ms = MACHINE(obj);
323 Error *error = NULL;
324 int64_t value;
325
326 visit_type_int(v, name, &value, &error);
327 if (error) {
328 error_propagate(errp, error);
329 return;
330 }
331
332 ms->phandle_start = value;
333 }
334
335 static char *machine_get_dt_compatible(Object *obj, Error **errp)
336 {
337 MachineState *ms = MACHINE(obj);
338
339 return g_strdup(ms->dt_compatible);
340 }
341
342 static void machine_set_dt_compatible(Object *obj, const char *value, Error **errp)
343 {
344 MachineState *ms = MACHINE(obj);
345
346 g_free(ms->dt_compatible);
347 ms->dt_compatible = g_strdup(value);
348 }
349
350 static bool machine_get_dump_guest_core(Object *obj, Error **errp)
351 {
352 MachineState *ms = MACHINE(obj);
353
354 return ms->dump_guest_core;
355 }
356
357 static void machine_set_dump_guest_core(Object *obj, bool value, Error **errp)
358 {
359 MachineState *ms = MACHINE(obj);
360
361 ms->dump_guest_core = value;
362 }
363
364 static bool machine_get_mem_merge(Object *obj, Error **errp)
365 {
366 MachineState *ms = MACHINE(obj);
367
368 return ms->mem_merge;
369 }
370
371 static void machine_set_mem_merge(Object *obj, bool value, Error **errp)
372 {
373 MachineState *ms = MACHINE(obj);
374
375 ms->mem_merge = value;
376 }
377
378 static bool machine_get_usb(Object *obj, Error **errp)
379 {
380 MachineState *ms = MACHINE(obj);
381
382 return ms->usb;
383 }
384
385 static void machine_set_usb(Object *obj, bool value, Error **errp)
386 {
387 MachineState *ms = MACHINE(obj);
388
389 ms->usb = value;
390 ms->usb_disabled = !value;
391 }
392
393 static bool machine_get_graphics(Object *obj, Error **errp)
394 {
395 MachineState *ms = MACHINE(obj);
396
397 return ms->enable_graphics;
398 }
399
400 static void machine_set_graphics(Object *obj, bool value, Error **errp)
401 {
402 MachineState *ms = MACHINE(obj);
403
404 ms->enable_graphics = value;
405 }
406
407 static bool machine_get_igd_gfx_passthru(Object *obj, Error **errp)
408 {
409 MachineState *ms = MACHINE(obj);
410
411 return ms->igd_gfx_passthru;
412 }
413
414 static void machine_set_igd_gfx_passthru(Object *obj, bool value, Error **errp)
415 {
416 MachineState *ms = MACHINE(obj);
417
418 ms->igd_gfx_passthru = value;
419 }
420
421 static char *machine_get_firmware(Object *obj, Error **errp)
422 {
423 MachineState *ms = MACHINE(obj);
424
425 return g_strdup(ms->firmware);
426 }
427
428 static void machine_set_firmware(Object *obj, const char *value, Error **errp)
429 {
430 MachineState *ms = MACHINE(obj);
431
432 g_free(ms->firmware);
433 ms->firmware = g_strdup(value);
434 }
435
436 static void machine_set_suppress_vmdesc(Object *obj, bool value, Error **errp)
437 {
438 MachineState *ms = MACHINE(obj);
439
440 ms->suppress_vmdesc = value;
441 }
442
443 static bool machine_get_suppress_vmdesc(Object *obj, Error **errp)
444 {
445 MachineState *ms = MACHINE(obj);
446
447 return ms->suppress_vmdesc;
448 }
449
450 static void machine_set_enforce_config_section(Object *obj, bool value,
451 Error **errp)
452 {
453 MachineState *ms = MACHINE(obj);
454
455 warn_report("enforce-config-section is deprecated, please use "
456 "-global migration.send-configuration=on|off instead");
457
458 ms->enforce_config_section = value;
459 }
460
461 static bool machine_get_enforce_config_section(Object *obj, Error **errp)
462 {
463 MachineState *ms = MACHINE(obj);
464
465 return ms->enforce_config_section;
466 }
467
468 static char *machine_get_memory_encryption(Object *obj, Error **errp)
469 {
470 MachineState *ms = MACHINE(obj);
471
472 return g_strdup(ms->memory_encryption);
473 }
474
475 static void machine_set_memory_encryption(Object *obj, const char *value,
476 Error **errp)
477 {
478 MachineState *ms = MACHINE(obj);
479
480 g_free(ms->memory_encryption);
481 ms->memory_encryption = g_strdup(value);
482 }
483
484 void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type)
485 {
486 strList *item = g_new0(strList, 1);
487
488 item->value = g_strdup(type);
489 item->next = mc->allowed_dynamic_sysbus_devices;
490 mc->allowed_dynamic_sysbus_devices = item;
491 }
492
493 static void validate_sysbus_device(SysBusDevice *sbdev, void *opaque)
494 {
495 MachineState *machine = opaque;
496 MachineClass *mc = MACHINE_GET_CLASS(machine);
497 bool allowed = false;
498 strList *wl;
499
500 for (wl = mc->allowed_dynamic_sysbus_devices;
501 !allowed && wl;
502 wl = wl->next) {
503 allowed |= !!object_dynamic_cast(OBJECT(sbdev), wl->value);
504 }
505
506 if (!allowed) {
507 error_report("Option '-device %s' cannot be handled by this machine",
508 object_class_get_name(object_get_class(OBJECT(sbdev))));
509 exit(1);
510 }
511 }
512
513 static void machine_init_notify(Notifier *notifier, void *data)
514 {
515 MachineState *machine = MACHINE(qdev_get_machine());
516
517 /*
518 * Loop through all dynamically created sysbus devices and check if they are
519 * all allowed. If a device is not allowed, error out.
520 */
521 foreach_dynamic_sysbus_device(validate_sysbus_device, machine);
522 }
523
524 HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine)
525 {
526 int i;
527 HotpluggableCPUList *head = NULL;
528 MachineClass *mc = MACHINE_GET_CLASS(machine);
529
530 /* force board to initialize possible_cpus if it hasn't been done yet */
531 mc->possible_cpu_arch_ids(machine);
532
533 for (i = 0; i < machine->possible_cpus->len; i++) {
534 Object *cpu;
535 HotpluggableCPUList *list_item = g_new0(typeof(*list_item), 1);
536 HotpluggableCPU *cpu_item = g_new0(typeof(*cpu_item), 1);
537
538 cpu_item->type = g_strdup(machine->possible_cpus->cpus[i].type);
539 cpu_item->vcpus_count = machine->possible_cpus->cpus[i].vcpus_count;
540 cpu_item->props = g_memdup(&machine->possible_cpus->cpus[i].props,
541 sizeof(*cpu_item->props));
542
543 cpu = machine->possible_cpus->cpus[i].cpu;
544 if (cpu) {
545 cpu_item->has_qom_path = true;
546 cpu_item->qom_path = object_get_canonical_path(cpu);
547 }
548 list_item->value = cpu_item;
549 list_item->next = head;
550 head = list_item;
551 }
552 return head;
553 }
554
555 /**
556 * machine_set_cpu_numa_node:
557 * @machine: machine object to modify
558 * @props: specifies which cpu objects to assign to
559 * numa node specified by @props.node_id
560 * @errp: if an error occurs, a pointer to an area to store the error
561 *
562 * Associate NUMA node specified by @props.node_id with cpu slots that
563 * match socket/core/thread-ids specified by @props. It's recommended to use
564 * query-hotpluggable-cpus.props values to specify affected cpu slots,
565 * which would lead to exact 1:1 mapping of cpu slots to NUMA node.
566 *
567 * However for CLI convenience it's possible to pass in subset of properties,
568 * which would affect all cpu slots that match it.
569 * Ex for pc machine:
570 * -smp 4,cores=2,sockets=2 -numa node,nodeid=0 -numa node,nodeid=1 \
571 * -numa cpu,node-id=0,socket_id=0 \
572 * -numa cpu,node-id=1,socket_id=1
573 * will assign all child cores of socket 0 to node 0 and
574 * of socket 1 to node 1.
575 *
576 * On attempt of reassigning (already assigned) cpu slot to another NUMA node,
577 * return error.
578 * Empty subset is disallowed and function will return with error in this case.
579 */
580 void machine_set_cpu_numa_node(MachineState *machine,
581 const CpuInstanceProperties *props, Error **errp)
582 {
583 MachineClass *mc = MACHINE_GET_CLASS(machine);
584 bool match = false;
585 int i;
586
587 if (!mc->possible_cpu_arch_ids) {
588 error_setg(errp, "mapping of CPUs to NUMA node is not supported");
589 return;
590 }
591
592 /* disabling node mapping is not supported, forbid it */
593 assert(props->has_node_id);
594
595 /* force board to initialize possible_cpus if it hasn't been done yet */
596 mc->possible_cpu_arch_ids(machine);
597
598 for (i = 0; i < machine->possible_cpus->len; i++) {
599 CPUArchId *slot = &machine->possible_cpus->cpus[i];
600
601 /* reject unsupported by board properties */
602 if (props->has_thread_id && !slot->props.has_thread_id) {
603 error_setg(errp, "thread-id is not supported");
604 return;
605 }
606
607 if (props->has_core_id && !slot->props.has_core_id) {
608 error_setg(errp, "core-id is not supported");
609 return;
610 }
611
612 if (props->has_socket_id && !slot->props.has_socket_id) {
613 error_setg(errp, "socket-id is not supported");
614 return;
615 }
616
617 /* skip slots with explicit mismatch */
618 if (props->has_thread_id && props->thread_id != slot->props.thread_id) {
619 continue;
620 }
621
622 if (props->has_core_id && props->core_id != slot->props.core_id) {
623 continue;
624 }
625
626 if (props->has_socket_id && props->socket_id != slot->props.socket_id) {
627 continue;
628 }
629
630 /* reject assignment if slot is already assigned, for compatibility
631 * of legacy cpu_index mapping with SPAPR core based mapping do not
632 * error out if cpu thread and matched core have the same node-id */
633 if (slot->props.has_node_id &&
634 slot->props.node_id != props->node_id) {
635 error_setg(errp, "CPU is already assigned to node-id: %" PRId64,
636 slot->props.node_id);
637 return;
638 }
639
640 /* assign slot to node as it's matched '-numa cpu' key */
641 match = true;
642 slot->props.node_id = props->node_id;
643 slot->props.has_node_id = props->has_node_id;
644 }
645
646 if (!match) {
647 error_setg(errp, "no match found");
648 }
649 }
650
651 static void machine_class_init(ObjectClass *oc, void *data)
652 {
653 MachineClass *mc = MACHINE_CLASS(oc);
654
655 /* Default 128 MB as guest ram size */
656 mc->default_ram_size = 128 * MiB;
657 mc->rom_file_has_mr = true;
658
659 /* numa node memory size aligned on 8MB by default.
660 * On Linux, each node's border has to be 8MB aligned
661 */
662 mc->numa_mem_align_shift = 23;
663 mc->numa_auto_assign_ram = numa_default_auto_assign_ram;
664
665 object_class_property_add_str(oc, "accel",
666 machine_get_accel, machine_set_accel, &error_abort);
667 object_class_property_set_description(oc, "accel",
668 "Accelerator list", &error_abort);
669
670 object_class_property_add(oc, "kernel-irqchip", "on|off|split",
671 NULL, machine_set_kernel_irqchip,
672 NULL, NULL, &error_abort);
673 object_class_property_set_description(oc, "kernel-irqchip",
674 "Configure KVM in-kernel irqchip", &error_abort);
675
676 object_class_property_add(oc, "kvm-shadow-mem", "int",
677 machine_get_kvm_shadow_mem, machine_set_kvm_shadow_mem,
678 NULL, NULL, &error_abort);
679 object_class_property_set_description(oc, "kvm-shadow-mem",
680 "KVM shadow MMU size", &error_abort);
681
682 object_class_property_add_str(oc, "kernel",
683 machine_get_kernel, machine_set_kernel, &error_abort);
684 object_class_property_set_description(oc, "kernel",
685 "Linux kernel image file", &error_abort);
686
687 object_class_property_add_str(oc, "initrd",
688 machine_get_initrd, machine_set_initrd, &error_abort);
689 object_class_property_set_description(oc, "initrd",
690 "Linux initial ramdisk file", &error_abort);
691
692 object_class_property_add_str(oc, "append",
693 machine_get_append, machine_set_append, &error_abort);
694 object_class_property_set_description(oc, "append",
695 "Linux kernel command line", &error_abort);
696
697 object_class_property_add_str(oc, "dtb",
698 machine_get_dtb, machine_set_dtb, &error_abort);
699 object_class_property_set_description(oc, "dtb",
700 "Linux kernel device tree file", &error_abort);
701
702 object_class_property_add_str(oc, "dumpdtb",
703 machine_get_dumpdtb, machine_set_dumpdtb, &error_abort);
704 object_class_property_set_description(oc, "dumpdtb",
705 "Dump current dtb to a file and quit", &error_abort);
706
707 object_class_property_add(oc, "phandle-start", "int",
708 machine_get_phandle_start, machine_set_phandle_start,
709 NULL, NULL, &error_abort);
710 object_class_property_set_description(oc, "phandle-start",
711 "The first phandle ID we may generate dynamically", &error_abort);
712
713 object_class_property_add_str(oc, "dt-compatible",
714 machine_get_dt_compatible, machine_set_dt_compatible, &error_abort);
715 object_class_property_set_description(oc, "dt-compatible",
716 "Overrides the \"compatible\" property of the dt root node",
717 &error_abort);
718
719 object_class_property_add_bool(oc, "dump-guest-core",
720 machine_get_dump_guest_core, machine_set_dump_guest_core, &error_abort);
721 object_class_property_set_description(oc, "dump-guest-core",
722 "Include guest memory in a core dump", &error_abort);
723
724 object_class_property_add_bool(oc, "mem-merge",
725 machine_get_mem_merge, machine_set_mem_merge, &error_abort);
726 object_class_property_set_description(oc, "mem-merge",
727 "Enable/disable memory merge support", &error_abort);
728
729 object_class_property_add_bool(oc, "usb",
730 machine_get_usb, machine_set_usb, &error_abort);
731 object_class_property_set_description(oc, "usb",
732 "Set on/off to enable/disable usb", &error_abort);
733
734 object_class_property_add_bool(oc, "graphics",
735 machine_get_graphics, machine_set_graphics, &error_abort);
736 object_class_property_set_description(oc, "graphics",
737 "Set on/off to enable/disable graphics emulation", &error_abort);
738
739 object_class_property_add_bool(oc, "igd-passthru",
740 machine_get_igd_gfx_passthru, machine_set_igd_gfx_passthru,
741 &error_abort);
742 object_class_property_set_description(oc, "igd-passthru",
743 "Set on/off to enable/disable igd passthrou", &error_abort);
744
745 object_class_property_add_str(oc, "firmware",
746 machine_get_firmware, machine_set_firmware,
747 &error_abort);
748 object_class_property_set_description(oc, "firmware",
749 "Firmware image", &error_abort);
750
751 object_class_property_add_bool(oc, "suppress-vmdesc",
752 machine_get_suppress_vmdesc, machine_set_suppress_vmdesc,
753 &error_abort);
754 object_class_property_set_description(oc, "suppress-vmdesc",
755 "Set on to disable self-describing migration", &error_abort);
756
757 object_class_property_add_bool(oc, "enforce-config-section",
758 machine_get_enforce_config_section, machine_set_enforce_config_section,
759 &error_abort);
760 object_class_property_set_description(oc, "enforce-config-section",
761 "Set on to enforce configuration section migration", &error_abort);
762
763 object_class_property_add_str(oc, "memory-encryption",
764 machine_get_memory_encryption, machine_set_memory_encryption,
765 &error_abort);
766 object_class_property_set_description(oc, "memory-encryption",
767 "Set memory encryption object to use", &error_abort);
768 }
769
770 static void machine_class_base_init(ObjectClass *oc, void *data)
771 {
772 if (!object_class_is_abstract(oc)) {
773 MachineClass *mc = MACHINE_CLASS(oc);
774 const char *cname = object_class_get_name(oc);
775 assert(g_str_has_suffix(cname, TYPE_MACHINE_SUFFIX));
776 mc->name = g_strndup(cname,
777 strlen(cname) - strlen(TYPE_MACHINE_SUFFIX));
778 mc->compat_props = g_ptr_array_new();
779 }
780 }
781
782 static void machine_initfn(Object *obj)
783 {
784 MachineState *ms = MACHINE(obj);
785 MachineClass *mc = MACHINE_GET_CLASS(obj);
786
787 ms->kernel_irqchip_allowed = true;
788 ms->kernel_irqchip_split = mc->default_kernel_irqchip_split;
789 ms->kvm_shadow_mem = -1;
790 ms->dump_guest_core = true;
791 ms->mem_merge = true;
792 ms->enable_graphics = true;
793
794 /* Register notifier when init is done for sysbus sanity checks */
795 ms->sysbus_notifier.notify = machine_init_notify;
796 qemu_add_machine_init_done_notifier(&ms->sysbus_notifier);
797 }
798
799 static void machine_finalize(Object *obj)
800 {
801 MachineState *ms = MACHINE(obj);
802
803 g_free(ms->accel);
804 g_free(ms->kernel_filename);
805 g_free(ms->initrd_filename);
806 g_free(ms->kernel_cmdline);
807 g_free(ms->dtb);
808 g_free(ms->dumpdtb);
809 g_free(ms->dt_compatible);
810 g_free(ms->firmware);
811 g_free(ms->device_memory);
812 }
813
814 bool machine_usb(MachineState *machine)
815 {
816 return machine->usb;
817 }
818
819 bool machine_kernel_irqchip_allowed(MachineState *machine)
820 {
821 return machine->kernel_irqchip_allowed;
822 }
823
824 bool machine_kernel_irqchip_required(MachineState *machine)
825 {
826 return machine->kernel_irqchip_required;
827 }
828
829 bool machine_kernel_irqchip_split(MachineState *machine)
830 {
831 return machine->kernel_irqchip_split;
832 }
833
834 int machine_kvm_shadow_mem(MachineState *machine)
835 {
836 return machine->kvm_shadow_mem;
837 }
838
839 int machine_phandle_start(MachineState *machine)
840 {
841 return machine->phandle_start;
842 }
843
844 bool machine_dump_guest_core(MachineState *machine)
845 {
846 return machine->dump_guest_core;
847 }
848
849 bool machine_mem_merge(MachineState *machine)
850 {
851 return machine->mem_merge;
852 }
853
854 static char *cpu_slot_to_string(const CPUArchId *cpu)
855 {
856 GString *s = g_string_new(NULL);
857 if (cpu->props.has_socket_id) {
858 g_string_append_printf(s, "socket-id: %"PRId64, cpu->props.socket_id);
859 }
860 if (cpu->props.has_core_id) {
861 if (s->len) {
862 g_string_append_printf(s, ", ");
863 }
864 g_string_append_printf(s, "core-id: %"PRId64, cpu->props.core_id);
865 }
866 if (cpu->props.has_thread_id) {
867 if (s->len) {
868 g_string_append_printf(s, ", ");
869 }
870 g_string_append_printf(s, "thread-id: %"PRId64, cpu->props.thread_id);
871 }
872 return g_string_free(s, false);
873 }
874
875 static void machine_numa_finish_cpu_init(MachineState *machine)
876 {
877 int i;
878 bool default_mapping;
879 GString *s = g_string_new(NULL);
880 MachineClass *mc = MACHINE_GET_CLASS(machine);
881 const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(machine);
882
883 assert(nb_numa_nodes);
884 for (i = 0; i < possible_cpus->len; i++) {
885 if (possible_cpus->cpus[i].props.has_node_id) {
886 break;
887 }
888 }
889 default_mapping = (i == possible_cpus->len);
890
891 for (i = 0; i < possible_cpus->len; i++) {
892 const CPUArchId *cpu_slot = &possible_cpus->cpus[i];
893
894 if (!cpu_slot->props.has_node_id) {
895 /* fetch default mapping from board and enable it */
896 CpuInstanceProperties props = cpu_slot->props;
897
898 props.node_id = mc->get_default_cpu_node_id(machine, i);
899 if (!default_mapping) {
900 /* record slots with not set mapping,
901 * TODO: make it hard error in future */
902 char *cpu_str = cpu_slot_to_string(cpu_slot);
903 g_string_append_printf(s, "%sCPU %d [%s]",
904 s->len ? ", " : "", i, cpu_str);
905 g_free(cpu_str);
906
907 /* non mapped cpus used to fallback to node 0 */
908 props.node_id = 0;
909 }
910
911 props.has_node_id = true;
912 machine_set_cpu_numa_node(machine, &props, &error_fatal);
913 }
914 }
915 if (s->len && !qtest_enabled()) {
916 warn_report("CPU(s) not present in any NUMA nodes: %s",
917 s->str);
918 warn_report("All CPU(s) up to maxcpus should be described "
919 "in NUMA config, ability to start up with partial NUMA "
920 "mappings is obsoleted and will be removed in future");
921 }
922 g_string_free(s, true);
923 }
924
925 void machine_run_board_init(MachineState *machine)
926 {
927 MachineClass *machine_class = MACHINE_GET_CLASS(machine);
928
929 numa_complete_configuration(machine);
930 if (nb_numa_nodes) {
931 machine_numa_finish_cpu_init(machine);
932 }
933
934 /* If the machine supports the valid_cpu_types check and the user
935 * specified a CPU with -cpu check here that the user CPU is supported.
936 */
937 if (machine_class->valid_cpu_types && machine->cpu_type) {
938 ObjectClass *class = object_class_by_name(machine->cpu_type);
939 int i;
940
941 for (i = 0; machine_class->valid_cpu_types[i]; i++) {
942 if (object_class_dynamic_cast(class,
943 machine_class->valid_cpu_types[i])) {
944 /* The user specificed CPU is in the valid field, we are
945 * good to go.
946 */
947 break;
948 }
949 }
950
951 if (!machine_class->valid_cpu_types[i]) {
952 /* The user specified CPU is not valid */
953 error_report("Invalid CPU type: %s", machine->cpu_type);
954 error_printf("The valid types are: %s",
955 machine_class->valid_cpu_types[0]);
956 for (i = 1; machine_class->valid_cpu_types[i]; i++) {
957 error_printf(", %s", machine_class->valid_cpu_types[i]);
958 }
959 error_printf("\n");
960
961 exit(1);
962 }
963 }
964
965 machine_class->init(machine);
966 }
967
968 static const TypeInfo machine_info = {
969 .name = TYPE_MACHINE,
970 .parent = TYPE_OBJECT,
971 .abstract = true,
972 .class_size = sizeof(MachineClass),
973 .class_init = machine_class_init,
974 .class_base_init = machine_class_base_init,
975 .instance_size = sizeof(MachineState),
976 .instance_init = machine_initfn,
977 .instance_finalize = machine_finalize,
978 };
979
980 static void machine_register_types(void)
981 {
982 type_register_static(&machine_info);
983 }
984
985 type_init(machine_register_types)