1 /* 2 * QEMU Machine 3 * 4 * Copyright (C) 2014 Red Hat Inc 5 * 6 * Authors: 7 * Marcel Apfelbaum <marcel.a@redhat.com> 8 * 9 * This work is licensed under the terms of the GNU GPL, version 2 or later. 10 * See the COPYING file in the top-level directory. 11 */ 12 13 #include "qemu/osdep.h" 14 #include "qemu/option.h" 15 #include "qapi/qmp/qerror.h" 16 #include "sysemu/replay.h" 17 #include "qemu/units.h" 18 #include "hw/boards.h" 19 #include "hw/loader.h" 20 #include "qapi/error.h" 21 #include "qapi/qapi-visit-common.h" 22 #include "qapi/visitor.h" 23 #include "hw/sysbus.h" 24 #include "sysemu/cpus.h" 25 #include "sysemu/sysemu.h" 26 #include "sysemu/reset.h" 27 #include "sysemu/runstate.h" 28 #include "sysemu/numa.h" 29 #include "qemu/error-report.h" 30 #include "sysemu/qtest.h" 31 #include "hw/pci/pci.h" 32 #include "hw/mem/nvdimm.h" 33 #include "migration/global_state.h" 34 #include "migration/vmstate.h" 35 #include "exec/confidential-guest-support.h" 36 #include "hw/virtio/virtio.h" 37 #include "hw/virtio/virtio-pci.h" 38 39 GlobalProperty hw_compat_6_0[] = { 40 { "gpex-pcihost", "allow-unmapped-accesses", "false" }, 41 { "i8042", "extended-state", "false"}, 42 { "nvme-ns", "eui64-default", "off"}, 43 }; 44 const size_t hw_compat_6_0_len = G_N_ELEMENTS(hw_compat_6_0); 45 46 GlobalProperty hw_compat_5_2[] = { 47 { "ICH9-LPC", "smm-compat", "on"}, 48 { "PIIX4_PM", "smm-compat", "on"}, 49 { "virtio-blk-device", "report-discard-granularity", "off" }, 50 { "virtio-net-pci", "vectors", "3"}, 51 }; 52 const size_t hw_compat_5_2_len = G_N_ELEMENTS(hw_compat_5_2); 53 54 GlobalProperty hw_compat_5_1[] = { 55 { "vhost-scsi", "num_queues", "1"}, 56 { "vhost-user-blk", "num-queues", "1"}, 57 { "vhost-user-scsi", "num_queues", "1"}, 58 { "virtio-blk-device", "num-queues", "1"}, 59 { "virtio-scsi-device", "num_queues", "1"}, 60 { "nvme", "use-intel-id", "on"}, 61 { "pvpanic", "events", "1"}, /* PVPANIC_PANICKED */ 62 { "pl011", "migrate-clk", "off" }, 63 { "virtio-pci", "x-ats-page-aligned", "off"}, 64 }; 65 const size_t hw_compat_5_1_len = G_N_ELEMENTS(hw_compat_5_1); 66 67 GlobalProperty hw_compat_5_0[] = { 68 { "pci-host-bridge", "x-config-reg-migration-enabled", "off" }, 69 { "virtio-balloon-device", "page-poison", "false" }, 70 { "vmport", "x-read-set-eax", "off" }, 71 { "vmport", "x-signal-unsupported-cmd", "off" }, 72 { "vmport", "x-report-vmx-type", "off" }, 73 { "vmport", "x-cmds-v2", "off" }, 74 { "virtio-device", "x-disable-legacy-check", "true" }, 75 }; 76 const size_t hw_compat_5_0_len = G_N_ELEMENTS(hw_compat_5_0); 77 78 GlobalProperty hw_compat_4_2[] = { 79 { "virtio-blk-device", "queue-size", "128"}, 80 { "virtio-scsi-device", "virtqueue_size", "128"}, 81 { "virtio-blk-device", "x-enable-wce-if-config-wce", "off" }, 82 { "virtio-blk-device", "seg-max-adjust", "off"}, 83 { "virtio-scsi-device", "seg_max_adjust", "off"}, 84 { "vhost-blk-device", "seg_max_adjust", "off"}, 85 { "usb-host", "suppress-remote-wake", "off" }, 86 { "usb-redir", "suppress-remote-wake", "off" }, 87 { "qxl", "revision", "4" }, 88 { "qxl-vga", "revision", "4" }, 89 { "fw_cfg", "acpi-mr-restore", "false" }, 90 { "virtio-device", "use-disabled-flag", "false" }, 91 }; 92 const size_t hw_compat_4_2_len = G_N_ELEMENTS(hw_compat_4_2); 93 94 GlobalProperty hw_compat_4_1[] = { 95 { "virtio-pci", "x-pcie-flr-init", "off" }, 96 }; 97 const size_t hw_compat_4_1_len = G_N_ELEMENTS(hw_compat_4_1); 98 99 GlobalProperty hw_compat_4_0[] = { 100 { "VGA", "edid", "false" }, 101 { "secondary-vga", "edid", "false" }, 102 { "bochs-display", "edid", "false" }, 103 { "virtio-vga", "edid", "false" }, 104 { "virtio-gpu-device", "edid", "false" }, 105 { "virtio-device", "use-started", "false" }, 106 { "virtio-balloon-device", "qemu-4-0-config-size", "true" }, 107 { "pl031", "migrate-tick-offset", "false" }, 108 }; 109 const size_t hw_compat_4_0_len = G_N_ELEMENTS(hw_compat_4_0); 110 111 GlobalProperty hw_compat_3_1[] = { 112 { "pcie-root-port", "x-speed", "2_5" }, 113 { "pcie-root-port", "x-width", "1" }, 114 { "memory-backend-file", "x-use-canonical-path-for-ramblock-id", "true" }, 115 { "memory-backend-memfd", "x-use-canonical-path-for-ramblock-id", "true" }, 116 { "tpm-crb", "ppi", "false" }, 117 { "tpm-tis", "ppi", "false" }, 118 { "usb-kbd", "serial", "42" }, 119 { "usb-mouse", "serial", "42" }, 120 { "usb-tablet", "serial", "42" }, 121 { "virtio-blk-device", "discard", "false" }, 122 { "virtio-blk-device", "write-zeroes", "false" }, 123 { "virtio-balloon-device", "qemu-4-0-config-size", "false" }, 124 { "pcie-root-port-base", "disable-acs", "true" }, /* Added in 4.1 */ 125 }; 126 const size_t hw_compat_3_1_len = G_N_ELEMENTS(hw_compat_3_1); 127 128 GlobalProperty hw_compat_3_0[] = {}; 129 const size_t hw_compat_3_0_len = G_N_ELEMENTS(hw_compat_3_0); 130 131 GlobalProperty hw_compat_2_12[] = { 132 { "migration", "decompress-error-check", "off" }, 133 { "hda-audio", "use-timer", "false" }, 134 { "cirrus-vga", "global-vmstate", "true" }, 135 { "VGA", "global-vmstate", "true" }, 136 { "vmware-svga", "global-vmstate", "true" }, 137 { "qxl-vga", "global-vmstate", "true" }, 138 }; 139 const size_t hw_compat_2_12_len = G_N_ELEMENTS(hw_compat_2_12); 140 141 GlobalProperty hw_compat_2_11[] = { 142 { "hpet", "hpet-offset-saved", "false" }, 143 { "virtio-blk-pci", "vectors", "2" }, 144 { "vhost-user-blk-pci", "vectors", "2" }, 145 { "e1000", "migrate_tso_props", "off" }, 146 }; 147 const size_t hw_compat_2_11_len = G_N_ELEMENTS(hw_compat_2_11); 148 149 GlobalProperty hw_compat_2_10[] = { 150 { "virtio-mouse-device", "wheel-axis", "false" }, 151 { "virtio-tablet-device", "wheel-axis", "false" }, 152 }; 153 const size_t hw_compat_2_10_len = G_N_ELEMENTS(hw_compat_2_10); 154 155 GlobalProperty hw_compat_2_9[] = { 156 { "pci-bridge", "shpc", "off" }, 157 { "intel-iommu", "pt", "off" }, 158 { "virtio-net-device", "x-mtu-bypass-backend", "off" }, 159 { "pcie-root-port", "x-migrate-msix", "false" }, 160 }; 161 const size_t hw_compat_2_9_len = G_N_ELEMENTS(hw_compat_2_9); 162 163 GlobalProperty hw_compat_2_8[] = { 164 { "fw_cfg_mem", "x-file-slots", "0x10" }, 165 { "fw_cfg_io", "x-file-slots", "0x10" }, 166 { "pflash_cfi01", "old-multiple-chip-handling", "on" }, 167 { "pci-bridge", "shpc", "on" }, 168 { TYPE_PCI_DEVICE, "x-pcie-extcap-init", "off" }, 169 { "virtio-pci", "x-pcie-deverr-init", "off" }, 170 { "virtio-pci", "x-pcie-lnkctl-init", "off" }, 171 { "virtio-pci", "x-pcie-pm-init", "off" }, 172 { "cirrus-vga", "vgamem_mb", "8" }, 173 { "isa-cirrus-vga", "vgamem_mb", "8" }, 174 }; 175 const size_t hw_compat_2_8_len = G_N_ELEMENTS(hw_compat_2_8); 176 177 GlobalProperty hw_compat_2_7[] = { 178 { "virtio-pci", "page-per-vq", "on" }, 179 { "virtio-serial-device", "emergency-write", "off" }, 180 { "ioapic", "version", "0x11" }, 181 { "intel-iommu", "x-buggy-eim", "true" }, 182 { "virtio-pci", "x-ignore-backend-features", "on" }, 183 }; 184 const size_t hw_compat_2_7_len = G_N_ELEMENTS(hw_compat_2_7); 185 186 GlobalProperty hw_compat_2_6[] = { 187 { "virtio-mmio", "format_transport_address", "off" }, 188 /* Optional because not all virtio-pci devices support legacy mode */ 189 { "virtio-pci", "disable-modern", "on", .optional = true }, 190 { "virtio-pci", "disable-legacy", "off", .optional = true }, 191 }; 192 const size_t hw_compat_2_6_len = G_N_ELEMENTS(hw_compat_2_6); 193 194 GlobalProperty hw_compat_2_5[] = { 195 { "isa-fdc", "fallback", "144" }, 196 { "pvscsi", "x-old-pci-configuration", "on" }, 197 { "pvscsi", "x-disable-pcie", "on" }, 198 { "vmxnet3", "x-old-msi-offsets", "on" }, 199 { "vmxnet3", "x-disable-pcie", "on" }, 200 }; 201 const size_t hw_compat_2_5_len = G_N_ELEMENTS(hw_compat_2_5); 202 203 GlobalProperty hw_compat_2_4[] = { 204 /* Optional because the 'scsi' property is Linux-only */ 205 { "virtio-blk-device", "scsi", "true", .optional = true }, 206 { "e1000", "extra_mac_registers", "off" }, 207 { "virtio-pci", "x-disable-pcie", "on" }, 208 { "virtio-pci", "migrate-extra", "off" }, 209 { "fw_cfg_mem", "dma_enabled", "off" }, 210 { "fw_cfg_io", "dma_enabled", "off" } 211 }; 212 const size_t hw_compat_2_4_len = G_N_ELEMENTS(hw_compat_2_4); 213 214 GlobalProperty hw_compat_2_3[] = { 215 { "virtio-blk-pci", "any_layout", "off" }, 216 { "virtio-balloon-pci", "any_layout", "off" }, 217 { "virtio-serial-pci", "any_layout", "off" }, 218 { "virtio-9p-pci", "any_layout", "off" }, 219 { "virtio-rng-pci", "any_layout", "off" }, 220 { TYPE_PCI_DEVICE, "x-pcie-lnksta-dllla", "off" }, 221 { "migration", "send-configuration", "off" }, 222 { "migration", "send-section-footer", "off" }, 223 { "migration", "store-global-state", "off" }, 224 }; 225 const size_t hw_compat_2_3_len = G_N_ELEMENTS(hw_compat_2_3); 226 227 GlobalProperty hw_compat_2_2[] = {}; 228 const size_t hw_compat_2_2_len = G_N_ELEMENTS(hw_compat_2_2); 229 230 GlobalProperty hw_compat_2_1[] = { 231 { "intel-hda", "old_msi_addr", "on" }, 232 { "VGA", "qemu-extended-regs", "off" }, 233 { "secondary-vga", "qemu-extended-regs", "off" }, 234 { "virtio-scsi-pci", "any_layout", "off" }, 235 { "usb-mouse", "usb_version", "1" }, 236 { "usb-kbd", "usb_version", "1" }, 237 { "virtio-pci", "virtio-pci-bus-master-bug-migration", "on" }, 238 }; 239 const size_t hw_compat_2_1_len = G_N_ELEMENTS(hw_compat_2_1); 240 241 MachineState *current_machine; 242 243 static char *machine_get_kernel(Object *obj, Error **errp) 244 { 245 MachineState *ms = MACHINE(obj); 246 247 return g_strdup(ms->kernel_filename); 248 } 249 250 static void machine_set_kernel(Object *obj, const char *value, Error **errp) 251 { 252 MachineState *ms = MACHINE(obj); 253 254 g_free(ms->kernel_filename); 255 ms->kernel_filename = g_strdup(value); 256 } 257 258 static char *machine_get_initrd(Object *obj, Error **errp) 259 { 260 MachineState *ms = MACHINE(obj); 261 262 return g_strdup(ms->initrd_filename); 263 } 264 265 static void machine_set_initrd(Object *obj, const char *value, Error **errp) 266 { 267 MachineState *ms = MACHINE(obj); 268 269 g_free(ms->initrd_filename); 270 ms->initrd_filename = g_strdup(value); 271 } 272 273 static char *machine_get_append(Object *obj, Error **errp) 274 { 275 MachineState *ms = MACHINE(obj); 276 277 return g_strdup(ms->kernel_cmdline); 278 } 279 280 static void machine_set_append(Object *obj, const char *value, Error **errp) 281 { 282 MachineState *ms = MACHINE(obj); 283 284 g_free(ms->kernel_cmdline); 285 ms->kernel_cmdline = g_strdup(value); 286 } 287 288 static char *machine_get_dtb(Object *obj, Error **errp) 289 { 290 MachineState *ms = MACHINE(obj); 291 292 return g_strdup(ms->dtb); 293 } 294 295 static void machine_set_dtb(Object *obj, const char *value, Error **errp) 296 { 297 MachineState *ms = MACHINE(obj); 298 299 g_free(ms->dtb); 300 ms->dtb = g_strdup(value); 301 } 302 303 static char *machine_get_dumpdtb(Object *obj, Error **errp) 304 { 305 MachineState *ms = MACHINE(obj); 306 307 return g_strdup(ms->dumpdtb); 308 } 309 310 static void machine_set_dumpdtb(Object *obj, const char *value, Error **errp) 311 { 312 MachineState *ms = MACHINE(obj); 313 314 g_free(ms->dumpdtb); 315 ms->dumpdtb = g_strdup(value); 316 } 317 318 static void machine_get_phandle_start(Object *obj, Visitor *v, 319 const char *name, void *opaque, 320 Error **errp) 321 { 322 MachineState *ms = MACHINE(obj); 323 int64_t value = ms->phandle_start; 324 325 visit_type_int(v, name, &value, errp); 326 } 327 328 static void machine_set_phandle_start(Object *obj, Visitor *v, 329 const char *name, void *opaque, 330 Error **errp) 331 { 332 MachineState *ms = MACHINE(obj); 333 int64_t value; 334 335 if (!visit_type_int(v, name, &value, errp)) { 336 return; 337 } 338 339 ms->phandle_start = value; 340 } 341 342 static char *machine_get_dt_compatible(Object *obj, Error **errp) 343 { 344 MachineState *ms = MACHINE(obj); 345 346 return g_strdup(ms->dt_compatible); 347 } 348 349 static void machine_set_dt_compatible(Object *obj, const char *value, Error **errp) 350 { 351 MachineState *ms = MACHINE(obj); 352 353 g_free(ms->dt_compatible); 354 ms->dt_compatible = g_strdup(value); 355 } 356 357 static bool machine_get_dump_guest_core(Object *obj, Error **errp) 358 { 359 MachineState *ms = MACHINE(obj); 360 361 return ms->dump_guest_core; 362 } 363 364 static void machine_set_dump_guest_core(Object *obj, bool value, Error **errp) 365 { 366 MachineState *ms = MACHINE(obj); 367 368 ms->dump_guest_core = value; 369 } 370 371 static bool machine_get_mem_merge(Object *obj, Error **errp) 372 { 373 MachineState *ms = MACHINE(obj); 374 375 return ms->mem_merge; 376 } 377 378 static void machine_set_mem_merge(Object *obj, bool value, Error **errp) 379 { 380 MachineState *ms = MACHINE(obj); 381 382 ms->mem_merge = value; 383 } 384 385 static bool machine_get_usb(Object *obj, Error **errp) 386 { 387 MachineState *ms = MACHINE(obj); 388 389 return ms->usb; 390 } 391 392 static void machine_set_usb(Object *obj, bool value, Error **errp) 393 { 394 MachineState *ms = MACHINE(obj); 395 396 ms->usb = value; 397 ms->usb_disabled = !value; 398 } 399 400 static bool machine_get_graphics(Object *obj, Error **errp) 401 { 402 MachineState *ms = MACHINE(obj); 403 404 return ms->enable_graphics; 405 } 406 407 static void machine_set_graphics(Object *obj, bool value, Error **errp) 408 { 409 MachineState *ms = MACHINE(obj); 410 411 ms->enable_graphics = value; 412 } 413 414 static char *machine_get_firmware(Object *obj, Error **errp) 415 { 416 MachineState *ms = MACHINE(obj); 417 418 return g_strdup(ms->firmware); 419 } 420 421 static void machine_set_firmware(Object *obj, const char *value, Error **errp) 422 { 423 MachineState *ms = MACHINE(obj); 424 425 g_free(ms->firmware); 426 ms->firmware = g_strdup(value); 427 } 428 429 static void machine_set_suppress_vmdesc(Object *obj, bool value, Error **errp) 430 { 431 MachineState *ms = MACHINE(obj); 432 433 ms->suppress_vmdesc = value; 434 } 435 436 static bool machine_get_suppress_vmdesc(Object *obj, Error **errp) 437 { 438 MachineState *ms = MACHINE(obj); 439 440 return ms->suppress_vmdesc; 441 } 442 443 static char *machine_get_memory_encryption(Object *obj, Error **errp) 444 { 445 MachineState *ms = MACHINE(obj); 446 447 if (ms->cgs) { 448 return g_strdup(object_get_canonical_path_component(OBJECT(ms->cgs))); 449 } 450 451 return NULL; 452 } 453 454 static void machine_set_memory_encryption(Object *obj, const char *value, 455 Error **errp) 456 { 457 Object *cgs = 458 object_resolve_path_component(object_get_objects_root(), value); 459 460 if (!cgs) { 461 error_setg(errp, "No such memory encryption object '%s'", value); 462 return; 463 } 464 465 object_property_set_link(obj, "confidential-guest-support", cgs, errp); 466 } 467 468 static void machine_check_confidential_guest_support(const Object *obj, 469 const char *name, 470 Object *new_target, 471 Error **errp) 472 { 473 /* 474 * So far the only constraint is that the target has the 475 * TYPE_CONFIDENTIAL_GUEST_SUPPORT interface, and that's checked 476 * by the QOM core 477 */ 478 } 479 480 static bool machine_get_nvdimm(Object *obj, Error **errp) 481 { 482 MachineState *ms = MACHINE(obj); 483 484 return ms->nvdimms_state->is_enabled; 485 } 486 487 static void machine_set_nvdimm(Object *obj, bool value, Error **errp) 488 { 489 MachineState *ms = MACHINE(obj); 490 491 ms->nvdimms_state->is_enabled = value; 492 } 493 494 static bool machine_get_hmat(Object *obj, Error **errp) 495 { 496 MachineState *ms = MACHINE(obj); 497 498 return ms->numa_state->hmat_enabled; 499 } 500 501 static void machine_set_hmat(Object *obj, bool value, Error **errp) 502 { 503 MachineState *ms = MACHINE(obj); 504 505 ms->numa_state->hmat_enabled = value; 506 } 507 508 static char *machine_get_nvdimm_persistence(Object *obj, Error **errp) 509 { 510 MachineState *ms = MACHINE(obj); 511 512 return g_strdup(ms->nvdimms_state->persistence_string); 513 } 514 515 static void machine_set_nvdimm_persistence(Object *obj, const char *value, 516 Error **errp) 517 { 518 MachineState *ms = MACHINE(obj); 519 NVDIMMState *nvdimms_state = ms->nvdimms_state; 520 521 if (strcmp(value, "cpu") == 0) { 522 nvdimms_state->persistence = 3; 523 } else if (strcmp(value, "mem-ctrl") == 0) { 524 nvdimms_state->persistence = 2; 525 } else { 526 error_setg(errp, "-machine nvdimm-persistence=%s: unsupported option", 527 value); 528 return; 529 } 530 531 g_free(nvdimms_state->persistence_string); 532 nvdimms_state->persistence_string = g_strdup(value); 533 } 534 535 void machine_class_allow_dynamic_sysbus_dev(MachineClass *mc, const char *type) 536 { 537 QAPI_LIST_PREPEND(mc->allowed_dynamic_sysbus_devices, g_strdup(type)); 538 } 539 540 bool device_is_dynamic_sysbus(MachineClass *mc, DeviceState *dev) 541 { 542 bool allowed = false; 543 strList *wl; 544 Object *obj = OBJECT(dev); 545 546 if (!object_dynamic_cast(obj, TYPE_SYS_BUS_DEVICE)) { 547 return false; 548 } 549 550 for (wl = mc->allowed_dynamic_sysbus_devices; 551 !allowed && wl; 552 wl = wl->next) { 553 allowed |= !!object_dynamic_cast(obj, wl->value); 554 } 555 556 return allowed; 557 } 558 559 static void validate_sysbus_device(SysBusDevice *sbdev, void *opaque) 560 { 561 MachineState *machine = opaque; 562 MachineClass *mc = MACHINE_GET_CLASS(machine); 563 564 if (!device_is_dynamic_sysbus(mc, DEVICE(sbdev))) { 565 error_report("Option '-device %s' cannot be handled by this machine", 566 object_class_get_name(object_get_class(OBJECT(sbdev)))); 567 exit(1); 568 } 569 } 570 571 static char *machine_get_memdev(Object *obj, Error **errp) 572 { 573 MachineState *ms = MACHINE(obj); 574 575 return g_strdup(ms->ram_memdev_id); 576 } 577 578 static void machine_set_memdev(Object *obj, const char *value, Error **errp) 579 { 580 MachineState *ms = MACHINE(obj); 581 582 g_free(ms->ram_memdev_id); 583 ms->ram_memdev_id = g_strdup(value); 584 } 585 586 587 static void machine_init_notify(Notifier *notifier, void *data) 588 { 589 MachineState *machine = MACHINE(qdev_get_machine()); 590 591 /* 592 * Loop through all dynamically created sysbus devices and check if they are 593 * all allowed. If a device is not allowed, error out. 594 */ 595 foreach_dynamic_sysbus_device(validate_sysbus_device, machine); 596 } 597 598 HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine) 599 { 600 int i; 601 HotpluggableCPUList *head = NULL; 602 MachineClass *mc = MACHINE_GET_CLASS(machine); 603 604 /* force board to initialize possible_cpus if it hasn't been done yet */ 605 mc->possible_cpu_arch_ids(machine); 606 607 for (i = 0; i < machine->possible_cpus->len; i++) { 608 Object *cpu; 609 HotpluggableCPU *cpu_item = g_new0(typeof(*cpu_item), 1); 610 611 cpu_item->type = g_strdup(machine->possible_cpus->cpus[i].type); 612 cpu_item->vcpus_count = machine->possible_cpus->cpus[i].vcpus_count; 613 cpu_item->props = g_memdup(&machine->possible_cpus->cpus[i].props, 614 sizeof(*cpu_item->props)); 615 616 cpu = machine->possible_cpus->cpus[i].cpu; 617 if (cpu) { 618 cpu_item->has_qom_path = true; 619 cpu_item->qom_path = object_get_canonical_path(cpu); 620 } 621 QAPI_LIST_PREPEND(head, cpu_item); 622 } 623 return head; 624 } 625 626 /** 627 * machine_set_cpu_numa_node: 628 * @machine: machine object to modify 629 * @props: specifies which cpu objects to assign to 630 * numa node specified by @props.node_id 631 * @errp: if an error occurs, a pointer to an area to store the error 632 * 633 * Associate NUMA node specified by @props.node_id with cpu slots that 634 * match socket/core/thread-ids specified by @props. It's recommended to use 635 * query-hotpluggable-cpus.props values to specify affected cpu slots, 636 * which would lead to exact 1:1 mapping of cpu slots to NUMA node. 637 * 638 * However for CLI convenience it's possible to pass in subset of properties, 639 * which would affect all cpu slots that match it. 640 * Ex for pc machine: 641 * -smp 4,cores=2,sockets=2 -numa node,nodeid=0 -numa node,nodeid=1 \ 642 * -numa cpu,node-id=0,socket_id=0 \ 643 * -numa cpu,node-id=1,socket_id=1 644 * will assign all child cores of socket 0 to node 0 and 645 * of socket 1 to node 1. 646 * 647 * On attempt of reassigning (already assigned) cpu slot to another NUMA node, 648 * return error. 649 * Empty subset is disallowed and function will return with error in this case. 650 */ 651 void machine_set_cpu_numa_node(MachineState *machine, 652 const CpuInstanceProperties *props, Error **errp) 653 { 654 MachineClass *mc = MACHINE_GET_CLASS(machine); 655 NodeInfo *numa_info = machine->numa_state->nodes; 656 bool match = false; 657 int i; 658 659 if (!mc->possible_cpu_arch_ids) { 660 error_setg(errp, "mapping of CPUs to NUMA node is not supported"); 661 return; 662 } 663 664 /* disabling node mapping is not supported, forbid it */ 665 assert(props->has_node_id); 666 667 /* force board to initialize possible_cpus if it hasn't been done yet */ 668 mc->possible_cpu_arch_ids(machine); 669 670 for (i = 0; i < machine->possible_cpus->len; i++) { 671 CPUArchId *slot = &machine->possible_cpus->cpus[i]; 672 673 /* reject unsupported by board properties */ 674 if (props->has_thread_id && !slot->props.has_thread_id) { 675 error_setg(errp, "thread-id is not supported"); 676 return; 677 } 678 679 if (props->has_core_id && !slot->props.has_core_id) { 680 error_setg(errp, "core-id is not supported"); 681 return; 682 } 683 684 if (props->has_socket_id && !slot->props.has_socket_id) { 685 error_setg(errp, "socket-id is not supported"); 686 return; 687 } 688 689 if (props->has_die_id && !slot->props.has_die_id) { 690 error_setg(errp, "die-id is not supported"); 691 return; 692 } 693 694 /* skip slots with explicit mismatch */ 695 if (props->has_thread_id && props->thread_id != slot->props.thread_id) { 696 continue; 697 } 698 699 if (props->has_core_id && props->core_id != slot->props.core_id) { 700 continue; 701 } 702 703 if (props->has_die_id && props->die_id != slot->props.die_id) { 704 continue; 705 } 706 707 if (props->has_socket_id && props->socket_id != slot->props.socket_id) { 708 continue; 709 } 710 711 /* reject assignment if slot is already assigned, for compatibility 712 * of legacy cpu_index mapping with SPAPR core based mapping do not 713 * error out if cpu thread and matched core have the same node-id */ 714 if (slot->props.has_node_id && 715 slot->props.node_id != props->node_id) { 716 error_setg(errp, "CPU is already assigned to node-id: %" PRId64, 717 slot->props.node_id); 718 return; 719 } 720 721 /* assign slot to node as it's matched '-numa cpu' key */ 722 match = true; 723 slot->props.node_id = props->node_id; 724 slot->props.has_node_id = props->has_node_id; 725 726 if (machine->numa_state->hmat_enabled) { 727 if ((numa_info[props->node_id].initiator < MAX_NODES) && 728 (props->node_id != numa_info[props->node_id].initiator)) { 729 error_setg(errp, "The initiator of CPU NUMA node %" PRId64 730 " should be itself", props->node_id); 731 return; 732 } 733 numa_info[props->node_id].has_cpu = true; 734 numa_info[props->node_id].initiator = props->node_id; 735 } 736 } 737 738 if (!match) { 739 error_setg(errp, "no match found"); 740 } 741 } 742 743 static void smp_parse(MachineState *ms, SMPConfiguration *config, Error **errp) 744 { 745 unsigned cpus = config->has_cpus ? config->cpus : 0; 746 unsigned sockets = config->has_sockets ? config->sockets : 0; 747 unsigned cores = config->has_cores ? config->cores : 0; 748 unsigned threads = config->has_threads ? config->threads : 0; 749 750 if (config->has_dies && config->dies != 0 && config->dies != 1) { 751 error_setg(errp, "dies not supported by this machine's CPU topology"); 752 } 753 754 /* compute missing values, prefer sockets over cores over threads */ 755 if (cpus == 0 || sockets == 0) { 756 cores = cores > 0 ? cores : 1; 757 threads = threads > 0 ? threads : 1; 758 if (cpus == 0) { 759 sockets = sockets > 0 ? sockets : 1; 760 cpus = cores * threads * sockets; 761 } else { 762 ms->smp.max_cpus = config->has_maxcpus ? config->maxcpus : cpus; 763 sockets = ms->smp.max_cpus / (cores * threads); 764 } 765 } else if (cores == 0) { 766 threads = threads > 0 ? threads : 1; 767 cores = cpus / (sockets * threads); 768 cores = cores > 0 ? cores : 1; 769 } else if (threads == 0) { 770 threads = cpus / (cores * sockets); 771 threads = threads > 0 ? threads : 1; 772 } else if (sockets * cores * threads < cpus) { 773 error_setg(errp, "cpu topology: " 774 "sockets (%u) * cores (%u) * threads (%u) < " 775 "smp_cpus (%u)", 776 sockets, cores, threads, cpus); 777 return; 778 } 779 780 ms->smp.max_cpus = config->has_maxcpus ? config->maxcpus : cpus; 781 782 if (ms->smp.max_cpus < cpus) { 783 error_setg(errp, "maxcpus must be equal to or greater than smp"); 784 return; 785 } 786 787 if (sockets * cores * threads != ms->smp.max_cpus) { 788 error_setg(errp, "Invalid CPU topology: " 789 "sockets (%u) * cores (%u) * threads (%u) " 790 "!= maxcpus (%u)", 791 sockets, cores, threads, 792 ms->smp.max_cpus); 793 return; 794 } 795 796 ms->smp.cpus = cpus; 797 ms->smp.cores = cores; 798 ms->smp.threads = threads; 799 ms->smp.sockets = sockets; 800 } 801 802 static void machine_class_init(ObjectClass *oc, void *data) 803 { 804 MachineClass *mc = MACHINE_CLASS(oc); 805 806 /* Default 128 MB as guest ram size */ 807 mc->default_ram_size = 128 * MiB; 808 mc->rom_file_has_mr = true; 809 mc->smp_parse = smp_parse; 810 811 /* numa node memory size aligned on 8MB by default. 812 * On Linux, each node's border has to be 8MB aligned 813 */ 814 mc->numa_mem_align_shift = 23; 815 816 object_class_property_add_str(oc, "kernel", 817 machine_get_kernel, machine_set_kernel); 818 object_class_property_set_description(oc, "kernel", 819 "Linux kernel image file"); 820 821 object_class_property_add_str(oc, "initrd", 822 machine_get_initrd, machine_set_initrd); 823 object_class_property_set_description(oc, "initrd", 824 "Linux initial ramdisk file"); 825 826 object_class_property_add_str(oc, "append", 827 machine_get_append, machine_set_append); 828 object_class_property_set_description(oc, "append", 829 "Linux kernel command line"); 830 831 object_class_property_add_str(oc, "dtb", 832 machine_get_dtb, machine_set_dtb); 833 object_class_property_set_description(oc, "dtb", 834 "Linux kernel device tree file"); 835 836 object_class_property_add_str(oc, "dumpdtb", 837 machine_get_dumpdtb, machine_set_dumpdtb); 838 object_class_property_set_description(oc, "dumpdtb", 839 "Dump current dtb to a file and quit"); 840 841 object_class_property_add(oc, "phandle-start", "int", 842 machine_get_phandle_start, machine_set_phandle_start, 843 NULL, NULL); 844 object_class_property_set_description(oc, "phandle-start", 845 "The first phandle ID we may generate dynamically"); 846 847 object_class_property_add_str(oc, "dt-compatible", 848 machine_get_dt_compatible, machine_set_dt_compatible); 849 object_class_property_set_description(oc, "dt-compatible", 850 "Overrides the \"compatible\" property of the dt root node"); 851 852 object_class_property_add_bool(oc, "dump-guest-core", 853 machine_get_dump_guest_core, machine_set_dump_guest_core); 854 object_class_property_set_description(oc, "dump-guest-core", 855 "Include guest memory in a core dump"); 856 857 object_class_property_add_bool(oc, "mem-merge", 858 machine_get_mem_merge, machine_set_mem_merge); 859 object_class_property_set_description(oc, "mem-merge", 860 "Enable/disable memory merge support"); 861 862 object_class_property_add_bool(oc, "usb", 863 machine_get_usb, machine_set_usb); 864 object_class_property_set_description(oc, "usb", 865 "Set on/off to enable/disable usb"); 866 867 object_class_property_add_bool(oc, "graphics", 868 machine_get_graphics, machine_set_graphics); 869 object_class_property_set_description(oc, "graphics", 870 "Set on/off to enable/disable graphics emulation"); 871 872 object_class_property_add_str(oc, "firmware", 873 machine_get_firmware, machine_set_firmware); 874 object_class_property_set_description(oc, "firmware", 875 "Firmware image"); 876 877 object_class_property_add_bool(oc, "suppress-vmdesc", 878 machine_get_suppress_vmdesc, machine_set_suppress_vmdesc); 879 object_class_property_set_description(oc, "suppress-vmdesc", 880 "Set on to disable self-describing migration"); 881 882 object_class_property_add_link(oc, "confidential-guest-support", 883 TYPE_CONFIDENTIAL_GUEST_SUPPORT, 884 offsetof(MachineState, cgs), 885 machine_check_confidential_guest_support, 886 OBJ_PROP_LINK_STRONG); 887 object_class_property_set_description(oc, "confidential-guest-support", 888 "Set confidential guest scheme to support"); 889 890 /* For compatibility */ 891 object_class_property_add_str(oc, "memory-encryption", 892 machine_get_memory_encryption, machine_set_memory_encryption); 893 object_class_property_set_description(oc, "memory-encryption", 894 "Set memory encryption object to use"); 895 896 object_class_property_add_str(oc, "memory-backend", 897 machine_get_memdev, machine_set_memdev); 898 object_class_property_set_description(oc, "memory-backend", 899 "Set RAM backend" 900 "Valid value is ID of hostmem based backend"); 901 } 902 903 static void machine_class_base_init(ObjectClass *oc, void *data) 904 { 905 MachineClass *mc = MACHINE_CLASS(oc); 906 mc->max_cpus = mc->max_cpus ?: 1; 907 mc->min_cpus = mc->min_cpus ?: 1; 908 mc->default_cpus = mc->default_cpus ?: 1; 909 910 if (!object_class_is_abstract(oc)) { 911 const char *cname = object_class_get_name(oc); 912 assert(g_str_has_suffix(cname, TYPE_MACHINE_SUFFIX)); 913 mc->name = g_strndup(cname, 914 strlen(cname) - strlen(TYPE_MACHINE_SUFFIX)); 915 mc->compat_props = g_ptr_array_new(); 916 } 917 } 918 919 static void machine_initfn(Object *obj) 920 { 921 MachineState *ms = MACHINE(obj); 922 MachineClass *mc = MACHINE_GET_CLASS(obj); 923 924 container_get(obj, "/peripheral"); 925 container_get(obj, "/peripheral-anon"); 926 927 ms->dump_guest_core = true; 928 ms->mem_merge = true; 929 ms->enable_graphics = true; 930 ms->kernel_cmdline = g_strdup(""); 931 932 if (mc->nvdimm_supported) { 933 Object *obj = OBJECT(ms); 934 935 ms->nvdimms_state = g_new0(NVDIMMState, 1); 936 object_property_add_bool(obj, "nvdimm", 937 machine_get_nvdimm, machine_set_nvdimm); 938 object_property_set_description(obj, "nvdimm", 939 "Set on/off to enable/disable " 940 "NVDIMM instantiation"); 941 942 object_property_add_str(obj, "nvdimm-persistence", 943 machine_get_nvdimm_persistence, 944 machine_set_nvdimm_persistence); 945 object_property_set_description(obj, "nvdimm-persistence", 946 "Set NVDIMM persistence" 947 "Valid values are cpu, mem-ctrl"); 948 } 949 950 if (mc->cpu_index_to_instance_props && mc->get_default_cpu_node_id) { 951 ms->numa_state = g_new0(NumaState, 1); 952 object_property_add_bool(obj, "hmat", 953 machine_get_hmat, machine_set_hmat); 954 object_property_set_description(obj, "hmat", 955 "Set on/off to enable/disable " 956 "ACPI Heterogeneous Memory Attribute " 957 "Table (HMAT)"); 958 } 959 960 /* Register notifier when init is done for sysbus sanity checks */ 961 ms->sysbus_notifier.notify = machine_init_notify; 962 qemu_add_machine_init_done_notifier(&ms->sysbus_notifier); 963 964 /* default to mc->default_cpus */ 965 ms->smp.cpus = mc->default_cpus; 966 ms->smp.max_cpus = mc->default_cpus; 967 ms->smp.cores = 1; 968 ms->smp.dies = 1; 969 ms->smp.threads = 1; 970 ms->smp.sockets = 1; 971 } 972 973 static void machine_finalize(Object *obj) 974 { 975 MachineState *ms = MACHINE(obj); 976 977 g_free(ms->kernel_filename); 978 g_free(ms->initrd_filename); 979 g_free(ms->kernel_cmdline); 980 g_free(ms->dtb); 981 g_free(ms->dumpdtb); 982 g_free(ms->dt_compatible); 983 g_free(ms->firmware); 984 g_free(ms->device_memory); 985 g_free(ms->nvdimms_state); 986 g_free(ms->numa_state); 987 } 988 989 bool machine_usb(MachineState *machine) 990 { 991 return machine->usb; 992 } 993 994 int machine_phandle_start(MachineState *machine) 995 { 996 return machine->phandle_start; 997 } 998 999 bool machine_dump_guest_core(MachineState *machine) 1000 { 1001 return machine->dump_guest_core; 1002 } 1003 1004 bool machine_mem_merge(MachineState *machine) 1005 { 1006 return machine->mem_merge; 1007 } 1008 1009 static char *cpu_slot_to_string(const CPUArchId *cpu) 1010 { 1011 GString *s = g_string_new(NULL); 1012 if (cpu->props.has_socket_id) { 1013 g_string_append_printf(s, "socket-id: %"PRId64, cpu->props.socket_id); 1014 } 1015 if (cpu->props.has_die_id) { 1016 g_string_append_printf(s, "die-id: %"PRId64, cpu->props.die_id); 1017 } 1018 if (cpu->props.has_core_id) { 1019 if (s->len) { 1020 g_string_append_printf(s, ", "); 1021 } 1022 g_string_append_printf(s, "core-id: %"PRId64, cpu->props.core_id); 1023 } 1024 if (cpu->props.has_thread_id) { 1025 if (s->len) { 1026 g_string_append_printf(s, ", "); 1027 } 1028 g_string_append_printf(s, "thread-id: %"PRId64, cpu->props.thread_id); 1029 } 1030 return g_string_free(s, false); 1031 } 1032 1033 static void numa_validate_initiator(NumaState *numa_state) 1034 { 1035 int i; 1036 NodeInfo *numa_info = numa_state->nodes; 1037 1038 for (i = 0; i < numa_state->num_nodes; i++) { 1039 if (numa_info[i].initiator == MAX_NODES) { 1040 error_report("The initiator of NUMA node %d is missing, use " 1041 "'-numa node,initiator' option to declare it", i); 1042 exit(1); 1043 } 1044 1045 if (!numa_info[numa_info[i].initiator].present) { 1046 error_report("NUMA node %" PRIu16 " is missing, use " 1047 "'-numa node' option to declare it first", 1048 numa_info[i].initiator); 1049 exit(1); 1050 } 1051 1052 if (!numa_info[numa_info[i].initiator].has_cpu) { 1053 error_report("The initiator of NUMA node %d is invalid", i); 1054 exit(1); 1055 } 1056 } 1057 } 1058 1059 static void machine_numa_finish_cpu_init(MachineState *machine) 1060 { 1061 int i; 1062 bool default_mapping; 1063 GString *s = g_string_new(NULL); 1064 MachineClass *mc = MACHINE_GET_CLASS(machine); 1065 const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(machine); 1066 1067 assert(machine->numa_state->num_nodes); 1068 for (i = 0; i < possible_cpus->len; i++) { 1069 if (possible_cpus->cpus[i].props.has_node_id) { 1070 break; 1071 } 1072 } 1073 default_mapping = (i == possible_cpus->len); 1074 1075 for (i = 0; i < possible_cpus->len; i++) { 1076 const CPUArchId *cpu_slot = &possible_cpus->cpus[i]; 1077 1078 if (!cpu_slot->props.has_node_id) { 1079 /* fetch default mapping from board and enable it */ 1080 CpuInstanceProperties props = cpu_slot->props; 1081 1082 props.node_id = mc->get_default_cpu_node_id(machine, i); 1083 if (!default_mapping) { 1084 /* record slots with not set mapping, 1085 * TODO: make it hard error in future */ 1086 char *cpu_str = cpu_slot_to_string(cpu_slot); 1087 g_string_append_printf(s, "%sCPU %d [%s]", 1088 s->len ? ", " : "", i, cpu_str); 1089 g_free(cpu_str); 1090 1091 /* non mapped cpus used to fallback to node 0 */ 1092 props.node_id = 0; 1093 } 1094 1095 props.has_node_id = true; 1096 machine_set_cpu_numa_node(machine, &props, &error_fatal); 1097 } 1098 } 1099 1100 if (machine->numa_state->hmat_enabled) { 1101 numa_validate_initiator(machine->numa_state); 1102 } 1103 1104 if (s->len && !qtest_enabled()) { 1105 warn_report("CPU(s) not present in any NUMA nodes: %s", 1106 s->str); 1107 warn_report("All CPU(s) up to maxcpus should be described " 1108 "in NUMA config, ability to start up with partial NUMA " 1109 "mappings is obsoleted and will be removed in future"); 1110 } 1111 g_string_free(s, true); 1112 } 1113 1114 MemoryRegion *machine_consume_memdev(MachineState *machine, 1115 HostMemoryBackend *backend) 1116 { 1117 MemoryRegion *ret = host_memory_backend_get_memory(backend); 1118 1119 if (memory_region_is_mapped(ret)) { 1120 error_report("memory backend %s can't be used multiple times.", 1121 object_get_canonical_path_component(OBJECT(backend))); 1122 exit(EXIT_FAILURE); 1123 } 1124 host_memory_backend_set_mapped(backend, true); 1125 vmstate_register_ram_global(ret); 1126 return ret; 1127 } 1128 1129 bool machine_smp_parse(MachineState *ms, QemuOpts *opts, Error **errp) 1130 { 1131 MachineClass *mc = MACHINE_GET_CLASS(ms); 1132 ERRP_GUARD(); 1133 1134 if (opts) { 1135 SMPConfiguration config = { 1136 .has_cpus = !!qemu_opt_get(opts, "cpus"), 1137 .cpus = qemu_opt_get_number(opts, "cpus", 0), 1138 .has_sockets = !!qemu_opt_get(opts, "sockets"), 1139 .sockets = qemu_opt_get_number(opts, "sockets", 0), 1140 .has_dies = !!qemu_opt_get(opts, "dies"), 1141 .dies = qemu_opt_get_number(opts, "dies", 0), 1142 .has_cores = !!qemu_opt_get(opts, "cores"), 1143 .cores = qemu_opt_get_number(opts, "cores", 0), 1144 .has_threads = !!qemu_opt_get(opts, "threads"), 1145 .threads = qemu_opt_get_number(opts, "threads", 0), 1146 .has_maxcpus = !!qemu_opt_get(opts, "maxcpus"), 1147 .maxcpus = qemu_opt_get_number(opts, "maxcpus", 0), 1148 }; 1149 1150 mc->smp_parse(ms, &config, errp); 1151 if (*errp) { 1152 return false; 1153 } 1154 } 1155 1156 /* sanity-check smp_cpus and max_cpus against mc */ 1157 if (ms->smp.cpus < mc->min_cpus) { 1158 error_setg(errp, "Invalid SMP CPUs %d. The min CPUs " 1159 "supported by machine '%s' is %d", 1160 ms->smp.cpus, 1161 mc->name, mc->min_cpus); 1162 return false; 1163 } else if (ms->smp.max_cpus > mc->max_cpus) { 1164 error_setg(errp, "Invalid SMP CPUs %d. The max CPUs " 1165 "supported by machine '%s' is %d", 1166 current_machine->smp.max_cpus, 1167 mc->name, mc->max_cpus); 1168 return false; 1169 } 1170 1171 if (ms->smp.cpus > 1) { 1172 Error *blocker = NULL; 1173 error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp"); 1174 replay_add_blocker(blocker); 1175 } 1176 return true; 1177 } 1178 1179 void machine_run_board_init(MachineState *machine) 1180 { 1181 MachineClass *machine_class = MACHINE_GET_CLASS(machine); 1182 ObjectClass *oc = object_class_by_name(machine->cpu_type); 1183 CPUClass *cc; 1184 1185 /* This checkpoint is required by replay to separate prior clock 1186 reading from the other reads, because timer polling functions query 1187 clock values from the log. */ 1188 replay_checkpoint(CHECKPOINT_INIT); 1189 1190 if (machine->ram_memdev_id) { 1191 Object *o; 1192 o = object_resolve_path_type(machine->ram_memdev_id, 1193 TYPE_MEMORY_BACKEND, NULL); 1194 machine->ram = machine_consume_memdev(machine, MEMORY_BACKEND(o)); 1195 } 1196 1197 if (machine->numa_state) { 1198 numa_complete_configuration(machine); 1199 if (machine->numa_state->num_nodes) { 1200 machine_numa_finish_cpu_init(machine); 1201 } 1202 } 1203 1204 /* If the machine supports the valid_cpu_types check and the user 1205 * specified a CPU with -cpu check here that the user CPU is supported. 1206 */ 1207 if (machine_class->valid_cpu_types && machine->cpu_type) { 1208 int i; 1209 1210 for (i = 0; machine_class->valid_cpu_types[i]; i++) { 1211 if (object_class_dynamic_cast(oc, 1212 machine_class->valid_cpu_types[i])) { 1213 /* The user specificed CPU is in the valid field, we are 1214 * good to go. 1215 */ 1216 break; 1217 } 1218 } 1219 1220 if (!machine_class->valid_cpu_types[i]) { 1221 /* The user specified CPU is not valid */ 1222 error_report("Invalid CPU type: %s", machine->cpu_type); 1223 error_printf("The valid types are: %s", 1224 machine_class->valid_cpu_types[0]); 1225 for (i = 1; machine_class->valid_cpu_types[i]; i++) { 1226 error_printf(", %s", machine_class->valid_cpu_types[i]); 1227 } 1228 error_printf("\n"); 1229 1230 exit(1); 1231 } 1232 } 1233 1234 /* Check if CPU type is deprecated and warn if so */ 1235 cc = CPU_CLASS(oc); 1236 if (cc && cc->deprecation_note) { 1237 warn_report("CPU model %s is deprecated -- %s", machine->cpu_type, 1238 cc->deprecation_note); 1239 } 1240 1241 if (machine->cgs) { 1242 /* 1243 * With confidential guests, the host can't see the real 1244 * contents of RAM, so there's no point in it trying to merge 1245 * areas. 1246 */ 1247 machine_set_mem_merge(OBJECT(machine), false, &error_abort); 1248 1249 /* 1250 * Virtio devices can't count on directly accessing guest 1251 * memory, so they need iommu_platform=on to use normal DMA 1252 * mechanisms. That requires also disabling legacy virtio 1253 * support for those virtio pci devices which allow it. 1254 */ 1255 object_register_sugar_prop(TYPE_VIRTIO_PCI, "disable-legacy", 1256 "on", true); 1257 object_register_sugar_prop(TYPE_VIRTIO_DEVICE, "iommu_platform", 1258 "on", false); 1259 } 1260 1261 accel_init_interfaces(ACCEL_GET_CLASS(machine->accelerator)); 1262 machine_class->init(machine); 1263 phase_advance(PHASE_MACHINE_INITIALIZED); 1264 } 1265 1266 static NotifierList machine_init_done_notifiers = 1267 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers); 1268 1269 void qemu_add_machine_init_done_notifier(Notifier *notify) 1270 { 1271 notifier_list_add(&machine_init_done_notifiers, notify); 1272 if (phase_check(PHASE_MACHINE_READY)) { 1273 notify->notify(notify, NULL); 1274 } 1275 } 1276 1277 void qemu_remove_machine_init_done_notifier(Notifier *notify) 1278 { 1279 notifier_remove(notify); 1280 } 1281 1282 void qdev_machine_creation_done(void) 1283 { 1284 cpu_synchronize_all_post_init(); 1285 1286 if (current_machine->boot_once) { 1287 qemu_boot_set(current_machine->boot_once, &error_fatal); 1288 qemu_register_reset(restore_boot_order, g_strdup(current_machine->boot_order)); 1289 } 1290 1291 /* 1292 * ok, initial machine setup is done, starting from now we can 1293 * only create hotpluggable devices 1294 */ 1295 phase_advance(PHASE_MACHINE_READY); 1296 qdev_assert_realized_properly(); 1297 1298 /* TODO: once all bus devices are qdevified, this should be done 1299 * when bus is created by qdev.c */ 1300 /* 1301 * TODO: If we had a main 'reset container' that the whole system 1302 * lived in, we could reset that using the multi-phase reset 1303 * APIs. For the moment, we just reset the sysbus, which will cause 1304 * all devices hanging off it (and all their child buses, recursively) 1305 * to be reset. Note that this will *not* reset any Device objects 1306 * which are not attached to some part of the qbus tree! 1307 */ 1308 qemu_register_reset(resettable_cold_reset_fn, sysbus_get_default()); 1309 1310 notifier_list_notify(&machine_init_done_notifiers, NULL); 1311 1312 if (rom_check_and_register_reset() != 0) { 1313 exit(1); 1314 } 1315 1316 replay_start(); 1317 1318 /* This checkpoint is required by replay to separate prior clock 1319 reading from the other reads, because timer polling functions query 1320 clock values from the log. */ 1321 replay_checkpoint(CHECKPOINT_RESET); 1322 qemu_system_reset(SHUTDOWN_CAUSE_NONE); 1323 register_global_state(); 1324 } 1325 1326 static const TypeInfo machine_info = { 1327 .name = TYPE_MACHINE, 1328 .parent = TYPE_OBJECT, 1329 .abstract = true, 1330 .class_size = sizeof(MachineClass), 1331 .class_init = machine_class_init, 1332 .class_base_init = machine_class_base_init, 1333 .instance_size = sizeof(MachineState), 1334 .instance_init = machine_initfn, 1335 .instance_finalize = machine_finalize, 1336 }; 1337 1338 static void machine_register_types(void) 1339 { 1340 type_register_static(&machine_info); 1341 } 1342 1343 type_init(machine_register_types) 1344