| 1 | /* |
| 2 | * virtio ccw machine |
| 3 | * |
| 4 | * Copyright 2012, 2020 IBM Corp. |
| 5 | * Copyright (c) 2009 Alexander Graf <agraf@suse.de> |
| 6 | * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com> |
| 7 | * Janosch Frank <frankja@linux.ibm.com> |
| 8 | * |
| 9 | * This work is licensed under the terms of the GNU GPL, version 2 or (at |
| 10 | * your option) any later version. See the COPYING file in the top-level |
| 11 | * directory. |
| 12 | */ |
| 13 | |
| 14 | #include "qemu/osdep.h" |
| 15 | #include "qapi/error.h" |
| 16 | #include "system/confidential-guest-support.h" |
| 17 | #include "hw/core/boards.h" |
| 18 | #include "hw/s390x/sclp.h" |
| 19 | #include "hw/s390x/s390_flic.h" |
| 20 | #include "virtio-ccw.h" |
| 21 | #include "qemu/config-file.h" |
| 22 | #include "qemu/ctype.h" |
| 23 | #include "qemu/error-report.h" |
| 24 | #include "qemu/option.h" |
| 25 | #include "qemu/qemu-print.h" |
| 26 | #include "qemu/units.h" |
| 27 | #include "hw/s390x/s390-pci-bus.h" |
| 28 | #include "system/reset.h" |
| 29 | #include "hw/s390x/storage-keys.h" |
| 30 | #include "hw/s390x/storage-attributes.h" |
| 31 | #include "hw/s390x/event-facility.h" |
| 32 | #include "ipl.h" |
| 33 | #include "hw/s390x/s390-virtio-ccw.h" |
| 34 | #include "hw/s390x/css-bridge.h" |
| 35 | #include "hw/s390x/ap-bridge.h" |
| 36 | #include "migration/register.h" |
| 37 | #include "target/s390x/cpu_models.h" |
| 38 | #include "hw/core/nmi.h" |
| 39 | #include "hw/core/qdev-properties.h" |
| 40 | #include "hw/s390x/tod.h" |
| 41 | #include "system/system.h" |
| 42 | #include "system/cpus.h" |
| 43 | #include "system/hostmem.h" |
| 44 | #include "target/s390x/kvm/pv.h" |
| 45 | #include "migration/blocker.h" |
| 46 | #include "qapi/visitor.h" |
| 47 | #include "qapi/qapi-visit-machine-s390x.h" |
| 48 | #include "hw/s390x/cpu-topology.h" |
| 49 | #include "kvm/kvm_s390x.h" |
| 50 | #include "hw/virtio/virtio-md-pci.h" |
| 51 | #include "hw/s390x/virtio-ccw-md.h" |
| 52 | #include "system/replay.h" |
| 53 | #include CONFIG_DEVICES |
| 54 | |
| 55 | static Error *pv_mig_blocker; |
| 56 | |
| 57 | static S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id, |
| 58 | Error **errp) |
| 59 | { |
| 60 | S390CPU *cpu = S390_CPU(object_new(typename)); |
| 61 | S390CPU *ret = NULL; |
| 62 | |
| 63 | if (!object_property_set_int(OBJECT(cpu), "core-id", core_id, errp)) { |
| 64 | goto out; |
| 65 | } |
| 66 | if (!qdev_realize(DEVICE(cpu), NULL, errp)) { |
| 67 | goto out; |
| 68 | } |
| 69 | ret = cpu; |
| 70 | |
| 71 | out: |
| 72 | object_unref(OBJECT(cpu)); |
| 73 | return ret; |
| 74 | } |
| 75 | |
| 76 | static void s390_init_cpus(MachineState *machine) |
| 77 | { |
| 78 | MachineClass *mc = MACHINE_GET_CLASS(machine); |
| 79 | S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc); |
| 80 | int i; |
| 81 | |
| 82 | if (machine->smp.threads > s390mc->max_threads) { |
| 83 | error_report("S390 does not support more than %d threads.", |
| 84 | s390mc->max_threads); |
| 85 | exit(1); |
| 86 | } |
| 87 | |
| 88 | /* initialize possible_cpus */ |
| 89 | mc->possible_cpu_arch_ids(machine); |
| 90 | |
| 91 | for (i = 0; i < machine->smp.cpus; i++) { |
| 92 | s390x_new_cpu(machine->cpu_type, i, &error_fatal); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | static const char *const reset_dev_types[] = { |
| 97 | TYPE_VIRTUAL_CSS_BRIDGE, |
| 98 | "s390-sclp-event-facility", |
| 99 | "s390-flic", |
| 100 | "diag288", |
| 101 | TYPE_S390_PCI_HOST_BRIDGE, |
| 102 | TYPE_AP_BRIDGE, |
| 103 | }; |
| 104 | |
| 105 | static void subsystem_reset(void) |
| 106 | { |
| 107 | DeviceState *dev; |
| 108 | int i; |
| 109 | |
| 110 | /* |
| 111 | * ISM firmware is sensitive to unexpected changes to the IOMMU, which can |
| 112 | * occur during reset of the vfio-pci device (unmap of entire aperture). |
| 113 | * Ensure any passthrough ISM devices are reset now, while CPUs are paused |
| 114 | * but before vfio-pci cleanup occurs. |
| 115 | */ |
| 116 | s390_pci_ism_reset(); |
| 117 | |
| 118 | for (i = 0; i < ARRAY_SIZE(reset_dev_types); i++) { |
| 119 | dev = DEVICE(object_resolve_path_type("", reset_dev_types[i], NULL)); |
| 120 | if (dev) { |
| 121 | device_cold_reset(dev); |
| 122 | } |
| 123 | } |
| 124 | if (s390_has_topology()) { |
| 125 | s390_topology_reset(); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | static void s390_set_memory_limit(S390CcwMachineState *s390ms, |
| 130 | uint64_t new_limit) |
| 131 | { |
| 132 | uint64_t hw_limit = 0; |
| 133 | int ret = 0; |
| 134 | |
| 135 | assert(!s390ms->memory_limit && new_limit); |
| 136 | if (kvm_enabled()) { |
| 137 | ret = kvm_s390_set_mem_limit(new_limit, &hw_limit); |
| 138 | } |
| 139 | if (ret == -E2BIG) { |
| 140 | error_report("host supports a maximum of %" PRIu64 " GB", |
| 141 | hw_limit / GiB); |
| 142 | exit(EXIT_FAILURE); |
| 143 | } else if (ret) { |
| 144 | error_report("setting the guest size failed"); |
| 145 | exit(EXIT_FAILURE); |
| 146 | } |
| 147 | s390ms->memory_limit = new_limit; |
| 148 | } |
| 149 | |
| 150 | static void s390_set_max_pagesize(S390CcwMachineState *s390ms, |
| 151 | uint64_t pagesize) |
| 152 | { |
| 153 | assert(!s390ms->max_pagesize && pagesize); |
| 154 | if (kvm_enabled()) { |
| 155 | kvm_s390_set_max_pagesize(pagesize, &error_fatal); |
| 156 | } |
| 157 | s390ms->max_pagesize = pagesize; |
| 158 | } |
| 159 | |
| 160 | static void s390_memory_init(MachineState *machine) |
| 161 | { |
| 162 | S390CcwMachineState *s390ms = S390_CCW_MACHINE(machine); |
| 163 | MemoryRegion *sysmem = get_system_memory(); |
| 164 | MemoryRegion *ram = machine->ram; |
| 165 | uint64_t ram_size = memory_region_size(ram); |
| 166 | uint64_t devmem_base, devmem_size; |
| 167 | |
| 168 | if (!QEMU_IS_ALIGNED(ram_size, 1 * MiB)) { |
| 169 | /* |
| 170 | * SCLP cannot possibly expose smaller granularity right now and KVM |
| 171 | * cannot handle smaller granularity. As we don't support NUMA, the |
| 172 | * region size directly corresponds to machine->ram_size, and the region |
| 173 | * is a single RAM memory region. |
| 174 | */ |
| 175 | error_report("ram size must be multiples of 1 MiB"); |
| 176 | exit(EXIT_FAILURE); |
| 177 | } |
| 178 | |
| 179 | devmem_size = 0; |
| 180 | devmem_base = ram_size; |
| 181 | #ifdef CONFIG_MEM_DEVICE |
| 182 | if (machine->ram_size < machine->maxram_size) { |
| 183 | |
| 184 | /* |
| 185 | * Make sure memory devices have a sane default alignment, even |
| 186 | * when weird initial memory sizes are specified. |
| 187 | */ |
| 188 | devmem_base = QEMU_ALIGN_UP(devmem_base, 1 * GiB); |
| 189 | devmem_size = machine->maxram_size - machine->ram_size; |
| 190 | } |
| 191 | #endif |
| 192 | s390_set_memory_limit(s390ms, devmem_base + devmem_size); |
| 193 | |
| 194 | /* Map the initial memory. Must happen after setting the memory limit. */ |
| 195 | memory_region_add_subregion(sysmem, 0, ram); |
| 196 | |
| 197 | /* Initialize address space for memory devices. */ |
| 198 | #ifdef CONFIG_MEM_DEVICE |
| 199 | if (devmem_size) { |
| 200 | machine_memory_devices_init(machine, devmem_base, devmem_size); |
| 201 | } |
| 202 | #endif /* CONFIG_MEM_DEVICE */ |
| 203 | |
| 204 | /* |
| 205 | * Configure the maximum page size. As no memory devices were created |
| 206 | * yet, this is the page size of initial memory only. |
| 207 | */ |
| 208 | s390_set_max_pagesize(s390ms, qemu_maxrampagesize()); |
| 209 | /* Initialize storage key device */ |
| 210 | s390_skeys_init(); |
| 211 | /* Initialize storage attributes device */ |
| 212 | s390_stattrib_init(); |
| 213 | } |
| 214 | |
| 215 | static void s390_init_ipl_dev(const char *kernel_filename, |
| 216 | const char *kernel_cmdline, |
| 217 | const char *initrd_filename, const char *firmware, |
| 218 | bool enforce_bios) |
| 219 | { |
| 220 | Object *new = object_new(TYPE_S390_IPL); |
| 221 | DeviceState *dev = DEVICE(new); |
| 222 | |
| 223 | if (kernel_filename) { |
| 224 | qdev_prop_set_string(dev, "kernel", kernel_filename); |
| 225 | } |
| 226 | if (initrd_filename) { |
| 227 | qdev_prop_set_string(dev, "initrd", initrd_filename); |
| 228 | } |
| 229 | qdev_prop_set_string(dev, "cmdline", kernel_cmdline); |
| 230 | qdev_prop_set_string(dev, "firmware", firmware); |
| 231 | qdev_prop_set_bit(dev, "enforce_bios", enforce_bios); |
| 232 | object_property_add_child(qdev_get_machine(), TYPE_S390_IPL, |
| 233 | new); |
| 234 | object_unref(new); |
| 235 | qdev_realize(dev, NULL, &error_fatal); |
| 236 | } |
| 237 | |
| 238 | static void s390_create_virtio_net(BusState *bus, const char *name) |
| 239 | { |
| 240 | DeviceState *dev; |
| 241 | int cnt = 0; |
| 242 | |
| 243 | while ((dev = qemu_create_nic_device(name, true, "virtio"))) { |
| 244 | g_autofree char *childname = g_strdup_printf("%s[%d]", name, cnt++); |
| 245 | object_property_add_child(OBJECT(bus), childname, OBJECT(dev)); |
| 246 | qdev_realize_and_unref(dev, bus, &error_fatal); |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | static void s390_create_sclpconsole(SCLPDevice *sclp, |
| 251 | const char *type, Chardev *chardev) |
| 252 | { |
| 253 | SCLPEventFacility *ef = sclp->event_facility; |
| 254 | BusState *ev_fac_bus = sclp_get_event_facility_bus(ef); |
| 255 | DeviceState *dev; |
| 256 | |
| 257 | dev = qdev_new(type); |
| 258 | object_property_add_child(OBJECT(ef), type, OBJECT(dev)); |
| 259 | qdev_prop_set_chr(dev, "chardev", chardev); |
| 260 | qdev_realize_and_unref(dev, ev_fac_bus, &error_fatal); |
| 261 | } |
| 262 | |
| 263 | static void s390_create_sclpcpi(SCLPDevice *sclp) |
| 264 | { |
| 265 | SCLPEventFacility *ef = sclp->event_facility; |
| 266 | BusState *ev_fac_bus = sclp_get_event_facility_bus(ef); |
| 267 | DeviceState *dev; |
| 268 | |
| 269 | dev = qdev_new(TYPE_SCLP_EVENT_CPI); |
| 270 | object_property_add_child(OBJECT(ef), "sclpcpi", OBJECT(dev)); |
| 271 | qdev_realize_and_unref(dev, ev_fac_bus, &error_fatal); |
| 272 | } |
| 273 | |
| 274 | static void ccw_init(MachineState *machine) |
| 275 | { |
| 276 | MachineClass *mc = MACHINE_GET_CLASS(machine); |
| 277 | S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc); |
| 278 | S390CcwMachineState *ms = S390_CCW_MACHINE(machine); |
| 279 | int ret; |
| 280 | VirtualCssBus *css_bus; |
| 281 | DeviceState *dev; |
| 282 | |
| 283 | ms->sclp = SCLP(object_new(TYPE_SCLP)); |
| 284 | object_property_add_child(OBJECT(machine), TYPE_SCLP, OBJECT(ms->sclp)); |
| 285 | qdev_realize_and_unref(DEVICE(ms->sclp), NULL, &error_fatal); |
| 286 | |
| 287 | /* init memory + setup max page size. Required for the CPU model */ |
| 288 | s390_memory_init(machine); |
| 289 | |
| 290 | /* init CPUs (incl. CPU model) early so s390_has_feature() works */ |
| 291 | s390_init_cpus(machine); |
| 292 | |
| 293 | /* Need CPU model to be determined before we can set up PV */ |
| 294 | if (machine->cgs) { |
| 295 | confidential_guest_kvm_init(machine->cgs, &error_fatal); |
| 296 | } |
| 297 | |
| 298 | s390_flic_init(); |
| 299 | |
| 300 | /* init the SIGP facility */ |
| 301 | s390_init_sigp(); |
| 302 | |
| 303 | /* create AP bridge and bus(es) */ |
| 304 | s390_init_ap(); |
| 305 | |
| 306 | /* get a BUS */ |
| 307 | css_bus = virtual_css_bus_init(); |
| 308 | s390_init_ipl_dev(machine->kernel_filename, machine->kernel_cmdline, |
| 309 | machine->initrd_filename, |
| 310 | machine->firmware ?: "s390-ccw.img", |
| 311 | true); |
| 312 | |
| 313 | dev = qdev_new(TYPE_S390_PCI_HOST_BRIDGE); |
| 314 | object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE, |
| 315 | OBJECT(dev)); |
| 316 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); |
| 317 | |
| 318 | s390_enable_css_support(s390_cpu_addr2state(0)); |
| 319 | |
| 320 | ret = css_create_css_image(VIRTUAL_CSSID, true); |
| 321 | assert(ret == 0); |
| 322 | |
| 323 | css_register_vmstate(); |
| 324 | |
| 325 | /* Create VirtIO network adapters */ |
| 326 | s390_create_virtio_net(BUS(css_bus), mc->default_nic); |
| 327 | |
| 328 | /* init consoles */ |
| 329 | if (serial_hd(0)) { |
| 330 | s390_create_sclpconsole(ms->sclp, "sclpconsole", serial_hd(0)); |
| 331 | } |
| 332 | if (serial_hd(1)) { |
| 333 | s390_create_sclpconsole(ms->sclp, "sclplmconsole", serial_hd(1)); |
| 334 | } |
| 335 | |
| 336 | /* init the TOD clock */ |
| 337 | s390_init_tod(); |
| 338 | |
| 339 | /* init SCLP event Control-Program Identification */ |
| 340 | if (s390mc->use_cpi) { |
| 341 | s390_create_sclpcpi(ms->sclp); |
| 342 | } |
| 343 | |
| 344 | } |
| 345 | |
| 346 | static void s390_cpu_plug(HotplugHandler *hotplug_dev, |
| 347 | DeviceState *dev, Error **errp) |
| 348 | { |
| 349 | ERRP_GUARD(); |
| 350 | MachineState *ms = MACHINE(hotplug_dev); |
| 351 | S390CPU *cpu = S390_CPU(dev); |
| 352 | |
| 353 | g_assert(!ms->possible_cpus->cpus[cpu->env.core_id].cpu); |
| 354 | ms->possible_cpus->cpus[cpu->env.core_id].cpu = CPU(dev); |
| 355 | |
| 356 | if (s390_has_topology()) { |
| 357 | s390_topology_setup_cpu(ms, cpu, errp); |
| 358 | if (*errp) { |
| 359 | return; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | if (dev->hotplugged) { |
| 364 | raise_irq_cpu_hotplug(); |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | static void s390_do_cpu_reset(CPUState *cs, run_on_cpu_data arg) |
| 369 | { |
| 370 | resettable_reset(OBJECT(cs), RESET_TYPE_S390_CPU_NORMAL); |
| 371 | } |
| 372 | |
| 373 | static void s390_do_cpu_initial_reset(CPUState *cs, run_on_cpu_data arg) |
| 374 | { |
| 375 | resettable_reset(OBJECT(cs), RESET_TYPE_S390_CPU_INITIAL); |
| 376 | } |
| 377 | |
| 378 | static void s390_do_cpu_load_normal(CPUState *cs, run_on_cpu_data arg) |
| 379 | { |
| 380 | S390CPUClass *scc = S390_CPU_GET_CLASS(cs); |
| 381 | |
| 382 | scc->load_normal(cs); |
| 383 | } |
| 384 | |
| 385 | static void s390_do_cpu_ipl(CPUState *cs, run_on_cpu_data arg) |
| 386 | { |
| 387 | S390CPU *cpu = S390_CPU(cs); |
| 388 | |
| 389 | s390_ipl_prepare_cpu(cpu); |
| 390 | s390_cpu_set_state(S390_CPU_STATE_OPERATING, cpu); |
| 391 | } |
| 392 | |
| 393 | static void s390_machine_unprotect(S390CcwMachineState *ms) |
| 394 | { |
| 395 | if (!s390_pv_vm_try_disable_async(ms)) { |
| 396 | s390_pv_vm_disable(); |
| 397 | } |
| 398 | ms->pv = false; |
| 399 | migrate_del_blocker(&pv_mig_blocker); |
| 400 | ram_block_discard_disable(false); |
| 401 | } |
| 402 | |
| 403 | static int s390_machine_protect(S390CcwMachineState *ms, |
| 404 | struct S390PVResponse *pv_resp) |
| 405 | { |
| 406 | Error *local_err = NULL; |
| 407 | int rc; |
| 408 | |
| 409 | /* |
| 410 | * Discarding of memory in RAM blocks does not work as expected with |
| 411 | * protected VMs. Sharing and unsharing pages would be required. Disable |
| 412 | * it for now, until until we have a solution to make at least Linux |
| 413 | * guests either support it (e.g., virtio-balloon) or fail gracefully. |
| 414 | */ |
| 415 | rc = ram_block_discard_disable(true); |
| 416 | if (rc) { |
| 417 | error_report("protected VMs: cannot disable RAM discard"); |
| 418 | return rc; |
| 419 | } |
| 420 | |
| 421 | error_setg(&pv_mig_blocker, |
| 422 | "protected VMs are currently not migratable."); |
| 423 | rc = migrate_add_blocker(&pv_mig_blocker, &local_err); |
| 424 | if (rc) { |
| 425 | ram_block_discard_disable(false); |
| 426 | error_report_err(local_err); |
| 427 | return rc; |
| 428 | } |
| 429 | |
| 430 | /* Create SE VM */ |
| 431 | rc = s390_pv_vm_enable(); |
| 432 | if (rc) { |
| 433 | ram_block_discard_disable(false); |
| 434 | migrate_del_blocker(&pv_mig_blocker); |
| 435 | return rc; |
| 436 | } |
| 437 | |
| 438 | ms->pv = true; |
| 439 | |
| 440 | /* Will return 0 if API is not available since it's not vital */ |
| 441 | rc = s390_pv_query_info(); |
| 442 | if (rc) { |
| 443 | goto out_err; |
| 444 | } |
| 445 | |
| 446 | /* Set SE header and unpack */ |
| 447 | rc = s390_ipl_prepare_pv_header(pv_resp, &local_err); |
| 448 | if (rc) { |
| 449 | goto out_err; |
| 450 | } |
| 451 | |
| 452 | /* Decrypt image */ |
| 453 | rc = s390_ipl_pv_unpack(pv_resp); |
| 454 | if (rc) { |
| 455 | goto out_err; |
| 456 | } |
| 457 | |
| 458 | /* Verify integrity */ |
| 459 | rc = s390_pv_verify(pv_resp); |
| 460 | if (rc) { |
| 461 | goto out_err; |
| 462 | } |
| 463 | return rc; |
| 464 | |
| 465 | out_err: |
| 466 | if (local_err) { |
| 467 | error_report_err(local_err); |
| 468 | } |
| 469 | s390_machine_unprotect(ms); |
| 470 | return rc; |
| 471 | } |
| 472 | |
| 473 | static void s390_pv_prepare_reset(S390CcwMachineState *ms) |
| 474 | { |
| 475 | CPUState *cs; |
| 476 | |
| 477 | if (!s390_is_pv()) { |
| 478 | return; |
| 479 | } |
| 480 | /* Unsharing requires all cpus to be stopped */ |
| 481 | CPU_FOREACH(cs) { |
| 482 | s390_cpu_set_state(S390_CPU_STATE_STOPPED, S390_CPU(cs)); |
| 483 | } |
| 484 | s390_pv_unshare(); |
| 485 | s390_pv_prep_reset(); |
| 486 | } |
| 487 | |
| 488 | static void s390_machine_reset(MachineState *machine, ResetType type) |
| 489 | { |
| 490 | S390CcwMachineState *ms = S390_CCW_MACHINE(machine); |
| 491 | struct S390PVResponse pv_resp; |
| 492 | enum s390_reset reset_type; |
| 493 | CPUState *cs, *t; |
| 494 | S390CPU *cpu; |
| 495 | |
| 496 | /* |
| 497 | * Temporarily drop the record/replay mutex to let rr_cpu_thread_fn() |
| 498 | * process the run_on_cpu() requests below. This is safe, because at this |
| 499 | * point one of the following is true: |
| 500 | * - All CPU threads are not running, either because the machine is being |
| 501 | * initialized, or because the guest requested a reset using diag 308. |
| 502 | * There is no risk to desync the record/replay state. |
| 503 | * - A snapshot is about to be loaded. The record/replay state consistency |
| 504 | * is not important. |
| 505 | */ |
| 506 | replay_mutex_unlock(); |
| 507 | |
| 508 | /* get the reset parameters, reset them once done */ |
| 509 | s390_ipl_get_reset_request(&cs, &reset_type); |
| 510 | |
| 511 | /* all CPUs are paused and synchronized at this point */ |
| 512 | s390_cmma_reset(); |
| 513 | |
| 514 | cpu = S390_CPU(cs); |
| 515 | |
| 516 | switch (reset_type) { |
| 517 | case S390_RESET_EXTERNAL: |
| 518 | case S390_RESET_REIPL: |
| 519 | /* |
| 520 | * Reset the subsystem which includes a AP reset. If a PV |
| 521 | * guest had APQNs attached the AP reset is a prerequisite to |
| 522 | * unprotecting since the UV checks if all APQNs are reset. |
| 523 | */ |
| 524 | subsystem_reset(); |
| 525 | if (s390_is_pv()) { |
| 526 | s390_machine_unprotect(ms); |
| 527 | } |
| 528 | |
| 529 | /* |
| 530 | * Device reset includes CPU clear resets so this has to be |
| 531 | * done AFTER the unprotect call above. |
| 532 | */ |
| 533 | qemu_devices_reset(type); |
| 534 | s390_crypto_reset(); |
| 535 | |
| 536 | /* configure and start the ipl CPU only */ |
| 537 | run_on_cpu(cs, s390_do_cpu_ipl, RUN_ON_CPU_NULL); |
| 538 | break; |
| 539 | case S390_RESET_MODIFIED_CLEAR: |
| 540 | /* |
| 541 | * Subsystem reset needs to be done before we unshare memory |
| 542 | * and lose access to VIRTIO structures in guest memory. |
| 543 | */ |
| 544 | subsystem_reset(); |
| 545 | s390_crypto_reset(); |
| 546 | s390_pv_prepare_reset(ms); |
| 547 | CPU_FOREACH(t) { |
| 548 | run_on_cpu(t, s390_do_cpu_full_reset, RUN_ON_CPU_NULL); |
| 549 | } |
| 550 | run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL); |
| 551 | break; |
| 552 | case S390_RESET_LOAD_NORMAL: |
| 553 | /* |
| 554 | * Subsystem reset needs to be done before we unshare memory |
| 555 | * and lose access to VIRTIO structures in guest memory. |
| 556 | */ |
| 557 | subsystem_reset(); |
| 558 | s390_pv_prepare_reset(ms); |
| 559 | CPU_FOREACH(t) { |
| 560 | if (t == cs) { |
| 561 | continue; |
| 562 | } |
| 563 | run_on_cpu(t, s390_do_cpu_reset, RUN_ON_CPU_NULL); |
| 564 | } |
| 565 | run_on_cpu(cs, s390_do_cpu_initial_reset, RUN_ON_CPU_NULL); |
| 566 | run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL); |
| 567 | break; |
| 568 | case S390_RESET_PV: /* Subcode 10 */ |
| 569 | subsystem_reset(); |
| 570 | s390_crypto_reset(); |
| 571 | |
| 572 | CPU_FOREACH(t) { |
| 573 | if (t == cs) { |
| 574 | continue; |
| 575 | } |
| 576 | run_on_cpu(t, s390_do_cpu_full_reset, RUN_ON_CPU_NULL); |
| 577 | } |
| 578 | run_on_cpu(cs, s390_do_cpu_reset, RUN_ON_CPU_NULL); |
| 579 | |
| 580 | if (s390_machine_protect(ms, &pv_resp)) { |
| 581 | s390_pv_inject_reset_error(cs, pv_resp); |
| 582 | /* |
| 583 | * Continue after the diag308 so the guest knows something |
| 584 | * went wrong. |
| 585 | */ |
| 586 | s390_cpu_set_state(S390_CPU_STATE_OPERATING, cpu); |
| 587 | goto out_lock; |
| 588 | } |
| 589 | |
| 590 | run_on_cpu(cs, s390_do_cpu_load_normal, RUN_ON_CPU_NULL); |
| 591 | break; |
| 592 | default: |
| 593 | g_assert_not_reached(); |
| 594 | } |
| 595 | |
| 596 | CPU_FOREACH(t) { |
| 597 | run_on_cpu(t, s390_do_cpu_set_diag318, RUN_ON_CPU_HOST_ULONG(0)); |
| 598 | } |
| 599 | s390_ipl_clear_reset_request(); |
| 600 | |
| 601 | out_lock: |
| 602 | /* |
| 603 | * Re-take the record/replay mutex, temporarily dropping the BQL in order |
| 604 | * to satisfy the ordering requirements. |
| 605 | */ |
| 606 | bql_unlock(); |
| 607 | replay_mutex_lock(); |
| 608 | bql_lock(); |
| 609 | } |
| 610 | |
| 611 | static void s390_machine_device_pre_plug(HotplugHandler *hotplug_dev, |
| 612 | DeviceState *dev, Error **errp) |
| 613 | { |
| 614 | if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW)) { |
| 615 | virtio_ccw_md_pre_plug(VIRTIO_MD_CCW(dev), MACHINE(hotplug_dev), errp); |
| 616 | } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_PCI)) { |
| 617 | virtio_md_pci_pre_plug(VIRTIO_MD_PCI(dev), MACHINE(hotplug_dev), errp); |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | static void s390_machine_device_plug(HotplugHandler *hotplug_dev, |
| 622 | DeviceState *dev, Error **errp) |
| 623 | { |
| 624 | S390CcwMachineState *s390ms = S390_CCW_MACHINE(hotplug_dev); |
| 625 | |
| 626 | if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { |
| 627 | s390_cpu_plug(hotplug_dev, dev, errp); |
| 628 | } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW) || |
| 629 | object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_PCI)) { |
| 630 | /* |
| 631 | * At this point, the device is realized and set all memdevs mapped, so |
| 632 | * qemu_maxrampagesize() will pick up the page sizes of these memdevs |
| 633 | * as well. Before we plug the device and expose any RAM memory regions |
| 634 | * to the system, make sure we don't exceed the previously set max page |
| 635 | * size. While only relevant for KVM, there is not really any use case |
| 636 | * for this with TCG, so we'll unconditionally reject it. |
| 637 | */ |
| 638 | if (qemu_maxrampagesize() != s390ms->max_pagesize) { |
| 639 | error_setg(errp, "Memory device uses a bigger page size than" |
| 640 | " initial memory"); |
| 641 | return; |
| 642 | } |
| 643 | if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW)) { |
| 644 | virtio_ccw_md_plug(VIRTIO_MD_CCW(dev), MACHINE(hotplug_dev), errp); |
| 645 | } else { |
| 646 | virtio_md_pci_plug(VIRTIO_MD_PCI(dev), MACHINE(hotplug_dev), errp); |
| 647 | } |
| 648 | } |
| 649 | } |
| 650 | |
| 651 | static void s390_machine_device_unplug_request(HotplugHandler *hotplug_dev, |
| 652 | DeviceState *dev, Error **errp) |
| 653 | { |
| 654 | if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { |
| 655 | error_setg(errp, "CPU hot unplug not supported on this machine"); |
| 656 | } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW)) { |
| 657 | virtio_ccw_md_unplug_request(VIRTIO_MD_CCW(dev), MACHINE(hotplug_dev), |
| 658 | errp); |
| 659 | } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_PCI)) { |
| 660 | virtio_md_pci_unplug_request(VIRTIO_MD_PCI(dev), MACHINE(hotplug_dev), |
| 661 | errp); |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | static void s390_machine_device_unplug(HotplugHandler *hotplug_dev, |
| 666 | DeviceState *dev, Error **errp) |
| 667 | { |
| 668 | if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW)) { |
| 669 | virtio_ccw_md_unplug(VIRTIO_MD_CCW(dev), MACHINE(hotplug_dev), errp); |
| 670 | } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_PCI)) { |
| 671 | virtio_md_pci_unplug(VIRTIO_MD_PCI(dev), MACHINE(hotplug_dev), errp); |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | static CpuInstanceProperties s390_cpu_index_to_props(MachineState *ms, |
| 676 | unsigned cpu_index) |
| 677 | { |
| 678 | MachineClass *mc = MACHINE_GET_CLASS(ms); |
| 679 | const CPUArchIdList *possible_cpus = mc->possible_cpu_arch_ids(ms); |
| 680 | |
| 681 | assert(cpu_index < possible_cpus->len); |
| 682 | return possible_cpus->cpus[cpu_index].props; |
| 683 | } |
| 684 | |
| 685 | static const CPUArchIdList *s390_possible_cpu_arch_ids(MachineState *ms) |
| 686 | { |
| 687 | int i; |
| 688 | unsigned int max_cpus = ms->smp.max_cpus; |
| 689 | |
| 690 | if (ms->possible_cpus) { |
| 691 | g_assert(ms->possible_cpus && ms->possible_cpus->len == max_cpus); |
| 692 | return ms->possible_cpus; |
| 693 | } |
| 694 | |
| 695 | ms->possible_cpus = g_malloc0(sizeof(CPUArchIdList) + |
| 696 | sizeof(CPUArchId) * max_cpus); |
| 697 | ms->possible_cpus->len = max_cpus; |
| 698 | for (i = 0; i < ms->possible_cpus->len; i++) { |
| 699 | CpuInstanceProperties *props = &ms->possible_cpus->cpus[i].props; |
| 700 | |
| 701 | ms->possible_cpus->cpus[i].type = ms->cpu_type; |
| 702 | ms->possible_cpus->cpus[i].vcpus_count = 1; |
| 703 | ms->possible_cpus->cpus[i].arch_id = i; |
| 704 | |
| 705 | props->has_core_id = true; |
| 706 | props->core_id = i; |
| 707 | props->has_socket_id = true; |
| 708 | props->socket_id = s390_std_socket(i, &ms->smp); |
| 709 | props->has_book_id = true; |
| 710 | props->book_id = s390_std_book(i, &ms->smp); |
| 711 | props->has_drawer_id = true; |
| 712 | props->drawer_id = s390_std_drawer(i, &ms->smp); |
| 713 | } |
| 714 | |
| 715 | return ms->possible_cpus; |
| 716 | } |
| 717 | |
| 718 | static HotplugHandler *s390_get_hotplug_handler(MachineState *machine, |
| 719 | DeviceState *dev) |
| 720 | { |
| 721 | if (object_dynamic_cast(OBJECT(dev), TYPE_CPU) || |
| 722 | object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_CCW) || |
| 723 | object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_MD_PCI)) { |
| 724 | return HOTPLUG_HANDLER(machine); |
| 725 | } |
| 726 | return NULL; |
| 727 | } |
| 728 | |
| 729 | static void s390_nmi(NMIState *ns) |
| 730 | { |
| 731 | s390_cpu_restart(S390_CPU(first_cpu)); |
| 732 | } |
| 733 | |
| 734 | static inline bool machine_get_aes_key_wrap(Object *obj, Error **errp) |
| 735 | { |
| 736 | S390CcwMachineState *ms = S390_CCW_MACHINE(obj); |
| 737 | |
| 738 | return ms->aes_key_wrap; |
| 739 | } |
| 740 | |
| 741 | static inline void machine_set_aes_key_wrap(Object *obj, bool value, |
| 742 | Error **errp) |
| 743 | { |
| 744 | S390CcwMachineState *ms = S390_CCW_MACHINE(obj); |
| 745 | |
| 746 | ms->aes_key_wrap = value; |
| 747 | } |
| 748 | |
| 749 | static inline bool machine_get_dea_key_wrap(Object *obj, Error **errp) |
| 750 | { |
| 751 | S390CcwMachineState *ms = S390_CCW_MACHINE(obj); |
| 752 | |
| 753 | return ms->dea_key_wrap; |
| 754 | } |
| 755 | |
| 756 | static inline void machine_set_dea_key_wrap(Object *obj, bool value, |
| 757 | Error **errp) |
| 758 | { |
| 759 | S390CcwMachineState *ms = S390_CCW_MACHINE(obj); |
| 760 | |
| 761 | ms->dea_key_wrap = value; |
| 762 | } |
| 763 | |
| 764 | static void machine_get_loadparm(Object *obj, Visitor *v, |
| 765 | const char *name, void *opaque, |
| 766 | Error **errp) |
| 767 | { |
| 768 | S390CcwMachineState *ms = S390_CCW_MACHINE(obj); |
| 769 | char *str = g_strndup((char *) ms->loadparm, sizeof(ms->loadparm)); |
| 770 | |
| 771 | visit_type_str(v, name, &str, errp); |
| 772 | g_free(str); |
| 773 | } |
| 774 | |
| 775 | static void machine_set_loadparm(Object *obj, Visitor *v, |
| 776 | const char *name, void *opaque, |
| 777 | Error **errp) |
| 778 | { |
| 779 | S390CcwMachineState *ms = S390_CCW_MACHINE(obj); |
| 780 | char *val; |
| 781 | |
| 782 | if (!visit_type_str(v, name, &val, errp)) { |
| 783 | return; |
| 784 | } |
| 785 | |
| 786 | s390_ipl_fmt_loadparm(ms->loadparm, val, errp); |
| 787 | g_free(val); |
| 788 | } |
| 789 | |
| 790 | static void machine_get_boot_certs(Object *obj, Visitor *v, |
| 791 | const char *name, void *opaque, |
| 792 | Error **errp) |
| 793 | { |
| 794 | S390CcwMachineState *ms = S390_CCW_MACHINE(obj); |
| 795 | BootCertificatesList **certs = &ms->boot_certs; |
| 796 | |
| 797 | visit_type_BootCertificatesList(v, name, certs, errp); |
| 798 | } |
| 799 | |
| 800 | static void machine_set_boot_certs(Object *obj, Visitor *v, const char *name, |
| 801 | void *opaque, Error **errp) |
| 802 | { |
| 803 | S390CcwMachineClass *s390mc = S390_CCW_MACHINE_GET_CLASS(obj); |
| 804 | S390CcwMachineState *ms = S390_CCW_MACHINE(obj); |
| 805 | BootCertificatesList *cert_list = NULL; |
| 806 | |
| 807 | if (!s390mc->use_certs) { |
| 808 | error_setg(errp, "boot-certs is not supported by this machine version"); |
| 809 | return; |
| 810 | } |
| 811 | |
| 812 | visit_type_BootCertificatesList(v, name, &cert_list, errp); |
| 813 | if (!cert_list) { |
| 814 | return; |
| 815 | } |
| 816 | |
| 817 | ms->boot_certs = cert_list; |
| 818 | } |
| 819 | |
| 820 | static inline bool machine_get_secure_boot(Object *obj, Error **errp) |
| 821 | { |
| 822 | S390CcwMachineState *ms = S390_CCW_MACHINE(obj); |
| 823 | |
| 824 | return ms->secure_boot; |
| 825 | } |
| 826 | |
| 827 | static inline void machine_set_secure_boot(Object *obj, bool value, |
| 828 | Error **errp) |
| 829 | { |
| 830 | S390CcwMachineClass *s390mc = S390_CCW_MACHINE_GET_CLASS(obj); |
| 831 | S390CcwMachineState *ms = S390_CCW_MACHINE(obj); |
| 832 | |
| 833 | if (!s390mc->use_secure) { |
| 834 | error_setg(errp, "secure-boot is not supported by this machine version"); |
| 835 | return; |
| 836 | } |
| 837 | |
| 838 | ms->secure_boot = value; |
| 839 | } |
| 840 | |
| 841 | /* |
| 842 | * S390x-specific global compatibility properties. |
| 843 | * |
| 844 | * On the s390 kernel, legacy virtio-pci is not usable because I/O BARs |
| 845 | * are not supported (IO_SPACE_LIMIT is 0), and would only result in |
| 846 | * unusable BARs and firmware warnings. |
| 847 | * |
| 848 | * Therefore, starting from v11.1, disable legacy virtio-pci by default, |
| 849 | * while older machine types keep legacy behavior for compatibility. |
| 850 | */ |
| 851 | static GlobalProperty hw_compat_s390x[] = { |
| 852 | { TYPE_VIRTIO_PCI, "disable-legacy", "on", .optional = true}, |
| 853 | }; |
| 854 | static const size_t hw_compat_s390x_len = G_N_ELEMENTS(hw_compat_s390x); |
| 855 | |
| 856 | static void ccw_machine_class_init(ObjectClass *oc, const void *data) |
| 857 | { |
| 858 | MachineClass *mc = MACHINE_CLASS(oc); |
| 859 | NMIClass *nc = NMI_CLASS(oc); |
| 860 | HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc); |
| 861 | S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc); |
| 862 | DumpSKeysInterface *dsi = DUMP_SKEYS_INTERFACE_CLASS(oc); |
| 863 | |
| 864 | s390mc->max_threads = 1; |
| 865 | s390mc->use_cpi = true; |
| 866 | s390mc->use_certs = true; |
| 867 | s390mc->use_secure = true; |
| 868 | mc->reset = s390_machine_reset; |
| 869 | mc->block_default_type = IF_VIRTIO; |
| 870 | mc->no_cdrom = 1; |
| 871 | mc->no_floppy = 1; |
| 872 | mc->no_parallel = 1; |
| 873 | mc->max_cpus = S390_MAX_CPUS; |
| 874 | mc->has_hotpluggable_cpus = true; |
| 875 | mc->smp_props.books_supported = true; |
| 876 | mc->smp_props.drawers_supported = true; |
| 877 | assert(!mc->get_hotplug_handler); |
| 878 | mc->get_hotplug_handler = s390_get_hotplug_handler; |
| 879 | mc->cpu_index_to_instance_props = s390_cpu_index_to_props; |
| 880 | mc->possible_cpu_arch_ids = s390_possible_cpu_arch_ids; |
| 881 | /* it is overridden with 'host' cpu *in kvm_arch_init* */ |
| 882 | mc->default_cpu_type = S390_CPU_TYPE_NAME("qemu"); |
| 883 | hc->pre_plug = s390_machine_device_pre_plug; |
| 884 | hc->plug = s390_machine_device_plug; |
| 885 | hc->unplug_request = s390_machine_device_unplug_request; |
| 886 | hc->unplug = s390_machine_device_unplug; |
| 887 | nc->raise_nmi = s390_nmi; |
| 888 | mc->default_ram_id = "s390.ram"; |
| 889 | mc->default_nic = "virtio-net-ccw"; |
| 890 | dsi->qmp_dump_skeys = s390_qmp_dump_skeys; |
| 891 | |
| 892 | object_class_property_add_bool(oc, "aes-key-wrap", |
| 893 | machine_get_aes_key_wrap, |
| 894 | machine_set_aes_key_wrap); |
| 895 | object_class_property_set_description(oc, "aes-key-wrap", |
| 896 | "enable/disable AES key wrapping using the CPACF wrapping key"); |
| 897 | |
| 898 | object_class_property_add_bool(oc, "dea-key-wrap", |
| 899 | machine_get_dea_key_wrap, |
| 900 | machine_set_dea_key_wrap); |
| 901 | object_class_property_set_description(oc, "dea-key-wrap", |
| 902 | "enable/disable DEA key wrapping using the CPACF wrapping key"); |
| 903 | |
| 904 | object_class_property_add(oc, "loadparm", "loadparm", |
| 905 | machine_get_loadparm, machine_set_loadparm, |
| 906 | NULL, NULL); |
| 907 | object_class_property_set_description(oc, "loadparm", |
| 908 | "Up to 8 chars in set of [A-Za-z0-9. ] (lower case chars converted" |
| 909 | " to upper case) to pass to machine loader, boot manager," |
| 910 | " and guest kernel"); |
| 911 | |
| 912 | object_class_property_add(oc, "boot-certs", "BootCertificatesList", |
| 913 | machine_get_boot_certs, machine_set_boot_certs, NULL, NULL); |
| 914 | object_class_property_set_description(oc, "boot-certs", |
| 915 | "provide paths to a directory and/or a certificate file for secure boot"); |
| 916 | |
| 917 | object_class_property_add_bool(oc, "secure-boot", |
| 918 | machine_get_secure_boot, |
| 919 | machine_set_secure_boot); |
| 920 | object_class_property_set_description(oc, "secure-boot", |
| 921 | "enable/disable secure boot"); |
| 922 | } |
| 923 | |
| 924 | static inline void s390_machine_initfn(Object *obj) |
| 925 | { |
| 926 | S390CcwMachineState *ms = S390_CCW_MACHINE(obj); |
| 927 | |
| 928 | ms->aes_key_wrap = true; |
| 929 | ms->dea_key_wrap = true; |
| 930 | } |
| 931 | |
| 932 | static const TypeInfo ccw_machine_info = { |
| 933 | .name = TYPE_S390_CCW_MACHINE, |
| 934 | .parent = TYPE_MACHINE, |
| 935 | .abstract = true, |
| 936 | .instance_size = sizeof(S390CcwMachineState), |
| 937 | .instance_init = s390_machine_initfn, |
| 938 | .class_size = sizeof(S390CcwMachineClass), |
| 939 | .class_init = ccw_machine_class_init, |
| 940 | .interfaces = (const InterfaceInfo[]) { |
| 941 | { TYPE_NMI }, |
| 942 | { TYPE_HOTPLUG_HANDLER}, |
| 943 | { TYPE_DUMP_SKEYS_INTERFACE}, |
| 944 | { } |
| 945 | }, |
| 946 | }; |
| 947 | |
| 948 | #define DEFINE_CCW_MACHINE_IMPL(latest, ...) \ |
| 949 | static void MACHINE_VER_SYM(mach_init, ccw, __VA_ARGS__)(MachineState *mach) \ |
| 950 | { \ |
| 951 | MACHINE_VER_SYM(instance_options, ccw, __VA_ARGS__)(mach); \ |
| 952 | ccw_init(mach); \ |
| 953 | } \ |
| 954 | static void MACHINE_VER_SYM(class_init, ccw, __VA_ARGS__)( \ |
| 955 | ObjectClass *oc, \ |
| 956 | const void *data) \ |
| 957 | { \ |
| 958 | MachineClass *mc = MACHINE_CLASS(oc); \ |
| 959 | /* Apply global s390x-wide default properties */ \ |
| 960 | compat_props_add(mc->compat_props, hw_compat_s390x, \ |
| 961 | hw_compat_s390x_len); \ |
| 962 | MACHINE_VER_SYM(class_options, ccw, __VA_ARGS__)(mc); \ |
| 963 | mc->desc = "Virtual s390x machine (version " MACHINE_VER_STR(__VA_ARGS__) ")"; \ |
| 964 | mc->init = MACHINE_VER_SYM(mach_init, ccw, __VA_ARGS__); \ |
| 965 | MACHINE_VER_DEPRECATION(__VA_ARGS__); \ |
| 966 | if (latest) { \ |
| 967 | mc->alias = "s390-ccw-virtio"; \ |
| 968 | mc->is_default = true; \ |
| 969 | } \ |
| 970 | } \ |
| 971 | static const TypeInfo MACHINE_VER_SYM(info, ccw, __VA_ARGS__) = \ |
| 972 | { \ |
| 973 | .name = MACHINE_VER_TYPE_NAME("s390-ccw-virtio", __VA_ARGS__), \ |
| 974 | .parent = TYPE_S390_CCW_MACHINE, \ |
| 975 | .class_init = MACHINE_VER_SYM(class_init, ccw, __VA_ARGS__), \ |
| 976 | }; \ |
| 977 | static void MACHINE_VER_SYM(register, ccw, __VA_ARGS__)(void) \ |
| 978 | { \ |
| 979 | MACHINE_VER_DELETION(__VA_ARGS__); \ |
| 980 | type_register_static(&MACHINE_VER_SYM(info, ccw, __VA_ARGS__)); \ |
| 981 | } \ |
| 982 | type_init(MACHINE_VER_SYM(register, ccw, __VA_ARGS__)) |
| 983 | |
| 984 | #define DEFINE_CCW_MACHINE_AS_LATEST(major, minor) \ |
| 985 | DEFINE_CCW_MACHINE_IMPL(true, major, minor) |
| 986 | |
| 987 | #define DEFINE_CCW_MACHINE(major, minor) \ |
| 988 | DEFINE_CCW_MACHINE_IMPL(false, major, minor) |
| 989 | |
| 990 | |
| 991 | static void ccw_machine_11_2_instance_options(MachineState *machine) |
| 992 | { |
| 993 | } |
| 994 | |
| 995 | static void ccw_machine_11_2_class_options(MachineClass *mc) |
| 996 | { |
| 997 | } |
| 998 | DEFINE_CCW_MACHINE_AS_LATEST(11, 2); |
| 999 | |
| 1000 | static void ccw_machine_11_1_instance_options(MachineState *machine) |
| 1001 | { |
| 1002 | ccw_machine_11_2_instance_options(machine); |
| 1003 | } |
| 1004 | |
| 1005 | static void ccw_machine_11_1_class_options(MachineClass *mc) |
| 1006 | { |
| 1007 | S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc); |
| 1008 | |
| 1009 | s390mc->use_certs = false; |
| 1010 | s390mc->use_secure = false; |
| 1011 | |
| 1012 | ccw_machine_11_2_class_options(mc); |
| 1013 | compat_props_add(mc->compat_props, hw_compat_11_1, hw_compat_11_1_len); |
| 1014 | } |
| 1015 | DEFINE_CCW_MACHINE(11, 1); |
| 1016 | |
| 1017 | static void ccw_machine_11_0_instance_options(MachineState *machine) |
| 1018 | { |
| 1019 | ccw_machine_11_1_instance_options(machine); |
| 1020 | } |
| 1021 | |
| 1022 | static void ccw_machine_11_0_class_options(MachineClass *mc) |
| 1023 | { |
| 1024 | /* |
| 1025 | * Preserve v11.0 and older version behavior: |
| 1026 | * keep legacy virtio-pci enabled. |
| 1027 | */ |
| 1028 | static GlobalProperty compat[] = { |
| 1029 | { TYPE_VIRTIO_PCI, "disable-legacy", "off", .optional = true }, |
| 1030 | }; |
| 1031 | ccw_machine_11_1_class_options(mc); |
| 1032 | compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat)); |
| 1033 | compat_props_add(mc->compat_props, hw_compat_11_0, hw_compat_11_0_len); |
| 1034 | } |
| 1035 | DEFINE_CCW_MACHINE(11, 0); |
| 1036 | |
| 1037 | static void ccw_machine_10_2_instance_options(MachineState *machine) |
| 1038 | { |
| 1039 | ccw_machine_11_0_instance_options(machine); |
| 1040 | } |
| 1041 | |
| 1042 | static void ccw_machine_10_2_class_options(MachineClass *mc) |
| 1043 | { |
| 1044 | ccw_machine_11_0_class_options(mc); |
| 1045 | compat_props_add(mc->compat_props, hw_compat_10_2, hw_compat_10_2_len); |
| 1046 | } |
| 1047 | DEFINE_CCW_MACHINE(10, 2); |
| 1048 | |
| 1049 | static void ccw_machine_10_1_instance_options(MachineState *machine) |
| 1050 | { |
| 1051 | ccw_machine_10_2_instance_options(machine); |
| 1052 | } |
| 1053 | |
| 1054 | static void ccw_machine_10_1_class_options(MachineClass *mc) |
| 1055 | { |
| 1056 | ccw_machine_10_2_class_options(mc); |
| 1057 | compat_props_add(mc->compat_props, hw_compat_10_1, hw_compat_10_1_len); |
| 1058 | } |
| 1059 | DEFINE_CCW_MACHINE(10, 1); |
| 1060 | |
| 1061 | static void ccw_machine_10_0_instance_options(MachineState *machine) |
| 1062 | { |
| 1063 | ccw_machine_10_1_instance_options(machine); |
| 1064 | } |
| 1065 | |
| 1066 | static void ccw_machine_10_0_class_options(MachineClass *mc) |
| 1067 | { |
| 1068 | S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc); |
| 1069 | s390mc->use_cpi = false; |
| 1070 | |
| 1071 | ccw_machine_10_1_class_options(mc); |
| 1072 | compat_props_add(mc->compat_props, hw_compat_10_0, hw_compat_10_0_len); |
| 1073 | } |
| 1074 | DEFINE_CCW_MACHINE(10, 0); |
| 1075 | |
| 1076 | static void ccw_machine_9_2_instance_options(MachineState *machine) |
| 1077 | { |
| 1078 | ccw_machine_10_0_instance_options(machine); |
| 1079 | } |
| 1080 | |
| 1081 | static void ccw_machine_9_2_class_options(MachineClass *mc) |
| 1082 | { |
| 1083 | static GlobalProperty compat[] = { |
| 1084 | { TYPE_S390_PCI_DEVICE, "relaxed-translation", "off", }, |
| 1085 | }; |
| 1086 | |
| 1087 | ccw_machine_10_0_class_options(mc); |
| 1088 | compat_props_add(mc->compat_props, hw_compat_9_2, hw_compat_9_2_len); |
| 1089 | compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat)); |
| 1090 | } |
| 1091 | DEFINE_CCW_MACHINE(9, 2); |
| 1092 | |
| 1093 | static void ccw_machine_9_1_instance_options(MachineState *machine) |
| 1094 | { |
| 1095 | ccw_machine_9_2_instance_options(machine); |
| 1096 | } |
| 1097 | |
| 1098 | static void ccw_machine_9_1_class_options(MachineClass *mc) |
| 1099 | { |
| 1100 | ccw_machine_9_2_class_options(mc); |
| 1101 | compat_props_add(mc->compat_props, hw_compat_9_1, hw_compat_9_1_len); |
| 1102 | } |
| 1103 | DEFINE_CCW_MACHINE(9, 1); |
| 1104 | |
| 1105 | static void ccw_machine_9_0_instance_options(MachineState *machine) |
| 1106 | { |
| 1107 | ccw_machine_9_1_instance_options(machine); |
| 1108 | } |
| 1109 | |
| 1110 | static void ccw_machine_9_0_class_options(MachineClass *mc) |
| 1111 | { |
| 1112 | static GlobalProperty compat[] = { |
| 1113 | { TYPE_QEMU_S390_FLIC, "migrate-all-state", "off", }, |
| 1114 | }; |
| 1115 | |
| 1116 | ccw_machine_9_1_class_options(mc); |
| 1117 | compat_props_add(mc->compat_props, hw_compat_9_0, hw_compat_9_0_len); |
| 1118 | compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat)); |
| 1119 | } |
| 1120 | DEFINE_CCW_MACHINE(9, 0); |
| 1121 | |
| 1122 | static void ccw_machine_8_2_instance_options(MachineState *machine) |
| 1123 | { |
| 1124 | ccw_machine_9_0_instance_options(machine); |
| 1125 | } |
| 1126 | |
| 1127 | static void ccw_machine_8_2_class_options(MachineClass *mc) |
| 1128 | { |
| 1129 | ccw_machine_9_0_class_options(mc); |
| 1130 | compat_props_add(mc->compat_props, hw_compat_8_2, hw_compat_8_2_len); |
| 1131 | } |
| 1132 | DEFINE_CCW_MACHINE(8, 2); |
| 1133 | |
| 1134 | static void ccw_machine_8_1_instance_options(MachineState *machine) |
| 1135 | { |
| 1136 | ccw_machine_8_2_instance_options(machine); |
| 1137 | } |
| 1138 | |
| 1139 | static void ccw_machine_8_1_class_options(MachineClass *mc) |
| 1140 | { |
| 1141 | ccw_machine_8_2_class_options(mc); |
| 1142 | compat_props_add(mc->compat_props, hw_compat_8_1, hw_compat_8_1_len); |
| 1143 | mc->smp_props.drawers_supported = false; |
| 1144 | mc->smp_props.books_supported = false; |
| 1145 | } |
| 1146 | DEFINE_CCW_MACHINE(8, 1); |
| 1147 | |
| 1148 | static void ccw_machine_8_0_instance_options(MachineState *machine) |
| 1149 | { |
| 1150 | ccw_machine_8_1_instance_options(machine); |
| 1151 | } |
| 1152 | |
| 1153 | static void ccw_machine_8_0_class_options(MachineClass *mc) |
| 1154 | { |
| 1155 | ccw_machine_8_1_class_options(mc); |
| 1156 | compat_props_add(mc->compat_props, hw_compat_8_0, hw_compat_8_0_len); |
| 1157 | } |
| 1158 | DEFINE_CCW_MACHINE(8, 0); |
| 1159 | |
| 1160 | static void ccw_machine_7_2_instance_options(MachineState *machine) |
| 1161 | { |
| 1162 | ccw_machine_8_0_instance_options(machine); |
| 1163 | } |
| 1164 | |
| 1165 | static void ccw_machine_7_2_class_options(MachineClass *mc) |
| 1166 | { |
| 1167 | ccw_machine_8_0_class_options(mc); |
| 1168 | compat_props_add(mc->compat_props, hw_compat_7_2, hw_compat_7_2_len); |
| 1169 | } |
| 1170 | DEFINE_CCW_MACHINE(7, 2); |
| 1171 | |
| 1172 | static void ccw_machine_7_1_instance_options(MachineState *machine) |
| 1173 | { |
| 1174 | static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V7_1 }; |
| 1175 | |
| 1176 | ccw_machine_7_2_instance_options(machine); |
| 1177 | s390_cpudef_featoff_greater(16, 1, S390_FEAT_PAIE); |
| 1178 | s390_set_qemu_cpu_model(0x8561, 15, 1, qemu_cpu_feat); |
| 1179 | } |
| 1180 | |
| 1181 | static void ccw_machine_7_1_class_options(MachineClass *mc) |
| 1182 | { |
| 1183 | S390CcwMachineClass *s390mc = S390_CCW_MACHINE_CLASS(mc); |
| 1184 | static GlobalProperty compat[] = { |
| 1185 | { TYPE_S390_PCI_DEVICE, "interpret", "off", }, |
| 1186 | { TYPE_S390_PCI_DEVICE, "forwarding-assist", "off", }, |
| 1187 | }; |
| 1188 | |
| 1189 | ccw_machine_7_2_class_options(mc); |
| 1190 | compat_props_add(mc->compat_props, hw_compat_7_1, hw_compat_7_1_len); |
| 1191 | compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat)); |
| 1192 | s390mc->max_threads = S390_MAX_CPUS; |
| 1193 | } |
| 1194 | DEFINE_CCW_MACHINE(7, 1); |
| 1195 | |
| 1196 | static void ccw_machine_7_0_instance_options(MachineState *machine) |
| 1197 | { |
| 1198 | static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V7_0 }; |
| 1199 | |
| 1200 | ccw_machine_7_1_instance_options(machine); |
| 1201 | s390_set_qemu_cpu_model(0x8561, 15, 1, qemu_cpu_feat); |
| 1202 | } |
| 1203 | |
| 1204 | static void ccw_machine_7_0_class_options(MachineClass *mc) |
| 1205 | { |
| 1206 | ccw_machine_7_1_class_options(mc); |
| 1207 | compat_props_add(mc->compat_props, hw_compat_7_0, hw_compat_7_0_len); |
| 1208 | } |
| 1209 | DEFINE_CCW_MACHINE(7, 0); |
| 1210 | |
| 1211 | static void ccw_machine_6_2_instance_options(MachineState *machine) |
| 1212 | { |
| 1213 | static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V6_2 }; |
| 1214 | |
| 1215 | ccw_machine_7_0_instance_options(machine); |
| 1216 | s390_set_qemu_cpu_model(0x3906, 14, 2, qemu_cpu_feat); |
| 1217 | } |
| 1218 | |
| 1219 | static void ccw_machine_6_2_class_options(MachineClass *mc) |
| 1220 | { |
| 1221 | ccw_machine_7_0_class_options(mc); |
| 1222 | compat_props_add(mc->compat_props, hw_compat_6_2, hw_compat_6_2_len); |
| 1223 | } |
| 1224 | DEFINE_CCW_MACHINE(6, 2); |
| 1225 | |
| 1226 | static void ccw_machine_6_1_instance_options(MachineState *machine) |
| 1227 | { |
| 1228 | ccw_machine_6_2_instance_options(machine); |
| 1229 | s390_cpudef_featoff_greater(16, 1, S390_FEAT_NNPA); |
| 1230 | s390_cpudef_featoff_greater(16, 1, S390_FEAT_VECTOR_PACKED_DECIMAL_ENH2); |
| 1231 | s390_cpudef_featoff_greater(16, 1, S390_FEAT_BEAR_ENH); |
| 1232 | s390_cpudef_featoff_greater(16, 1, S390_FEAT_RDP); |
| 1233 | s390_cpudef_featoff_greater(16, 1, S390_FEAT_PAI); |
| 1234 | } |
| 1235 | |
| 1236 | static void ccw_machine_6_1_class_options(MachineClass *mc) |
| 1237 | { |
| 1238 | ccw_machine_6_2_class_options(mc); |
| 1239 | compat_props_add(mc->compat_props, hw_compat_6_1, hw_compat_6_1_len); |
| 1240 | mc->smp_props.prefer_sockets = true; |
| 1241 | } |
| 1242 | DEFINE_CCW_MACHINE(6, 1); |
| 1243 | |
| 1244 | static void ccw_machine_6_0_instance_options(MachineState *machine) |
| 1245 | { |
| 1246 | static const S390FeatInit qemu_cpu_feat = { S390_FEAT_LIST_QEMU_V6_0 }; |
| 1247 | |
| 1248 | ccw_machine_6_1_instance_options(machine); |
| 1249 | s390_set_qemu_cpu_model(0x2964, 13, 2, qemu_cpu_feat); |
| 1250 | } |
| 1251 | |
| 1252 | static void ccw_machine_6_0_class_options(MachineClass *mc) |
| 1253 | { |
| 1254 | ccw_machine_6_1_class_options(mc); |
| 1255 | compat_props_add(mc->compat_props, hw_compat_6_0, hw_compat_6_0_len); |
| 1256 | } |
| 1257 | DEFINE_CCW_MACHINE(6, 0); |
| 1258 | |
| 1259 | static void ccw_machine_5_2_instance_options(MachineState *machine) |
| 1260 | { |
| 1261 | ccw_machine_6_0_instance_options(machine); |
| 1262 | } |
| 1263 | |
| 1264 | static void ccw_machine_5_2_class_options(MachineClass *mc) |
| 1265 | { |
| 1266 | ccw_machine_6_0_class_options(mc); |
| 1267 | compat_props_add(mc->compat_props, hw_compat_5_2, hw_compat_5_2_len); |
| 1268 | } |
| 1269 | DEFINE_CCW_MACHINE(5, 2); |
| 1270 | |
| 1271 | static void ccw_machine_5_1_instance_options(MachineState *machine) |
| 1272 | { |
| 1273 | ccw_machine_5_2_instance_options(machine); |
| 1274 | } |
| 1275 | |
| 1276 | static void ccw_machine_5_1_class_options(MachineClass *mc) |
| 1277 | { |
| 1278 | ccw_machine_5_2_class_options(mc); |
| 1279 | compat_props_add(mc->compat_props, hw_compat_5_1, hw_compat_5_1_len); |
| 1280 | } |
| 1281 | DEFINE_CCW_MACHINE(5, 1); |
| 1282 | |
| 1283 | static void ccw_machine_register_types(void) |
| 1284 | { |
| 1285 | type_register_static(&ccw_machine_info); |
| 1286 | } |
| 1287 | |
| 1288 | type_init(ccw_machine_register_types) |