]> git.proxmox.com Git - mirror_qemu.git/blob - softmmu/vl.c
Merge remote-tracking branch 'remotes/armbru/tags/pull-qom-fdc-2021-03-16-v5' into...
[mirror_qemu.git] / softmmu / vl.c
1 /*
2 * QEMU System Emulator
3 *
4 * Copyright (c) 2003-2008 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25 #include "qemu/osdep.h"
26 #include "qemu-common.h"
27 #include "qemu/datadir.h"
28 #include "qemu/units.h"
29 #include "exec/cpu-common.h"
30 #include "hw/boards.h"
31 #include "hw/qdev-properties.h"
32 #include "qapi/error.h"
33 #include "qapi/qmp/qdict.h"
34 #include "qapi/qmp/qjson.h"
35 #include "qemu-version.h"
36 #include "qemu/cutils.h"
37 #include "qemu/help_option.h"
38 #include "qemu/uuid.h"
39 #include "sysemu/reset.h"
40 #include "sysemu/runstate.h"
41 #include "sysemu/runstate-action.h"
42 #include "sysemu/seccomp.h"
43 #include "sysemu/tcg.h"
44 #include "sysemu/xen.h"
45
46 #include "qemu/error-report.h"
47 #include "qemu/sockets.h"
48 #include "qemu/accel.h"
49 #include "hw/usb.h"
50 #include "hw/isa/isa.h"
51 #include "hw/scsi/scsi.h"
52 #include "hw/display/vga.h"
53 #include "sysemu/watchdog.h"
54 #include "hw/firmware/smbios.h"
55 #include "hw/acpi/acpi.h"
56 #include "hw/xen/xen.h"
57 #include "hw/loader.h"
58 #include "monitor/qdev.h"
59 #include "net/net.h"
60 #include "net/slirp.h"
61 #include "monitor/monitor.h"
62 #include "ui/console.h"
63 #include "ui/input.h"
64 #include "sysemu/sysemu.h"
65 #include "sysemu/numa.h"
66 #include "sysemu/hostmem.h"
67 #include "exec/gdbstub.h"
68 #include "qemu/timer.h"
69 #include "chardev/char.h"
70 #include "qemu/bitmap.h"
71 #include "qemu/log.h"
72 #include "sysemu/blockdev.h"
73 #include "hw/block/block.h"
74 #include "hw/i386/x86.h"
75 #include "hw/i386/pc.h"
76 #include "migration/misc.h"
77 #include "migration/snapshot.h"
78 #include "sysemu/tpm.h"
79 #include "sysemu/dma.h"
80 #include "hw/audio/soundhw.h"
81 #include "audio/audio.h"
82 #include "sysemu/cpus.h"
83 #include "sysemu/cpu-timers.h"
84 #include "migration/colo.h"
85 #include "migration/postcopy-ram.h"
86 #include "sysemu/kvm.h"
87 #include "sysemu/hax.h"
88 #include "qapi/qobject-input-visitor.h"
89 #include "qemu/option.h"
90 #include "qemu/config-file.h"
91 #include "qemu-options.h"
92 #include "qemu/main-loop.h"
93 #ifdef CONFIG_VIRTFS
94 #include "fsdev/qemu-fsdev.h"
95 #endif
96 #include "sysemu/qtest.h"
97
98 #include "disas/disas.h"
99
100 #include "trace.h"
101 #include "trace/control.h"
102 #include "qemu/plugin.h"
103 #include "qemu/queue.h"
104 #include "sysemu/arch_init.h"
105 #include "exec/confidential-guest-support.h"
106
107 #include "ui/qemu-spice.h"
108 #include "qapi/string-input-visitor.h"
109 #include "qapi/opts-visitor.h"
110 #include "qapi/clone-visitor.h"
111 #include "qom/object_interfaces.h"
112 #include "semihosting/semihost.h"
113 #include "crypto/init.h"
114 #include "sysemu/replay.h"
115 #include "qapi/qapi-events-run-state.h"
116 #include "qapi/qapi-visit-block-core.h"
117 #include "qapi/qapi-visit-ui.h"
118 #include "qapi/qapi-commands-block-core.h"
119 #include "qapi/qapi-commands-migration.h"
120 #include "qapi/qapi-commands-misc.h"
121 #include "qapi/qapi-visit-qom.h"
122 #include "qapi/qapi-commands-ui.h"
123 #include "qapi/qmp/qerror.h"
124 #include "sysemu/iothread.h"
125 #include "qemu/guest-random.h"
126
127 #define MAX_VIRTIO_CONSOLES 1
128
129 typedef struct BlockdevOptionsQueueEntry {
130 BlockdevOptions *bdo;
131 Location loc;
132 QSIMPLEQ_ENTRY(BlockdevOptionsQueueEntry) entry;
133 } BlockdevOptionsQueueEntry;
134
135 typedef QSIMPLEQ_HEAD(, BlockdevOptionsQueueEntry) BlockdevOptionsQueue;
136
137 typedef struct ObjectOption {
138 ObjectOptions *opts;
139 QTAILQ_ENTRY(ObjectOption) next;
140 } ObjectOption;
141
142 static const char *cpu_option;
143 static const char *mem_path;
144 static const char *incoming;
145 static const char *loadvm;
146 static QTAILQ_HEAD(, ObjectOption) object_opts = QTAILQ_HEAD_INITIALIZER(object_opts);
147 static ram_addr_t maxram_size;
148 static uint64_t ram_slots;
149 static int display_remote;
150 static int snapshot;
151 static bool preconfig_requested;
152 static QemuPluginList plugin_list = QTAILQ_HEAD_INITIALIZER(plugin_list);
153 static BlockdevOptionsQueue bdo_queue = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue);
154 static bool nographic = false;
155 static int mem_prealloc; /* force preallocation of physical target memory */
156 static ram_addr_t ram_size;
157 static const char *vga_model = NULL;
158 static DisplayOptions dpy;
159 static int num_serial_hds;
160 static Chardev **serial_hds;
161 static const char *log_mask;
162 static const char *log_file;
163 static bool list_data_dirs;
164 static const char *watchdog;
165 static const char *qtest_chrdev;
166 static const char *qtest_log;
167
168 static int has_defaults = 1;
169 static int default_serial = 1;
170 static int default_parallel = 1;
171 static int default_monitor = 1;
172 static int default_floppy = 1;
173 static int default_cdrom = 1;
174 static int default_sdcard = 1;
175 static int default_vga = 1;
176 static int default_net = 1;
177
178 static struct {
179 const char *driver;
180 int *flag;
181 } default_list[] = {
182 { .driver = "isa-serial", .flag = &default_serial },
183 { .driver = "isa-parallel", .flag = &default_parallel },
184 { .driver = "isa-fdc", .flag = &default_floppy },
185 { .driver = "floppy", .flag = &default_floppy },
186 { .driver = "ide-cd", .flag = &default_cdrom },
187 { .driver = "ide-hd", .flag = &default_cdrom },
188 { .driver = "scsi-cd", .flag = &default_cdrom },
189 { .driver = "scsi-hd", .flag = &default_cdrom },
190 { .driver = "VGA", .flag = &default_vga },
191 { .driver = "isa-vga", .flag = &default_vga },
192 { .driver = "cirrus-vga", .flag = &default_vga },
193 { .driver = "isa-cirrus-vga", .flag = &default_vga },
194 { .driver = "vmware-svga", .flag = &default_vga },
195 { .driver = "qxl-vga", .flag = &default_vga },
196 { .driver = "virtio-vga", .flag = &default_vga },
197 { .driver = "ati-vga", .flag = &default_vga },
198 { .driver = "vhost-user-vga", .flag = &default_vga },
199 };
200
201 static QemuOptsList qemu_rtc_opts = {
202 .name = "rtc",
203 .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head),
204 .merge_lists = true,
205 .desc = {
206 {
207 .name = "base",
208 .type = QEMU_OPT_STRING,
209 },{
210 .name = "clock",
211 .type = QEMU_OPT_STRING,
212 },{
213 .name = "driftfix",
214 .type = QEMU_OPT_STRING,
215 },
216 { /* end of list */ }
217 },
218 };
219
220 static QemuOptsList qemu_option_rom_opts = {
221 .name = "option-rom",
222 .implied_opt_name = "romfile",
223 .head = QTAILQ_HEAD_INITIALIZER(qemu_option_rom_opts.head),
224 .desc = {
225 {
226 .name = "bootindex",
227 .type = QEMU_OPT_NUMBER,
228 }, {
229 .name = "romfile",
230 .type = QEMU_OPT_STRING,
231 },
232 { /* end of list */ }
233 },
234 };
235
236 static QemuOptsList qemu_machine_opts = {
237 .name = "machine",
238 .implied_opt_name = "type",
239 .merge_lists = true,
240 .head = QTAILQ_HEAD_INITIALIZER(qemu_machine_opts.head),
241 .desc = {
242 /*
243 * no elements => accept any
244 * sanity checking will happen later
245 * when setting machine properties
246 */
247 { }
248 },
249 };
250
251 static QemuOptsList qemu_accel_opts = {
252 .name = "accel",
253 .implied_opt_name = "accel",
254 .head = QTAILQ_HEAD_INITIALIZER(qemu_accel_opts.head),
255 .desc = {
256 /*
257 * no elements => accept any
258 * sanity checking will happen later
259 * when setting accelerator properties
260 */
261 { }
262 },
263 };
264
265 static QemuOptsList qemu_boot_opts = {
266 .name = "boot-opts",
267 .implied_opt_name = "order",
268 .merge_lists = true,
269 .head = QTAILQ_HEAD_INITIALIZER(qemu_boot_opts.head),
270 .desc = {
271 {
272 .name = "order",
273 .type = QEMU_OPT_STRING,
274 }, {
275 .name = "once",
276 .type = QEMU_OPT_STRING,
277 }, {
278 .name = "menu",
279 .type = QEMU_OPT_BOOL,
280 }, {
281 .name = "splash",
282 .type = QEMU_OPT_STRING,
283 }, {
284 .name = "splash-time",
285 .type = QEMU_OPT_NUMBER,
286 }, {
287 .name = "reboot-timeout",
288 .type = QEMU_OPT_NUMBER,
289 }, {
290 .name = "strict",
291 .type = QEMU_OPT_BOOL,
292 },
293 { /*End of list */ }
294 },
295 };
296
297 static QemuOptsList qemu_add_fd_opts = {
298 .name = "add-fd",
299 .head = QTAILQ_HEAD_INITIALIZER(qemu_add_fd_opts.head),
300 .desc = {
301 {
302 .name = "fd",
303 .type = QEMU_OPT_NUMBER,
304 .help = "file descriptor of which a duplicate is added to fd set",
305 },{
306 .name = "set",
307 .type = QEMU_OPT_NUMBER,
308 .help = "ID of the fd set to add fd to",
309 },{
310 .name = "opaque",
311 .type = QEMU_OPT_STRING,
312 .help = "free-form string used to describe fd",
313 },
314 { /* end of list */ }
315 },
316 };
317
318 static QemuOptsList qemu_object_opts = {
319 .name = "object",
320 .implied_opt_name = "qom-type",
321 .head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head),
322 .desc = {
323 { }
324 },
325 };
326
327 static QemuOptsList qemu_tpmdev_opts = {
328 .name = "tpmdev",
329 .implied_opt_name = "type",
330 .head = QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts.head),
331 .desc = {
332 /* options are defined in the TPM backends */
333 { /* end of list */ }
334 },
335 };
336
337 static QemuOptsList qemu_overcommit_opts = {
338 .name = "overcommit",
339 .head = QTAILQ_HEAD_INITIALIZER(qemu_overcommit_opts.head),
340 .desc = {
341 {
342 .name = "mem-lock",
343 .type = QEMU_OPT_BOOL,
344 },
345 {
346 .name = "cpu-pm",
347 .type = QEMU_OPT_BOOL,
348 },
349 { /* end of list */ }
350 },
351 };
352
353 static QemuOptsList qemu_msg_opts = {
354 .name = "msg",
355 .head = QTAILQ_HEAD_INITIALIZER(qemu_msg_opts.head),
356 .desc = {
357 {
358 .name = "timestamp",
359 .type = QEMU_OPT_BOOL,
360 },
361 {
362 .name = "guest-name",
363 .type = QEMU_OPT_BOOL,
364 .help = "Prepends guest name for error messages but only if "
365 "-name guest is set otherwise option is ignored\n",
366 },
367 { /* end of list */ }
368 },
369 };
370
371 static QemuOptsList qemu_name_opts = {
372 .name = "name",
373 .implied_opt_name = "guest",
374 .merge_lists = true,
375 .head = QTAILQ_HEAD_INITIALIZER(qemu_name_opts.head),
376 .desc = {
377 {
378 .name = "guest",
379 .type = QEMU_OPT_STRING,
380 .help = "Sets the name of the guest.\n"
381 "This name will be displayed in the SDL window caption.\n"
382 "The name will also be used for the VNC server",
383 }, {
384 .name = "process",
385 .type = QEMU_OPT_STRING,
386 .help = "Sets the name of the QEMU process, as shown in top etc",
387 }, {
388 .name = "debug-threads",
389 .type = QEMU_OPT_BOOL,
390 .help = "When enabled, name the individual threads; defaults off.\n"
391 "NOTE: The thread names are for debugging and not a\n"
392 "stable API.",
393 },
394 { /* End of list */ }
395 },
396 };
397
398 static QemuOptsList qemu_mem_opts = {
399 .name = "memory",
400 .implied_opt_name = "size",
401 .head = QTAILQ_HEAD_INITIALIZER(qemu_mem_opts.head),
402 .merge_lists = true,
403 .desc = {
404 {
405 .name = "size",
406 .type = QEMU_OPT_SIZE,
407 },
408 {
409 .name = "slots",
410 .type = QEMU_OPT_NUMBER,
411 },
412 {
413 .name = "maxmem",
414 .type = QEMU_OPT_SIZE,
415 },
416 { /* end of list */ }
417 },
418 };
419
420 static QemuOptsList qemu_icount_opts = {
421 .name = "icount",
422 .implied_opt_name = "shift",
423 .merge_lists = true,
424 .head = QTAILQ_HEAD_INITIALIZER(qemu_icount_opts.head),
425 .desc = {
426 {
427 .name = "shift",
428 .type = QEMU_OPT_STRING,
429 }, {
430 .name = "align",
431 .type = QEMU_OPT_BOOL,
432 }, {
433 .name = "sleep",
434 .type = QEMU_OPT_BOOL,
435 }, {
436 .name = "rr",
437 .type = QEMU_OPT_STRING,
438 }, {
439 .name = "rrfile",
440 .type = QEMU_OPT_STRING,
441 }, {
442 .name = "rrsnapshot",
443 .type = QEMU_OPT_STRING,
444 },
445 { /* end of list */ }
446 },
447 };
448
449 static QemuOptsList qemu_fw_cfg_opts = {
450 .name = "fw_cfg",
451 .implied_opt_name = "name",
452 .head = QTAILQ_HEAD_INITIALIZER(qemu_fw_cfg_opts.head),
453 .desc = {
454 {
455 .name = "name",
456 .type = QEMU_OPT_STRING,
457 .help = "Sets the fw_cfg name of the blob to be inserted",
458 }, {
459 .name = "file",
460 .type = QEMU_OPT_STRING,
461 .help = "Sets the name of the file from which "
462 "the fw_cfg blob will be loaded",
463 }, {
464 .name = "string",
465 .type = QEMU_OPT_STRING,
466 .help = "Sets content of the blob to be inserted from a string",
467 }, {
468 .name = "gen_id",
469 .type = QEMU_OPT_STRING,
470 .help = "Sets id of the object generating the fw_cfg blob "
471 "to be inserted",
472 },
473 { /* end of list */ }
474 },
475 };
476
477 static QemuOptsList qemu_action_opts = {
478 .name = "action",
479 .merge_lists = true,
480 .head = QTAILQ_HEAD_INITIALIZER(qemu_action_opts.head),
481 .desc = {
482 {
483 .name = "shutdown",
484 .type = QEMU_OPT_STRING,
485 },{
486 .name = "reboot",
487 .type = QEMU_OPT_STRING,
488 },{
489 .name = "panic",
490 .type = QEMU_OPT_STRING,
491 },{
492 .name = "watchdog",
493 .type = QEMU_OPT_STRING,
494 },
495 { /* end of list */ }
496 },
497 };
498
499 /**
500 * Get machine options
501 *
502 * Returns: machine options (never null).
503 */
504 static QemuOpts *qemu_get_machine_opts(void)
505 {
506 return qemu_find_opts_singleton("machine");
507 }
508
509 const char *qemu_get_vm_name(void)
510 {
511 return qemu_name;
512 }
513
514 static int default_driver_check(void *opaque, QemuOpts *opts, Error **errp)
515 {
516 const char *driver = qemu_opt_get(opts, "driver");
517 int i;
518
519 if (!driver)
520 return 0;
521 for (i = 0; i < ARRAY_SIZE(default_list); i++) {
522 if (strcmp(default_list[i].driver, driver) != 0)
523 continue;
524 *(default_list[i].flag) = 0;
525 }
526 return 0;
527 }
528
529 static int parse_name(void *opaque, QemuOpts *opts, Error **errp)
530 {
531 const char *proc_name;
532
533 if (qemu_opt_get(opts, "debug-threads")) {
534 qemu_thread_naming(qemu_opt_get_bool(opts, "debug-threads", false));
535 }
536 qemu_name = qemu_opt_get(opts, "guest");
537
538 proc_name = qemu_opt_get(opts, "process");
539 if (proc_name) {
540 os_set_proc_name(proc_name);
541 }
542
543 return 0;
544 }
545
546 bool defaults_enabled(void)
547 {
548 return has_defaults;
549 }
550
551 #ifndef _WIN32
552 static int parse_add_fd(void *opaque, QemuOpts *opts, Error **errp)
553 {
554 int fd, dupfd, flags;
555 int64_t fdset_id;
556 const char *fd_opaque = NULL;
557 AddfdInfo *fdinfo;
558
559 fd = qemu_opt_get_number(opts, "fd", -1);
560 fdset_id = qemu_opt_get_number(opts, "set", -1);
561 fd_opaque = qemu_opt_get(opts, "opaque");
562
563 if (fd < 0) {
564 error_setg(errp, "fd option is required and must be non-negative");
565 return -1;
566 }
567
568 if (fd <= STDERR_FILENO) {
569 error_setg(errp, "fd cannot be a standard I/O stream");
570 return -1;
571 }
572
573 /*
574 * All fds inherited across exec() necessarily have FD_CLOEXEC
575 * clear, while qemu sets FD_CLOEXEC on all other fds used internally.
576 */
577 flags = fcntl(fd, F_GETFD);
578 if (flags == -1 || (flags & FD_CLOEXEC)) {
579 error_setg(errp, "fd is not valid or already in use");
580 return -1;
581 }
582
583 if (fdset_id < 0) {
584 error_setg(errp, "set option is required and must be non-negative");
585 return -1;
586 }
587
588 #ifdef F_DUPFD_CLOEXEC
589 dupfd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
590 #else
591 dupfd = dup(fd);
592 if (dupfd != -1) {
593 qemu_set_cloexec(dupfd);
594 }
595 #endif
596 if (dupfd == -1) {
597 error_setg(errp, "error duplicating fd: %s", strerror(errno));
598 return -1;
599 }
600
601 /* add the duplicate fd, and optionally the opaque string, to the fd set */
602 fdinfo = monitor_fdset_add_fd(dupfd, true, fdset_id, !!fd_opaque, fd_opaque,
603 &error_abort);
604 g_free(fdinfo);
605
606 return 0;
607 }
608
609 static int cleanup_add_fd(void *opaque, QemuOpts *opts, Error **errp)
610 {
611 int fd;
612
613 fd = qemu_opt_get_number(opts, "fd", -1);
614 close(fd);
615
616 return 0;
617 }
618 #endif
619
620 /***********************************************************/
621 /* QEMU Block devices */
622
623 #define HD_OPTS "media=disk"
624 #define CDROM_OPTS "media=cdrom"
625 #define FD_OPTS ""
626 #define PFLASH_OPTS ""
627 #define MTD_OPTS ""
628 #define SD_OPTS ""
629
630 static int drive_init_func(void *opaque, QemuOpts *opts, Error **errp)
631 {
632 BlockInterfaceType *block_default_type = opaque;
633
634 return drive_new(opts, *block_default_type, errp) == NULL;
635 }
636
637 static int drive_enable_snapshot(void *opaque, QemuOpts *opts, Error **errp)
638 {
639 if (qemu_opt_get(opts, "snapshot") == NULL) {
640 qemu_opt_set(opts, "snapshot", "on", &error_abort);
641 }
642 return 0;
643 }
644
645 static void default_drive(int enable, int snapshot, BlockInterfaceType type,
646 int index, const char *optstr)
647 {
648 QemuOpts *opts;
649 DriveInfo *dinfo;
650
651 if (!enable || drive_get_by_index(type, index)) {
652 return;
653 }
654
655 opts = drive_add(type, index, NULL, optstr);
656 if (snapshot) {
657 drive_enable_snapshot(NULL, opts, NULL);
658 }
659
660 dinfo = drive_new(opts, type, &error_abort);
661 dinfo->is_default = true;
662
663 }
664
665 static void configure_blockdev(BlockdevOptionsQueue *bdo_queue,
666 MachineClass *machine_class, int snapshot)
667 {
668 /*
669 * If the currently selected machine wishes to override the
670 * units-per-bus property of its default HBA interface type, do so
671 * now.
672 */
673 if (machine_class->units_per_default_bus) {
674 override_max_devs(machine_class->block_default_type,
675 machine_class->units_per_default_bus);
676 }
677
678 /* open the virtual block devices */
679 while (!QSIMPLEQ_EMPTY(bdo_queue)) {
680 BlockdevOptionsQueueEntry *bdo = QSIMPLEQ_FIRST(bdo_queue);
681
682 QSIMPLEQ_REMOVE_HEAD(bdo_queue, entry);
683 loc_push_restore(&bdo->loc);
684 qmp_blockdev_add(bdo->bdo, &error_fatal);
685 loc_pop(&bdo->loc);
686 qapi_free_BlockdevOptions(bdo->bdo);
687 g_free(bdo);
688 }
689 if (snapshot) {
690 qemu_opts_foreach(qemu_find_opts("drive"), drive_enable_snapshot,
691 NULL, NULL);
692 }
693 if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func,
694 &machine_class->block_default_type, &error_fatal)) {
695 /* We printed help */
696 exit(0);
697 }
698
699 default_drive(default_cdrom, snapshot, machine_class->block_default_type, 2,
700 CDROM_OPTS);
701 default_drive(default_floppy, snapshot, IF_FLOPPY, 0, FD_OPTS);
702 default_drive(default_sdcard, snapshot, IF_SD, 0, SD_OPTS);
703
704 }
705
706 static QemuOptsList qemu_smp_opts = {
707 .name = "smp-opts",
708 .implied_opt_name = "cpus",
709 .merge_lists = true,
710 .head = QTAILQ_HEAD_INITIALIZER(qemu_smp_opts.head),
711 .desc = {
712 {
713 .name = "cpus",
714 .type = QEMU_OPT_NUMBER,
715 }, {
716 .name = "sockets",
717 .type = QEMU_OPT_NUMBER,
718 }, {
719 .name = "dies",
720 .type = QEMU_OPT_NUMBER,
721 }, {
722 .name = "cores",
723 .type = QEMU_OPT_NUMBER,
724 }, {
725 .name = "threads",
726 .type = QEMU_OPT_NUMBER,
727 }, {
728 .name = "maxcpus",
729 .type = QEMU_OPT_NUMBER,
730 },
731 { /*End of list */ }
732 },
733 };
734
735 static void realtime_init(void)
736 {
737 if (enable_mlock) {
738 if (os_mlock() < 0) {
739 error_report("locking memory failed");
740 exit(1);
741 }
742 }
743 }
744
745
746 static void configure_msg(QemuOpts *opts)
747 {
748 message_with_timestamp = qemu_opt_get_bool(opts, "timestamp", false);
749 error_with_guestname = qemu_opt_get_bool(opts, "guest-name", false);
750 }
751
752
753 /***********************************************************/
754 /* USB devices */
755
756 static int usb_device_add(const char *devname)
757 {
758 USBDevice *dev = NULL;
759
760 if (!machine_usb(current_machine)) {
761 return -1;
762 }
763
764 dev = usbdevice_create(devname);
765 if (!dev)
766 return -1;
767
768 return 0;
769 }
770
771 static int usb_parse(const char *cmdline)
772 {
773 int r;
774 r = usb_device_add(cmdline);
775 if (r < 0) {
776 error_report("could not add USB device '%s'", cmdline);
777 }
778 return r;
779 }
780
781 /***********************************************************/
782 /* machine registration */
783
784 static MachineClass *find_machine(const char *name, GSList *machines)
785 {
786 GSList *el;
787
788 for (el = machines; el; el = el->next) {
789 MachineClass *mc = el->data;
790
791 if (!strcmp(mc->name, name) || !g_strcmp0(mc->alias, name)) {
792 return mc;
793 }
794 }
795
796 return NULL;
797 }
798
799 static MachineClass *find_default_machine(GSList *machines)
800 {
801 GSList *el;
802 MachineClass *default_machineclass = NULL;
803
804 for (el = machines; el; el = el->next) {
805 MachineClass *mc = el->data;
806
807 if (mc->is_default) {
808 assert(default_machineclass == NULL && "Multiple default machines");
809 default_machineclass = mc;
810 }
811 }
812
813 return default_machineclass;
814 }
815
816 static int machine_help_func(QemuOpts *opts, MachineState *machine)
817 {
818 ObjectProperty *prop;
819 ObjectPropertyIterator iter;
820
821 if (!qemu_opt_has_help_opt(opts)) {
822 return 0;
823 }
824
825 object_property_iter_init(&iter, OBJECT(machine));
826 while ((prop = object_property_iter_next(&iter))) {
827 if (!prop->set) {
828 continue;
829 }
830
831 printf("%s.%s=%s", MACHINE_GET_CLASS(machine)->name,
832 prop->name, prop->type);
833 if (prop->description) {
834 printf(" (%s)\n", prop->description);
835 } else {
836 printf("\n");
837 }
838 }
839
840 return 1;
841 }
842
843 static void version(void)
844 {
845 printf("QEMU emulator version " QEMU_FULL_VERSION "\n"
846 QEMU_COPYRIGHT "\n");
847 }
848
849 static void help(int exitcode)
850 {
851 version();
852 printf("usage: %s [options] [disk_image]\n\n"
853 "'disk_image' is a raw hard disk image for IDE hard disk 0\n\n",
854 error_get_progname());
855
856 #define QEMU_OPTIONS_GENERATE_HELP
857 #include "qemu-options-wrapper.h"
858
859 printf("\nDuring emulation, the following keys are useful:\n"
860 "ctrl-alt-f toggle full screen\n"
861 "ctrl-alt-n switch to virtual console 'n'\n"
862 "ctrl-alt toggle mouse and keyboard grab\n"
863 "\n"
864 "When using -nographic, press 'ctrl-a h' to get some help.\n"
865 "\n"
866 QEMU_HELP_BOTTOM "\n");
867
868 exit(exitcode);
869 }
870
871 #define HAS_ARG 0x0001
872
873 typedef struct QEMUOption {
874 const char *name;
875 int flags;
876 int index;
877 uint32_t arch_mask;
878 } QEMUOption;
879
880 static const QEMUOption qemu_options[] = {
881 { "h", 0, QEMU_OPTION_h, QEMU_ARCH_ALL },
882 #define QEMU_OPTIONS_GENERATE_OPTIONS
883 #include "qemu-options-wrapper.h"
884 { NULL },
885 };
886
887 typedef struct VGAInterfaceInfo {
888 const char *opt_name; /* option name */
889 const char *name; /* human-readable name */
890 /* Class names indicating that support is available.
891 * If no class is specified, the interface is always available */
892 const char *class_names[2];
893 } VGAInterfaceInfo;
894
895 static const VGAInterfaceInfo vga_interfaces[VGA_TYPE_MAX] = {
896 [VGA_NONE] = {
897 .opt_name = "none",
898 .name = "no graphic card",
899 },
900 [VGA_STD] = {
901 .opt_name = "std",
902 .name = "standard VGA",
903 .class_names = { "VGA", "isa-vga" },
904 },
905 [VGA_CIRRUS] = {
906 .opt_name = "cirrus",
907 .name = "Cirrus VGA",
908 .class_names = { "cirrus-vga", "isa-cirrus-vga" },
909 },
910 [VGA_VMWARE] = {
911 .opt_name = "vmware",
912 .name = "VMWare SVGA",
913 .class_names = { "vmware-svga" },
914 },
915 [VGA_VIRTIO] = {
916 .opt_name = "virtio",
917 .name = "Virtio VGA",
918 .class_names = { "virtio-vga" },
919 },
920 [VGA_QXL] = {
921 .opt_name = "qxl",
922 .name = "QXL VGA",
923 .class_names = { "qxl-vga" },
924 },
925 [VGA_TCX] = {
926 .opt_name = "tcx",
927 .name = "TCX framebuffer",
928 .class_names = { "sun-tcx" },
929 },
930 [VGA_CG3] = {
931 .opt_name = "cg3",
932 .name = "CG3 framebuffer",
933 .class_names = { "cgthree" },
934 },
935 [VGA_XENFB] = {
936 .opt_name = "xenfb",
937 .name = "Xen paravirtualized framebuffer",
938 },
939 };
940
941 static bool vga_interface_available(VGAInterfaceType t)
942 {
943 const VGAInterfaceInfo *ti = &vga_interfaces[t];
944
945 assert(t < VGA_TYPE_MAX);
946 return !ti->class_names[0] ||
947 module_object_class_by_name(ti->class_names[0]) ||
948 module_object_class_by_name(ti->class_names[1]);
949 }
950
951 static const char *
952 get_default_vga_model(const MachineClass *machine_class)
953 {
954 if (machine_class->default_display) {
955 return machine_class->default_display;
956 } else if (vga_interface_available(VGA_CIRRUS)) {
957 return "cirrus";
958 } else if (vga_interface_available(VGA_STD)) {
959 return "std";
960 }
961
962 return NULL;
963 }
964
965 static void select_vgahw(const MachineClass *machine_class, const char *p)
966 {
967 const char *opts;
968 int t;
969
970 if (g_str_equal(p, "help")) {
971 const char *def = get_default_vga_model(machine_class);
972
973 for (t = 0; t < VGA_TYPE_MAX; t++) {
974 const VGAInterfaceInfo *ti = &vga_interfaces[t];
975
976 if (vga_interface_available(t) && ti->opt_name) {
977 printf("%-20s %s%s\n", ti->opt_name, ti->name ?: "",
978 g_str_equal(ti->opt_name, def) ? " (default)" : "");
979 }
980 }
981 exit(0);
982 }
983
984 assert(vga_interface_type == VGA_NONE);
985 for (t = 0; t < VGA_TYPE_MAX; t++) {
986 const VGAInterfaceInfo *ti = &vga_interfaces[t];
987 if (ti->opt_name && strstart(p, ti->opt_name, &opts)) {
988 if (!vga_interface_available(t)) {
989 error_report("%s not available", ti->name);
990 exit(1);
991 }
992 vga_interface_type = t;
993 break;
994 }
995 }
996 if (t == VGA_TYPE_MAX) {
997 invalid_vga:
998 error_report("unknown vga type: %s", p);
999 exit(1);
1000 }
1001 while (*opts) {
1002 const char *nextopt;
1003
1004 if (strstart(opts, ",retrace=", &nextopt)) {
1005 opts = nextopt;
1006 if (strstart(opts, "dumb", &nextopt))
1007 vga_retrace_method = VGA_RETRACE_DUMB;
1008 else if (strstart(opts, "precise", &nextopt))
1009 vga_retrace_method = VGA_RETRACE_PRECISE;
1010 else goto invalid_vga;
1011 } else goto invalid_vga;
1012 opts = nextopt;
1013 }
1014 }
1015
1016 static void parse_display_qapi(const char *optarg)
1017 {
1018 DisplayOptions *opts;
1019 Visitor *v;
1020
1021 v = qobject_input_visitor_new_str(optarg, "type", &error_fatal);
1022
1023 visit_type_DisplayOptions(v, NULL, &opts, &error_fatal);
1024 QAPI_CLONE_MEMBERS(DisplayOptions, &dpy, opts);
1025
1026 qapi_free_DisplayOptions(opts);
1027 visit_free(v);
1028 }
1029
1030 DisplayOptions *qmp_query_display_options(Error **errp)
1031 {
1032 return QAPI_CLONE(DisplayOptions, &dpy);
1033 }
1034
1035 static void parse_display(const char *p)
1036 {
1037 const char *opts;
1038
1039 if (is_help_option(p)) {
1040 qemu_display_help();
1041 exit(0);
1042 }
1043
1044 if (strstart(p, "sdl", &opts)) {
1045 /*
1046 * sdl DisplayType needs hand-crafted parser instead of
1047 * parse_display_qapi() due to some options not in
1048 * DisplayOptions, specifically:
1049 * - frame
1050 * Already deprecated.
1051 * - ctrl_grab + alt_grab
1052 * Not clear yet what happens to them long-term. Should
1053 * replaced by something better or deprecated and dropped.
1054 */
1055 dpy.type = DISPLAY_TYPE_SDL;
1056 while (*opts) {
1057 const char *nextopt;
1058
1059 if (strstart(opts, ",alt_grab=", &nextopt)) {
1060 opts = nextopt;
1061 if (strstart(opts, "on", &nextopt)) {
1062 alt_grab = 1;
1063 } else if (strstart(opts, "off", &nextopt)) {
1064 alt_grab = 0;
1065 } else {
1066 goto invalid_sdl_args;
1067 }
1068 } else if (strstart(opts, ",ctrl_grab=", &nextopt)) {
1069 opts = nextopt;
1070 if (strstart(opts, "on", &nextopt)) {
1071 ctrl_grab = 1;
1072 } else if (strstart(opts, "off", &nextopt)) {
1073 ctrl_grab = 0;
1074 } else {
1075 goto invalid_sdl_args;
1076 }
1077 } else if (strstart(opts, ",window_close=", &nextopt)) {
1078 opts = nextopt;
1079 dpy.has_window_close = true;
1080 if (strstart(opts, "on", &nextopt)) {
1081 dpy.window_close = true;
1082 } else if (strstart(opts, "off", &nextopt)) {
1083 dpy.window_close = false;
1084 } else {
1085 goto invalid_sdl_args;
1086 }
1087 } else if (strstart(opts, ",show-cursor=", &nextopt)) {
1088 opts = nextopt;
1089 dpy.has_show_cursor = true;
1090 if (strstart(opts, "on", &nextopt)) {
1091 dpy.show_cursor = true;
1092 } else if (strstart(opts, "off", &nextopt)) {
1093 dpy.show_cursor = false;
1094 } else {
1095 goto invalid_sdl_args;
1096 }
1097 } else if (strstart(opts, ",gl=", &nextopt)) {
1098 opts = nextopt;
1099 dpy.has_gl = true;
1100 if (strstart(opts, "on", &nextopt)) {
1101 dpy.gl = DISPLAYGL_MODE_ON;
1102 } else if (strstart(opts, "core", &nextopt)) {
1103 dpy.gl = DISPLAYGL_MODE_CORE;
1104 } else if (strstart(opts, "es", &nextopt)) {
1105 dpy.gl = DISPLAYGL_MODE_ES;
1106 } else if (strstart(opts, "off", &nextopt)) {
1107 dpy.gl = DISPLAYGL_MODE_OFF;
1108 } else {
1109 goto invalid_sdl_args;
1110 }
1111 } else {
1112 invalid_sdl_args:
1113 error_report("invalid SDL option string");
1114 exit(1);
1115 }
1116 opts = nextopt;
1117 }
1118 } else if (strstart(p, "vnc", &opts)) {
1119 /*
1120 * vnc isn't a (local) DisplayType but a protocol for remote
1121 * display access.
1122 */
1123 if (*opts == '=') {
1124 vnc_parse(opts + 1);
1125 } else {
1126 error_report("VNC requires a display argument vnc=<display>");
1127 exit(1);
1128 }
1129 } else {
1130 parse_display_qapi(p);
1131 }
1132 }
1133
1134 static inline bool nonempty_str(const char *str)
1135 {
1136 return str && *str;
1137 }
1138
1139 static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp)
1140 {
1141 gchar *buf;
1142 size_t size;
1143 const char *name, *file, *str, *gen_id;
1144 FWCfgState *fw_cfg = (FWCfgState *) opaque;
1145
1146 if (fw_cfg == NULL) {
1147 error_setg(errp, "fw_cfg device not available");
1148 return -1;
1149 }
1150 name = qemu_opt_get(opts, "name");
1151 file = qemu_opt_get(opts, "file");
1152 str = qemu_opt_get(opts, "string");
1153 gen_id = qemu_opt_get(opts, "gen_id");
1154
1155 /* we need the name, and exactly one of: file, content string, gen_id */
1156 if (!nonempty_str(name) ||
1157 nonempty_str(file) + nonempty_str(str) + nonempty_str(gen_id) != 1) {
1158 error_setg(errp, "name, plus exactly one of file,"
1159 " string and gen_id, are needed");
1160 return -1;
1161 }
1162 if (strlen(name) > FW_CFG_MAX_FILE_PATH - 1) {
1163 error_setg(errp, "name too long (max. %d char)",
1164 FW_CFG_MAX_FILE_PATH - 1);
1165 return -1;
1166 }
1167 if (nonempty_str(gen_id)) {
1168 /*
1169 * In this particular case where the content is populated
1170 * internally, the "etc/" namespace protection is relaxed,
1171 * so do not emit a warning.
1172 */
1173 } else if (strncmp(name, "opt/", 4) != 0) {
1174 warn_report("externally provided fw_cfg item names "
1175 "should be prefixed with \"opt/\"");
1176 }
1177 if (nonempty_str(str)) {
1178 size = strlen(str); /* NUL terminator NOT included in fw_cfg blob */
1179 buf = g_memdup(str, size);
1180 } else if (nonempty_str(gen_id)) {
1181 if (!fw_cfg_add_from_generator(fw_cfg, name, gen_id, errp)) {
1182 return -1;
1183 }
1184 return 0;
1185 } else {
1186 GError *err = NULL;
1187 if (!g_file_get_contents(file, &buf, &size, &err)) {
1188 error_setg(errp, "can't load %s: %s", file, err->message);
1189 g_error_free(err);
1190 return -1;
1191 }
1192 }
1193 /* For legacy, keep user files in a specific global order. */
1194 fw_cfg_set_order_override(fw_cfg, FW_CFG_ORDER_OVERRIDE_USER);
1195 fw_cfg_add_file(fw_cfg, name, buf, size);
1196 fw_cfg_reset_order_override(fw_cfg);
1197 return 0;
1198 }
1199
1200 static int device_help_func(void *opaque, QemuOpts *opts, Error **errp)
1201 {
1202 return qdev_device_help(opts);
1203 }
1204
1205 static int device_init_func(void *opaque, QemuOpts *opts, Error **errp)
1206 {
1207 DeviceState *dev;
1208
1209 dev = qdev_device_add(opts, errp);
1210 if (!dev && *errp) {
1211 error_report_err(*errp);
1212 return -1;
1213 } else if (dev) {
1214 object_unref(OBJECT(dev));
1215 }
1216 return 0;
1217 }
1218
1219 static int chardev_init_func(void *opaque, QemuOpts *opts, Error **errp)
1220 {
1221 Error *local_err = NULL;
1222
1223 if (!qemu_chr_new_from_opts(opts, NULL, &local_err)) {
1224 if (local_err) {
1225 error_propagate(errp, local_err);
1226 return -1;
1227 }
1228 exit(0);
1229 }
1230 return 0;
1231 }
1232
1233 #ifdef CONFIG_VIRTFS
1234 static int fsdev_init_func(void *opaque, QemuOpts *opts, Error **errp)
1235 {
1236 return qemu_fsdev_add(opts, errp);
1237 }
1238 #endif
1239
1240 static int mon_init_func(void *opaque, QemuOpts *opts, Error **errp)
1241 {
1242 return monitor_init_opts(opts, errp);
1243 }
1244
1245 static void monitor_parse(const char *optarg, const char *mode, bool pretty)
1246 {
1247 static int monitor_device_index = 0;
1248 QemuOpts *opts;
1249 const char *p;
1250 char label[32];
1251
1252 if (strstart(optarg, "chardev:", &p)) {
1253 snprintf(label, sizeof(label), "%s", p);
1254 } else {
1255 snprintf(label, sizeof(label), "compat_monitor%d",
1256 monitor_device_index);
1257 opts = qemu_chr_parse_compat(label, optarg, true);
1258 if (!opts) {
1259 error_report("parse error: %s", optarg);
1260 exit(1);
1261 }
1262 }
1263
1264 opts = qemu_opts_create(qemu_find_opts("mon"), label, 1, &error_fatal);
1265 qemu_opt_set(opts, "mode", mode, &error_abort);
1266 qemu_opt_set(opts, "chardev", label, &error_abort);
1267 if (!strcmp(mode, "control")) {
1268 qemu_opt_set_bool(opts, "pretty", pretty, &error_abort);
1269 } else {
1270 assert(pretty == false);
1271 }
1272 monitor_device_index++;
1273 }
1274
1275 struct device_config {
1276 enum {
1277 DEV_USB, /* -usbdevice */
1278 DEV_SERIAL, /* -serial */
1279 DEV_PARALLEL, /* -parallel */
1280 DEV_DEBUGCON, /* -debugcon */
1281 DEV_GDB, /* -gdb, -s */
1282 DEV_SCLP, /* s390 sclp */
1283 } type;
1284 const char *cmdline;
1285 Location loc;
1286 QTAILQ_ENTRY(device_config) next;
1287 };
1288
1289 static QTAILQ_HEAD(, device_config) device_configs =
1290 QTAILQ_HEAD_INITIALIZER(device_configs);
1291
1292 static void add_device_config(int type, const char *cmdline)
1293 {
1294 struct device_config *conf;
1295
1296 conf = g_malloc0(sizeof(*conf));
1297 conf->type = type;
1298 conf->cmdline = cmdline;
1299 loc_save(&conf->loc);
1300 QTAILQ_INSERT_TAIL(&device_configs, conf, next);
1301 }
1302
1303 static int foreach_device_config(int type, int (*func)(const char *cmdline))
1304 {
1305 struct device_config *conf;
1306 int rc;
1307
1308 QTAILQ_FOREACH(conf, &device_configs, next) {
1309 if (conf->type != type)
1310 continue;
1311 loc_push_restore(&conf->loc);
1312 rc = func(conf->cmdline);
1313 loc_pop(&conf->loc);
1314 if (rc) {
1315 return rc;
1316 }
1317 }
1318 return 0;
1319 }
1320
1321 static void qemu_disable_default_devices(void)
1322 {
1323 MachineClass *machine_class = MACHINE_GET_CLASS(current_machine);
1324
1325 qemu_opts_foreach(qemu_find_opts("device"),
1326 default_driver_check, NULL, NULL);
1327 qemu_opts_foreach(qemu_find_opts("global"),
1328 default_driver_check, NULL, NULL);
1329
1330 if (!vga_model && !default_vga) {
1331 vga_interface_type = VGA_DEVICE;
1332 }
1333 if (!has_defaults || machine_class->no_serial) {
1334 default_serial = 0;
1335 }
1336 if (!has_defaults || machine_class->no_parallel) {
1337 default_parallel = 0;
1338 }
1339 if (!has_defaults || machine_class->no_floppy) {
1340 default_floppy = 0;
1341 }
1342 if (!has_defaults || machine_class->no_cdrom) {
1343 default_cdrom = 0;
1344 }
1345 if (!has_defaults || machine_class->no_sdcard) {
1346 default_sdcard = 0;
1347 }
1348 if (!has_defaults) {
1349 default_monitor = 0;
1350 default_net = 0;
1351 default_vga = 0;
1352 }
1353 }
1354
1355 static void qemu_create_default_devices(void)
1356 {
1357 MachineClass *machine_class = MACHINE_GET_CLASS(current_machine);
1358
1359 if (is_daemonized()) {
1360 /* According to documentation and historically, -nographic redirects
1361 * serial port, parallel port and monitor to stdio, which does not work
1362 * with -daemonize. We can redirect these to null instead, but since
1363 * -nographic is legacy, let's just error out.
1364 * We disallow -nographic only if all other ports are not redirected
1365 * explicitly, to not break existing legacy setups which uses
1366 * -nographic _and_ redirects all ports explicitly - this is valid
1367 * usage, -nographic is just a no-op in this case.
1368 */
1369 if (nographic
1370 && (default_parallel || default_serial || default_monitor)) {
1371 error_report("-nographic cannot be used with -daemonize");
1372 exit(1);
1373 }
1374 }
1375
1376 if (nographic) {
1377 if (default_parallel)
1378 add_device_config(DEV_PARALLEL, "null");
1379 if (default_serial && default_monitor) {
1380 add_device_config(DEV_SERIAL, "mon:stdio");
1381 } else {
1382 if (default_serial)
1383 add_device_config(DEV_SERIAL, "stdio");
1384 if (default_monitor)
1385 monitor_parse("stdio", "readline", false);
1386 }
1387 } else {
1388 if (default_serial)
1389 add_device_config(DEV_SERIAL, "vc:80Cx24C");
1390 if (default_parallel)
1391 add_device_config(DEV_PARALLEL, "vc:80Cx24C");
1392 if (default_monitor)
1393 monitor_parse("vc:80Cx24C", "readline", false);
1394 }
1395
1396 if (default_net) {
1397 QemuOptsList *net = qemu_find_opts("net");
1398 qemu_opts_parse(net, "nic", true, &error_abort);
1399 #ifdef CONFIG_SLIRP
1400 qemu_opts_parse(net, "user", true, &error_abort);
1401 #endif
1402 }
1403
1404 #if defined(CONFIG_VNC)
1405 if (!QTAILQ_EMPTY(&(qemu_find_opts("vnc")->head))) {
1406 display_remote++;
1407 }
1408 #endif
1409 if (dpy.type == DISPLAY_TYPE_DEFAULT && !display_remote) {
1410 if (!qemu_display_find_default(&dpy)) {
1411 dpy.type = DISPLAY_TYPE_NONE;
1412 #if defined(CONFIG_VNC)
1413 vnc_parse("localhost:0,to=99,id=default");
1414 #endif
1415 }
1416 }
1417 if (dpy.type == DISPLAY_TYPE_DEFAULT) {
1418 dpy.type = DISPLAY_TYPE_NONE;
1419 }
1420
1421 /* If no default VGA is requested, the default is "none". */
1422 if (default_vga) {
1423 vga_model = get_default_vga_model(machine_class);
1424 }
1425 if (vga_model) {
1426 select_vgahw(machine_class, vga_model);
1427 }
1428 }
1429
1430 static int serial_parse(const char *devname)
1431 {
1432 int index = num_serial_hds;
1433 char label[32];
1434
1435 if (strcmp(devname, "none") == 0)
1436 return 0;
1437 snprintf(label, sizeof(label), "serial%d", index);
1438 serial_hds = g_renew(Chardev *, serial_hds, index + 1);
1439
1440 serial_hds[index] = qemu_chr_new_mux_mon(label, devname, NULL);
1441 if (!serial_hds[index]) {
1442 error_report("could not connect serial device"
1443 " to character backend '%s'", devname);
1444 return -1;
1445 }
1446 num_serial_hds++;
1447 return 0;
1448 }
1449
1450 Chardev *serial_hd(int i)
1451 {
1452 assert(i >= 0);
1453 if (i < num_serial_hds) {
1454 return serial_hds[i];
1455 }
1456 return NULL;
1457 }
1458
1459 static int parallel_parse(const char *devname)
1460 {
1461 static int index = 0;
1462 char label[32];
1463
1464 if (strcmp(devname, "none") == 0)
1465 return 0;
1466 if (index == MAX_PARALLEL_PORTS) {
1467 error_report("too many parallel ports");
1468 exit(1);
1469 }
1470 snprintf(label, sizeof(label), "parallel%d", index);
1471 parallel_hds[index] = qemu_chr_new_mux_mon(label, devname, NULL);
1472 if (!parallel_hds[index]) {
1473 error_report("could not connect parallel device"
1474 " to character backend '%s'", devname);
1475 return -1;
1476 }
1477 index++;
1478 return 0;
1479 }
1480
1481 static int debugcon_parse(const char *devname)
1482 {
1483 QemuOpts *opts;
1484
1485 if (!qemu_chr_new_mux_mon("debugcon", devname, NULL)) {
1486 error_report("invalid character backend '%s'", devname);
1487 exit(1);
1488 }
1489 opts = qemu_opts_create(qemu_find_opts("device"), "debugcon", 1, NULL);
1490 if (!opts) {
1491 error_report("already have a debugcon device");
1492 exit(1);
1493 }
1494 qemu_opt_set(opts, "driver", "isa-debugcon", &error_abort);
1495 qemu_opt_set(opts, "chardev", "debugcon", &error_abort);
1496 return 0;
1497 }
1498
1499 static gint machine_class_cmp(gconstpointer a, gconstpointer b)
1500 {
1501 const MachineClass *mc1 = a, *mc2 = b;
1502 int res;
1503
1504 if (mc1->family == NULL) {
1505 if (mc2->family == NULL) {
1506 /* Compare standalone machine types against each other; they sort
1507 * in increasing order.
1508 */
1509 return strcmp(object_class_get_name(OBJECT_CLASS(mc1)),
1510 object_class_get_name(OBJECT_CLASS(mc2)));
1511 }
1512
1513 /* Standalone machine types sort after families. */
1514 return 1;
1515 }
1516
1517 if (mc2->family == NULL) {
1518 /* Families sort before standalone machine types. */
1519 return -1;
1520 }
1521
1522 /* Families sort between each other alphabetically increasingly. */
1523 res = strcmp(mc1->family, mc2->family);
1524 if (res != 0) {
1525 return res;
1526 }
1527
1528 /* Within the same family, machine types sort in decreasing order. */
1529 return strcmp(object_class_get_name(OBJECT_CLASS(mc2)),
1530 object_class_get_name(OBJECT_CLASS(mc1)));
1531 }
1532
1533 static MachineClass *machine_parse(const char *name, GSList *machines)
1534 {
1535 MachineClass *mc;
1536 GSList *el;
1537
1538 if (is_help_option(name)) {
1539 printf("Supported machines are:\n");
1540 machines = g_slist_sort(machines, machine_class_cmp);
1541 for (el = machines; el; el = el->next) {
1542 MachineClass *mc = el->data;
1543 if (mc->alias) {
1544 printf("%-20s %s (alias of %s)\n", mc->alias, mc->desc, mc->name);
1545 }
1546 printf("%-20s %s%s%s\n", mc->name, mc->desc,
1547 mc->is_default ? " (default)" : "",
1548 mc->deprecation_reason ? " (deprecated)" : "");
1549 }
1550 exit(0);
1551 }
1552
1553 mc = find_machine(name, machines);
1554 if (!mc) {
1555 error_report("unsupported machine type");
1556 error_printf("Use -machine help to list supported machines\n");
1557 exit(1);
1558 }
1559 return mc;
1560 }
1561
1562 static const char *pid_file;
1563 static Notifier qemu_unlink_pidfile_notifier;
1564
1565 static void qemu_unlink_pidfile(Notifier *n, void *data)
1566 {
1567 if (pid_file) {
1568 unlink(pid_file);
1569 }
1570 }
1571
1572 static const QEMUOption *lookup_opt(int argc, char **argv,
1573 const char **poptarg, int *poptind)
1574 {
1575 const QEMUOption *popt;
1576 int optind = *poptind;
1577 char *r = argv[optind];
1578 const char *optarg;
1579
1580 loc_set_cmdline(argv, optind, 1);
1581 optind++;
1582 /* Treat --foo the same as -foo. */
1583 if (r[1] == '-')
1584 r++;
1585 popt = qemu_options;
1586 for(;;) {
1587 if (!popt->name) {
1588 error_report("invalid option");
1589 exit(1);
1590 }
1591 if (!strcmp(popt->name, r + 1))
1592 break;
1593 popt++;
1594 }
1595 if (popt->flags & HAS_ARG) {
1596 if (optind >= argc) {
1597 error_report("requires an argument");
1598 exit(1);
1599 }
1600 optarg = argv[optind++];
1601 loc_set_cmdline(argv, optind - 2, 2);
1602 } else {
1603 optarg = NULL;
1604 }
1605
1606 *poptarg = optarg;
1607 *poptind = optind;
1608
1609 return popt;
1610 }
1611
1612 static MachineClass *select_machine(void)
1613 {
1614 GSList *machines = object_class_get_list(TYPE_MACHINE, false);
1615 MachineClass *machine_class = find_default_machine(machines);
1616 const char *optarg;
1617 QemuOpts *opts;
1618 Location loc;
1619
1620 loc_push_none(&loc);
1621
1622 opts = qemu_get_machine_opts();
1623 qemu_opts_loc_restore(opts);
1624
1625 optarg = qemu_opt_get(opts, "type");
1626 if (optarg) {
1627 machine_class = machine_parse(optarg, machines);
1628 }
1629
1630 if (!machine_class) {
1631 error_report("No machine specified, and there is no default");
1632 error_printf("Use -machine help to list supported machines\n");
1633 exit(1);
1634 }
1635
1636 loc_pop(&loc);
1637 g_slist_free(machines);
1638 return machine_class;
1639 }
1640
1641 static int object_parse_property_opt(Object *obj,
1642 const char *name, const char *value,
1643 const char *skip, Error **errp)
1644 {
1645 if (g_str_equal(name, skip)) {
1646 return 0;
1647 }
1648
1649 if (!object_property_parse(obj, name, value, errp)) {
1650 return -1;
1651 }
1652
1653 return 0;
1654 }
1655
1656 static int machine_set_property(void *opaque,
1657 const char *name, const char *value,
1658 Error **errp)
1659 {
1660 g_autofree char *qom_name = g_strdup(name);
1661 char *p;
1662
1663 for (p = qom_name; *p; p++) {
1664 if (*p == '_') {
1665 *p = '-';
1666 }
1667 }
1668
1669 /* Legacy options do not correspond to MachineState properties. */
1670 if (g_str_equal(qom_name, "accel")) {
1671 return 0;
1672 }
1673 if (g_str_equal(qom_name, "igd-passthru")) {
1674 object_register_sugar_prop(ACCEL_CLASS_NAME("xen"), qom_name, value,
1675 false);
1676 return 0;
1677 }
1678 if (g_str_equal(qom_name, "kvm-shadow-mem")) {
1679 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, value,
1680 false);
1681 return 0;
1682 }
1683 if (g_str_equal(qom_name, "kernel-irqchip")) {
1684 object_register_sugar_prop(ACCEL_CLASS_NAME("kvm"), qom_name, value,
1685 false);
1686 object_register_sugar_prop(ACCEL_CLASS_NAME("whpx"), qom_name, value,
1687 false);
1688 return 0;
1689 }
1690
1691 return object_parse_property_opt(opaque, name, value, "type", errp);
1692 }
1693
1694 static void object_option_foreach_add(bool (*type_opt_predicate)(const char *))
1695 {
1696 ObjectOption *opt, *next;
1697
1698 QTAILQ_FOREACH_SAFE(opt, &object_opts, next, next) {
1699 const char *type = ObjectType_str(opt->opts->qom_type);
1700 if (type_opt_predicate(type)) {
1701 user_creatable_add_qapi(opt->opts, &error_fatal);
1702 qapi_free_ObjectOptions(opt->opts);
1703 QTAILQ_REMOVE(&object_opts, opt, next);
1704 g_free(opt);
1705 }
1706 }
1707 }
1708
1709 static void object_option_parse(const char *optarg)
1710 {
1711 ObjectOption *opt;
1712 QemuOpts *opts;
1713 const char *type;
1714 Visitor *v;
1715
1716 if (optarg[0] == '{') {
1717 QObject *obj = qobject_from_json(optarg, &error_fatal);
1718
1719 v = qobject_input_visitor_new(obj);
1720 qobject_unref(obj);
1721 } else {
1722 opts = qemu_opts_parse_noisily(qemu_find_opts("object"),
1723 optarg, true);
1724 if (!opts) {
1725 exit(1);
1726 }
1727
1728 type = qemu_opt_get(opts, "qom-type");
1729 if (!type) {
1730 error_setg(&error_fatal, QERR_MISSING_PARAMETER, "qom-type");
1731 }
1732 if (user_creatable_print_help(type, opts)) {
1733 exit(0);
1734 }
1735
1736 v = opts_visitor_new(opts);
1737 }
1738
1739 opt = g_new0(ObjectOption, 1);
1740 visit_type_ObjectOptions(v, NULL, &opt->opts, &error_fatal);
1741 visit_free(v);
1742
1743 QTAILQ_INSERT_TAIL(&object_opts, opt, next);
1744 }
1745
1746 /*
1747 * Initial object creation happens before all other
1748 * QEMU data types are created. The majority of objects
1749 * can be created at this point. The rng-egd object
1750 * cannot be created here, as it depends on the chardev
1751 * already existing.
1752 */
1753 static bool object_create_early(const char *type)
1754 {
1755 /*
1756 * Objects should not be made "delayed" without a reason. If you
1757 * add one, state the reason in a comment!
1758 */
1759
1760 /* Reason: rng-egd property "chardev" */
1761 if (g_str_equal(type, "rng-egd")) {
1762 return false;
1763 }
1764
1765 #if defined(CONFIG_VHOST_USER) && defined(CONFIG_LINUX)
1766 /* Reason: cryptodev-vhost-user property "chardev" */
1767 if (g_str_equal(type, "cryptodev-vhost-user")) {
1768 return false;
1769 }
1770 #endif
1771
1772 /* Reason: vhost-user-blk-server property "node-name" */
1773 if (g_str_equal(type, "vhost-user-blk-server")) {
1774 return false;
1775 }
1776 /*
1777 * Reason: filter-* property "netdev" etc.
1778 */
1779 if (g_str_equal(type, "filter-buffer") ||
1780 g_str_equal(type, "filter-dump") ||
1781 g_str_equal(type, "filter-mirror") ||
1782 g_str_equal(type, "filter-redirector") ||
1783 g_str_equal(type, "colo-compare") ||
1784 g_str_equal(type, "filter-rewriter") ||
1785 g_str_equal(type, "filter-replay")) {
1786 return false;
1787 }
1788
1789 /*
1790 * Allocation of large amounts of memory may delay
1791 * chardev initialization for too long, and trigger timeouts
1792 * on software that waits for a monitor socket to be created
1793 * (e.g. libvirt).
1794 */
1795 if (g_str_has_prefix(type, "memory-backend-")) {
1796 return false;
1797 }
1798
1799 return true;
1800 }
1801
1802 static void qemu_apply_machine_options(void)
1803 {
1804 MachineClass *machine_class = MACHINE_GET_CLASS(current_machine);
1805 QemuOpts *machine_opts = qemu_get_machine_opts();
1806 const char *boot_order = NULL;
1807 const char *boot_once = NULL;
1808 QemuOpts *opts;
1809
1810 qemu_opt_foreach(machine_opts, machine_set_property, current_machine,
1811 &error_fatal);
1812 current_machine->ram_size = ram_size;
1813 current_machine->maxram_size = maxram_size;
1814 current_machine->ram_slots = ram_slots;
1815
1816 opts = qemu_opts_find(qemu_find_opts("boot-opts"), NULL);
1817 if (opts) {
1818 boot_order = qemu_opt_get(opts, "order");
1819 if (boot_order) {
1820 validate_bootdevices(boot_order, &error_fatal);
1821 }
1822
1823 boot_once = qemu_opt_get(opts, "once");
1824 if (boot_once) {
1825 validate_bootdevices(boot_once, &error_fatal);
1826 }
1827
1828 boot_menu = qemu_opt_get_bool(opts, "menu", boot_menu);
1829 boot_strict = qemu_opt_get_bool(opts, "strict", false);
1830 }
1831
1832 if (!boot_order) {
1833 boot_order = machine_class->default_boot_order;
1834 }
1835
1836 current_machine->boot_order = boot_order;
1837 current_machine->boot_once = boot_once;
1838
1839 if (semihosting_enabled() && !semihosting_get_argc()) {
1840 const char *kernel_filename = qemu_opt_get(machine_opts, "kernel");
1841 const char *kernel_cmdline = qemu_opt_get(machine_opts, "append") ?: "";
1842 /* fall back to the -kernel/-append */
1843 semihosting_arg_fallback(kernel_filename, kernel_cmdline);
1844 }
1845 }
1846
1847 static void qemu_create_early_backends(void)
1848 {
1849 MachineClass *machine_class = MACHINE_GET_CLASS(current_machine);
1850
1851 if ((alt_grab || ctrl_grab) && dpy.type != DISPLAY_TYPE_SDL) {
1852 error_report("-alt-grab and -ctrl-grab are only valid "
1853 "for SDL, ignoring option");
1854 }
1855 if (dpy.has_window_close &&
1856 (dpy.type != DISPLAY_TYPE_GTK && dpy.type != DISPLAY_TYPE_SDL)) {
1857 error_report("-no-quit is only valid for GTK and SDL, "
1858 "ignoring option");
1859 }
1860
1861 qemu_display_early_init(&dpy);
1862 qemu_console_early_init();
1863
1864 if (dpy.has_gl && dpy.gl != DISPLAYGL_MODE_OFF && display_opengl == 0) {
1865 #if defined(CONFIG_OPENGL)
1866 error_report("OpenGL is not supported by the display");
1867 #else
1868 error_report("OpenGL support is disabled");
1869 #endif
1870 exit(1);
1871 }
1872
1873 object_option_foreach_add(object_create_early);
1874
1875 /* spice needs the timers to be initialized by this point */
1876 /* spice must initialize before audio as it changes the default auiodev */
1877 /* spice must initialize before chardevs (for spicevmc and spiceport) */
1878 qemu_spice.init();
1879
1880 qemu_opts_foreach(qemu_find_opts("chardev"),
1881 chardev_init_func, NULL, &error_fatal);
1882
1883 #ifdef CONFIG_VIRTFS
1884 qemu_opts_foreach(qemu_find_opts("fsdev"),
1885 fsdev_init_func, NULL, &error_fatal);
1886 #endif
1887
1888 /*
1889 * Note: we need to create audio and block backends before
1890 * machine_set_property(), so machine properties can refer to
1891 * them.
1892 */
1893 configure_blockdev(&bdo_queue, machine_class, snapshot);
1894 audio_init_audiodevs();
1895 }
1896
1897
1898 /*
1899 * The remainder of object creation happens after the
1900 * creation of chardev, fsdev, net clients and device data types.
1901 */
1902 static bool object_create_late(const char *type)
1903 {
1904 return !object_create_early(type);
1905 }
1906
1907 static void qemu_create_late_backends(void)
1908 {
1909 if (qtest_chrdev) {
1910 qtest_server_init(qtest_chrdev, qtest_log, &error_fatal);
1911 }
1912
1913 net_init_clients(&error_fatal);
1914
1915 object_option_foreach_add(object_create_late);
1916
1917 if (tpm_init() < 0) {
1918 exit(1);
1919 }
1920
1921 qemu_opts_foreach(qemu_find_opts("mon"),
1922 mon_init_func, NULL, &error_fatal);
1923
1924 if (foreach_device_config(DEV_SERIAL, serial_parse) < 0)
1925 exit(1);
1926 if (foreach_device_config(DEV_PARALLEL, parallel_parse) < 0)
1927 exit(1);
1928 if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
1929 exit(1);
1930
1931 /* now chardevs have been created we may have semihosting to connect */
1932 qemu_semihosting_connect_chardevs();
1933 qemu_semihosting_console_init();
1934 }
1935
1936 static bool have_custom_ram_size(void)
1937 {
1938 QemuOpts *opts = qemu_find_opts_singleton("memory");
1939 return !!qemu_opt_get_size(opts, "size", 0);
1940 }
1941
1942 static void qemu_resolve_machine_memdev(void)
1943 {
1944 if (current_machine->ram_memdev_id) {
1945 Object *backend;
1946 ram_addr_t backend_size;
1947
1948 backend = object_resolve_path_type(current_machine->ram_memdev_id,
1949 TYPE_MEMORY_BACKEND, NULL);
1950 if (!backend) {
1951 error_report("Memory backend '%s' not found",
1952 current_machine->ram_memdev_id);
1953 exit(EXIT_FAILURE);
1954 }
1955 backend_size = object_property_get_uint(backend, "size", &error_abort);
1956 if (have_custom_ram_size() && backend_size != ram_size) {
1957 error_report("Size specified by -m option must match size of "
1958 "explicitly specified 'memory-backend' property");
1959 exit(EXIT_FAILURE);
1960 }
1961 if (mem_path) {
1962 error_report("'-mem-path' can't be used together with"
1963 "'-machine memory-backend'");
1964 exit(EXIT_FAILURE);
1965 }
1966 ram_size = backend_size;
1967 }
1968
1969 if (!xen_enabled()) {
1970 /* On 32-bit hosts, QEMU is limited by virtual address space */
1971 if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
1972 error_report("at most 2047 MB RAM can be simulated");
1973 exit(1);
1974 }
1975 }
1976 }
1977
1978 static void set_memory_options(MachineClass *mc)
1979 {
1980 uint64_t sz;
1981 const char *mem_str;
1982 const ram_addr_t default_ram_size = mc->default_ram_size;
1983 QemuOpts *opts = qemu_find_opts_singleton("memory");
1984 Location loc;
1985
1986 loc_push_none(&loc);
1987 qemu_opts_loc_restore(opts);
1988
1989 sz = 0;
1990 mem_str = qemu_opt_get(opts, "size");
1991 if (mem_str) {
1992 if (!*mem_str) {
1993 error_report("missing 'size' option value");
1994 exit(EXIT_FAILURE);
1995 }
1996
1997 sz = qemu_opt_get_size(opts, "size", ram_size);
1998
1999 /* Fix up legacy suffix-less format */
2000 if (g_ascii_isdigit(mem_str[strlen(mem_str) - 1])) {
2001 uint64_t overflow_check = sz;
2002
2003 sz *= MiB;
2004 if (sz / MiB != overflow_check) {
2005 error_report("too large 'size' option value");
2006 exit(EXIT_FAILURE);
2007 }
2008 }
2009 }
2010
2011 /* backward compatibility behaviour for case "-m 0" */
2012 if (sz == 0) {
2013 sz = default_ram_size;
2014 }
2015
2016 sz = QEMU_ALIGN_UP(sz, 8192);
2017 if (mc->fixup_ram_size) {
2018 sz = mc->fixup_ram_size(sz);
2019 }
2020 ram_size = sz;
2021 if (ram_size != sz) {
2022 error_report("ram size too large");
2023 exit(EXIT_FAILURE);
2024 }
2025
2026 /* store value for the future use */
2027 qemu_opt_set_number(opts, "size", ram_size, &error_abort);
2028 maxram_size = ram_size;
2029
2030 if (qemu_opt_get(opts, "maxmem")) {
2031 uint64_t slots;
2032
2033 sz = qemu_opt_get_size(opts, "maxmem", 0);
2034 slots = qemu_opt_get_number(opts, "slots", 0);
2035 if (sz < ram_size) {
2036 error_report("invalid value of -m option maxmem: "
2037 "maximum memory size (0x%" PRIx64 ") must be at least "
2038 "the initial memory size (0x" RAM_ADDR_FMT ")",
2039 sz, ram_size);
2040 exit(EXIT_FAILURE);
2041 } else if (slots && sz == ram_size) {
2042 error_report("invalid value of -m option maxmem: "
2043 "memory slots were specified but maximum memory size "
2044 "(0x%" PRIx64 ") is equal to the initial memory size "
2045 "(0x" RAM_ADDR_FMT ")", sz, ram_size);
2046 exit(EXIT_FAILURE);
2047 }
2048
2049 maxram_size = sz;
2050 ram_slots = slots;
2051 } else if (qemu_opt_get(opts, "slots")) {
2052 error_report("invalid -m option value: missing 'maxmem' option");
2053 exit(EXIT_FAILURE);
2054 }
2055
2056 loc_pop(&loc);
2057 }
2058
2059 static void qemu_create_machine(MachineClass *machine_class)
2060 {
2061 object_set_machine_compat_props(machine_class->compat_props);
2062
2063 set_memory_options(machine_class);
2064
2065 current_machine = MACHINE(object_new_with_class(OBJECT_CLASS(machine_class)));
2066 if (machine_help_func(qemu_get_machine_opts(), current_machine)) {
2067 exit(0);
2068 }
2069 object_property_add_child(object_get_root(), "machine",
2070 OBJECT(current_machine));
2071 object_property_add_child(container_get(OBJECT(current_machine),
2072 "/unattached"),
2073 "sysbus", OBJECT(sysbus_get_default()));
2074
2075 if (machine_class->minimum_page_bits) {
2076 if (!set_preferred_target_page_bits(machine_class->minimum_page_bits)) {
2077 /* This would be a board error: specifying a minimum smaller than
2078 * a target's compile-time fixed setting.
2079 */
2080 g_assert_not_reached();
2081 }
2082 }
2083
2084 cpu_exec_init_all();
2085 page_size_init();
2086
2087 if (machine_class->hw_version) {
2088 qemu_set_hw_version(machine_class->hw_version);
2089 }
2090
2091 machine_smp_parse(current_machine,
2092 qemu_opts_find(qemu_find_opts("smp-opts"), NULL), &error_fatal);
2093
2094 /*
2095 * Get the default machine options from the machine if it is not already
2096 * specified either by the configuration file or by the command line.
2097 */
2098 if (machine_class->default_machine_opts) {
2099 qemu_opts_set_defaults(qemu_find_opts("machine"),
2100 machine_class->default_machine_opts, 0);
2101 }
2102 }
2103
2104 static int global_init_func(void *opaque, QemuOpts *opts, Error **errp)
2105 {
2106 GlobalProperty *g;
2107
2108 g = g_malloc0(sizeof(*g));
2109 g->driver = qemu_opt_get(opts, "driver");
2110 g->property = qemu_opt_get(opts, "property");
2111 g->value = qemu_opt_get(opts, "value");
2112 qdev_prop_register_global(g);
2113 return 0;
2114 }
2115
2116 static void qemu_read_default_config_file(Error **errp)
2117 {
2118 ERRP_GUARD();
2119 int ret;
2120 g_autofree char *file = get_relocated_path(CONFIG_QEMU_CONFDIR "/qemu.conf");
2121
2122 ret = qemu_read_config_file(file, errp);
2123 if (ret < 0) {
2124 if (ret == -ENOENT) {
2125 error_free(*errp);
2126 *errp = NULL;
2127 }
2128 }
2129 }
2130
2131 static int qemu_set_option(const char *str)
2132 {
2133 Error *local_err = NULL;
2134 char group[64], id[64], arg[64];
2135 QemuOptsList *list;
2136 QemuOpts *opts;
2137 int rc, offset;
2138
2139 rc = sscanf(str, "%63[^.].%63[^.].%63[^=]%n", group, id, arg, &offset);
2140 if (rc < 3 || str[offset] != '=') {
2141 error_report("can't parse: \"%s\"", str);
2142 return -1;
2143 }
2144
2145 list = qemu_find_opts(group);
2146 if (list == NULL) {
2147 return -1;
2148 }
2149
2150 opts = qemu_opts_find(list, id);
2151 if (!opts) {
2152 error_report("there is no %s \"%s\" defined",
2153 list->name, id);
2154 return -1;
2155 }
2156
2157 if (!qemu_opt_set(opts, arg, str + offset + 1, &local_err)) {
2158 error_report_err(local_err);
2159 return -1;
2160 }
2161 return 0;
2162 }
2163
2164 static void user_register_global_props(void)
2165 {
2166 qemu_opts_foreach(qemu_find_opts("global"),
2167 global_init_func, NULL, NULL);
2168 }
2169
2170 static int do_configure_icount(void *opaque, QemuOpts *opts, Error **errp)
2171 {
2172 icount_configure(opts, errp);
2173 return 0;
2174 }
2175
2176 static int accelerator_set_property(void *opaque,
2177 const char *name, const char *value,
2178 Error **errp)
2179 {
2180 return object_parse_property_opt(opaque, name, value, "accel", errp);
2181 }
2182
2183 static int do_configure_accelerator(void *opaque, QemuOpts *opts, Error **errp)
2184 {
2185 bool *p_init_failed = opaque;
2186 const char *acc = qemu_opt_get(opts, "accel");
2187 AccelClass *ac = accel_find(acc);
2188 AccelState *accel;
2189 int ret;
2190 bool qtest_with_kvm;
2191
2192 qtest_with_kvm = g_str_equal(acc, "kvm") && qtest_chrdev != NULL;
2193
2194 if (!ac) {
2195 *p_init_failed = true;
2196 if (!qtest_with_kvm) {
2197 error_report("invalid accelerator %s", acc);
2198 }
2199 return 0;
2200 }
2201 accel = ACCEL(object_new_with_class(OBJECT_CLASS(ac)));
2202 object_apply_compat_props(OBJECT(accel));
2203 qemu_opt_foreach(opts, accelerator_set_property,
2204 accel,
2205 &error_fatal);
2206
2207 ret = accel_init_machine(accel, current_machine);
2208 if (ret < 0) {
2209 *p_init_failed = true;
2210 if (!qtest_with_kvm || ret != -ENOENT) {
2211 error_report("failed to initialize %s: %s", acc, strerror(-ret));
2212 }
2213 return 0;
2214 }
2215
2216 return 1;
2217 }
2218
2219 static void configure_accelerators(const char *progname)
2220 {
2221 const char *accelerators;
2222 bool init_failed = false;
2223
2224 qemu_opts_foreach(qemu_find_opts("icount"),
2225 do_configure_icount, NULL, &error_fatal);
2226
2227 accelerators = qemu_opt_get(qemu_get_machine_opts(), "accel");
2228 if (QTAILQ_EMPTY(&qemu_accel_opts.head)) {
2229 char **accel_list, **tmp;
2230
2231 if (accelerators == NULL) {
2232 /* Select the default accelerator */
2233 bool have_tcg = accel_find("tcg");
2234 bool have_kvm = accel_find("kvm");
2235
2236 if (have_tcg && have_kvm) {
2237 if (g_str_has_suffix(progname, "kvm")) {
2238 /* If the program name ends with "kvm", we prefer KVM */
2239 accelerators = "kvm:tcg";
2240 } else {
2241 accelerators = "tcg:kvm";
2242 }
2243 } else if (have_kvm) {
2244 accelerators = "kvm";
2245 } else if (have_tcg) {
2246 accelerators = "tcg";
2247 } else {
2248 error_report("No accelerator selected and"
2249 " no default accelerator available");
2250 exit(1);
2251 }
2252 }
2253 accel_list = g_strsplit(accelerators, ":", 0);
2254
2255 for (tmp = accel_list; *tmp; tmp++) {
2256 /*
2257 * Filter invalid accelerators here, to prevent obscenities
2258 * such as "-machine accel=tcg,,thread=single".
2259 */
2260 if (accel_find(*tmp)) {
2261 qemu_opts_parse_noisily(qemu_find_opts("accel"), *tmp, true);
2262 } else {
2263 init_failed = true;
2264 error_report("invalid accelerator %s", *tmp);
2265 }
2266 }
2267 g_strfreev(accel_list);
2268 } else {
2269 if (accelerators != NULL) {
2270 error_report("The -accel and \"-machine accel=\" options are incompatible");
2271 exit(1);
2272 }
2273 }
2274
2275 if (!qemu_opts_foreach(qemu_find_opts("accel"),
2276 do_configure_accelerator, &init_failed, &error_fatal)) {
2277 if (!init_failed) {
2278 error_report("no accelerator found");
2279 }
2280 exit(1);
2281 }
2282
2283 if (init_failed && !qtest_chrdev) {
2284 AccelClass *ac = ACCEL_GET_CLASS(current_accel());
2285 error_report("falling back to %s", ac->name);
2286 }
2287
2288 if (icount_enabled() && !tcg_enabled()) {
2289 error_report("-icount is not allowed with hardware virtualization");
2290 exit(1);
2291 }
2292 }
2293
2294 static void create_default_memdev(MachineState *ms, const char *path)
2295 {
2296 Object *obj;
2297 MachineClass *mc = MACHINE_GET_CLASS(ms);
2298
2299 obj = object_new(path ? TYPE_MEMORY_BACKEND_FILE : TYPE_MEMORY_BACKEND_RAM);
2300 if (path) {
2301 object_property_set_str(obj, "mem-path", path, &error_fatal);
2302 }
2303 object_property_set_int(obj, "size", ms->ram_size, &error_fatal);
2304 object_property_add_child(object_get_objects_root(), mc->default_ram_id,
2305 obj);
2306 /* Ensure backend's memory region name is equal to mc->default_ram_id */
2307 object_property_set_bool(obj, "x-use-canonical-path-for-ramblock-id",
2308 false, &error_fatal);
2309 user_creatable_complete(USER_CREATABLE(obj), &error_fatal);
2310 object_unref(obj);
2311 object_property_set_str(OBJECT(ms), "memory-backend", mc->default_ram_id,
2312 &error_fatal);
2313 }
2314
2315 static void qemu_validate_options(void)
2316 {
2317 QemuOpts *machine_opts = qemu_get_machine_opts();
2318 const char *kernel_filename = qemu_opt_get(machine_opts, "kernel");
2319 const char *initrd_filename = qemu_opt_get(machine_opts, "initrd");
2320 const char *kernel_cmdline = qemu_opt_get(machine_opts, "append");
2321
2322 if (kernel_filename == NULL) {
2323 if (kernel_cmdline != NULL) {
2324 error_report("-append only allowed with -kernel option");
2325 exit(1);
2326 }
2327
2328 if (initrd_filename != NULL) {
2329 error_report("-initrd only allowed with -kernel option");
2330 exit(1);
2331 }
2332 }
2333
2334 if (loadvm && preconfig_requested) {
2335 error_report("'preconfig' and 'loadvm' options are "
2336 "mutually exclusive");
2337 exit(EXIT_FAILURE);
2338 }
2339 if (incoming && preconfig_requested && strcmp(incoming, "defer") != 0) {
2340 error_report("'preconfig' supports '-incoming defer' only");
2341 exit(EXIT_FAILURE);
2342 }
2343
2344 #ifdef CONFIG_CURSES
2345 if (is_daemonized() && dpy.type == DISPLAY_TYPE_CURSES) {
2346 error_report("curses display cannot be used with -daemonize");
2347 exit(1);
2348 }
2349 #endif
2350 }
2351
2352 static void qemu_process_sugar_options(void)
2353 {
2354 if (mem_prealloc) {
2355 char *val;
2356
2357 val = g_strdup_printf("%d",
2358 (uint32_t) qemu_opt_get_number(qemu_find_opts_singleton("smp-opts"), "cpus", 1));
2359 object_register_sugar_prop("memory-backend", "prealloc-threads", val,
2360 false);
2361 g_free(val);
2362 object_register_sugar_prop("memory-backend", "prealloc", "on", false);
2363 }
2364
2365 if (watchdog) {
2366 int i = select_watchdog(watchdog);
2367 if (i > 0)
2368 exit (i == 1 ? 1 : 0);
2369 }
2370 }
2371
2372 /* -action processing */
2373
2374 /*
2375 * Process all the -action parameters parsed from cmdline.
2376 */
2377 static int process_runstate_actions(void *opaque, QemuOpts *opts, Error **errp)
2378 {
2379 Error *local_err = NULL;
2380 QDict *qdict = qemu_opts_to_qdict(opts, NULL);
2381 QObject *ret = NULL;
2382 qmp_marshal_set_action(qdict, &ret, &local_err);
2383 qobject_unref(ret);
2384 qobject_unref(qdict);
2385 if (local_err) {
2386 error_propagate(errp, local_err);
2387 return 1;
2388 }
2389 return 0;
2390 }
2391
2392 static void qemu_process_early_options(void)
2393 {
2394 #ifdef CONFIG_SECCOMP
2395 QemuOptsList *olist = qemu_find_opts_err("sandbox", NULL);
2396 if (olist) {
2397 qemu_opts_foreach(olist, parse_sandbox, NULL, &error_fatal);
2398 }
2399 #endif
2400
2401 qemu_opts_foreach(qemu_find_opts("name"),
2402 parse_name, NULL, &error_fatal);
2403
2404 if (qemu_opts_foreach(qemu_find_opts("action"),
2405 process_runstate_actions, NULL, &error_fatal)) {
2406 exit(1);
2407 }
2408
2409 #ifndef _WIN32
2410 qemu_opts_foreach(qemu_find_opts("add-fd"),
2411 parse_add_fd, NULL, &error_fatal);
2412
2413 qemu_opts_foreach(qemu_find_opts("add-fd"),
2414 cleanup_add_fd, NULL, &error_fatal);
2415 #endif
2416
2417 /* Open the logfile at this point and set the log mask if necessary. */
2418 if (log_file) {
2419 qemu_set_log_filename(log_file, &error_fatal);
2420 }
2421 if (log_mask) {
2422 int mask;
2423 mask = qemu_str_to_log_mask(log_mask);
2424 if (!mask) {
2425 qemu_print_log_usage(stdout);
2426 exit(1);
2427 }
2428 qemu_set_log(mask);
2429 } else {
2430 qemu_set_log(0);
2431 }
2432
2433 qemu_add_default_firmwarepath();
2434 }
2435
2436 static void qemu_process_help_options(void)
2437 {
2438 /*
2439 * Check for -cpu help and -device help before we call select_machine(),
2440 * which will return an error if the architecture has no default machine
2441 * type and the user did not specify one, so that the user doesn't need
2442 * to say '-cpu help -machine something'.
2443 */
2444 if (cpu_option && is_help_option(cpu_option)) {
2445 list_cpus(cpu_option);
2446 exit(0);
2447 }
2448
2449 if (qemu_opts_foreach(qemu_find_opts("device"),
2450 device_help_func, NULL, NULL)) {
2451 exit(0);
2452 }
2453
2454 /* -L help lists the data directories and exits. */
2455 if (list_data_dirs) {
2456 qemu_list_data_dirs();
2457 exit(0);
2458 }
2459 }
2460
2461 static void qemu_maybe_daemonize(const char *pid_file)
2462 {
2463 Error *err;
2464
2465 os_daemonize();
2466 rcu_disable_atfork();
2467
2468 if (pid_file && !qemu_write_pidfile(pid_file, &err)) {
2469 error_reportf_err(err, "cannot create PID file: ");
2470 exit(1);
2471 }
2472
2473 qemu_unlink_pidfile_notifier.notify = qemu_unlink_pidfile;
2474 qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier);
2475 }
2476
2477 static void qemu_init_displays(void)
2478 {
2479 DisplayState *ds;
2480
2481 /* init local displays */
2482 ds = init_displaystate();
2483 qemu_display_init(ds, &dpy);
2484
2485 /* must be after terminal init, SDL library changes signal handlers */
2486 os_setup_signal_handling();
2487
2488 /* init remote displays */
2489 #ifdef CONFIG_VNC
2490 qemu_opts_foreach(qemu_find_opts("vnc"),
2491 vnc_init_func, NULL, &error_fatal);
2492 #endif
2493
2494 if (using_spice) {
2495 qemu_spice.display_init();
2496 }
2497 }
2498
2499 static void qemu_init_board(void)
2500 {
2501 MachineClass *machine_class = MACHINE_GET_CLASS(current_machine);
2502
2503 if (machine_class->default_ram_id && current_machine->ram_size &&
2504 numa_uses_legacy_mem() && !current_machine->ram_memdev_id) {
2505 create_default_memdev(current_machine, mem_path);
2506 }
2507
2508 /* process plugin before CPUs are created, but once -smp has been parsed */
2509 qemu_plugin_load_list(&plugin_list, &error_fatal);
2510
2511 /* From here on we enter MACHINE_PHASE_INITIALIZED. */
2512 machine_run_board_init(current_machine);
2513
2514 drive_check_orphaned();
2515
2516 realtime_init();
2517
2518 if (hax_enabled()) {
2519 /* FIXME: why isn't cpu_synchronize_all_post_init enough? */
2520 hax_sync_vcpus();
2521 }
2522 }
2523
2524 static void qemu_create_cli_devices(void)
2525 {
2526 soundhw_init();
2527
2528 qemu_opts_foreach(qemu_find_opts("fw_cfg"),
2529 parse_fw_cfg, fw_cfg_find(), &error_fatal);
2530
2531 /* init USB devices */
2532 if (machine_usb(current_machine)) {
2533 if (foreach_device_config(DEV_USB, usb_parse) < 0)
2534 exit(1);
2535 }
2536
2537 /* init generic devices */
2538 rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE);
2539 qemu_opts_foreach(qemu_find_opts("device"),
2540 device_init_func, NULL, &error_fatal);
2541 rom_reset_order_override();
2542 }
2543
2544 static void qemu_machine_creation_done(void)
2545 {
2546 MachineState *machine = MACHINE(qdev_get_machine());
2547
2548 /* Did we create any drives that we failed to create a device for? */
2549 drive_check_orphaned();
2550
2551 /* Don't warn about the default network setup that you get if
2552 * no command line -net or -netdev options are specified. There
2553 * are two cases that we would otherwise complain about:
2554 * (1) board doesn't support a NIC but the implicit "-net nic"
2555 * requested one
2556 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
2557 * sets up a nic that isn't connected to anything.
2558 */
2559 if (!default_net && (!qtest_enabled() || has_defaults)) {
2560 net_check_clients();
2561 }
2562
2563 qdev_prop_check_globals();
2564
2565 qdev_machine_creation_done();
2566
2567 if (machine->cgs) {
2568 /*
2569 * Verify that Confidential Guest Support has actually been initialized
2570 */
2571 assert(machine->cgs->ready);
2572 }
2573
2574 if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) {
2575 exit(1);
2576 }
2577 }
2578
2579 void qmp_x_exit_preconfig(Error **errp)
2580 {
2581 if (phase_check(PHASE_MACHINE_INITIALIZED)) {
2582 error_setg(errp, "The command is permitted only before machine initialization");
2583 return;
2584 }
2585
2586 qemu_init_board();
2587 qemu_create_cli_devices();
2588 qemu_machine_creation_done();
2589
2590 if (loadvm) {
2591 Error *local_err = NULL;
2592 if (!load_snapshot(loadvm, NULL, false, NULL, &local_err)) {
2593 error_report_err(local_err);
2594 autostart = 0;
2595 exit(1);
2596 }
2597 }
2598 if (replay_mode != REPLAY_MODE_NONE) {
2599 replay_vmstate_init();
2600 }
2601
2602 if (incoming) {
2603 Error *local_err = NULL;
2604 if (strcmp(incoming, "defer") != 0) {
2605 qmp_migrate_incoming(incoming, &local_err);
2606 if (local_err) {
2607 error_reportf_err(local_err, "-incoming %s: ", incoming);
2608 exit(1);
2609 }
2610 }
2611 } else if (autostart) {
2612 qmp_cont(NULL);
2613 }
2614 }
2615
2616 void qemu_init(int argc, char **argv, char **envp)
2617 {
2618 QemuOpts *opts;
2619 QemuOpts *icount_opts = NULL, *accel_opts = NULL;
2620 QemuOptsList *olist;
2621 int optind;
2622 const char *optarg;
2623 MachineClass *machine_class;
2624 bool userconfig = true;
2625 FILE *vmstate_dump_file = NULL;
2626
2627 qemu_add_opts(&qemu_drive_opts);
2628 qemu_add_drive_opts(&qemu_legacy_drive_opts);
2629 qemu_add_drive_opts(&qemu_common_drive_opts);
2630 qemu_add_drive_opts(&qemu_drive_opts);
2631 qemu_add_drive_opts(&bdrv_runtime_opts);
2632 qemu_add_opts(&qemu_chardev_opts);
2633 qemu_add_opts(&qemu_device_opts);
2634 qemu_add_opts(&qemu_netdev_opts);
2635 qemu_add_opts(&qemu_nic_opts);
2636 qemu_add_opts(&qemu_net_opts);
2637 qemu_add_opts(&qemu_rtc_opts);
2638 qemu_add_opts(&qemu_global_opts);
2639 qemu_add_opts(&qemu_mon_opts);
2640 qemu_add_opts(&qemu_trace_opts);
2641 qemu_plugin_add_opts();
2642 qemu_add_opts(&qemu_option_rom_opts);
2643 qemu_add_opts(&qemu_machine_opts);
2644 qemu_add_opts(&qemu_accel_opts);
2645 qemu_add_opts(&qemu_mem_opts);
2646 qemu_add_opts(&qemu_smp_opts);
2647 qemu_add_opts(&qemu_boot_opts);
2648 qemu_add_opts(&qemu_add_fd_opts);
2649 qemu_add_opts(&qemu_object_opts);
2650 qemu_add_opts(&qemu_tpmdev_opts);
2651 qemu_add_opts(&qemu_overcommit_opts);
2652 qemu_add_opts(&qemu_msg_opts);
2653 qemu_add_opts(&qemu_name_opts);
2654 qemu_add_opts(&qemu_numa_opts);
2655 qemu_add_opts(&qemu_icount_opts);
2656 qemu_add_opts(&qemu_semihosting_config_opts);
2657 qemu_add_opts(&qemu_fw_cfg_opts);
2658 qemu_add_opts(&qemu_action_opts);
2659 module_call_init(MODULE_INIT_OPTS);
2660
2661 error_init(argv[0]);
2662 qemu_init_exec_dir(argv[0]);
2663
2664 qemu_init_subsystems();
2665
2666 /* first pass of option parsing */
2667 optind = 1;
2668 while (optind < argc) {
2669 if (argv[optind][0] != '-') {
2670 /* disk image */
2671 optind++;
2672 } else {
2673 const QEMUOption *popt;
2674
2675 popt = lookup_opt(argc, argv, &optarg, &optind);
2676 switch (popt->index) {
2677 case QEMU_OPTION_nouserconfig:
2678 userconfig = false;
2679 break;
2680 }
2681 }
2682 }
2683
2684 if (userconfig) {
2685 qemu_read_default_config_file(&error_fatal);
2686 }
2687
2688 /* second pass of option parsing */
2689 optind = 1;
2690 for(;;) {
2691 if (optind >= argc)
2692 break;
2693 if (argv[optind][0] != '-') {
2694 loc_set_cmdline(argv, optind, 1);
2695 drive_add(IF_DEFAULT, 0, argv[optind++], HD_OPTS);
2696 } else {
2697 const QEMUOption *popt;
2698
2699 popt = lookup_opt(argc, argv, &optarg, &optind);
2700 if (!(popt->arch_mask & arch_type)) {
2701 error_report("Option not supported for this target");
2702 exit(1);
2703 }
2704 switch(popt->index) {
2705 case QEMU_OPTION_cpu:
2706 /* hw initialization will check this */
2707 cpu_option = optarg;
2708 break;
2709 case QEMU_OPTION_hda:
2710 case QEMU_OPTION_hdb:
2711 case QEMU_OPTION_hdc:
2712 case QEMU_OPTION_hdd:
2713 drive_add(IF_DEFAULT, popt->index - QEMU_OPTION_hda, optarg,
2714 HD_OPTS);
2715 break;
2716 case QEMU_OPTION_blockdev:
2717 {
2718 Visitor *v;
2719 BlockdevOptionsQueueEntry *bdo;
2720
2721 v = qobject_input_visitor_new_str(optarg, "driver",
2722 &error_fatal);
2723
2724 bdo = g_new(BlockdevOptionsQueueEntry, 1);
2725 visit_type_BlockdevOptions(v, NULL, &bdo->bdo,
2726 &error_fatal);
2727 visit_free(v);
2728 loc_save(&bdo->loc);
2729 QSIMPLEQ_INSERT_TAIL(&bdo_queue, bdo, entry);
2730 break;
2731 }
2732 case QEMU_OPTION_drive:
2733 if (drive_def(optarg) == NULL) {
2734 exit(1);
2735 }
2736 break;
2737 case QEMU_OPTION_set:
2738 if (qemu_set_option(optarg) != 0)
2739 exit(1);
2740 break;
2741 case QEMU_OPTION_global:
2742 if (qemu_global_option(optarg) != 0)
2743 exit(1);
2744 break;
2745 case QEMU_OPTION_mtdblock:
2746 drive_add(IF_MTD, -1, optarg, MTD_OPTS);
2747 break;
2748 case QEMU_OPTION_sd:
2749 drive_add(IF_SD, -1, optarg, SD_OPTS);
2750 break;
2751 case QEMU_OPTION_pflash:
2752 drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
2753 break;
2754 case QEMU_OPTION_snapshot:
2755 {
2756 Error *blocker = NULL;
2757 snapshot = 1;
2758 error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED,
2759 "-snapshot");
2760 replay_add_blocker(blocker);
2761 }
2762 break;
2763 case QEMU_OPTION_numa:
2764 opts = qemu_opts_parse_noisily(qemu_find_opts("numa"),
2765 optarg, true);
2766 if (!opts) {
2767 exit(1);
2768 }
2769 break;
2770 case QEMU_OPTION_display:
2771 parse_display(optarg);
2772 break;
2773 case QEMU_OPTION_nographic:
2774 olist = qemu_find_opts("machine");
2775 qemu_opts_parse_noisily(olist, "graphics=off", false);
2776 nographic = true;
2777 dpy.type = DISPLAY_TYPE_NONE;
2778 break;
2779 case QEMU_OPTION_curses:
2780 #ifdef CONFIG_CURSES
2781 dpy.type = DISPLAY_TYPE_CURSES;
2782 #else
2783 error_report("curses or iconv support is disabled");
2784 exit(1);
2785 #endif
2786 break;
2787 case QEMU_OPTION_portrait:
2788 graphic_rotate = 90;
2789 break;
2790 case QEMU_OPTION_rotate:
2791 graphic_rotate = strtol(optarg, (char **) &optarg, 10);
2792 if (graphic_rotate != 0 && graphic_rotate != 90 &&
2793 graphic_rotate != 180 && graphic_rotate != 270) {
2794 error_report("only 90, 180, 270 deg rotation is available");
2795 exit(1);
2796 }
2797 break;
2798 case QEMU_OPTION_kernel:
2799 qemu_opts_set(qemu_find_opts("machine"), "kernel", optarg, &error_abort);
2800 break;
2801 case QEMU_OPTION_initrd:
2802 qemu_opts_set(qemu_find_opts("machine"), "initrd", optarg, &error_abort);
2803 break;
2804 case QEMU_OPTION_append:
2805 qemu_opts_set(qemu_find_opts("machine"), "append", optarg, &error_abort);
2806 break;
2807 case QEMU_OPTION_dtb:
2808 qemu_opts_set(qemu_find_opts("machine"), "dtb", optarg, &error_abort);
2809 break;
2810 case QEMU_OPTION_cdrom:
2811 drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
2812 break;
2813 case QEMU_OPTION_boot:
2814 opts = qemu_opts_parse_noisily(qemu_find_opts("boot-opts"),
2815 optarg, true);
2816 if (!opts) {
2817 exit(1);
2818 }
2819 break;
2820 case QEMU_OPTION_fda:
2821 case QEMU_OPTION_fdb:
2822 drive_add(IF_FLOPPY, popt->index - QEMU_OPTION_fda,
2823 optarg, FD_OPTS);
2824 break;
2825 case QEMU_OPTION_no_fd_bootchk:
2826 fd_bootchk = 0;
2827 break;
2828 case QEMU_OPTION_netdev:
2829 default_net = 0;
2830 if (net_client_parse(qemu_find_opts("netdev"), optarg) == -1) {
2831 exit(1);
2832 }
2833 break;
2834 case QEMU_OPTION_nic:
2835 default_net = 0;
2836 if (net_client_parse(qemu_find_opts("nic"), optarg) == -1) {
2837 exit(1);
2838 }
2839 break;
2840 case QEMU_OPTION_net:
2841 default_net = 0;
2842 if (net_client_parse(qemu_find_opts("net"), optarg) == -1) {
2843 exit(1);
2844 }
2845 break;
2846 #ifdef CONFIG_LIBISCSI
2847 case QEMU_OPTION_iscsi:
2848 opts = qemu_opts_parse_noisily(qemu_find_opts("iscsi"),
2849 optarg, false);
2850 if (!opts) {
2851 exit(1);
2852 }
2853 break;
2854 #endif
2855 case QEMU_OPTION_audio_help:
2856 audio_legacy_help();
2857 exit (0);
2858 break;
2859 case QEMU_OPTION_audiodev:
2860 audio_parse_option(optarg);
2861 break;
2862 case QEMU_OPTION_soundhw:
2863 select_soundhw (optarg);
2864 break;
2865 case QEMU_OPTION_h:
2866 help(0);
2867 break;
2868 case QEMU_OPTION_version:
2869 version();
2870 exit(0);
2871 break;
2872 case QEMU_OPTION_m:
2873 opts = qemu_opts_parse_noisily(qemu_find_opts("memory"),
2874 optarg, true);
2875 if (!opts) {
2876 exit(EXIT_FAILURE);
2877 }
2878 break;
2879 #ifdef CONFIG_TPM
2880 case QEMU_OPTION_tpmdev:
2881 if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg) < 0) {
2882 exit(1);
2883 }
2884 break;
2885 #endif
2886 case QEMU_OPTION_mempath:
2887 mem_path = optarg;
2888 break;
2889 case QEMU_OPTION_mem_prealloc:
2890 mem_prealloc = 1;
2891 break;
2892 case QEMU_OPTION_d:
2893 log_mask = optarg;
2894 break;
2895 case QEMU_OPTION_D:
2896 log_file = optarg;
2897 break;
2898 case QEMU_OPTION_DFILTER:
2899 qemu_set_dfilter_ranges(optarg, &error_fatal);
2900 break;
2901 case QEMU_OPTION_seed:
2902 qemu_guest_random_seed_main(optarg, &error_fatal);
2903 break;
2904 case QEMU_OPTION_s:
2905 add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT);
2906 break;
2907 case QEMU_OPTION_gdb:
2908 add_device_config(DEV_GDB, optarg);
2909 break;
2910 case QEMU_OPTION_L:
2911 if (is_help_option(optarg)) {
2912 list_data_dirs = true;
2913 } else {
2914 qemu_add_data_dir(g_strdup(optarg));
2915 }
2916 break;
2917 case QEMU_OPTION_bios:
2918 qemu_opts_set(qemu_find_opts("machine"), "firmware", optarg, &error_abort);
2919 break;
2920 case QEMU_OPTION_singlestep:
2921 singlestep = 1;
2922 break;
2923 case QEMU_OPTION_S:
2924 autostart = 0;
2925 break;
2926 case QEMU_OPTION_k:
2927 keyboard_layout = optarg;
2928 break;
2929 case QEMU_OPTION_vga:
2930 vga_model = optarg;
2931 default_vga = 0;
2932 break;
2933 case QEMU_OPTION_g:
2934 {
2935 const char *p;
2936 int w, h, depth;
2937 p = optarg;
2938 w = strtol(p, (char **)&p, 10);
2939 if (w <= 0) {
2940 graphic_error:
2941 error_report("invalid resolution or depth");
2942 exit(1);
2943 }
2944 if (*p != 'x')
2945 goto graphic_error;
2946 p++;
2947 h = strtol(p, (char **)&p, 10);
2948 if (h <= 0)
2949 goto graphic_error;
2950 if (*p == 'x') {
2951 p++;
2952 depth = strtol(p, (char **)&p, 10);
2953 if (depth != 1 && depth != 2 && depth != 4 &&
2954 depth != 8 && depth != 15 && depth != 16 &&
2955 depth != 24 && depth != 32)
2956 goto graphic_error;
2957 } else if (*p == '\0') {
2958 depth = graphic_depth;
2959 } else {
2960 goto graphic_error;
2961 }
2962
2963 graphic_width = w;
2964 graphic_height = h;
2965 graphic_depth = depth;
2966 }
2967 break;
2968 case QEMU_OPTION_echr:
2969 {
2970 char *r;
2971 term_escape_char = strtol(optarg, &r, 0);
2972 if (r == optarg)
2973 printf("Bad argument to echr\n");
2974 break;
2975 }
2976 case QEMU_OPTION_monitor:
2977 default_monitor = 0;
2978 if (strncmp(optarg, "none", 4)) {
2979 monitor_parse(optarg, "readline", false);
2980 }
2981 break;
2982 case QEMU_OPTION_qmp:
2983 monitor_parse(optarg, "control", false);
2984 default_monitor = 0;
2985 break;
2986 case QEMU_OPTION_qmp_pretty:
2987 monitor_parse(optarg, "control", true);
2988 default_monitor = 0;
2989 break;
2990 case QEMU_OPTION_mon:
2991 opts = qemu_opts_parse_noisily(qemu_find_opts("mon"), optarg,
2992 true);
2993 if (!opts) {
2994 exit(1);
2995 }
2996 default_monitor = 0;
2997 break;
2998 case QEMU_OPTION_chardev:
2999 opts = qemu_opts_parse_noisily(qemu_find_opts("chardev"),
3000 optarg, true);
3001 if (!opts) {
3002 exit(1);
3003 }
3004 break;
3005 case QEMU_OPTION_fsdev:
3006 olist = qemu_find_opts("fsdev");
3007 if (!olist) {
3008 error_report("fsdev support is disabled");
3009 exit(1);
3010 }
3011 opts = qemu_opts_parse_noisily(olist, optarg, true);
3012 if (!opts) {
3013 exit(1);
3014 }
3015 break;
3016 case QEMU_OPTION_virtfs: {
3017 QemuOpts *fsdev;
3018 QemuOpts *device;
3019 const char *writeout, *sock_fd, *socket, *path, *security_model,
3020 *multidevs;
3021
3022 olist = qemu_find_opts("virtfs");
3023 if (!olist) {
3024 error_report("virtfs support is disabled");
3025 exit(1);
3026 }
3027 opts = qemu_opts_parse_noisily(olist, optarg, true);
3028 if (!opts) {
3029 exit(1);
3030 }
3031
3032 if (qemu_opt_get(opts, "fsdriver") == NULL ||
3033 qemu_opt_get(opts, "mount_tag") == NULL) {
3034 error_report("Usage: -virtfs fsdriver,mount_tag=tag");
3035 exit(1);
3036 }
3037 fsdev = qemu_opts_create(qemu_find_opts("fsdev"),
3038 qemu_opts_id(opts) ?:
3039 qemu_opt_get(opts, "mount_tag"),
3040 1, NULL);
3041 if (!fsdev) {
3042 error_report("duplicate or invalid fsdev id: %s",
3043 qemu_opt_get(opts, "mount_tag"));
3044 exit(1);
3045 }
3046
3047 writeout = qemu_opt_get(opts, "writeout");
3048 if (writeout) {
3049 #ifdef CONFIG_SYNC_FILE_RANGE
3050 qemu_opt_set(fsdev, "writeout", writeout, &error_abort);
3051 #else
3052 error_report("writeout=immediate not supported "
3053 "on this platform");
3054 exit(1);
3055 #endif
3056 }
3057 qemu_opt_set(fsdev, "fsdriver",
3058 qemu_opt_get(opts, "fsdriver"), &error_abort);
3059 path = qemu_opt_get(opts, "path");
3060 if (path) {
3061 qemu_opt_set(fsdev, "path", path, &error_abort);
3062 }
3063 security_model = qemu_opt_get(opts, "security_model");
3064 if (security_model) {
3065 qemu_opt_set(fsdev, "security_model", security_model,
3066 &error_abort);
3067 }
3068 socket = qemu_opt_get(opts, "socket");
3069 if (socket) {
3070 qemu_opt_set(fsdev, "socket", socket, &error_abort);
3071 }
3072 sock_fd = qemu_opt_get(opts, "sock_fd");
3073 if (sock_fd) {
3074 qemu_opt_set(fsdev, "sock_fd", sock_fd, &error_abort);
3075 }
3076
3077 qemu_opt_set_bool(fsdev, "readonly",
3078 qemu_opt_get_bool(opts, "readonly", 0),
3079 &error_abort);
3080 multidevs = qemu_opt_get(opts, "multidevs");
3081 if (multidevs) {
3082 qemu_opt_set(fsdev, "multidevs", multidevs, &error_abort);
3083 }
3084 device = qemu_opts_create(qemu_find_opts("device"), NULL, 0,
3085 &error_abort);
3086 qemu_opt_set(device, "driver", "virtio-9p-pci", &error_abort);
3087 qemu_opt_set(device, "fsdev",
3088 qemu_opts_id(fsdev), &error_abort);
3089 qemu_opt_set(device, "mount_tag",
3090 qemu_opt_get(opts, "mount_tag"), &error_abort);
3091 break;
3092 }
3093 case QEMU_OPTION_serial:
3094 add_device_config(DEV_SERIAL, optarg);
3095 default_serial = 0;
3096 if (strncmp(optarg, "mon:", 4) == 0) {
3097 default_monitor = 0;
3098 }
3099 break;
3100 case QEMU_OPTION_watchdog:
3101 if (watchdog) {
3102 error_report("only one watchdog option may be given");
3103 exit(1);
3104 }
3105 watchdog = optarg;
3106 break;
3107 case QEMU_OPTION_action:
3108 olist = qemu_find_opts("action");
3109 if (!qemu_opts_parse_noisily(olist, optarg, false)) {
3110 exit(1);
3111 }
3112 break;
3113 case QEMU_OPTION_watchdog_action:
3114 if (select_watchdog_action(optarg) == -1) {
3115 error_report("unknown -watchdog-action parameter");
3116 exit(1);
3117 }
3118 break;
3119 case QEMU_OPTION_parallel:
3120 add_device_config(DEV_PARALLEL, optarg);
3121 default_parallel = 0;
3122 if (strncmp(optarg, "mon:", 4) == 0) {
3123 default_monitor = 0;
3124 }
3125 break;
3126 case QEMU_OPTION_debugcon:
3127 add_device_config(DEV_DEBUGCON, optarg);
3128 break;
3129 case QEMU_OPTION_loadvm:
3130 loadvm = optarg;
3131 break;
3132 case QEMU_OPTION_full_screen:
3133 dpy.has_full_screen = true;
3134 dpy.full_screen = true;
3135 break;
3136 case QEMU_OPTION_alt_grab:
3137 alt_grab = 1;
3138 break;
3139 case QEMU_OPTION_ctrl_grab:
3140 ctrl_grab = 1;
3141 break;
3142 case QEMU_OPTION_no_quit:
3143 dpy.has_window_close = true;
3144 dpy.window_close = false;
3145 break;
3146 case QEMU_OPTION_sdl:
3147 #ifdef CONFIG_SDL
3148 dpy.type = DISPLAY_TYPE_SDL;
3149 break;
3150 #else
3151 error_report("SDL support is disabled");
3152 exit(1);
3153 #endif
3154 case QEMU_OPTION_pidfile:
3155 pid_file = optarg;
3156 break;
3157 case QEMU_OPTION_win2k_hack:
3158 win2k_install_hack = 1;
3159 break;
3160 case QEMU_OPTION_acpitable:
3161 opts = qemu_opts_parse_noisily(qemu_find_opts("acpi"),
3162 optarg, true);
3163 if (!opts) {
3164 exit(1);
3165 }
3166 acpi_table_add(opts, &error_fatal);
3167 break;
3168 case QEMU_OPTION_smbios:
3169 opts = qemu_opts_parse_noisily(qemu_find_opts("smbios"),
3170 optarg, false);
3171 if (!opts) {
3172 exit(1);
3173 }
3174 smbios_entry_add(opts, &error_fatal);
3175 break;
3176 case QEMU_OPTION_fwcfg:
3177 opts = qemu_opts_parse_noisily(qemu_find_opts("fw_cfg"),
3178 optarg, true);
3179 if (opts == NULL) {
3180 exit(1);
3181 }
3182 break;
3183 case QEMU_OPTION_preconfig:
3184 preconfig_requested = true;
3185 break;
3186 case QEMU_OPTION_enable_kvm:
3187 olist = qemu_find_opts("machine");
3188 qemu_opts_parse_noisily(olist, "accel=kvm", false);
3189 break;
3190 case QEMU_OPTION_M:
3191 case QEMU_OPTION_machine:
3192 olist = qemu_find_opts("machine");
3193 opts = qemu_opts_parse_noisily(olist, optarg, true);
3194 if (!opts) {
3195 exit(1);
3196 }
3197 break;
3198 case QEMU_OPTION_accel:
3199 accel_opts = qemu_opts_parse_noisily(qemu_find_opts("accel"),
3200 optarg, true);
3201 optarg = qemu_opt_get(accel_opts, "accel");
3202 if (!optarg || is_help_option(optarg)) {
3203 printf("Accelerators supported in QEMU binary:\n");
3204 GSList *el, *accel_list = object_class_get_list(TYPE_ACCEL,
3205 false);
3206 for (el = accel_list; el; el = el->next) {
3207 gchar *typename = g_strdup(object_class_get_name(
3208 OBJECT_CLASS(el->data)));
3209 /* omit qtest which is used for tests only */
3210 if (g_strcmp0(typename, ACCEL_CLASS_NAME("qtest")) &&
3211 g_str_has_suffix(typename, ACCEL_CLASS_SUFFIX)) {
3212 gchar **optname = g_strsplit(typename,
3213 ACCEL_CLASS_SUFFIX, 0);
3214 printf("%s\n", optname[0]);
3215 g_strfreev(optname);
3216 }
3217 g_free(typename);
3218 }
3219 g_slist_free(accel_list);
3220 exit(0);
3221 }
3222 break;
3223 case QEMU_OPTION_usb:
3224 olist = qemu_find_opts("machine");
3225 qemu_opts_parse_noisily(olist, "usb=on", false);
3226 break;
3227 case QEMU_OPTION_usbdevice:
3228 olist = qemu_find_opts("machine");
3229 qemu_opts_parse_noisily(olist, "usb=on", false);
3230 add_device_config(DEV_USB, optarg);
3231 break;
3232 case QEMU_OPTION_device:
3233 if (!qemu_opts_parse_noisily(qemu_find_opts("device"),
3234 optarg, true)) {
3235 exit(1);
3236 }
3237 break;
3238 case QEMU_OPTION_smp:
3239 if (!qemu_opts_parse_noisily(qemu_find_opts("smp-opts"),
3240 optarg, true)) {
3241 exit(1);
3242 }
3243 break;
3244 case QEMU_OPTION_vnc:
3245 vnc_parse(optarg);
3246 break;
3247 case QEMU_OPTION_no_acpi:
3248 olist = qemu_find_opts("machine");
3249 qemu_opts_parse_noisily(olist, "acpi=off", false);
3250 break;
3251 case QEMU_OPTION_no_hpet:
3252 olist = qemu_find_opts("machine");
3253 qemu_opts_parse_noisily(olist, "hpet=off", false);
3254 break;
3255 case QEMU_OPTION_no_reboot:
3256 olist = qemu_find_opts("action");
3257 qemu_opts_parse_noisily(olist, "reboot=shutdown", false);
3258 break;
3259 case QEMU_OPTION_no_shutdown:
3260 olist = qemu_find_opts("action");
3261 qemu_opts_parse_noisily(olist, "shutdown=pause", false);
3262 break;
3263 case QEMU_OPTION_uuid:
3264 if (qemu_uuid_parse(optarg, &qemu_uuid) < 0) {
3265 error_report("failed to parse UUID string: wrong format");
3266 exit(1);
3267 }
3268 qemu_uuid_set = true;
3269 break;
3270 case QEMU_OPTION_option_rom:
3271 if (nb_option_roms >= MAX_OPTION_ROMS) {
3272 error_report("too many option ROMs");
3273 exit(1);
3274 }
3275 opts = qemu_opts_parse_noisily(qemu_find_opts("option-rom"),
3276 optarg, true);
3277 if (!opts) {
3278 exit(1);
3279 }
3280 option_rom[nb_option_roms].name = qemu_opt_get(opts, "romfile");
3281 option_rom[nb_option_roms].bootindex =
3282 qemu_opt_get_number(opts, "bootindex", -1);
3283 if (!option_rom[nb_option_roms].name) {
3284 error_report("Option ROM file is not specified");
3285 exit(1);
3286 }
3287 nb_option_roms++;
3288 break;
3289 case QEMU_OPTION_semihosting:
3290 qemu_semihosting_enable();
3291 break;
3292 case QEMU_OPTION_semihosting_config:
3293 if (qemu_semihosting_config_options(optarg) != 0) {
3294 exit(1);
3295 }
3296 break;
3297 case QEMU_OPTION_name:
3298 opts = qemu_opts_parse_noisily(qemu_find_opts("name"),
3299 optarg, true);
3300 if (!opts) {
3301 exit(1);
3302 }
3303 /* Capture guest name if -msg guest-name is used later */
3304 error_guest_name = qemu_opt_get(opts, "guest");
3305 break;
3306 case QEMU_OPTION_prom_env:
3307 if (nb_prom_envs >= MAX_PROM_ENVS) {
3308 error_report("too many prom variables");
3309 exit(1);
3310 }
3311 prom_envs[nb_prom_envs] = optarg;
3312 nb_prom_envs++;
3313 break;
3314 case QEMU_OPTION_old_param:
3315 old_param = 1;
3316 break;
3317 case QEMU_OPTION_rtc:
3318 opts = qemu_opts_parse_noisily(qemu_find_opts("rtc"), optarg,
3319 false);
3320 if (!opts) {
3321 exit(1);
3322 }
3323 break;
3324 case QEMU_OPTION_icount:
3325 icount_opts = qemu_opts_parse_noisily(qemu_find_opts("icount"),
3326 optarg, true);
3327 if (!icount_opts) {
3328 exit(1);
3329 }
3330 break;
3331 case QEMU_OPTION_incoming:
3332 if (!incoming) {
3333 runstate_set(RUN_STATE_INMIGRATE);
3334 }
3335 incoming = optarg;
3336 break;
3337 case QEMU_OPTION_only_migratable:
3338 only_migratable = 1;
3339 break;
3340 case QEMU_OPTION_nodefaults:
3341 has_defaults = 0;
3342 break;
3343 case QEMU_OPTION_xen_domid:
3344 if (!(xen_available())) {
3345 error_report("Option not supported for this target");
3346 exit(1);
3347 }
3348 xen_domid = atoi(optarg);
3349 break;
3350 case QEMU_OPTION_xen_attach:
3351 if (!(xen_available())) {
3352 error_report("Option not supported for this target");
3353 exit(1);
3354 }
3355 xen_mode = XEN_ATTACH;
3356 break;
3357 case QEMU_OPTION_xen_domid_restrict:
3358 if (!(xen_available())) {
3359 error_report("Option not supported for this target");
3360 exit(1);
3361 }
3362 xen_domid_restrict = true;
3363 break;
3364 case QEMU_OPTION_trace:
3365 trace_opt_parse(optarg);
3366 break;
3367 case QEMU_OPTION_plugin:
3368 qemu_plugin_opt_parse(optarg, &plugin_list);
3369 break;
3370 case QEMU_OPTION_readconfig:
3371 qemu_read_config_file(optarg, &error_fatal);
3372 break;
3373 case QEMU_OPTION_spice:
3374 olist = qemu_find_opts_err("spice", NULL);
3375 if (!olist) {
3376 ui_module_load_one("spice-core");
3377 olist = qemu_find_opts("spice");
3378 }
3379 if (!olist) {
3380 error_report("spice support is disabled");
3381 exit(1);
3382 }
3383 opts = qemu_opts_parse_noisily(olist, optarg, false);
3384 if (!opts) {
3385 exit(1);
3386 }
3387 display_remote++;
3388 break;
3389 case QEMU_OPTION_writeconfig:
3390 {
3391 FILE *fp;
3392 warn_report("-writeconfig is deprecated and will go away without a replacement");
3393 if (strcmp(optarg, "-") == 0) {
3394 fp = stdout;
3395 } else {
3396 fp = fopen(optarg, "w");
3397 if (fp == NULL) {
3398 error_report("open %s: %s", optarg,
3399 strerror(errno));
3400 exit(1);
3401 }
3402 }
3403 qemu_config_write(fp);
3404 if (fp != stdout) {
3405 fclose(fp);
3406 }
3407 break;
3408 }
3409 case QEMU_OPTION_qtest:
3410 qtest_chrdev = optarg;
3411 break;
3412 case QEMU_OPTION_qtest_log:
3413 qtest_log = optarg;
3414 break;
3415 case QEMU_OPTION_sandbox:
3416 olist = qemu_find_opts("sandbox");
3417 if (!olist) {
3418 #ifndef CONFIG_SECCOMP
3419 error_report("-sandbox support is not enabled "
3420 "in this QEMU binary");
3421 #endif
3422 exit(1);
3423 }
3424
3425 opts = qemu_opts_parse_noisily(olist, optarg, true);
3426 if (!opts) {
3427 exit(1);
3428 }
3429 break;
3430 case QEMU_OPTION_add_fd:
3431 #ifndef _WIN32
3432 opts = qemu_opts_parse_noisily(qemu_find_opts("add-fd"),
3433 optarg, false);
3434 if (!opts) {
3435 exit(1);
3436 }
3437 #else
3438 error_report("File descriptor passing is disabled on this "
3439 "platform");
3440 exit(1);
3441 #endif
3442 break;
3443 case QEMU_OPTION_object:
3444 object_option_parse(optarg);
3445 break;
3446 case QEMU_OPTION_overcommit:
3447 opts = qemu_opts_parse_noisily(qemu_find_opts("overcommit"),
3448 optarg, false);
3449 if (!opts) {
3450 exit(1);
3451 }
3452 enable_mlock = qemu_opt_get_bool(opts, "mem-lock", false);
3453 enable_cpu_pm = qemu_opt_get_bool(opts, "cpu-pm", false);
3454 break;
3455 case QEMU_OPTION_msg:
3456 opts = qemu_opts_parse_noisily(qemu_find_opts("msg"), optarg,
3457 false);
3458 if (!opts) {
3459 exit(1);
3460 }
3461 configure_msg(opts);
3462 break;
3463 case QEMU_OPTION_dump_vmstate:
3464 if (vmstate_dump_file) {
3465 error_report("only one '-dump-vmstate' "
3466 "option may be given");
3467 exit(1);
3468 }
3469 vmstate_dump_file = fopen(optarg, "w");
3470 if (vmstate_dump_file == NULL) {
3471 error_report("open %s: %s", optarg, strerror(errno));
3472 exit(1);
3473 }
3474 break;
3475 case QEMU_OPTION_enable_sync_profile:
3476 qsp_enable();
3477 break;
3478 case QEMU_OPTION_nouserconfig:
3479 /* Nothing to be parsed here. Especially, do not error out below. */
3480 break;
3481 default:
3482 if (os_parse_cmd_args(popt->index, optarg)) {
3483 error_report("Option not supported in this build");
3484 exit(1);
3485 }
3486 }
3487 }
3488 }
3489 /*
3490 * Clear error location left behind by the loop.
3491 * Best done right after the loop. Do not insert code here!
3492 */
3493 loc_set_none();
3494
3495 qemu_validate_options();
3496 qemu_process_sugar_options();
3497
3498 /*
3499 * These options affect everything else and should be processed
3500 * before daemonizing.
3501 */
3502 qemu_process_early_options();
3503
3504 qemu_process_help_options();
3505 qemu_maybe_daemonize(pid_file);
3506
3507 /*
3508 * The trace backend must be initialized after daemonizing.
3509 * trace_init_backends() will call st_init(), which will create the
3510 * trace thread in the parent, and also register st_flush_trace_buffer()
3511 * in atexit(). This function will force the parent to wait for the
3512 * writeout thread to finish, which will not occur, and the parent
3513 * process will be left in the host.
3514 */
3515 if (!trace_init_backends()) {
3516 exit(1);
3517 }
3518 trace_init_file();
3519
3520 qemu_init_main_loop(&error_fatal);
3521 cpu_timers_init();
3522
3523 user_register_global_props();
3524 replay_configure(icount_opts);
3525
3526 configure_rtc(qemu_find_opts_singleton("rtc"));
3527
3528 qemu_create_machine(select_machine());
3529
3530 suspend_mux_open();
3531
3532 qemu_disable_default_devices();
3533 qemu_create_default_devices();
3534 qemu_create_early_backends();
3535
3536 qemu_apply_machine_options();
3537 phase_advance(PHASE_MACHINE_CREATED);
3538
3539 /*
3540 * Note: uses machine properties such as kernel-irqchip, must run
3541 * after machine_set_property().
3542 */
3543 configure_accelerators(argv[0]);
3544 phase_advance(PHASE_ACCEL_CREATED);
3545
3546 /*
3547 * Beware, QOM objects created before this point miss global and
3548 * compat properties.
3549 *
3550 * Global properties get set up by qdev_prop_register_global(),
3551 * called from user_register_global_props(), and certain option
3552 * desugaring. Also in CPU feature desugaring (buried in
3553 * parse_cpu_option()), which happens below this point, but may
3554 * only target the CPU type, which can only be created after
3555 * parse_cpu_option() returned the type.
3556 *
3557 * Machine compat properties: object_set_machine_compat_props().
3558 * Accelerator compat props: object_set_accelerator_compat_props(),
3559 * called from do_configure_accelerator().
3560 */
3561
3562 machine_class = MACHINE_GET_CLASS(current_machine);
3563 if (!qtest_enabled() && machine_class->deprecation_reason) {
3564 error_report("Machine type '%s' is deprecated: %s",
3565 machine_class->name, machine_class->deprecation_reason);
3566 }
3567
3568 /*
3569 * Note: creates a QOM object, must run only after global and
3570 * compat properties have been set up.
3571 */
3572 migration_object_init();
3573
3574 qemu_create_late_backends();
3575
3576 /* parse features once if machine provides default cpu_type */
3577 current_machine->cpu_type = machine_class->default_cpu_type;
3578 if (cpu_option) {
3579 current_machine->cpu_type = parse_cpu_option(cpu_option);
3580 }
3581 /* NB: for machine none cpu_type could STILL be NULL here! */
3582 accel_init_interfaces(ACCEL_GET_CLASS(current_machine->accelerator));
3583
3584 qemu_resolve_machine_memdev();
3585 parse_numa_opts(current_machine);
3586
3587 if (vmstate_dump_file) {
3588 /* dump and exit */
3589 dump_vmstate_json_to_file(vmstate_dump_file);
3590 exit(0);
3591 }
3592
3593 if (!preconfig_requested) {
3594 qmp_x_exit_preconfig(&error_fatal);
3595 }
3596 qemu_init_displays();
3597 accel_setup_post(current_machine);
3598 os_setup_post();
3599 resume_mux_open();
3600 }