1b0c632dbSHeiko Carstens /* 2b0c632dbSHeiko Carstens * s390host.c -- hosting zSeries kernel virtual machines 3b0c632dbSHeiko Carstens * 4b0c632dbSHeiko Carstens * Copyright IBM Corp. 2008 5b0c632dbSHeiko Carstens * 6b0c632dbSHeiko Carstens * This program is free software; you can redistribute it and/or modify 7b0c632dbSHeiko Carstens * it under the terms of the GNU General Public License (version 2 only) 8b0c632dbSHeiko Carstens * as published by the Free Software Foundation. 9b0c632dbSHeiko Carstens * 10b0c632dbSHeiko Carstens * Author(s): Carsten Otte <cotte@de.ibm.com> 11b0c632dbSHeiko Carstens * Christian Borntraeger <borntraeger@de.ibm.com> 12b0c632dbSHeiko Carstens * Heiko Carstens <heiko.carstens@de.ibm.com> 13b0c632dbSHeiko Carstens */ 14b0c632dbSHeiko Carstens 15b0c632dbSHeiko Carstens #include <linux/compiler.h> 16b0c632dbSHeiko Carstens #include <linux/err.h> 17b0c632dbSHeiko Carstens #include <linux/fs.h> 18*ca872302SChristian Borntraeger #include <linux/hrtimer.h> 19b0c632dbSHeiko Carstens #include <linux/init.h> 20b0c632dbSHeiko Carstens #include <linux/kvm.h> 21b0c632dbSHeiko Carstens #include <linux/kvm_host.h> 22b0c632dbSHeiko Carstens #include <linux/module.h> 23b0c632dbSHeiko Carstens #include <linux/slab.h> 24ba5c1e9bSCarsten Otte #include <linux/timer.h> 25b0c632dbSHeiko Carstens #include <asm/lowcore.h> 26b0c632dbSHeiko Carstens #include <asm/pgtable.h> 27f5daba1dSHeiko Carstens #include <asm/nmi.h> 288f2abe6aSChristian Borntraeger #include "kvm-s390.h" 29b0c632dbSHeiko Carstens #include "gaccess.h" 30b0c632dbSHeiko Carstens 31b0c632dbSHeiko Carstens #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU 32b0c632dbSHeiko Carstens 33b0c632dbSHeiko Carstens struct kvm_stats_debugfs_item debugfs_entries[] = { 34b0c632dbSHeiko Carstens { "userspace_handled", VCPU_STAT(exit_userspace) }, 350eaeafa1SChristian Borntraeger { "exit_null", VCPU_STAT(exit_null) }, 368f2abe6aSChristian Borntraeger { "exit_validity", VCPU_STAT(exit_validity) }, 378f2abe6aSChristian Borntraeger { "exit_stop_request", VCPU_STAT(exit_stop_request) }, 388f2abe6aSChristian Borntraeger { "exit_external_request", VCPU_STAT(exit_external_request) }, 398f2abe6aSChristian Borntraeger { "exit_external_interrupt", VCPU_STAT(exit_external_interrupt) }, 40ba5c1e9bSCarsten Otte { "exit_instruction", VCPU_STAT(exit_instruction) }, 41ba5c1e9bSCarsten Otte { "exit_program_interruption", VCPU_STAT(exit_program_interruption) }, 42ba5c1e9bSCarsten Otte { "exit_instr_and_program_int", VCPU_STAT(exit_instr_and_program) }, 43f5e10b09SChristian Borntraeger { "instruction_lctlg", VCPU_STAT(instruction_lctlg) }, 44ba5c1e9bSCarsten Otte { "instruction_lctl", VCPU_STAT(instruction_lctl) }, 45ba5c1e9bSCarsten Otte { "deliver_emergency_signal", VCPU_STAT(deliver_emergency_signal) }, 46ba5c1e9bSCarsten Otte { "deliver_service_signal", VCPU_STAT(deliver_service_signal) }, 47ba5c1e9bSCarsten Otte { "deliver_virtio_interrupt", VCPU_STAT(deliver_virtio_interrupt) }, 48ba5c1e9bSCarsten Otte { "deliver_stop_signal", VCPU_STAT(deliver_stop_signal) }, 49ba5c1e9bSCarsten Otte { "deliver_prefix_signal", VCPU_STAT(deliver_prefix_signal) }, 50ba5c1e9bSCarsten Otte { "deliver_restart_signal", VCPU_STAT(deliver_restart_signal) }, 51ba5c1e9bSCarsten Otte { "deliver_program_interruption", VCPU_STAT(deliver_program_int) }, 52ba5c1e9bSCarsten Otte { "exit_wait_state", VCPU_STAT(exit_wait_state) }, 53453423dcSChristian Borntraeger { "instruction_stidp", VCPU_STAT(instruction_stidp) }, 54453423dcSChristian Borntraeger { "instruction_spx", VCPU_STAT(instruction_spx) }, 55453423dcSChristian Borntraeger { "instruction_stpx", VCPU_STAT(instruction_stpx) }, 56453423dcSChristian Borntraeger { "instruction_stap", VCPU_STAT(instruction_stap) }, 57453423dcSChristian Borntraeger { "instruction_storage_key", VCPU_STAT(instruction_storage_key) }, 58453423dcSChristian Borntraeger { "instruction_stsch", VCPU_STAT(instruction_stsch) }, 59453423dcSChristian Borntraeger { "instruction_chsc", VCPU_STAT(instruction_chsc) }, 60453423dcSChristian Borntraeger { "instruction_stsi", VCPU_STAT(instruction_stsi) }, 61453423dcSChristian Borntraeger { "instruction_stfl", VCPU_STAT(instruction_stfl) }, 625288fbf0SChristian Borntraeger { "instruction_sigp_sense", VCPU_STAT(instruction_sigp_sense) }, 635288fbf0SChristian Borntraeger { "instruction_sigp_emergency", VCPU_STAT(instruction_sigp_emergency) }, 645288fbf0SChristian Borntraeger { "instruction_sigp_stop", VCPU_STAT(instruction_sigp_stop) }, 655288fbf0SChristian Borntraeger { "instruction_sigp_set_arch", VCPU_STAT(instruction_sigp_arch) }, 665288fbf0SChristian Borntraeger { "instruction_sigp_set_prefix", VCPU_STAT(instruction_sigp_prefix) }, 675288fbf0SChristian Borntraeger { "instruction_sigp_restart", VCPU_STAT(instruction_sigp_restart) }, 68e28acfeaSChristian Borntraeger { "diagnose_44", VCPU_STAT(diagnose_44) }, 69b0c632dbSHeiko Carstens { NULL } 70b0c632dbSHeiko Carstens }; 71b0c632dbSHeiko Carstens 72b0c632dbSHeiko Carstens 73b0c632dbSHeiko Carstens /* Section: not file related */ 74b0c632dbSHeiko Carstens void kvm_arch_hardware_enable(void *garbage) 75b0c632dbSHeiko Carstens { 76b0c632dbSHeiko Carstens /* every s390 is virtualization enabled ;-) */ 77b0c632dbSHeiko Carstens } 78b0c632dbSHeiko Carstens 79b0c632dbSHeiko Carstens void kvm_arch_hardware_disable(void *garbage) 80b0c632dbSHeiko Carstens { 81b0c632dbSHeiko Carstens } 82b0c632dbSHeiko Carstens 83b0c632dbSHeiko Carstens int kvm_arch_hardware_setup(void) 84b0c632dbSHeiko Carstens { 85b0c632dbSHeiko Carstens return 0; 86b0c632dbSHeiko Carstens } 87b0c632dbSHeiko Carstens 88b0c632dbSHeiko Carstens void kvm_arch_hardware_unsetup(void) 89b0c632dbSHeiko Carstens { 90b0c632dbSHeiko Carstens } 91b0c632dbSHeiko Carstens 92b0c632dbSHeiko Carstens void kvm_arch_check_processor_compat(void *rtn) 93b0c632dbSHeiko Carstens { 94b0c632dbSHeiko Carstens } 95b0c632dbSHeiko Carstens 96b0c632dbSHeiko Carstens int kvm_arch_init(void *opaque) 97b0c632dbSHeiko Carstens { 98b0c632dbSHeiko Carstens return 0; 99b0c632dbSHeiko Carstens } 100b0c632dbSHeiko Carstens 101b0c632dbSHeiko Carstens void kvm_arch_exit(void) 102b0c632dbSHeiko Carstens { 103b0c632dbSHeiko Carstens } 104b0c632dbSHeiko Carstens 105b0c632dbSHeiko Carstens /* Section: device related */ 106b0c632dbSHeiko Carstens long kvm_arch_dev_ioctl(struct file *filp, 107b0c632dbSHeiko Carstens unsigned int ioctl, unsigned long arg) 108b0c632dbSHeiko Carstens { 109b0c632dbSHeiko Carstens if (ioctl == KVM_S390_ENABLE_SIE) 110b0c632dbSHeiko Carstens return s390_enable_sie(); 111b0c632dbSHeiko Carstens return -EINVAL; 112b0c632dbSHeiko Carstens } 113b0c632dbSHeiko Carstens 114b0c632dbSHeiko Carstens int kvm_dev_ioctl_check_extension(long ext) 115b0c632dbSHeiko Carstens { 1162bd0ac4eSCarsten Otte switch (ext) { 1172bd0ac4eSCarsten Otte default: 118b0c632dbSHeiko Carstens return 0; 119b0c632dbSHeiko Carstens } 1202bd0ac4eSCarsten Otte } 121b0c632dbSHeiko Carstens 122b0c632dbSHeiko Carstens /* Section: vm related */ 123b0c632dbSHeiko Carstens /* 124b0c632dbSHeiko Carstens * Get (and clear) the dirty memory log for a memory slot. 125b0c632dbSHeiko Carstens */ 126b0c632dbSHeiko Carstens int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, 127b0c632dbSHeiko Carstens struct kvm_dirty_log *log) 128b0c632dbSHeiko Carstens { 129b0c632dbSHeiko Carstens return 0; 130b0c632dbSHeiko Carstens } 131b0c632dbSHeiko Carstens 132b0c632dbSHeiko Carstens long kvm_arch_vm_ioctl(struct file *filp, 133b0c632dbSHeiko Carstens unsigned int ioctl, unsigned long arg) 134b0c632dbSHeiko Carstens { 135b0c632dbSHeiko Carstens struct kvm *kvm = filp->private_data; 136b0c632dbSHeiko Carstens void __user *argp = (void __user *)arg; 137b0c632dbSHeiko Carstens int r; 138b0c632dbSHeiko Carstens 139b0c632dbSHeiko Carstens switch (ioctl) { 140ba5c1e9bSCarsten Otte case KVM_S390_INTERRUPT: { 141ba5c1e9bSCarsten Otte struct kvm_s390_interrupt s390int; 142ba5c1e9bSCarsten Otte 143ba5c1e9bSCarsten Otte r = -EFAULT; 144ba5c1e9bSCarsten Otte if (copy_from_user(&s390int, argp, sizeof(s390int))) 145ba5c1e9bSCarsten Otte break; 146ba5c1e9bSCarsten Otte r = kvm_s390_inject_vm(kvm, &s390int); 147ba5c1e9bSCarsten Otte break; 148ba5c1e9bSCarsten Otte } 149b0c632dbSHeiko Carstens default: 150b0c632dbSHeiko Carstens r = -EINVAL; 151b0c632dbSHeiko Carstens } 152b0c632dbSHeiko Carstens 153b0c632dbSHeiko Carstens return r; 154b0c632dbSHeiko Carstens } 155b0c632dbSHeiko Carstens 156b0c632dbSHeiko Carstens struct kvm *kvm_arch_create_vm(void) 157b0c632dbSHeiko Carstens { 158b0c632dbSHeiko Carstens struct kvm *kvm; 159b0c632dbSHeiko Carstens int rc; 160b0c632dbSHeiko Carstens char debug_name[16]; 161b0c632dbSHeiko Carstens 162b0c632dbSHeiko Carstens rc = s390_enable_sie(); 163b0c632dbSHeiko Carstens if (rc) 164b0c632dbSHeiko Carstens goto out_nokvm; 165b0c632dbSHeiko Carstens 166b0c632dbSHeiko Carstens rc = -ENOMEM; 167b0c632dbSHeiko Carstens kvm = kzalloc(sizeof(struct kvm), GFP_KERNEL); 168b0c632dbSHeiko Carstens if (!kvm) 169b0c632dbSHeiko Carstens goto out_nokvm; 170b0c632dbSHeiko Carstens 171b0c632dbSHeiko Carstens kvm->arch.sca = (struct sca_block *) get_zeroed_page(GFP_KERNEL); 172b0c632dbSHeiko Carstens if (!kvm->arch.sca) 173b0c632dbSHeiko Carstens goto out_nosca; 174b0c632dbSHeiko Carstens 175b0c632dbSHeiko Carstens sprintf(debug_name, "kvm-%u", current->pid); 176b0c632dbSHeiko Carstens 177b0c632dbSHeiko Carstens kvm->arch.dbf = debug_register(debug_name, 8, 2, 8 * sizeof(long)); 178b0c632dbSHeiko Carstens if (!kvm->arch.dbf) 179b0c632dbSHeiko Carstens goto out_nodbf; 180b0c632dbSHeiko Carstens 181ba5c1e9bSCarsten Otte spin_lock_init(&kvm->arch.float_int.lock); 182ba5c1e9bSCarsten Otte INIT_LIST_HEAD(&kvm->arch.float_int.list); 183ba5c1e9bSCarsten Otte 184b0c632dbSHeiko Carstens debug_register_view(kvm->arch.dbf, &debug_sprintf_view); 185b0c632dbSHeiko Carstens VM_EVENT(kvm, 3, "%s", "vm created"); 186b0c632dbSHeiko Carstens 187b0c632dbSHeiko Carstens return kvm; 188b0c632dbSHeiko Carstens out_nodbf: 189b0c632dbSHeiko Carstens free_page((unsigned long)(kvm->arch.sca)); 190b0c632dbSHeiko Carstens out_nosca: 191b0c632dbSHeiko Carstens kfree(kvm); 192b0c632dbSHeiko Carstens out_nokvm: 193b0c632dbSHeiko Carstens return ERR_PTR(rc); 194b0c632dbSHeiko Carstens } 195b0c632dbSHeiko Carstens 196d329c035SChristian Borntraeger void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu) 197d329c035SChristian Borntraeger { 198d329c035SChristian Borntraeger VCPU_EVENT(vcpu, 3, "%s", "free cpu"); 199d329c035SChristian Borntraeger free_page((unsigned long)(vcpu->arch.sie_block)); 2006692cef3SChristian Borntraeger kvm_vcpu_uninit(vcpu); 201d329c035SChristian Borntraeger kfree(vcpu); 202d329c035SChristian Borntraeger } 203d329c035SChristian Borntraeger 204d329c035SChristian Borntraeger static void kvm_free_vcpus(struct kvm *kvm) 205d329c035SChristian Borntraeger { 206d329c035SChristian Borntraeger unsigned int i; 207d329c035SChristian Borntraeger 208d329c035SChristian Borntraeger for (i = 0; i < KVM_MAX_VCPUS; ++i) { 209d329c035SChristian Borntraeger if (kvm->vcpus[i]) { 210d329c035SChristian Borntraeger kvm_arch_vcpu_destroy(kvm->vcpus[i]); 211d329c035SChristian Borntraeger kvm->vcpus[i] = NULL; 212d329c035SChristian Borntraeger } 213d329c035SChristian Borntraeger } 214d329c035SChristian Borntraeger } 215d329c035SChristian Borntraeger 216ad8ba2cdSSheng Yang void kvm_arch_sync_events(struct kvm *kvm) 217ad8ba2cdSSheng Yang { 218ad8ba2cdSSheng Yang } 219ad8ba2cdSSheng Yang 220b0c632dbSHeiko Carstens void kvm_arch_destroy_vm(struct kvm *kvm) 221b0c632dbSHeiko Carstens { 222d329c035SChristian Borntraeger kvm_free_vcpus(kvm); 223dfdded7cSCarsten Otte kvm_free_physmem(kvm); 224b0c632dbSHeiko Carstens free_page((unsigned long)(kvm->arch.sca)); 225d329c035SChristian Borntraeger debug_unregister(kvm->arch.dbf); 226b0c632dbSHeiko Carstens kfree(kvm); 227b0c632dbSHeiko Carstens } 228b0c632dbSHeiko Carstens 229b0c632dbSHeiko Carstens /* Section: vcpu related */ 230b0c632dbSHeiko Carstens int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu) 231b0c632dbSHeiko Carstens { 232b0c632dbSHeiko Carstens return 0; 233b0c632dbSHeiko Carstens } 234b0c632dbSHeiko Carstens 235b0c632dbSHeiko Carstens void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu) 236b0c632dbSHeiko Carstens { 2376692cef3SChristian Borntraeger /* Nothing todo */ 238b0c632dbSHeiko Carstens } 239b0c632dbSHeiko Carstens 240b0c632dbSHeiko Carstens void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) 241b0c632dbSHeiko Carstens { 242b0c632dbSHeiko Carstens save_fp_regs(&vcpu->arch.host_fpregs); 243b0c632dbSHeiko Carstens save_access_regs(vcpu->arch.host_acrs); 244b0c632dbSHeiko Carstens vcpu->arch.guest_fpregs.fpc &= FPC_VALID_MASK; 245b0c632dbSHeiko Carstens restore_fp_regs(&vcpu->arch.guest_fpregs); 246b0c632dbSHeiko Carstens restore_access_regs(vcpu->arch.guest_acrs); 247b0c632dbSHeiko Carstens } 248b0c632dbSHeiko Carstens 249b0c632dbSHeiko Carstens void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu) 250b0c632dbSHeiko Carstens { 251b0c632dbSHeiko Carstens save_fp_regs(&vcpu->arch.guest_fpregs); 252b0c632dbSHeiko Carstens save_access_regs(vcpu->arch.guest_acrs); 253b0c632dbSHeiko Carstens restore_fp_regs(&vcpu->arch.host_fpregs); 254b0c632dbSHeiko Carstens restore_access_regs(vcpu->arch.host_acrs); 255b0c632dbSHeiko Carstens } 256b0c632dbSHeiko Carstens 257b0c632dbSHeiko Carstens static void kvm_s390_vcpu_initial_reset(struct kvm_vcpu *vcpu) 258b0c632dbSHeiko Carstens { 259b0c632dbSHeiko Carstens /* this equals initial cpu reset in pop, but we don't switch to ESA */ 260b0c632dbSHeiko Carstens vcpu->arch.sie_block->gpsw.mask = 0UL; 261b0c632dbSHeiko Carstens vcpu->arch.sie_block->gpsw.addr = 0UL; 262b0c632dbSHeiko Carstens vcpu->arch.sie_block->prefix = 0UL; 263b0c632dbSHeiko Carstens vcpu->arch.sie_block->ihcpu = 0xffff; 264b0c632dbSHeiko Carstens vcpu->arch.sie_block->cputm = 0UL; 265b0c632dbSHeiko Carstens vcpu->arch.sie_block->ckc = 0UL; 266b0c632dbSHeiko Carstens vcpu->arch.sie_block->todpr = 0; 267b0c632dbSHeiko Carstens memset(vcpu->arch.sie_block->gcr, 0, 16 * sizeof(__u64)); 268b0c632dbSHeiko Carstens vcpu->arch.sie_block->gcr[0] = 0xE0UL; 269b0c632dbSHeiko Carstens vcpu->arch.sie_block->gcr[14] = 0xC2000000UL; 270b0c632dbSHeiko Carstens vcpu->arch.guest_fpregs.fpc = 0; 271b0c632dbSHeiko Carstens asm volatile("lfpc %0" : : "Q" (vcpu->arch.guest_fpregs.fpc)); 272b0c632dbSHeiko Carstens vcpu->arch.sie_block->gbea = 1; 273b0c632dbSHeiko Carstens } 274b0c632dbSHeiko Carstens 2754da29e90SChristian Borntraeger /* The current code can have up to 256 pages for virtio */ 2764da29e90SChristian Borntraeger #define VIRTIODESCSPACE (256ul * 4096ul) 2774da29e90SChristian Borntraeger 278b0c632dbSHeiko Carstens int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu) 279b0c632dbSHeiko Carstens { 280b0c632dbSHeiko Carstens atomic_set(&vcpu->arch.sie_block->cpuflags, CPUSTAT_ZARCH); 2814da29e90SChristian Borntraeger vcpu->arch.sie_block->gmslm = vcpu->kvm->arch.guest_memsize + 2824da29e90SChristian Borntraeger vcpu->kvm->arch.guest_origin + 2834da29e90SChristian Borntraeger VIRTIODESCSPACE - 1ul; 2844da29e90SChristian Borntraeger vcpu->arch.sie_block->gmsor = vcpu->kvm->arch.guest_origin; 285b0c632dbSHeiko Carstens vcpu->arch.sie_block->ecb = 2; 286b0c632dbSHeiko Carstens vcpu->arch.sie_block->eca = 0xC1002001U; 287*ca872302SChristian Borntraeger hrtimer_init(&vcpu->arch.ckc_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS); 288*ca872302SChristian Borntraeger tasklet_init(&vcpu->arch.tasklet, kvm_s390_tasklet, 289ba5c1e9bSCarsten Otte (unsigned long) vcpu); 290*ca872302SChristian Borntraeger vcpu->arch.ckc_timer.function = kvm_s390_idle_wakeup; 291453423dcSChristian Borntraeger get_cpu_id(&vcpu->arch.cpu_id); 29292e6ecf3SChristian Borntraeger vcpu->arch.cpu_id.version = 0xff; 293b0c632dbSHeiko Carstens return 0; 294b0c632dbSHeiko Carstens } 295b0c632dbSHeiko Carstens 296b0c632dbSHeiko Carstens struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, 297b0c632dbSHeiko Carstens unsigned int id) 298b0c632dbSHeiko Carstens { 299b0c632dbSHeiko Carstens struct kvm_vcpu *vcpu = kzalloc(sizeof(struct kvm_vcpu), GFP_KERNEL); 300b0c632dbSHeiko Carstens int rc = -ENOMEM; 301b0c632dbSHeiko Carstens 302b0c632dbSHeiko Carstens if (!vcpu) 303b0c632dbSHeiko Carstens goto out_nomem; 304b0c632dbSHeiko Carstens 305180c12fbSChristian Borntraeger vcpu->arch.sie_block = (struct kvm_s390_sie_block *) 306180c12fbSChristian Borntraeger get_zeroed_page(GFP_KERNEL); 307b0c632dbSHeiko Carstens 308b0c632dbSHeiko Carstens if (!vcpu->arch.sie_block) 309b0c632dbSHeiko Carstens goto out_free_cpu; 310b0c632dbSHeiko Carstens 311b0c632dbSHeiko Carstens vcpu->arch.sie_block->icpua = id; 312b0c632dbSHeiko Carstens BUG_ON(!kvm->arch.sca); 313b0c632dbSHeiko Carstens BUG_ON(kvm->arch.sca->cpu[id].sda); 314b0c632dbSHeiko Carstens kvm->arch.sca->cpu[id].sda = (__u64) vcpu->arch.sie_block; 315b0c632dbSHeiko Carstens vcpu->arch.sie_block->scaoh = (__u32)(((__u64)kvm->arch.sca) >> 32); 316b0c632dbSHeiko Carstens vcpu->arch.sie_block->scaol = (__u32)(__u64)kvm->arch.sca; 317b0c632dbSHeiko Carstens 318ba5c1e9bSCarsten Otte spin_lock_init(&vcpu->arch.local_int.lock); 319ba5c1e9bSCarsten Otte INIT_LIST_HEAD(&vcpu->arch.local_int.list); 320ba5c1e9bSCarsten Otte vcpu->arch.local_int.float_int = &kvm->arch.float_int; 321ba5c1e9bSCarsten Otte spin_lock_bh(&kvm->arch.float_int.lock); 322ba5c1e9bSCarsten Otte kvm->arch.float_int.local_int[id] = &vcpu->arch.local_int; 323ba5c1e9bSCarsten Otte init_waitqueue_head(&vcpu->arch.local_int.wq); 3245288fbf0SChristian Borntraeger vcpu->arch.local_int.cpuflags = &vcpu->arch.sie_block->cpuflags; 325ba5c1e9bSCarsten Otte spin_unlock_bh(&kvm->arch.float_int.lock); 326ba5c1e9bSCarsten Otte 327b0c632dbSHeiko Carstens rc = kvm_vcpu_init(vcpu, kvm, id); 328b0c632dbSHeiko Carstens if (rc) 329b0c632dbSHeiko Carstens goto out_free_cpu; 330b0c632dbSHeiko Carstens VM_EVENT(kvm, 3, "create cpu %d at %p, sie block at %p", id, vcpu, 331b0c632dbSHeiko Carstens vcpu->arch.sie_block); 332b0c632dbSHeiko Carstens 333b0c632dbSHeiko Carstens return vcpu; 334b0c632dbSHeiko Carstens out_free_cpu: 335b0c632dbSHeiko Carstens kfree(vcpu); 336b0c632dbSHeiko Carstens out_nomem: 337b0c632dbSHeiko Carstens return ERR_PTR(rc); 338b0c632dbSHeiko Carstens } 339b0c632dbSHeiko Carstens 340b0c632dbSHeiko Carstens int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu) 341b0c632dbSHeiko Carstens { 342b0c632dbSHeiko Carstens /* kvm common code refers to this, but never calls it */ 343b0c632dbSHeiko Carstens BUG(); 344b0c632dbSHeiko Carstens return 0; 345b0c632dbSHeiko Carstens } 346b0c632dbSHeiko Carstens 347b0c632dbSHeiko Carstens static int kvm_arch_vcpu_ioctl_initial_reset(struct kvm_vcpu *vcpu) 348b0c632dbSHeiko Carstens { 349b0c632dbSHeiko Carstens vcpu_load(vcpu); 350b0c632dbSHeiko Carstens kvm_s390_vcpu_initial_reset(vcpu); 351b0c632dbSHeiko Carstens vcpu_put(vcpu); 352b0c632dbSHeiko Carstens return 0; 353b0c632dbSHeiko Carstens } 354b0c632dbSHeiko Carstens 355b0c632dbSHeiko Carstens int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) 356b0c632dbSHeiko Carstens { 357b0c632dbSHeiko Carstens vcpu_load(vcpu); 358b0c632dbSHeiko Carstens memcpy(&vcpu->arch.guest_gprs, ®s->gprs, sizeof(regs->gprs)); 359b0c632dbSHeiko Carstens vcpu_put(vcpu); 360b0c632dbSHeiko Carstens return 0; 361b0c632dbSHeiko Carstens } 362b0c632dbSHeiko Carstens 363b0c632dbSHeiko Carstens int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs) 364b0c632dbSHeiko Carstens { 365b0c632dbSHeiko Carstens vcpu_load(vcpu); 366b0c632dbSHeiko Carstens memcpy(®s->gprs, &vcpu->arch.guest_gprs, sizeof(regs->gprs)); 367b0c632dbSHeiko Carstens vcpu_put(vcpu); 368b0c632dbSHeiko Carstens return 0; 369b0c632dbSHeiko Carstens } 370b0c632dbSHeiko Carstens 371b0c632dbSHeiko Carstens int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu, 372b0c632dbSHeiko Carstens struct kvm_sregs *sregs) 373b0c632dbSHeiko Carstens { 374b0c632dbSHeiko Carstens vcpu_load(vcpu); 375b0c632dbSHeiko Carstens memcpy(&vcpu->arch.guest_acrs, &sregs->acrs, sizeof(sregs->acrs)); 376b0c632dbSHeiko Carstens memcpy(&vcpu->arch.sie_block->gcr, &sregs->crs, sizeof(sregs->crs)); 377b0c632dbSHeiko Carstens vcpu_put(vcpu); 378b0c632dbSHeiko Carstens return 0; 379b0c632dbSHeiko Carstens } 380b0c632dbSHeiko Carstens 381b0c632dbSHeiko Carstens int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, 382b0c632dbSHeiko Carstens struct kvm_sregs *sregs) 383b0c632dbSHeiko Carstens { 384b0c632dbSHeiko Carstens vcpu_load(vcpu); 385b0c632dbSHeiko Carstens memcpy(&sregs->acrs, &vcpu->arch.guest_acrs, sizeof(sregs->acrs)); 386b0c632dbSHeiko Carstens memcpy(&sregs->crs, &vcpu->arch.sie_block->gcr, sizeof(sregs->crs)); 387b0c632dbSHeiko Carstens vcpu_put(vcpu); 388b0c632dbSHeiko Carstens return 0; 389b0c632dbSHeiko Carstens } 390b0c632dbSHeiko Carstens 391b0c632dbSHeiko Carstens int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) 392b0c632dbSHeiko Carstens { 393b0c632dbSHeiko Carstens vcpu_load(vcpu); 394b0c632dbSHeiko Carstens memcpy(&vcpu->arch.guest_fpregs.fprs, &fpu->fprs, sizeof(fpu->fprs)); 395b0c632dbSHeiko Carstens vcpu->arch.guest_fpregs.fpc = fpu->fpc; 396b0c632dbSHeiko Carstens vcpu_put(vcpu); 397b0c632dbSHeiko Carstens return 0; 398b0c632dbSHeiko Carstens } 399b0c632dbSHeiko Carstens 400b0c632dbSHeiko Carstens int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu) 401b0c632dbSHeiko Carstens { 402b0c632dbSHeiko Carstens vcpu_load(vcpu); 403b0c632dbSHeiko Carstens memcpy(&fpu->fprs, &vcpu->arch.guest_fpregs.fprs, sizeof(fpu->fprs)); 404b0c632dbSHeiko Carstens fpu->fpc = vcpu->arch.guest_fpregs.fpc; 405b0c632dbSHeiko Carstens vcpu_put(vcpu); 406b0c632dbSHeiko Carstens return 0; 407b0c632dbSHeiko Carstens } 408b0c632dbSHeiko Carstens 409b0c632dbSHeiko Carstens static int kvm_arch_vcpu_ioctl_set_initial_psw(struct kvm_vcpu *vcpu, psw_t psw) 410b0c632dbSHeiko Carstens { 411b0c632dbSHeiko Carstens int rc = 0; 412b0c632dbSHeiko Carstens 413b0c632dbSHeiko Carstens vcpu_load(vcpu); 414b0c632dbSHeiko Carstens if (atomic_read(&vcpu->arch.sie_block->cpuflags) & CPUSTAT_RUNNING) 415b0c632dbSHeiko Carstens rc = -EBUSY; 416b0c632dbSHeiko Carstens else 417b0c632dbSHeiko Carstens vcpu->arch.sie_block->gpsw = psw; 418b0c632dbSHeiko Carstens vcpu_put(vcpu); 419b0c632dbSHeiko Carstens return rc; 420b0c632dbSHeiko Carstens } 421b0c632dbSHeiko Carstens 422b0c632dbSHeiko Carstens int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu, 423b0c632dbSHeiko Carstens struct kvm_translation *tr) 424b0c632dbSHeiko Carstens { 425b0c632dbSHeiko Carstens return -EINVAL; /* not implemented yet */ 426b0c632dbSHeiko Carstens } 427b0c632dbSHeiko Carstens 428d0bfb940SJan Kiszka int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, 429d0bfb940SJan Kiszka struct kvm_guest_debug *dbg) 430b0c632dbSHeiko Carstens { 431b0c632dbSHeiko Carstens return -EINVAL; /* not implemented yet */ 432b0c632dbSHeiko Carstens } 433b0c632dbSHeiko Carstens 43462d9f0dbSMarcelo Tosatti int kvm_arch_vcpu_ioctl_get_mpstate(struct kvm_vcpu *vcpu, 43562d9f0dbSMarcelo Tosatti struct kvm_mp_state *mp_state) 43662d9f0dbSMarcelo Tosatti { 43762d9f0dbSMarcelo Tosatti return -EINVAL; /* not implemented yet */ 43862d9f0dbSMarcelo Tosatti } 43962d9f0dbSMarcelo Tosatti 44062d9f0dbSMarcelo Tosatti int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu, 44162d9f0dbSMarcelo Tosatti struct kvm_mp_state *mp_state) 44262d9f0dbSMarcelo Tosatti { 44362d9f0dbSMarcelo Tosatti return -EINVAL; /* not implemented yet */ 44462d9f0dbSMarcelo Tosatti } 44562d9f0dbSMarcelo Tosatti 446b0c632dbSHeiko Carstens static void __vcpu_run(struct kvm_vcpu *vcpu) 447b0c632dbSHeiko Carstens { 448b0c632dbSHeiko Carstens memcpy(&vcpu->arch.sie_block->gg14, &vcpu->arch.guest_gprs[14], 16); 449b0c632dbSHeiko Carstens 450b0c632dbSHeiko Carstens if (need_resched()) 451b0c632dbSHeiko Carstens schedule(); 452b0c632dbSHeiko Carstens 45371cde587SChristian Borntraeger if (test_thread_flag(TIF_MCCK_PENDING)) 45471cde587SChristian Borntraeger s390_handle_mcck(); 45571cde587SChristian Borntraeger 4560ff31867SCarsten Otte kvm_s390_deliver_pending_interrupts(vcpu); 4570ff31867SCarsten Otte 458b0c632dbSHeiko Carstens vcpu->arch.sie_block->icptcode = 0; 459b0c632dbSHeiko Carstens local_irq_disable(); 460b0c632dbSHeiko Carstens kvm_guest_enter(); 461b0c632dbSHeiko Carstens local_irq_enable(); 462b0c632dbSHeiko Carstens VCPU_EVENT(vcpu, 6, "entering sie flags %x", 463b0c632dbSHeiko Carstens atomic_read(&vcpu->arch.sie_block->cpuflags)); 4641f0d0f09SCarsten Otte if (sie64a(vcpu->arch.sie_block, vcpu->arch.guest_gprs)) { 4651f0d0f09SCarsten Otte VCPU_EVENT(vcpu, 3, "%s", "fault in sie instruction"); 4661f0d0f09SCarsten Otte kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); 4671f0d0f09SCarsten Otte } 468b0c632dbSHeiko Carstens VCPU_EVENT(vcpu, 6, "exit sie icptcode %d", 469b0c632dbSHeiko Carstens vcpu->arch.sie_block->icptcode); 470b0c632dbSHeiko Carstens local_irq_disable(); 471b0c632dbSHeiko Carstens kvm_guest_exit(); 472b0c632dbSHeiko Carstens local_irq_enable(); 473b0c632dbSHeiko Carstens 474b0c632dbSHeiko Carstens memcpy(&vcpu->arch.guest_gprs[14], &vcpu->arch.sie_block->gg14, 16); 475b0c632dbSHeiko Carstens } 476b0c632dbSHeiko Carstens 477b0c632dbSHeiko Carstens int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) 478b0c632dbSHeiko Carstens { 4798f2abe6aSChristian Borntraeger int rc; 480b0c632dbSHeiko Carstens sigset_t sigsaved; 481b0c632dbSHeiko Carstens 482b0c632dbSHeiko Carstens vcpu_load(vcpu); 483b0c632dbSHeiko Carstens 484b0c632dbSHeiko Carstens if (vcpu->sigset_active) 485b0c632dbSHeiko Carstens sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved); 486b0c632dbSHeiko Carstens 487b0c632dbSHeiko Carstens atomic_set_mask(CPUSTAT_RUNNING, &vcpu->arch.sie_block->cpuflags); 488b0c632dbSHeiko Carstens 489ba5c1e9bSCarsten Otte BUG_ON(vcpu->kvm->arch.float_int.local_int[vcpu->vcpu_id] == NULL); 490ba5c1e9bSCarsten Otte 4918f2abe6aSChristian Borntraeger switch (kvm_run->exit_reason) { 4928f2abe6aSChristian Borntraeger case KVM_EXIT_S390_SIEIC: 4938f2abe6aSChristian Borntraeger vcpu->arch.sie_block->gpsw.mask = kvm_run->s390_sieic.mask; 4948f2abe6aSChristian Borntraeger vcpu->arch.sie_block->gpsw.addr = kvm_run->s390_sieic.addr; 4958f2abe6aSChristian Borntraeger break; 4968f2abe6aSChristian Borntraeger case KVM_EXIT_UNKNOWN: 4978f2abe6aSChristian Borntraeger case KVM_EXIT_S390_RESET: 4988f2abe6aSChristian Borntraeger break; 4998f2abe6aSChristian Borntraeger default: 5008f2abe6aSChristian Borntraeger BUG(); 5018f2abe6aSChristian Borntraeger } 5028f2abe6aSChristian Borntraeger 5038f2abe6aSChristian Borntraeger might_sleep(); 5048f2abe6aSChristian Borntraeger 5058f2abe6aSChristian Borntraeger do { 506b0c632dbSHeiko Carstens __vcpu_run(vcpu); 5078f2abe6aSChristian Borntraeger rc = kvm_handle_sie_intercept(vcpu); 5088f2abe6aSChristian Borntraeger } while (!signal_pending(current) && !rc); 5098f2abe6aSChristian Borntraeger 5108f2abe6aSChristian Borntraeger if (signal_pending(current) && !rc) 5118f2abe6aSChristian Borntraeger rc = -EINTR; 5128f2abe6aSChristian Borntraeger 5138f2abe6aSChristian Borntraeger if (rc == -ENOTSUPP) { 5148f2abe6aSChristian Borntraeger /* intercept cannot be handled in-kernel, prepare kvm-run */ 5158f2abe6aSChristian Borntraeger kvm_run->exit_reason = KVM_EXIT_S390_SIEIC; 5168f2abe6aSChristian Borntraeger kvm_run->s390_sieic.icptcode = vcpu->arch.sie_block->icptcode; 5178f2abe6aSChristian Borntraeger kvm_run->s390_sieic.mask = vcpu->arch.sie_block->gpsw.mask; 5188f2abe6aSChristian Borntraeger kvm_run->s390_sieic.addr = vcpu->arch.sie_block->gpsw.addr; 5198f2abe6aSChristian Borntraeger kvm_run->s390_sieic.ipa = vcpu->arch.sie_block->ipa; 5208f2abe6aSChristian Borntraeger kvm_run->s390_sieic.ipb = vcpu->arch.sie_block->ipb; 5218f2abe6aSChristian Borntraeger rc = 0; 5228f2abe6aSChristian Borntraeger } 5238f2abe6aSChristian Borntraeger 5248f2abe6aSChristian Borntraeger if (rc == -EREMOTE) { 5258f2abe6aSChristian Borntraeger /* intercept was handled, but userspace support is needed 5268f2abe6aSChristian Borntraeger * kvm_run has been prepared by the handler */ 5278f2abe6aSChristian Borntraeger rc = 0; 5288f2abe6aSChristian Borntraeger } 5298f2abe6aSChristian Borntraeger 530b0c632dbSHeiko Carstens if (vcpu->sigset_active) 531b0c632dbSHeiko Carstens sigprocmask(SIG_SETMASK, &sigsaved, NULL); 532b0c632dbSHeiko Carstens 533b0c632dbSHeiko Carstens vcpu_put(vcpu); 534b0c632dbSHeiko Carstens 535b0c632dbSHeiko Carstens vcpu->stat.exit_userspace++; 5367e8e6ab4SHeiko Carstens return rc; 537b0c632dbSHeiko Carstens } 538b0c632dbSHeiko Carstens 539b0c632dbSHeiko Carstens static int __guestcopy(struct kvm_vcpu *vcpu, u64 guestdest, const void *from, 540b0c632dbSHeiko Carstens unsigned long n, int prefix) 541b0c632dbSHeiko Carstens { 542b0c632dbSHeiko Carstens if (prefix) 543b0c632dbSHeiko Carstens return copy_to_guest(vcpu, guestdest, from, n); 544b0c632dbSHeiko Carstens else 545b0c632dbSHeiko Carstens return copy_to_guest_absolute(vcpu, guestdest, from, n); 546b0c632dbSHeiko Carstens } 547b0c632dbSHeiko Carstens 548b0c632dbSHeiko Carstens /* 549b0c632dbSHeiko Carstens * store status at address 550b0c632dbSHeiko Carstens * we use have two special cases: 551b0c632dbSHeiko Carstens * KVM_S390_STORE_STATUS_NOADDR: -> 0x1200 on 64 bit 552b0c632dbSHeiko Carstens * KVM_S390_STORE_STATUS_PREFIXED: -> prefix 553b0c632dbSHeiko Carstens */ 554b0c632dbSHeiko Carstens int __kvm_s390_vcpu_store_status(struct kvm_vcpu *vcpu, unsigned long addr) 555b0c632dbSHeiko Carstens { 556b0c632dbSHeiko Carstens const unsigned char archmode = 1; 557b0c632dbSHeiko Carstens int prefix; 558b0c632dbSHeiko Carstens 559b0c632dbSHeiko Carstens if (addr == KVM_S390_STORE_STATUS_NOADDR) { 560b0c632dbSHeiko Carstens if (copy_to_guest_absolute(vcpu, 163ul, &archmode, 1)) 561b0c632dbSHeiko Carstens return -EFAULT; 562b0c632dbSHeiko Carstens addr = SAVE_AREA_BASE; 563b0c632dbSHeiko Carstens prefix = 0; 564b0c632dbSHeiko Carstens } else if (addr == KVM_S390_STORE_STATUS_PREFIXED) { 565b0c632dbSHeiko Carstens if (copy_to_guest(vcpu, 163ul, &archmode, 1)) 566b0c632dbSHeiko Carstens return -EFAULT; 567b0c632dbSHeiko Carstens addr = SAVE_AREA_BASE; 568b0c632dbSHeiko Carstens prefix = 1; 569b0c632dbSHeiko Carstens } else 570b0c632dbSHeiko Carstens prefix = 0; 571b0c632dbSHeiko Carstens 572b0c632dbSHeiko Carstens if (__guestcopy(vcpu, addr + offsetof(struct save_area_s390x, fp_regs), 573b0c632dbSHeiko Carstens vcpu->arch.guest_fpregs.fprs, 128, prefix)) 574b0c632dbSHeiko Carstens return -EFAULT; 575b0c632dbSHeiko Carstens 576b0c632dbSHeiko Carstens if (__guestcopy(vcpu, addr + offsetof(struct save_area_s390x, gp_regs), 577b0c632dbSHeiko Carstens vcpu->arch.guest_gprs, 128, prefix)) 578b0c632dbSHeiko Carstens return -EFAULT; 579b0c632dbSHeiko Carstens 580b0c632dbSHeiko Carstens if (__guestcopy(vcpu, addr + offsetof(struct save_area_s390x, psw), 581b0c632dbSHeiko Carstens &vcpu->arch.sie_block->gpsw, 16, prefix)) 582b0c632dbSHeiko Carstens return -EFAULT; 583b0c632dbSHeiko Carstens 584b0c632dbSHeiko Carstens if (__guestcopy(vcpu, addr + offsetof(struct save_area_s390x, pref_reg), 585b0c632dbSHeiko Carstens &vcpu->arch.sie_block->prefix, 4, prefix)) 586b0c632dbSHeiko Carstens return -EFAULT; 587b0c632dbSHeiko Carstens 588b0c632dbSHeiko Carstens if (__guestcopy(vcpu, 589b0c632dbSHeiko Carstens addr + offsetof(struct save_area_s390x, fp_ctrl_reg), 590b0c632dbSHeiko Carstens &vcpu->arch.guest_fpregs.fpc, 4, prefix)) 591b0c632dbSHeiko Carstens return -EFAULT; 592b0c632dbSHeiko Carstens 593b0c632dbSHeiko Carstens if (__guestcopy(vcpu, addr + offsetof(struct save_area_s390x, tod_reg), 594b0c632dbSHeiko Carstens &vcpu->arch.sie_block->todpr, 4, prefix)) 595b0c632dbSHeiko Carstens return -EFAULT; 596b0c632dbSHeiko Carstens 597b0c632dbSHeiko Carstens if (__guestcopy(vcpu, addr + offsetof(struct save_area_s390x, timer), 598b0c632dbSHeiko Carstens &vcpu->arch.sie_block->cputm, 8, prefix)) 599b0c632dbSHeiko Carstens return -EFAULT; 600b0c632dbSHeiko Carstens 601b0c632dbSHeiko Carstens if (__guestcopy(vcpu, addr + offsetof(struct save_area_s390x, clk_cmp), 602b0c632dbSHeiko Carstens &vcpu->arch.sie_block->ckc, 8, prefix)) 603b0c632dbSHeiko Carstens return -EFAULT; 604b0c632dbSHeiko Carstens 605b0c632dbSHeiko Carstens if (__guestcopy(vcpu, addr + offsetof(struct save_area_s390x, acc_regs), 606b0c632dbSHeiko Carstens &vcpu->arch.guest_acrs, 64, prefix)) 607b0c632dbSHeiko Carstens return -EFAULT; 608b0c632dbSHeiko Carstens 609b0c632dbSHeiko Carstens if (__guestcopy(vcpu, 610b0c632dbSHeiko Carstens addr + offsetof(struct save_area_s390x, ctrl_regs), 611b0c632dbSHeiko Carstens &vcpu->arch.sie_block->gcr, 128, prefix)) 612b0c632dbSHeiko Carstens return -EFAULT; 613b0c632dbSHeiko Carstens return 0; 614b0c632dbSHeiko Carstens } 615b0c632dbSHeiko Carstens 616b0c632dbSHeiko Carstens static int kvm_s390_vcpu_store_status(struct kvm_vcpu *vcpu, unsigned long addr) 617b0c632dbSHeiko Carstens { 618b0c632dbSHeiko Carstens int rc; 619b0c632dbSHeiko Carstens 620b0c632dbSHeiko Carstens vcpu_load(vcpu); 621b0c632dbSHeiko Carstens rc = __kvm_s390_vcpu_store_status(vcpu, addr); 622b0c632dbSHeiko Carstens vcpu_put(vcpu); 623b0c632dbSHeiko Carstens return rc; 624b0c632dbSHeiko Carstens } 625b0c632dbSHeiko Carstens 626b0c632dbSHeiko Carstens long kvm_arch_vcpu_ioctl(struct file *filp, 627b0c632dbSHeiko Carstens unsigned int ioctl, unsigned long arg) 628b0c632dbSHeiko Carstens { 629b0c632dbSHeiko Carstens struct kvm_vcpu *vcpu = filp->private_data; 630b0c632dbSHeiko Carstens void __user *argp = (void __user *)arg; 631b0c632dbSHeiko Carstens 632b0c632dbSHeiko Carstens switch (ioctl) { 633ba5c1e9bSCarsten Otte case KVM_S390_INTERRUPT: { 634ba5c1e9bSCarsten Otte struct kvm_s390_interrupt s390int; 635ba5c1e9bSCarsten Otte 636ba5c1e9bSCarsten Otte if (copy_from_user(&s390int, argp, sizeof(s390int))) 637ba5c1e9bSCarsten Otte return -EFAULT; 638ba5c1e9bSCarsten Otte return kvm_s390_inject_vcpu(vcpu, &s390int); 639ba5c1e9bSCarsten Otte } 640b0c632dbSHeiko Carstens case KVM_S390_STORE_STATUS: 641b0c632dbSHeiko Carstens return kvm_s390_vcpu_store_status(vcpu, arg); 642b0c632dbSHeiko Carstens case KVM_S390_SET_INITIAL_PSW: { 643b0c632dbSHeiko Carstens psw_t psw; 644b0c632dbSHeiko Carstens 645b0c632dbSHeiko Carstens if (copy_from_user(&psw, argp, sizeof(psw))) 646b0c632dbSHeiko Carstens return -EFAULT; 647b0c632dbSHeiko Carstens return kvm_arch_vcpu_ioctl_set_initial_psw(vcpu, psw); 648b0c632dbSHeiko Carstens } 649b0c632dbSHeiko Carstens case KVM_S390_INITIAL_RESET: 650b0c632dbSHeiko Carstens return kvm_arch_vcpu_ioctl_initial_reset(vcpu); 651b0c632dbSHeiko Carstens default: 652b0c632dbSHeiko Carstens ; 653b0c632dbSHeiko Carstens } 654b0c632dbSHeiko Carstens return -EINVAL; 655b0c632dbSHeiko Carstens } 656b0c632dbSHeiko Carstens 657b0c632dbSHeiko Carstens /* Section: memory related */ 658b0c632dbSHeiko Carstens int kvm_arch_set_memory_region(struct kvm *kvm, 659b0c632dbSHeiko Carstens struct kvm_userspace_memory_region *mem, 660b0c632dbSHeiko Carstens struct kvm_memory_slot old, 661b0c632dbSHeiko Carstens int user_alloc) 662b0c632dbSHeiko Carstens { 6632668dab7SCarsten Otte int i; 6642668dab7SCarsten Otte 665b0c632dbSHeiko Carstens /* A few sanity checks. We can have exactly one memory slot which has 666b0c632dbSHeiko Carstens to start at guest virtual zero and which has to be located at a 667b0c632dbSHeiko Carstens page boundary in userland and which has to end at a page boundary. 668b0c632dbSHeiko Carstens The memory in userland is ok to be fragmented into various different 669b0c632dbSHeiko Carstens vmas. It is okay to mmap() and munmap() stuff in this slot after 670b0c632dbSHeiko Carstens doing this call at any time */ 671b0c632dbSHeiko Carstens 6722668dab7SCarsten Otte if (mem->slot || kvm->arch.guest_memsize) 673b0c632dbSHeiko Carstens return -EINVAL; 674b0c632dbSHeiko Carstens 675b0c632dbSHeiko Carstens if (mem->guest_phys_addr) 676b0c632dbSHeiko Carstens return -EINVAL; 677b0c632dbSHeiko Carstens 678b0c632dbSHeiko Carstens if (mem->userspace_addr & (PAGE_SIZE - 1)) 679b0c632dbSHeiko Carstens return -EINVAL; 680b0c632dbSHeiko Carstens 681b0c632dbSHeiko Carstens if (mem->memory_size & (PAGE_SIZE - 1)) 682b0c632dbSHeiko Carstens return -EINVAL; 683b0c632dbSHeiko Carstens 6842668dab7SCarsten Otte if (!user_alloc) 6852668dab7SCarsten Otte return -EINVAL; 6862668dab7SCarsten Otte 6872668dab7SCarsten Otte /* lock all vcpus */ 6882668dab7SCarsten Otte for (i = 0; i < KVM_MAX_VCPUS; ++i) { 6892668dab7SCarsten Otte if (!kvm->vcpus[i]) 6902668dab7SCarsten Otte continue; 6912668dab7SCarsten Otte if (!mutex_trylock(&kvm->vcpus[i]->mutex)) 6922668dab7SCarsten Otte goto fail_out; 6932668dab7SCarsten Otte } 6942668dab7SCarsten Otte 695b0c632dbSHeiko Carstens kvm->arch.guest_origin = mem->userspace_addr; 696b0c632dbSHeiko Carstens kvm->arch.guest_memsize = mem->memory_size; 697b0c632dbSHeiko Carstens 6982668dab7SCarsten Otte /* update sie control blocks, and unlock all vcpus */ 6992668dab7SCarsten Otte for (i = 0; i < KVM_MAX_VCPUS; ++i) { 7002668dab7SCarsten Otte if (kvm->vcpus[i]) { 7012668dab7SCarsten Otte kvm->vcpus[i]->arch.sie_block->gmsor = 7022668dab7SCarsten Otte kvm->arch.guest_origin; 7032668dab7SCarsten Otte kvm->vcpus[i]->arch.sie_block->gmslm = 7042668dab7SCarsten Otte kvm->arch.guest_memsize + 7052668dab7SCarsten Otte kvm->arch.guest_origin + 7062668dab7SCarsten Otte VIRTIODESCSPACE - 1ul; 7072668dab7SCarsten Otte mutex_unlock(&kvm->vcpus[i]->mutex); 7082668dab7SCarsten Otte } 7092668dab7SCarsten Otte } 710b0c632dbSHeiko Carstens 711b0c632dbSHeiko Carstens return 0; 7122668dab7SCarsten Otte 7132668dab7SCarsten Otte fail_out: 7142668dab7SCarsten Otte for (; i >= 0; i--) 7152668dab7SCarsten Otte mutex_unlock(&kvm->vcpus[i]->mutex); 7162668dab7SCarsten Otte return -EINVAL; 717b0c632dbSHeiko Carstens } 718b0c632dbSHeiko Carstens 71934d4cb8fSMarcelo Tosatti void kvm_arch_flush_shadow(struct kvm *kvm) 72034d4cb8fSMarcelo Tosatti { 72134d4cb8fSMarcelo Tosatti } 72234d4cb8fSMarcelo Tosatti 723b0c632dbSHeiko Carstens gfn_t unalias_gfn(struct kvm *kvm, gfn_t gfn) 724b0c632dbSHeiko Carstens { 725b0c632dbSHeiko Carstens return gfn; 726b0c632dbSHeiko Carstens } 727b0c632dbSHeiko Carstens 728b0c632dbSHeiko Carstens static int __init kvm_s390_init(void) 729b0c632dbSHeiko Carstens { 730b0c632dbSHeiko Carstens return kvm_init(NULL, sizeof(struct kvm_vcpu), THIS_MODULE); 731b0c632dbSHeiko Carstens } 732b0c632dbSHeiko Carstens 733b0c632dbSHeiko Carstens static void __exit kvm_s390_exit(void) 734b0c632dbSHeiko Carstens { 735b0c632dbSHeiko Carstens kvm_exit(); 736b0c632dbSHeiko Carstens } 737b0c632dbSHeiko Carstens 738b0c632dbSHeiko Carstens module_init(kvm_s390_init); 739b0c632dbSHeiko Carstens module_exit(kvm_s390_exit); 740