qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20141010' into staging

various s390x updates:
- cpu state handling in qemu and migration
- vhost-scsi-ccw bugfix

# gpg: Signature made Fri 10 Oct 2014 14:01:34 BST using RSA key ID C6F02FAF
# gpg: Can't check signature: public key not found

* remotes/cohuck/tags/s390x-20141010:
s390x/virtio-ccw: fix vhost-scsi intialization
s390x/migration: migrate CPU state
s390x/kvm: synchronize the cpu state after SIGP (INITIAL) CPU RESET
s390x/kvm: reuse kvm_s390_reset_vcpu() to get rid of ifdefs
s390x/kvm: propagate s390 cpu state to kvm
s390x/kvm: proper use of the cpu states OPERATING and STOPPED
s390x/kvm: introduce proper states for s390 cpus
linux-headers: update to 3.17-rc7

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

+323 -96
+1 -1
hw/s390x/ipl.c
··· 176 176 } 177 177 } 178 178 179 - s390_add_running_cpu(cpu); 179 + s390_cpu_set_state(CPU_STATE_OPERATING, cpu); 180 180 } 181 181 182 182 static void s390_ipl_class_init(ObjectClass *klass, void *data)
-32
hw/s390x/s390-virtio.c
··· 125 125 s390_virtio_hcall_set_status); 126 126 } 127 127 128 - /* 129 - * The number of running CPUs. On s390 a shutdown is the state of all CPUs 130 - * being either stopped or disabled (for interrupts) waiting. We have to 131 - * track this number to call the shutdown sequence accordingly. This 132 - * number is modified either on startup or while holding the big qemu lock. 133 - */ 134 - static unsigned s390_running_cpus; 135 - 136 - void s390_add_running_cpu(S390CPU *cpu) 137 - { 138 - CPUState *cs = CPU(cpu); 139 - 140 - if (cs->halted) { 141 - s390_running_cpus++; 142 - cs->halted = 0; 143 - cs->exception_index = -1; 144 - } 145 - } 146 - 147 - unsigned s390_del_running_cpu(S390CPU *cpu) 148 - { 149 - CPUState *cs = CPU(cpu); 150 - 151 - if (cs->halted == 0) { 152 - assert(s390_running_cpus >= 1); 153 - s390_running_cpus--; 154 - cs->halted = 1; 155 - cs->exception_index = EXCP_HLT; 156 - } 157 - return s390_running_cpus; 158 - } 159 - 160 128 void s390_init_ipl_dev(const char *kernel_filename, 161 129 const char *kernel_cmdline, 162 130 const char *initrd_filename,
+1 -1
hw/s390x/virtio-ccw.c
··· 1528 1528 static const TypeInfo vhost_ccw_scsi = { 1529 1529 .name = TYPE_VHOST_SCSI_CCW, 1530 1530 .parent = TYPE_VIRTIO_CCW_DEVICE, 1531 - .instance_size = sizeof(VirtIOSCSICcw), 1531 + .instance_size = sizeof(VHostSCSICcw), 1532 1532 .instance_init = vhost_ccw_scsi_instance_init, 1533 1533 .class_init = vhost_ccw_scsi_class_init, 1534 1534 };
+5 -1
linux-headers/asm-mips/kvm_para.h
··· 1 - #include <asm-generic/kvm_para.h> 1 + #ifndef _ASM_MIPS_KVM_PARA_H 2 + #define _ASM_MIPS_KVM_PARA_H 3 + 4 + 5 + #endif /* _ASM_MIPS_KVM_PARA_H */
+2
linux-headers/asm-powerpc/kvm.h
··· 548 548 549 549 #define KVM_REG_PPC_VRSAVE (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb4) 550 550 #define KVM_REG_PPC_LPCR (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb5) 551 + #define KVM_REG_PPC_LPCR_64 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb5) 551 552 #define KVM_REG_PPC_PPR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb6) 552 553 553 554 /* Architecture compatibility level */ ··· 555 556 556 557 #define KVM_REG_PPC_DABRX (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xb8) 557 558 #define KVM_REG_PPC_WORT (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xb9) 559 + #define KVM_REG_PPC_SPRG9 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xba) 558 560 559 561 /* Transactional Memory checkpointed state: 560 562 * This is all GPRs, all VSX regs and a subset of SPRs
+3
linux-headers/asm-x86/kvm.h
··· 23 23 #define GP_VECTOR 13 24 24 #define PF_VECTOR 14 25 25 #define MF_VECTOR 16 26 + #define AC_VECTOR 17 26 27 #define MC_VECTOR 18 28 + #define XM_VECTOR 19 29 + #define VE_VECTOR 20 27 30 28 31 /* Select x86 specific features in <linux/kvm.h> */ 29 32 #define __KVM_HAVE_PIT
+10 -3
linux-headers/linux/kvm.h
··· 162 162 #define KVM_EXIT_TPR_ACCESS 12 163 163 #define KVM_EXIT_S390_SIEIC 13 164 164 #define KVM_EXIT_S390_RESET 14 165 - #define KVM_EXIT_DCR 15 165 + #define KVM_EXIT_DCR 15 /* deprecated */ 166 166 #define KVM_EXIT_NMI 16 167 167 #define KVM_EXIT_INTERNAL_ERROR 17 168 168 #define KVM_EXIT_OSI 18 ··· 268 268 __u64 trans_exc_code; 269 269 __u32 pgm_code; 270 270 } s390_ucontrol; 271 - /* KVM_EXIT_DCR */ 271 + /* KVM_EXIT_DCR (deprecated) */ 272 272 struct { 273 273 __u32 dcrn; 274 274 __u32 data; ··· 399 399 __u64 vapic_addr; 400 400 }; 401 401 402 - /* for KVM_SET_MPSTATE */ 402 + /* for KVM_SET_MP_STATE */ 403 403 404 + /* not all states are valid on all architectures */ 404 405 #define KVM_MP_STATE_RUNNABLE 0 405 406 #define KVM_MP_STATE_UNINITIALIZED 1 406 407 #define KVM_MP_STATE_INIT_RECEIVED 2 407 408 #define KVM_MP_STATE_HALTED 3 408 409 #define KVM_MP_STATE_SIPI_RECEIVED 4 410 + #define KVM_MP_STATE_STOPPED 5 411 + #define KVM_MP_STATE_CHECK_STOP 6 412 + #define KVM_MP_STATE_OPERATING 7 413 + #define KVM_MP_STATE_LOAD 8 409 414 410 415 struct kvm_mp_state { 411 416 __u32 mp_state; ··· 758 763 #define KVM_CAP_VM_ATTRIBUTES 101 759 764 #define KVM_CAP_ARM_PSCI_0_2 102 760 765 #define KVM_CAP_PPC_FIXUP_HCALL 103 766 + #define KVM_CAP_PPC_ENABLE_HCALL 104 767 + #define KVM_CAP_CHECK_EXTENSION_VM 105 761 768 762 769 #ifdef KVM_CAP_IRQ_ROUTING 763 770
+3
linux-headers/linux/kvm_para.h
··· 20 20 #define KVM_HC_FEATURES 3 21 21 #define KVM_HC_PPC_MAP_MAGIC_PAGE 4 22 22 #define KVM_HC_KICK_CPU 5 23 + #define KVM_HC_MIPS_GET_CLOCK_FREQ 6 24 + #define KVM_HC_MIPS_EXIT_VM 7 25 + #define KVM_HC_MIPS_CONSOLE_OUTPUT 8 23 26 24 27 /* 25 28 * hypercalls use architecture specific
+34
linux-headers/linux/vfio.h
··· 30 30 */ 31 31 #define VFIO_DMA_CC_IOMMU 4 32 32 33 + /* Check if EEH is supported */ 34 + #define VFIO_EEH 5 35 + 33 36 /* 34 37 * The IOCTL interface is designed for extensibility by embedding the 35 38 * structure length (argsz) and flags into structures passed between ··· 454 457 }; 455 458 456 459 #define VFIO_IOMMU_SPAPR_TCE_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12) 460 + 461 + /* 462 + * EEH PE operation struct provides ways to: 463 + * - enable/disable EEH functionality; 464 + * - unfreeze IO/DMA for frozen PE; 465 + * - read PE state; 466 + * - reset PE; 467 + * - configure PE. 468 + */ 469 + struct vfio_eeh_pe_op { 470 + __u32 argsz; 471 + __u32 flags; 472 + __u32 op; 473 + }; 474 + 475 + #define VFIO_EEH_PE_DISABLE 0 /* Disable EEH functionality */ 476 + #define VFIO_EEH_PE_ENABLE 1 /* Enable EEH functionality */ 477 + #define VFIO_EEH_PE_UNFREEZE_IO 2 /* Enable IO for frozen PE */ 478 + #define VFIO_EEH_PE_UNFREEZE_DMA 3 /* Enable DMA for frozen PE */ 479 + #define VFIO_EEH_PE_GET_STATE 4 /* PE state retrieval */ 480 + #define VFIO_EEH_PE_STATE_NORMAL 0 /* PE in functional state */ 481 + #define VFIO_EEH_PE_STATE_RESET 1 /* PE reset in progress */ 482 + #define VFIO_EEH_PE_STATE_STOPPED 2 /* Stopped DMA and IO */ 483 + #define VFIO_EEH_PE_STATE_STOPPED_DMA 4 /* Stopped DMA only */ 484 + #define VFIO_EEH_PE_STATE_UNAVAIL 5 /* State unavailable */ 485 + #define VFIO_EEH_PE_RESET_DEACTIVATE 5 /* Deassert PE reset */ 486 + #define VFIO_EEH_PE_RESET_HOT 6 /* Assert hot reset */ 487 + #define VFIO_EEH_PE_RESET_FUNDAMENTAL 7 /* Assert fundamental reset */ 488 + #define VFIO_EEH_PE_CONFIGURE 8 /* PE configuration */ 489 + 490 + #define VFIO_EEH_PE_OP _IO(VFIO_TYPE, VFIO_BASE + 21) 457 491 458 492 /* ***************************************************************** */ 459 493
+1 -1
linux-headers/linux/vhost.h
··· 14 14 15 15 #include <linux/ioctl.h> 16 16 #include <linux/virtio_config.h> 17 - #include "hw/virtio/virtio_ring.h" 17 + #include <linux/virtio_ring.h> 18 18 19 19 struct vhost_vring_state { 20 20 unsigned int index;
+1 -1
target-s390x/Makefile.objs
··· 1 1 obj-y += translate.o helper.o cpu.o interrupt.o 2 2 obj-y += int_helper.o fpu_helper.o cc_helper.o mem_helper.o misc_helper.o 3 3 obj-y += gdbstub.o 4 - obj-$(CONFIG_SOFTMMU) += ioinst.o arch_dump.o 4 + obj-$(CONFIG_SOFTMMU) += machine.o ioinst.o arch_dump.o 5 5 obj-$(CONFIG_KVM) += kvm.o
+4
target-s390x/cpu-qom.h
··· 77 77 78 78 #define ENV_OFFSET offsetof(S390CPU, env) 79 79 80 + #ifndef CONFIG_USER_ONLY 81 + extern const struct VMStateDescription vmstate_s390_cpu; 82 + #endif 83 + 80 84 void s390_cpu_do_interrupt(CPUState *cpu); 81 85 bool s390_cpu_exec_interrupt(CPUState *cpu, int int_req); 82 86 void s390_cpu_dump_state(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
+86 -28
target-s390x/cpu.c
··· 26 26 #include "cpu.h" 27 27 #include "qemu-common.h" 28 28 #include "qemu/timer.h" 29 + #include "qemu/error-report.h" 29 30 #include "hw/hw.h" 31 + #include "trace.h" 30 32 #ifndef CONFIG_USER_ONLY 31 33 #include "sysemu/arch_init.h" 32 34 #endif ··· 81 83 S390CPU *cpu = S390_CPU(s); 82 84 cpu->env.psw.addr = ldl_phys(s->as, 4) & PSW_MASK_ESA_ADDR; 83 85 cpu->env.psw.mask = PSW_MASK_32 | PSW_MASK_64; 84 - s390_add_running_cpu(cpu); 86 + s390_cpu_set_state(CPU_STATE_OPERATING, cpu); 85 87 } 86 88 #endif 87 89 ··· 93 95 CPUS390XState *env = &cpu->env; 94 96 95 97 env->pfault_token = -1UL; 96 - s390_del_running_cpu(cpu); 97 98 scc->parent_reset(s); 98 - #if !defined(CONFIG_USER_ONLY) 99 - s->halted = 1; 100 - #endif 99 + s390_cpu_set_state(CPU_STATE_STOPPED, cpu); 101 100 tlb_flush(s, 1); 102 101 } 103 102 ··· 118 117 119 118 env->pfault_token = -1UL; 120 119 121 - #if defined(CONFIG_KVM) 122 120 /* Reset state inside the kernel that we cannot access yet from QEMU. */ 123 121 if (kvm_enabled()) { 124 - if (kvm_vcpu_ioctl(s, KVM_S390_INITIAL_RESET, NULL)) { 125 - perror("Initial CPU reset failed"); 126 - } 122 + kvm_s390_reset_vcpu(cpu); 127 123 } 128 - #endif 129 124 } 130 125 131 126 /* CPUClass:reset() */ ··· 135 130 S390CPUClass *scc = S390_CPU_GET_CLASS(cpu); 136 131 CPUS390XState *env = &cpu->env; 137 132 138 - s390_del_running_cpu(cpu); 139 - 140 133 scc->parent_reset(s); 134 + s390_cpu_set_state(CPU_STATE_STOPPED, cpu); 141 135 142 136 memset(env, 0, offsetof(CPUS390XState, cpu_num)); 143 137 ··· 147 141 148 142 env->pfault_token = -1UL; 149 143 150 - /* set halted to 1 to make sure we can add the cpu in 151 - * s390_ipl_cpu code, where CPUState::halted is set back to 0 152 - * after incrementing the cpu counter */ 153 - #if !defined(CONFIG_USER_ONLY) 154 - s->halted = 1; 155 - 144 + /* Reset state inside the kernel that we cannot access yet from QEMU. */ 156 145 if (kvm_enabled()) { 157 146 kvm_s390_reset_vcpu(cpu); 158 147 } 159 - #endif 160 148 tlb_flush(s, 1); 161 149 } 162 150 ··· 206 194 env->tod_basetime = 0; 207 195 env->tod_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, s390x_tod_timer, cpu); 208 196 env->cpu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, s390x_cpu_timer, cpu); 209 - /* set CPUState::halted state to 1 to avoid decrementing the running 210 - * cpu counter in s390_cpu_reset to a negative number at 211 - * initial ipl */ 212 - cs->halted = 1; 197 + s390_cpu_set_state(CPU_STATE_STOPPED, cpu); 213 198 #endif 214 199 env->cpu_num = cpu_num++; 215 200 env->ext_index = -1; ··· 229 214 #endif 230 215 } 231 216 232 - static const VMStateDescription vmstate_s390_cpu = { 233 - .name = "cpu", 234 - .unmigratable = 1, 235 - }; 217 + #if !defined(CONFIG_USER_ONLY) 218 + static bool disabled_wait(CPUState *cpu) 219 + { 220 + return cpu->halted && !(S390_CPU(cpu)->env.psw.mask & 221 + (PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK)); 222 + } 223 + 224 + static unsigned s390_count_running_cpus(void) 225 + { 226 + CPUState *cpu; 227 + int nr_running = 0; 228 + 229 + CPU_FOREACH(cpu) { 230 + uint8_t state = S390_CPU(cpu)->env.cpu_state; 231 + if (state == CPU_STATE_OPERATING || 232 + state == CPU_STATE_LOAD) { 233 + if (!disabled_wait(cpu)) { 234 + nr_running++; 235 + } 236 + } 237 + } 238 + 239 + return nr_running; 240 + } 241 + 242 + unsigned int s390_cpu_halt(S390CPU *cpu) 243 + { 244 + CPUState *cs = CPU(cpu); 245 + trace_cpu_halt(cs->cpu_index); 246 + 247 + if (!cs->halted) { 248 + cs->halted = 1; 249 + cs->exception_index = EXCP_HLT; 250 + } 251 + 252 + return s390_count_running_cpus(); 253 + } 254 + 255 + void s390_cpu_unhalt(S390CPU *cpu) 256 + { 257 + CPUState *cs = CPU(cpu); 258 + trace_cpu_unhalt(cs->cpu_index); 259 + 260 + if (cs->halted) { 261 + cs->halted = 0; 262 + cs->exception_index = -1; 263 + } 264 + } 265 + 266 + unsigned int s390_cpu_set_state(uint8_t cpu_state, S390CPU *cpu) 267 + { 268 + trace_cpu_set_state(CPU(cpu)->cpu_index, cpu_state); 269 + 270 + switch (cpu_state) { 271 + case CPU_STATE_STOPPED: 272 + case CPU_STATE_CHECK_STOP: 273 + /* halt the cpu for common infrastructure */ 274 + s390_cpu_halt(cpu); 275 + break; 276 + case CPU_STATE_OPERATING: 277 + case CPU_STATE_LOAD: 278 + /* unhalt the cpu for common infrastructure */ 279 + s390_cpu_unhalt(cpu); 280 + break; 281 + default: 282 + error_report("Requested CPU state is not a valid S390 CPU state: %u", 283 + cpu_state); 284 + exit(1); 285 + } 286 + if (kvm_enabled() && cpu->env.cpu_state != cpu_state) { 287 + kvm_s390_set_cpu_state(cpu, cpu_state); 288 + } 289 + cpu->env.cpu_state = cpu_state; 290 + 291 + return s390_count_running_cpus(); 292 + } 293 + #endif 236 294 237 295 static void s390_cpu_class_init(ObjectClass *oc, void *data) 238 296 { ··· 260 318 cc->handle_mmu_fault = s390_cpu_handle_mmu_fault; 261 319 #else 262 320 cc->get_phys_page_debug = s390_cpu_get_phys_page_debug; 321 + cc->vmsd = &vmstate_s390_cpu; 263 322 cc->write_elf64_note = s390_cpu_write_elf64_note; 264 323 cc->write_elf64_qemunote = s390_cpu_write_elf64_qemunote; 265 324 cc->cpu_exec_interrupt = s390_cpu_exec_interrupt; 266 325 #endif 267 - dc->vmsd = &vmstate_s390_cpu; 268 326 cc->gdb_num_core_regs = S390_NUM_CORE_REGS; 269 327 cc->gdb_core_xml_file = "s390x-core64.xml"; 270 328 }
+33 -8
target-s390x/cpu.h
··· 141 141 QEMUTimer *tod_timer; 142 142 143 143 QEMUTimer *cpu_timer; 144 + 145 + /* 146 + * The cpu state represents the logical state of a cpu. In contrast to other 147 + * architectures, there is a difference between a halt and a stop on s390. 148 + * If all cpus are either stopped (including check stop) or in the disabled 149 + * wait state, the vm can be shut down. 150 + */ 151 + #define CPU_STATE_UNINITIALIZED 0x00 152 + #define CPU_STATE_STOPPED 0x01 153 + #define CPU_STATE_CHECK_STOP 0x02 154 + #define CPU_STATE_OPERATING 0x03 155 + #define CPU_STATE_LOAD 0x04 156 + uint8_t cpu_state; 157 + 144 158 } CPUS390XState; 145 159 146 160 #include "cpu-qom.h" ··· 375 389 void s390_virtio_irq(int config_change, uint64_t token); 376 390 377 391 #ifdef CONFIG_KVM 378 - void kvm_s390_reset_vcpu(S390CPU *cpu); 379 392 void kvm_s390_virtio_irq(int config_change, uint64_t token); 380 393 void kvm_s390_service_interrupt(uint32_t parm); 381 394 void kvm_s390_vcpu_interrupt(S390CPU *cpu, struct kvm_s390_irq *irq); 382 395 void kvm_s390_floating_interrupt(struct kvm_s390_irq *irq); 383 396 int kvm_s390_inject_flic(struct kvm_s390_irq *irq); 384 397 #else 385 - static inline void kvm_s390_reset_vcpu(S390CPU *cpu) 386 - { 387 - } 388 398 static inline void kvm_s390_virtio_irq(int config_change, uint64_t token) 389 399 { 390 400 } ··· 393 403 } 394 404 #endif 395 405 S390CPU *s390_cpu_addr2state(uint16_t cpu_addr); 396 - void s390_add_running_cpu(S390CPU *cpu); 397 - unsigned s390_del_running_cpu(S390CPU *cpu); 406 + unsigned int s390_cpu_halt(S390CPU *cpu); 407 + void s390_cpu_unhalt(S390CPU *cpu); 408 + unsigned int s390_cpu_set_state(uint8_t cpu_state, S390CPU *cpu); 398 409 399 410 /* service interrupts are floating therefore we must not pass an cpustate */ 400 411 void s390_sclp_extint(uint32_t parm); ··· 403 414 extern const hwaddr virtio_size; 404 415 405 416 #else 406 - static inline void s390_add_running_cpu(S390CPU *cpu) 417 + static inline unsigned int s390_cpu_halt(S390CPU *cpu) 418 + { 419 + return 0; 420 + } 421 + 422 + static inline void s390_cpu_unhalt(S390CPU *cpu) 407 423 { 408 424 } 409 425 410 - static inline unsigned s390_del_running_cpu(S390CPU *cpu) 426 + static inline unsigned int s390_cpu_set_state(uint8_t cpu_state, S390CPU *cpu) 411 427 { 412 428 return 0; 413 429 } ··· 1052 1068 int kvm_s390_cpu_restart(S390CPU *cpu); 1053 1069 int kvm_s390_get_memslot_count(KVMState *s); 1054 1070 void kvm_s390_clear_cmma_callback(void *opaque); 1071 + int kvm_s390_set_cpu_state(S390CPU *cpu, uint8_t cpu_state); 1072 + void kvm_s390_reset_vcpu(S390CPU *cpu); 1055 1073 #else 1056 1074 static inline void kvm_s390_io_interrupt(uint16_t subchannel_id, 1057 1075 uint16_t subchannel_nr, ··· 1081 1099 static inline int kvm_s390_get_memslot_count(KVMState *s) 1082 1100 { 1083 1101 return MAX_AVAIL_SLOTS; 1102 + } 1103 + static inline int kvm_s390_set_cpu_state(S390CPU *cpu, uint8_t cpu_state) 1104 + { 1105 + return -ENOSYS; 1106 + } 1107 + static inline void kvm_s390_reset_vcpu(S390CPU *cpu) 1108 + { 1084 1109 } 1085 1110 #endif 1086 1111
+7 -12
target-s390x/helper.c
··· 504 504 505 505 void load_psw(CPUS390XState *env, uint64_t mask, uint64_t addr) 506 506 { 507 + env->psw.addr = addr; 508 + env->psw.mask = mask; 509 + env->cc_op = (mask >> 44) & 3; 510 + 507 511 if (mask & PSW_MASK_WAIT) { 508 512 S390CPU *cpu = s390_env_get_cpu(env); 509 - CPUState *cs = CPU(cpu); 510 - if (!(mask & (PSW_MASK_IO | PSW_MASK_EXT | PSW_MASK_MCHECK))) { 511 - if (s390_del_running_cpu(cpu) == 0) { 513 + if (s390_cpu_halt(cpu) == 0) { 512 514 #ifndef CONFIG_USER_ONLY 513 - qemu_system_shutdown_request(); 515 + qemu_system_shutdown_request(); 514 516 #endif 515 - } 516 517 } 517 - cs->halted = 1; 518 - cs->exception_index = EXCP_HLT; 519 518 } 520 - 521 - env->psw.addr = addr; 522 - env->psw.mask = mask; 523 - env->cc_op = (mask >> 44) & 3; 524 519 } 525 520 526 521 static uint64_t get_psw_mask(CPUS390XState *env) ··· 818 813 qemu_log_mask(CPU_LOG_INT, "%s: %d at pc=%" PRIx64 "\n", 819 814 __func__, cs->exception_index, env->psw.addr); 820 815 821 - s390_add_running_cpu(cpu); 816 + s390_cpu_set_state(CPU_STATE_OPERATING, cpu); 822 817 /* handle machine checks */ 823 818 if ((env->psw.mask & PSW_MASK_MCHECK) && 824 819 (cs->exception_index == -1)) {
+50 -8
target-s390x/kvm.c
··· 181 181 return cpu->cpu_index; 182 182 } 183 183 184 - int kvm_arch_init_vcpu(CPUState *cpu) 184 + int kvm_arch_init_vcpu(CPUState *cs) 185 185 { 186 - /* nothing todo yet */ 186 + S390CPU *cpu = S390_CPU(cs); 187 + kvm_s390_set_cpu_state(cpu, cpu->env.cpu_state); 187 188 return 0; 188 189 } 189 190 ··· 197 198 * Before this ioctl cpu_synchronize_state() is called in common kvm 198 199 * code (kvm-all) */ 199 200 if (kvm_vcpu_ioctl(cs, KVM_S390_INITIAL_RESET, NULL)) { 200 - perror("Can't reset vcpu\n"); 201 + error_report("Initial CPU reset failed on CPU %i\n", cs->cpu_index); 201 202 } 202 203 } 203 204 ··· 921 922 CPUState *cs = arg; 922 923 S390CPU *cpu = S390_CPU(cs); 923 924 924 - s390_add_running_cpu(cpu); 925 + s390_cpu_set_state(CPU_STATE_OPERATING, cpu); 925 926 DPRINTF("DONE: KVM cpu start: %p\n", &cpu->env); 926 927 } 927 928 ··· 934 935 }; 935 936 936 937 kvm_s390_vcpu_interrupt(cpu, &irq); 937 - s390_add_running_cpu(cpu); 938 + s390_cpu_set_state(CPU_STATE_OPERATING, cpu); 938 939 } 939 940 940 941 int kvm_s390_cpu_restart(S390CPU *cpu) ··· 951 952 952 953 cpu_synchronize_state(cpu); 953 954 scc->initial_cpu_reset(cpu); 955 + cpu_synchronize_post_reset(cpu); 954 956 } 955 957 956 958 static void sigp_cpu_reset(void *arg) ··· 960 962 961 963 cpu_synchronize_state(cpu); 962 964 scc->cpu_reset(cpu); 965 + cpu_synchronize_post_reset(cpu); 963 966 } 964 967 965 968 #define SIGP_ORDER_MASK 0x000000ff ··· 1074 1077 error_report("Unmanageable %s! CPU%i new PSW: 0x%016lx:%016lx", 1075 1078 str, cs->cpu_index, ldq_phys(cs->as, cpu->env.psa + pswoffset), 1076 1079 ldq_phys(cs->as, cpu->env.psa + pswoffset + 8)); 1077 - s390_del_running_cpu(cpu); 1080 + s390_cpu_halt(cpu); 1078 1081 guest_panicked(); 1079 1082 } 1080 1083 ··· 1103 1106 break; 1104 1107 case ICPT_WAITPSW: 1105 1108 /* disabled wait, since enabled wait is handled in kernel */ 1106 - if (s390_del_running_cpu(cpu) == 0) { 1109 + cpu_synchronize_state(cs); 1110 + if (s390_cpu_halt(cpu) == 0) { 1107 1111 if (is_special_wait_psw(cs)) { 1108 1112 qemu_system_shutdown_request(); 1109 1113 } else { ··· 1113 1117 r = EXCP_HALTED; 1114 1118 break; 1115 1119 case ICPT_CPU_STOP: 1116 - if (s390_del_running_cpu(cpu) == 0) { 1120 + if (s390_cpu_set_state(CPU_STATE_STOPPED, cpu) == 0) { 1117 1121 qemu_system_shutdown_request(); 1118 1122 } 1119 1123 r = EXCP_HALTED; ··· 1320 1324 { 1321 1325 return kvm_check_extension(s, KVM_CAP_NR_MEMSLOTS); 1322 1326 } 1327 + 1328 + int kvm_s390_set_cpu_state(S390CPU *cpu, uint8_t cpu_state) 1329 + { 1330 + struct kvm_mp_state mp_state = {}; 1331 + int ret; 1332 + 1333 + /* the kvm part might not have been initialized yet */ 1334 + if (CPU(cpu)->kvm_state == NULL) { 1335 + return 0; 1336 + } 1337 + 1338 + switch (cpu_state) { 1339 + case CPU_STATE_STOPPED: 1340 + mp_state.mp_state = KVM_MP_STATE_STOPPED; 1341 + break; 1342 + case CPU_STATE_CHECK_STOP: 1343 + mp_state.mp_state = KVM_MP_STATE_CHECK_STOP; 1344 + break; 1345 + case CPU_STATE_OPERATING: 1346 + mp_state.mp_state = KVM_MP_STATE_OPERATING; 1347 + break; 1348 + case CPU_STATE_LOAD: 1349 + mp_state.mp_state = KVM_MP_STATE_LOAD; 1350 + break; 1351 + default: 1352 + error_report("Requested CPU state is not a valid S390 CPU state: %u", 1353 + cpu_state); 1354 + exit(1); 1355 + } 1356 + 1357 + ret = kvm_vcpu_ioctl(CPU(cpu), KVM_SET_MP_STATE, &mp_state); 1358 + if (ret) { 1359 + trace_kvm_failed_cpu_state_set(CPU(cpu)->cpu_index, cpu_state, 1360 + strerror(-ret)); 1361 + } 1362 + 1363 + return ret; 1364 + }
+76
target-s390x/machine.c
··· 1 + /* 2 + * S390x machine definitions and functions 3 + * 4 + * Copyright IBM Corp. 2014 5 + * 6 + * Authors: 7 + * Thomas Huth <thuth@linux.vnet.ibm.com> 8 + * Christian Borntraeger <borntraeger@de.ibm.com> 9 + * Jason J. Herne <jjherne@us.ibm.com> 10 + * 11 + * This work is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License as published 13 + * by the Free Software Foundation; either version 2 of the License, 14 + * or (at your option) any later version. 15 + */ 16 + 17 + #include "hw/hw.h" 18 + #include "cpu.h" 19 + #include "sysemu/kvm.h" 20 + 21 + static int cpu_post_load(void *opaque, int version_id) 22 + { 23 + S390CPU *cpu = opaque; 24 + 25 + /* 26 + * As the cpu state is pushed to kvm via kvm_set_mp_state rather 27 + * than via cpu_synchronize_state, we need update kvm here. 28 + */ 29 + if (kvm_enabled()) { 30 + kvm_s390_set_cpu_state(cpu, cpu->env.cpu_state); 31 + } 32 + 33 + return 0; 34 + } 35 + 36 + const VMStateDescription vmstate_s390_cpu = { 37 + .name = "cpu", 38 + .post_load = cpu_post_load, 39 + .version_id = 1, 40 + .minimum_version_id = 1, 41 + .fields = (VMStateField[]) { 42 + VMSTATE_UINT64(env.fregs[0].ll, S390CPU), 43 + VMSTATE_UINT64(env.fregs[1].ll, S390CPU), 44 + VMSTATE_UINT64(env.fregs[2].ll, S390CPU), 45 + VMSTATE_UINT64(env.fregs[3].ll, S390CPU), 46 + VMSTATE_UINT64(env.fregs[4].ll, S390CPU), 47 + VMSTATE_UINT64(env.fregs[5].ll, S390CPU), 48 + VMSTATE_UINT64(env.fregs[6].ll, S390CPU), 49 + VMSTATE_UINT64(env.fregs[7].ll, S390CPU), 50 + VMSTATE_UINT64(env.fregs[8].ll, S390CPU), 51 + VMSTATE_UINT64(env.fregs[9].ll, S390CPU), 52 + VMSTATE_UINT64(env.fregs[10].ll, S390CPU), 53 + VMSTATE_UINT64(env.fregs[11].ll, S390CPU), 54 + VMSTATE_UINT64(env.fregs[12].ll, S390CPU), 55 + VMSTATE_UINT64(env.fregs[13].ll, S390CPU), 56 + VMSTATE_UINT64(env.fregs[14].ll, S390CPU), 57 + VMSTATE_UINT64(env.fregs[15].ll, S390CPU), 58 + VMSTATE_UINT64_ARRAY(env.regs, S390CPU, 16), 59 + VMSTATE_UINT64(env.psw.mask, S390CPU), 60 + VMSTATE_UINT64(env.psw.addr, S390CPU), 61 + VMSTATE_UINT64(env.psa, S390CPU), 62 + VMSTATE_UINT32(env.fpc, S390CPU), 63 + VMSTATE_UINT32(env.todpr, S390CPU), 64 + VMSTATE_UINT64(env.pfault_token, S390CPU), 65 + VMSTATE_UINT64(env.pfault_compare, S390CPU), 66 + VMSTATE_UINT64(env.pfault_select, S390CPU), 67 + VMSTATE_UINT64(env.cputm, S390CPU), 68 + VMSTATE_UINT64(env.ckc, S390CPU), 69 + VMSTATE_UINT64(env.gbea, S390CPU), 70 + VMSTATE_UINT64(env.pp, S390CPU), 71 + VMSTATE_UINT32_ARRAY(env.aregs, S390CPU, 16), 72 + VMSTATE_UINT64_ARRAY(env.cregs, S390CPU, 16), 73 + VMSTATE_UINT8(env.cpu_state, S390CPU), 74 + VMSTATE_END_OF_LIST() 75 + }, 76 + };
+6
trace-events
··· 1369 1369 # target-s390x/kvm.c 1370 1370 kvm_enable_cmma(int rc) "CMMA: enabling with result code %d" 1371 1371 kvm_clear_cmma(int rc) "CMMA: clearing with result code %d" 1372 + kvm_failed_cpu_state_set(int cpu_index, uint8_t state, const char *msg) "Warning: Unable to set cpu %d state %" PRIu8 " to KVM: %s" 1372 1373 1373 1374 # hw/dma/i8257.c 1374 1375 i8257_unregistered_dma(int nchan, int dma_pos, int dma_len) "unregistered DMA channel used nchan=%d dma_pos=%d dma_len=%d" 1376 + 1377 + # target-s390x/cpu.c 1378 + cpu_set_state(int cpu_index, uint8_t state) "setting cpu %d state to %" PRIu8 1379 + cpu_halt(int cpu_index) "halting cpu %d" 1380 + cpu_unhalt(int cpu_index) "unhalting cpu %d"