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, QemuOpts *opts) 744 { 745 if (opts) { 746 unsigned cpus = qemu_opt_get_number(opts, "cpus", 0); 747 unsigned sockets = qemu_opt_get_number(opts, "sockets", 0); 748 unsigned cores = qemu_opt_get_number(opts, "cores", 0); 749 unsigned threads = qemu_opt_get_number(opts, "threads", 0); 750 751 /* compute missing values, prefer sockets over cores over threads */ 752 if (cpus == 0 || sockets == 0) { 753 cores = cores > 0 ? cores : 1; 754 threads = threads > 0 ? threads : 1; 755 if (cpus == 0) { 756 sockets = sockets > 0 ? sockets : 1; 757 cpus = cores * threads * sockets; 758 } else { 759 ms->smp.max_cpus = 760 qemu_opt_get_number(opts, "maxcpus", cpus); 761 sockets = ms->smp.max_cpus / (cores * threads); 762 } 763 } else if (cores == 0) { 764 threads = threads > 0 ? threads : 1; 765 cores = cpus / (sockets * threads); 766 cores = cores > 0 ? cores : 1; 767 } else if (threads == 0) { 768 threads = cpus / (cores * sockets); 769 threads = threads > 0 ? threads : 1; 770 } else if (sockets * cores * threads < cpus) { 771 error_report("cpu topology: " 772 "sockets (%u) * cores (%u) * threads (%u) < " 773 "smp_cpus (%u)", 774 sockets, cores, threads, cpus); 775 exit(1); 776 } 777 778 ms->smp.max_cpus = 779 qemu_opt_get_number(opts, "maxcpus", cpus); 780 781 if (ms->smp.max_cpus < cpus) { 782 error_report("maxcpus must be equal to or greater than smp"); 783 exit(1); 784 } 785 786 if (sockets * cores * threads != ms->smp.max_cpus) { 787 error_report("Invalid CPU topology: " 788 "sockets (%u) * cores (%u) * threads (%u) " 789 "!= maxcpus (%u)", 790 sockets, cores, threads, 791 ms->smp.max_cpus); 792 exit(1); 793 } 794 795 ms->smp.cpus = cpus; 796 ms->smp.cores = cores; 797 ms->smp.threads = threads; 798 ms->smp.sockets = sockets; 799 } 800 801 if (ms->smp.cpus > 1) { 802 Error *blocker = NULL; 803 error_setg(&blocker, QERR_REPLAY_NOT_SUPPORTED, "smp"); 804 replay_add_blocker(blocker); 805 } 806 } 807 808 static void machine_class_init(ObjectClass *oc, void *data) 809 { 810 MachineClass *mc = MACHINE_CLASS(oc); 811 812 /* Default 128 MB as guest ram size */ 813 mc->default_ram_size = 128 * MiB; 814 mc->rom_file_has_mr = true; 815 mc->smp_parse = smp_parse; 816 817 /* numa node memory size aligned on 8MB by default. 818 * On Linux, each node's border has to be 8MB aligned 819 */ 820 mc->numa_mem_align_shift = 23; 821 822 object_class_property_add_str(oc, "kernel", 823 machine_get_kernel, machine_set_kernel); 824 object_class_property_set_description(oc, "kernel", 825 "Linux kernel image file"); 826 827 object_class_property_add_str(oc, "initrd", 828 machine_get_initrd, machine_set_initrd); 829 object_class_property_set_description(oc, "initrd", 830 "Linux initial ramdisk file"); 831 832 object_class_property_add_str(oc, "append", 833 machine_get_append, machine_set_append); 834 object_class_property_set_description(oc, "append", 835 "Linux kernel command line"); 836 837 object_class_property_add_str(oc, "dtb", 838 machine_get_dtb, machine_set_dtb); 839 object_class_property_set_description(oc, "dtb", 840 "Linux kernel device tree file"); 841 842 object_class_property_add_str(oc, "dumpdtb", 843 machine_get_dumpdtb, machine_set_dumpdtb); 844 object_class_property_set_description(oc, "dumpdtb", 845 "Dump current dtb to a file and quit"); 846 847 object_class_property_add(oc, "phandle-start", "int", 848 machine_get_phandle_start, machine_set_phandle_start, 849 NULL, NULL); 850 object_class_property_set_description(oc, "phandle-start", 851 "The first phandle ID we may generate dynamically"); 852 853 object_class_property_add_str(oc, "dt-compatible", 854 machine_get_dt_compatible, machine_set_dt_compatible); 855 object_class_property_set_description(oc, "dt-compatible", 856 "Overrides the \"compatible\" property of the dt root node"); 857 858 object_class_property_add_bool(oc, "dump-guest-core", 859 machine_get_dump_guest_core, machine_set_dump_guest_core); 860 object_class_property_set_description(oc, "dump-guest-core", 861 "Include guest memory in a core dump"); 862 863 object_class_property_add_bool(oc, "mem-merge", 864 machine_get_mem_merge, machine_set_mem_merge); 865 object_class_property_set_description(oc, "mem-merge", 866 "Enable/disable memory merge support"); 867 868 object_class_property_add_bool(oc, "usb", 869 machine_get_usb, machine_set_usb); 870 object_class_property_set_description(oc, "usb", 871 "Set on/off to enable/disable usb"); 872 873 object_class_property_add_bool(oc, "graphics", 874 machine_get_graphics, machine_set_graphics); 875 object_class_property_set_description(oc, "graphics", 876 "Set on/off to enable/disable graphics emulation"); 877 878 object_class_property_add_str(oc, "firmware", 879 machine_get_firmware, machine_set_firmware); 880 object_class_property_set_description(oc, "firmware", 881 "Firmware image"); 882 883 object_class_property_add_bool(oc, "suppress-vmdesc", 884 machine_get_suppress_vmdesc, machine_set_suppress_vmdesc); 885 object_class_property_set_description(oc, "suppress-vmdesc", 886 "Set on to disable self-describing migration"); 887 888 object_class_property_add_link(oc, "confidential-guest-support", 889 TYPE_CONFIDENTIAL_GUEST_SUPPORT, 890 offsetof(MachineState, cgs), 891 machine_check_confidential_guest_support, 892 OBJ_PROP_LINK_STRONG); 893 object_class_property_set_description(oc, "confidential-guest-support", 894 "Set confidential guest scheme to support"); 895 896 /* For compatibility */ 897 object_class_property_add_str(oc, "memory-encryption", 898 machine_get_memory_encryption, machine_set_memory_encryption); 899 object_class_property_set_description(oc, "memory-encryption", 900 "Set memory encryption object to use"); 901 902 object_class_property_add_str(oc, "memory-backend", 903 machine_get_memdev, machine_set_memdev); 904 object_class_property_set_description(oc, "memory-backend", 905 "Set RAM backend" 906 "Valid value is ID of hostmem based backend"); 907 } 908 909 static void machine_class_base_init(ObjectClass *oc, void *data) 910 { 911 MachineClass *mc = MACHINE_CLASS(oc); 912 mc->max_cpus = mc->max_cpus ?: 1; 913 mc->min_cpus = mc->min_cpus ?: 1; 914 mc->default_cpus = mc->default_cpus ?: 1; 915 916 if (!object_class_is_abstract(oc)) { 917 const char *cname = object_class_get_name(oc); 918 assert(g_str_has_suffix(cname, TYPE_MACHINE_SUFFIX)); 919 mc->name = g_strndup(cname, 920 strlen(cname) - strlen(TYPE_MACHINE_SUFFIX)); 921 mc->compat_props = g_ptr_array_new(); 922 } 923 } 924 925 static void machine_initfn(Object *obj) 926 { 927 MachineState *ms = MACHINE(obj); 928 MachineClass *mc = MACHINE_GET_CLASS(obj); 929 930 container_get(obj, "/peripheral"); 931 container_get(obj, "/peripheral-anon"); 932 933 ms->dump_guest_core = true; 934 ms->mem_merge = true; 935 ms->enable_graphics = true; 936 ms->kernel_cmdline = g_strdup(""); 937 938 if (mc->nvdimm_supported) { 939 Object *obj = OBJECT(ms); 940 941 ms->nvdimms_state = g_new0(NVDIMMState, 1); 942 object_property_add_bool(obj, "nvdimm", 943 machine_get_nvdimm, machine_set_nvdimm); 944 object_property_set_description(obj, "nvdimm", 945 "Set on/off to enable/disable " 946 "NVDIMM instantiation"); 947 948 object_property_add_str(obj, "nvdimm-persistence", 949 machine_get_nvdimm_persistence, 950 machine_set_nvdimm_persistence); 951 object_property_set_description(obj, "nvdimm-persistence", 952 "Set NVDIMM persistence" 953 "Valid values are cpu, mem-ctrl"); 954 } 955 956 if (mc->cpu_index_to_instance_props && mc->get_default_cpu_node_id) { 957 ms->numa_state = g_new0(NumaState, 1); 958 object_property_add_bool(obj, "hmat", 959 machine_get_hmat, machine_set_hmat); 960 object_property_set_description(obj, "hmat", 961 "Set on/off to enable/disable " 962 "ACPI Heterogeneous Memory Attribute " 963 "Table (HMAT)"); 964 } 965 966 /* Register notifier when init is done for sysbus sanity checks */ 967 ms->sysbus_notifier.notify = machine_init_notify; 968 qemu_add_machine_init_done_notifier(&ms->sysbus_notifier); 969 970 /* default to mc->default_cpus */ 971 ms->smp.cpus = mc->default_cpus; 972 ms->smp.max_cpus = mc->default_cpus; 973 ms->smp.cores = 1; 974 ms->smp.threads = 1; 975 ms->smp.sockets = 1; 976 } 977 978 static void machine_finalize(Object *obj) 979 { 980 MachineState *ms = MACHINE(obj); 981 982 g_free(ms->kernel_filename); 983 g_free(ms->initrd_filename); 984 g_free(ms->kernel_cmdline); 985 g_free(ms->dtb); 986 g_free(ms->dumpdtb); 987 g_free(ms->dt_compatible); 988 g_free(ms->firmware); 989 g_free(ms->device_memory); 990 g_free(ms->nvdimms_state); 991 g_free(ms->numa_state); 992 } 993 994 bool machine_usb(MachineState *machine) 995 { 996 return machine->usb; 997 } 998 999 int machine_phandle_start(MachineState *machine) 1000 { 1001 return machine->phandle_start; 1002 } 1003 1004 bool machine_dump_guest_core(MachineState *machine) 1005 { 1006 return machine->dump_guest_core; 1007 } 1008 1009 bool machine_mem_merge(MachineState *machine) 1010 { 1011 return machine->mem_merge; 1012 } 1013 1014 static char *cpu_slot_to_string(const CPUArchId *cpu) 1015 { 1016 GString *s = g_string_new(NULL); 1017 if (cpu->props.has_socket_id) { 1018 g_string_append_printf(s, "socket-id: %"PRId64, cpu->props.socket_id); 1019 } 1020 if (cpu->props.has_die_id) { 1021 g_string_append_printf(s, "die-id: %"PRId64, cpu->props.die_id); 1022 } 1023 if (cpu->props.has_core_id) { 1024 if (s->len) { 1025 g_string_append_printf(s, ", "); 1026 } 1027 g_string_append_printf(s, "core-id: %"PRId64, cpu->props.core_id); 1028 } 1029 if (cpu->props.has_thread_id) { 1030 if (s->len) { 1031 g_string_append_printf(s, ", "); 1032 } 1033 g_string_append_printf(s, "thread-id: %"PRId64, cpu->props.thread_id); 1034 } 1035 return g_string_free(s, false); 1036 } 1037 1038 static void numa_validate_initiator(NumaState *numa_state) 1039 { 1040 int i; 1041 NodeInfo *numa_info = numa_state->nodes; 1042 1043 for (i = 0; i < numa_state->num_nodes; i++) { 1044 if (numa_info[i].initiator == MAX_NODES) { 1045 error_report("The initiator of NUMA node %d is missing, use " 1046 "'-numa node,initiator' option to declare it", i); 1047 exit(1); 1048 } 1049 1050 if (!numa_info[numa_info[i].initiator].present) { 1051 error_report("NUMA node %" PRIu16 " is missing, use " 1052 "'-numa node' option to declare it first", 1053 numa_info[i].initiator); 1054 exit(1); 1055 } 1056 1057 if (!numa_info[numa_info[i].initiator].has_cpu) { 1058 error_report("The initiator of NUMA node %d is invalid", i); 1059 exit(1); 1060 } 1061 } 1062 } 1063 1064 static void machine_numa_finish_cpu_init(MachineState *machine) 1065 { 1066 int i; 1067 bool default_mapping; 1068 GString *s = g_string_new(NULL); 1069 MachineClass *mc = MACHINE_GET_CLASS(machine); 1070 const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(machine); 1071 1072 assert(machine->numa_state->num_nodes); 1073 for (i = 0; i < possible_cpus->len; i++) { 1074 if (possible_cpus->cpus[i].props.has_node_id) { 1075 break; 1076 } 1077 } 1078 default_mapping = (i == possible_cpus->len); 1079 1080 for (i = 0; i < possible_cpus->len; i++) { 1081 const CPUArchId *cpu_slot = &possible_cpus->cpus[i]; 1082 1083 if (!cpu_slot->props.has_node_id) { 1084 /* fetch default mapping from board and enable it */ 1085 CpuInstanceProperties props = cpu_slot->props; 1086 1087 props.node_id = mc->get_default_cpu_node_id(machine, i); 1088 if (!default_mapping) { 1089 /* record slots with not set mapping, 1090 * TODO: make it hard error in future */ 1091 char *cpu_str = cpu_slot_to_string(cpu_slot); 1092 g_string_append_printf(s, "%sCPU %d [%s]", 1093 s->len ? ", " : "", i, cpu_str); 1094 g_free(cpu_str); 1095 1096 /* non mapped cpus used to fallback to node 0 */ 1097 props.node_id = 0; 1098 } 1099 1100 props.has_node_id = true; 1101 machine_set_cpu_numa_node(machine, &props, &error_fatal); 1102 } 1103 } 1104 1105 if (machine->numa_state->hmat_enabled) { 1106 numa_validate_initiator(machine->numa_state); 1107 } 1108 1109 if (s->len && !qtest_enabled()) { 1110 warn_report("CPU(s) not present in any NUMA nodes: %s", 1111 s->str); 1112 warn_report("All CPU(s) up to maxcpus should be described " 1113 "in NUMA config, ability to start up with partial NUMA " 1114 "mappings is obsoleted and will be removed in future"); 1115 } 1116 g_string_free(s, true); 1117 } 1118 1119 MemoryRegion *machine_consume_memdev(MachineState *machine, 1120 HostMemoryBackend *backend) 1121 { 1122 MemoryRegion *ret = host_memory_backend_get_memory(backend); 1123 1124 if (memory_region_is_mapped(ret)) { 1125 error_report("memory backend %s can't be used multiple times.", 1126 object_get_canonical_path_component(OBJECT(backend))); 1127 exit(EXIT_FAILURE); 1128 } 1129 host_memory_backend_set_mapped(backend, true); 1130 vmstate_register_ram_global(ret); 1131 return ret; 1132 } 1133 1134 bool machine_smp_parse(MachineState *ms, QemuOpts *opts, Error **errp) 1135 { 1136 MachineClass *mc = MACHINE_GET_CLASS(ms); 1137 1138 mc->smp_parse(ms, opts); 1139 1140 /* sanity-check smp_cpus and max_cpus against mc */ 1141 if (ms->smp.cpus < mc->min_cpus) { 1142 error_setg(errp, "Invalid SMP CPUs %d. The min CPUs " 1143 "supported by machine '%s' is %d", 1144 ms->smp.cpus, 1145 mc->name, mc->min_cpus); 1146 return false; 1147 } else if (ms->smp.max_cpus > mc->max_cpus) { 1148 error_setg(errp, "Invalid SMP CPUs %d. The max CPUs " 1149 "supported by machine '%s' is %d", 1150 current_machine->smp.max_cpus, 1151 mc->name, mc->max_cpus); 1152 return false; 1153 } 1154 return true; 1155 } 1156 1157 void machine_run_board_init(MachineState *machine) 1158 { 1159 MachineClass *machine_class = MACHINE_GET_CLASS(machine); 1160 ObjectClass *oc = object_class_by_name(machine->cpu_type); 1161 CPUClass *cc; 1162 1163 /* This checkpoint is required by replay to separate prior clock 1164 reading from the other reads, because timer polling functions query 1165 clock values from the log. */ 1166 replay_checkpoint(CHECKPOINT_INIT); 1167 1168 if (machine->ram_memdev_id) { 1169 Object *o; 1170 o = object_resolve_path_type(machine->ram_memdev_id, 1171 TYPE_MEMORY_BACKEND, NULL); 1172 machine->ram = machine_consume_memdev(machine, MEMORY_BACKEND(o)); 1173 } 1174 1175 if (machine->numa_state) { 1176 numa_complete_configuration(machine); 1177 if (machine->numa_state->num_nodes) { 1178 machine_numa_finish_cpu_init(machine); 1179 } 1180 } 1181 1182 /* If the machine supports the valid_cpu_types check and the user 1183 * specified a CPU with -cpu check here that the user CPU is supported. 1184 */ 1185 if (machine_class->valid_cpu_types && machine->cpu_type) { 1186 int i; 1187 1188 for (i = 0; machine_class->valid_cpu_types[i]; i++) { 1189 if (object_class_dynamic_cast(oc, 1190 machine_class->valid_cpu_types[i])) { 1191 /* The user specificed CPU is in the valid field, we are 1192 * good to go. 1193 */ 1194 break; 1195 } 1196 } 1197 1198 if (!machine_class->valid_cpu_types[i]) { 1199 /* The user specified CPU is not valid */ 1200 error_report("Invalid CPU type: %s", machine->cpu_type); 1201 error_printf("The valid types are: %s", 1202 machine_class->valid_cpu_types[0]); 1203 for (i = 1; machine_class->valid_cpu_types[i]; i++) { 1204 error_printf(", %s", machine_class->valid_cpu_types[i]); 1205 } 1206 error_printf("\n"); 1207 1208 exit(1); 1209 } 1210 } 1211 1212 /* Check if CPU type is deprecated and warn if so */ 1213 cc = CPU_CLASS(oc); 1214 if (cc && cc->deprecation_note) { 1215 warn_report("CPU model %s is deprecated -- %s", machine->cpu_type, 1216 cc->deprecation_note); 1217 } 1218 1219 if (machine->cgs) { 1220 /* 1221 * With confidential guests, the host can't see the real 1222 * contents of RAM, so there's no point in it trying to merge 1223 * areas. 1224 */ 1225 machine_set_mem_merge(OBJECT(machine), false, &error_abort); 1226 1227 /* 1228 * Virtio devices can't count on directly accessing guest 1229 * memory, so they need iommu_platform=on to use normal DMA 1230 * mechanisms. That requires also disabling legacy virtio 1231 * support for those virtio pci devices which allow it. 1232 */ 1233 object_register_sugar_prop(TYPE_VIRTIO_PCI, "disable-legacy", 1234 "on", true); 1235 object_register_sugar_prop(TYPE_VIRTIO_DEVICE, "iommu_platform", 1236 "on", false); 1237 } 1238 1239 accel_init_interfaces(ACCEL_GET_CLASS(machine->accelerator)); 1240 machine_class->init(machine); 1241 phase_advance(PHASE_MACHINE_INITIALIZED); 1242 } 1243 1244 static NotifierList machine_init_done_notifiers = 1245 NOTIFIER_LIST_INITIALIZER(machine_init_done_notifiers); 1246 1247 void qemu_add_machine_init_done_notifier(Notifier *notify) 1248 { 1249 notifier_list_add(&machine_init_done_notifiers, notify); 1250 if (phase_check(PHASE_MACHINE_READY)) { 1251 notify->notify(notify, NULL); 1252 } 1253 } 1254 1255 void qemu_remove_machine_init_done_notifier(Notifier *notify) 1256 { 1257 notifier_remove(notify); 1258 } 1259 1260 void qdev_machine_creation_done(void) 1261 { 1262 cpu_synchronize_all_post_init(); 1263 1264 if (current_machine->boot_once) { 1265 qemu_boot_set(current_machine->boot_once, &error_fatal); 1266 qemu_register_reset(restore_boot_order, g_strdup(current_machine->boot_order)); 1267 } 1268 1269 /* 1270 * ok, initial machine setup is done, starting from now we can 1271 * only create hotpluggable devices 1272 */ 1273 phase_advance(PHASE_MACHINE_READY); 1274 qdev_assert_realized_properly(); 1275 1276 /* TODO: once all bus devices are qdevified, this should be done 1277 * when bus is created by qdev.c */ 1278 /* 1279 * TODO: If we had a main 'reset container' that the whole system 1280 * lived in, we could reset that using the multi-phase reset 1281 * APIs. For the moment, we just reset the sysbus, which will cause 1282 * all devices hanging off it (and all their child buses, recursively) 1283 * to be reset. Note that this will *not* reset any Device objects 1284 * which are not attached to some part of the qbus tree! 1285 */ 1286 qemu_register_reset(resettable_cold_reset_fn, sysbus_get_default()); 1287 1288 notifier_list_notify(&machine_init_done_notifiers, NULL); 1289 1290 if (rom_check_and_register_reset() != 0) { 1291 exit(1); 1292 } 1293 1294 replay_start(); 1295 1296 /* This checkpoint is required by replay to separate prior clock 1297 reading from the other reads, because timer polling functions query 1298 clock values from the log. */ 1299 replay_checkpoint(CHECKPOINT_RESET); 1300 qemu_system_reset(SHUTDOWN_CAUSE_NONE); 1301 register_global_state(); 1302 } 1303 1304 static const TypeInfo machine_info = { 1305 .name = TYPE_MACHINE, 1306 .parent = TYPE_OBJECT, 1307 .abstract = true, 1308 .class_size = sizeof(MachineClass), 1309 .class_init = machine_class_init, 1310 .class_base_init = machine_class_base_init, 1311 .instance_size = sizeof(MachineState), 1312 .instance_init = machine_initfn, 1313 .instance_finalize = machine_finalize, 1314 }; 1315 1316 static void machine_register_types(void) 1317 { 1318 type_register_static(&machine_info); 1319 } 1320 1321 type_init(machine_register_types) 1322