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