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