Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 1 | /* |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 2 | * handling privileged instructions |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 3 | * |
Christian Borntraeger | 69d0d3a | 2013-06-12 13:54:53 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 2008, 2013 |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License (version 2 only) |
| 8 | * as published by the Free Software Foundation. |
| 9 | * |
| 10 | * Author(s): Carsten Otte <cotte@de.ibm.com> |
| 11 | * Christian Borntraeger <borntraeger@de.ibm.com> |
| 12 | */ |
| 13 | |
| 14 | #include <linux/kvm.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/gfp.h> |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 16 | #include <linux/errno.h> |
Heiko Carstens | b13b5dc | 2013-03-25 17:22:55 +0100 | [diff] [blame] | 17 | #include <linux/compat.h> |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 18 | #include <asm/asm-offsets.h> |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 19 | #include <asm/current.h> |
| 20 | #include <asm/debug.h> |
| 21 | #include <asm/ebcdic.h> |
| 22 | #include <asm/sysinfo.h> |
Christian Borntraeger | 69d0d3a | 2013-06-12 13:54:53 +0200 | [diff] [blame] | 23 | #include <asm/pgtable.h> |
| 24 | #include <asm/pgalloc.h> |
| 25 | #include <asm/io.h> |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 26 | #include <asm/ptrace.h> |
| 27 | #include <asm/compat.h> |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 28 | #include "gaccess.h" |
| 29 | #include "kvm-s390.h" |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 30 | #include "trace.h" |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 31 | |
| 32 | static int handle_set_prefix(struct kvm_vcpu *vcpu) |
| 33 | { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 34 | u64 operand2; |
| 35 | u32 address = 0; |
| 36 | u8 tmp; |
| 37 | |
| 38 | vcpu->stat.instruction_spx++; |
| 39 | |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 40 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 41 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 42 | |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 43 | operand2 = kvm_s390_get_base_disp_s(vcpu); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 44 | |
| 45 | /* must be word boundary */ |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 46 | if (operand2 & 3) |
| 47 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 48 | |
| 49 | /* get the value */ |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 50 | if (get_guest(vcpu, address, (u32 __user *) operand2)) |
| 51 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 52 | |
| 53 | address = address & 0x7fffe000u; |
| 54 | |
| 55 | /* make sure that the new value is valid memory */ |
| 56 | if (copy_from_guest_absolute(vcpu, &tmp, address, 1) || |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 57 | (copy_from_guest_absolute(vcpu, &tmp, address + PAGE_SIZE, 1))) |
| 58 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 59 | |
Christian Borntraeger | 8d26cf7 | 2012-01-11 11:19:32 +0100 | [diff] [blame] | 60 | kvm_s390_set_prefix(vcpu, address); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 61 | |
| 62 | VCPU_EVENT(vcpu, 5, "setting prefix to %x", address); |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 63 | trace_kvm_s390_handle_prefix(vcpu, 1, address); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | static int handle_store_prefix(struct kvm_vcpu *vcpu) |
| 68 | { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 69 | u64 operand2; |
| 70 | u32 address; |
| 71 | |
| 72 | vcpu->stat.instruction_stpx++; |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 73 | |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 74 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 75 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 76 | |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 77 | operand2 = kvm_s390_get_base_disp_s(vcpu); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 78 | |
| 79 | /* must be word boundary */ |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 80 | if (operand2 & 3) |
| 81 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 82 | |
| 83 | address = vcpu->arch.sie_block->prefix; |
| 84 | address = address & 0x7fffe000u; |
| 85 | |
| 86 | /* get the value */ |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 87 | if (put_guest(vcpu, address, (u32 __user *)operand2)) |
| 88 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 89 | |
| 90 | VCPU_EVENT(vcpu, 5, "storing prefix to %x", address); |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 91 | trace_kvm_s390_handle_prefix(vcpu, 0, address); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | static int handle_store_cpu_address(struct kvm_vcpu *vcpu) |
| 96 | { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 97 | u64 useraddr; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 98 | |
| 99 | vcpu->stat.instruction_stap++; |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 100 | |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 101 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 102 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 103 | |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 104 | useraddr = kvm_s390_get_base_disp_s(vcpu); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 105 | |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 106 | if (useraddr & 1) |
| 107 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 108 | |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 109 | if (put_guest(vcpu, vcpu->vcpu_id, (u16 __user *)useraddr)) |
| 110 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 111 | |
Heiko Carstens | 33e1911 | 2009-01-09 12:14:56 +0100 | [diff] [blame] | 112 | VCPU_EVENT(vcpu, 5, "storing cpu address to %llx", useraddr); |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 113 | trace_kvm_s390_handle_stap(vcpu, useraddr); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | static int handle_skey(struct kvm_vcpu *vcpu) |
| 118 | { |
| 119 | vcpu->stat.instruction_storage_key++; |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 120 | |
| 121 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 122 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 123 | |
Martin Schwidefsky | dfcf7dc | 2013-05-17 14:41:32 +0200 | [diff] [blame] | 124 | vcpu->arch.sie_block->gpsw.addr = |
| 125 | __rewind_psw(vcpu->arch.sie_block->gpsw, 4); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 126 | VCPU_EVENT(vcpu, 4, "%s", "retrying storage key operation"); |
| 127 | return 0; |
| 128 | } |
| 129 | |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 130 | static int handle_tpi(struct kvm_vcpu *vcpu) |
| 131 | { |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 132 | struct kvm_s390_interrupt_info *inti; |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 133 | u64 addr; |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 134 | int cc; |
| 135 | |
| 136 | addr = kvm_s390_get_base_disp_s(vcpu); |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 137 | if (addr & 3) |
| 138 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 139 | cc = 0; |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 140 | inti = kvm_s390_get_io_int(vcpu->kvm, vcpu->run->s.regs.crs[6], 0); |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 141 | if (!inti) |
| 142 | goto no_interrupt; |
| 143 | cc = 1; |
| 144 | if (addr) { |
| 145 | /* |
| 146 | * Store the two-word I/O interruption code into the |
| 147 | * provided area. |
| 148 | */ |
Thomas Huth | 133608f | 2013-06-20 17:22:03 +0200 | [diff] [blame] | 149 | if (put_guest(vcpu, inti->io.subchannel_id, (u16 __user *)addr) |
| 150 | || put_guest(vcpu, inti->io.subchannel_nr, (u16 __user *)(addr + 2)) |
| 151 | || put_guest(vcpu, inti->io.io_int_parm, (u32 __user *)(addr + 4))) |
| 152 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 153 | } else { |
| 154 | /* |
| 155 | * Store the three-word I/O interruption code into |
| 156 | * the appropriate lowcore area. |
| 157 | */ |
Heiko Carstens | 0a75ca2 | 2013-03-05 13:14:47 +0100 | [diff] [blame] | 158 | put_guest(vcpu, inti->io.subchannel_id, (u16 __user *) __LC_SUBCHANNEL_ID); |
| 159 | put_guest(vcpu, inti->io.subchannel_nr, (u16 __user *) __LC_SUBCHANNEL_NR); |
| 160 | put_guest(vcpu, inti->io.io_int_parm, (u32 __user *) __LC_IO_INT_PARM); |
| 161 | put_guest(vcpu, inti->io.io_int_word, (u32 __user *) __LC_IO_INT_WORD); |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 162 | } |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 163 | kfree(inti); |
Heiko Carstens | 7c959e8 | 2013-03-05 13:14:46 +0100 | [diff] [blame] | 164 | no_interrupt: |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 165 | /* Set condition code and we're done. */ |
Thomas Huth | ea828eb | 2013-07-26 15:04:06 +0200 | [diff] [blame^] | 166 | kvm_s390_set_psw_cc(vcpu, cc); |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | static int handle_tsch(struct kvm_vcpu *vcpu) |
| 171 | { |
| 172 | struct kvm_s390_interrupt_info *inti; |
| 173 | |
| 174 | inti = kvm_s390_get_io_int(vcpu->kvm, 0, |
| 175 | vcpu->run->s.regs.gprs[1]); |
| 176 | |
| 177 | /* |
| 178 | * Prepare exit to userspace. |
| 179 | * We indicate whether we dequeued a pending I/O interrupt |
| 180 | * so that userspace can re-inject it if the instruction gets |
| 181 | * a program check. While this may re-order the pending I/O |
| 182 | * interrupts, this is no problem since the priority is kept |
| 183 | * intact. |
| 184 | */ |
| 185 | vcpu->run->exit_reason = KVM_EXIT_S390_TSCH; |
| 186 | vcpu->run->s390_tsch.dequeued = !!inti; |
| 187 | if (inti) { |
| 188 | vcpu->run->s390_tsch.subchannel_id = inti->io.subchannel_id; |
| 189 | vcpu->run->s390_tsch.subchannel_nr = inti->io.subchannel_nr; |
| 190 | vcpu->run->s390_tsch.io_int_parm = inti->io.io_int_parm; |
| 191 | vcpu->run->s390_tsch.io_int_word = inti->io.io_int_word; |
| 192 | } |
| 193 | vcpu->run->s390_tsch.ipb = vcpu->arch.sie_block->ipb; |
| 194 | kfree(inti); |
| 195 | return -EREMOTE; |
| 196 | } |
| 197 | |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 198 | static int handle_io_inst(struct kvm_vcpu *vcpu) |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 199 | { |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 200 | VCPU_EVENT(vcpu, 4, "%s", "I/O instruction"); |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 201 | |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 202 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 203 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 204 | |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 205 | if (vcpu->kvm->arch.css_support) { |
| 206 | /* |
| 207 | * Most I/O instructions will be handled by userspace. |
| 208 | * Exceptions are tpi and the interrupt portion of tsch. |
| 209 | */ |
| 210 | if (vcpu->arch.sie_block->ipa == 0xb236) |
| 211 | return handle_tpi(vcpu); |
| 212 | if (vcpu->arch.sie_block->ipa == 0xb235) |
| 213 | return handle_tsch(vcpu); |
| 214 | /* Handle in userspace. */ |
| 215 | return -EOPNOTSUPP; |
| 216 | } else { |
| 217 | /* |
| 218 | * Set condition code 3 to stop the guest from issueing channel |
| 219 | * I/O instructions. |
| 220 | */ |
Thomas Huth | ea828eb | 2013-07-26 15:04:06 +0200 | [diff] [blame^] | 221 | kvm_s390_set_psw_cc(vcpu, 3); |
Cornelia Huck | fa6b7fe | 2012-12-20 15:32:12 +0100 | [diff] [blame] | 222 | return 0; |
| 223 | } |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 224 | } |
| 225 | |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 226 | static int handle_stfl(struct kvm_vcpu *vcpu) |
| 227 | { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 228 | int rc; |
| 229 | |
| 230 | vcpu->stat.instruction_stfl++; |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 231 | |
| 232 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 233 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 234 | |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 235 | rc = copy_to_guest(vcpu, offsetof(struct _lowcore, stfl_fac_list), |
Michael Mueller | 78c4b59 | 2013-07-26 15:04:04 +0200 | [diff] [blame] | 236 | vfacilities, 4); |
Heiko Carstens | dc5008b | 2013-03-05 13:14:43 +0100 | [diff] [blame] | 237 | if (rc) |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 238 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Michael Mueller | 78c4b59 | 2013-07-26 15:04:04 +0200 | [diff] [blame] | 239 | VCPU_EVENT(vcpu, 5, "store facility list value %x", |
| 240 | *(unsigned int *) vfacilities); |
| 241 | trace_kvm_s390_handle_stfl(vcpu, *(unsigned int *) vfacilities); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 242 | return 0; |
| 243 | } |
| 244 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 245 | static void handle_new_psw(struct kvm_vcpu *vcpu) |
| 246 | { |
| 247 | /* Check whether the new psw is enabled for machine checks. */ |
| 248 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_MCHECK) |
| 249 | kvm_s390_deliver_pending_machine_checks(vcpu); |
| 250 | } |
| 251 | |
| 252 | #define PSW_MASK_ADDR_MODE (PSW_MASK_EA | PSW_MASK_BA) |
| 253 | #define PSW_MASK_UNASSIGNED 0xb80800fe7fffffffUL |
Heiko Carstens | d21683e | 2013-03-25 17:22:49 +0100 | [diff] [blame] | 254 | #define PSW_ADDR_24 0x0000000000ffffffUL |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 255 | #define PSW_ADDR_31 0x000000007fffffffUL |
| 256 | |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 257 | static int is_valid_psw(psw_t *psw) { |
| 258 | if (psw->mask & PSW_MASK_UNASSIGNED) |
| 259 | return 0; |
| 260 | if ((psw->mask & PSW_MASK_ADDR_MODE) == PSW_MASK_BA) { |
| 261 | if (psw->addr & ~PSW_ADDR_31) |
| 262 | return 0; |
| 263 | } |
| 264 | if (!(psw->mask & PSW_MASK_ADDR_MODE) && (psw->addr & ~PSW_ADDR_24)) |
| 265 | return 0; |
| 266 | if ((psw->mask & PSW_MASK_ADDR_MODE) == PSW_MASK_EA) |
| 267 | return 0; |
| 268 | return 1; |
| 269 | } |
| 270 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 271 | int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu) |
| 272 | { |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 273 | psw_t *gpsw = &vcpu->arch.sie_block->gpsw; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 274 | psw_compat_t new_psw; |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 275 | u64 addr; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 276 | |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 277 | if (gpsw->mask & PSW_MASK_PSTATE) |
Thomas Huth | 208dd75 | 2013-06-20 17:21:59 +0200 | [diff] [blame] | 278 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 279 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 280 | addr = kvm_s390_get_base_disp_s(vcpu); |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 281 | if (addr & 7) |
| 282 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 283 | if (copy_from_guest(vcpu, &new_psw, addr, sizeof(new_psw))) |
| 284 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 285 | if (!(new_psw.mask & PSW32_MASK_BASE)) |
| 286 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 287 | gpsw->mask = (new_psw.mask & ~PSW32_MASK_BASE) << 32; |
| 288 | gpsw->mask |= new_psw.addr & PSW32_ADDR_AMODE; |
| 289 | gpsw->addr = new_psw.addr & ~PSW32_ADDR_AMODE; |
| 290 | if (!is_valid_psw(gpsw)) |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 291 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 292 | handle_new_psw(vcpu); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 293 | return 0; |
| 294 | } |
| 295 | |
| 296 | static int handle_lpswe(struct kvm_vcpu *vcpu) |
| 297 | { |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 298 | psw_t new_psw; |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 299 | u64 addr; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 300 | |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 301 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 302 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 303 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 304 | addr = kvm_s390_get_base_disp_s(vcpu); |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 305 | if (addr & 7) |
| 306 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 307 | if (copy_from_guest(vcpu, &new_psw, addr, sizeof(new_psw))) |
| 308 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Heiko Carstens | 3736b87 | 2013-03-25 17:22:52 +0100 | [diff] [blame] | 309 | vcpu->arch.sie_block->gpsw = new_psw; |
| 310 | if (!is_valid_psw(&vcpu->arch.sie_block->gpsw)) |
Heiko Carstens | 6fd0fcc | 2013-03-25 17:22:51 +0100 | [diff] [blame] | 311 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 312 | handle_new_psw(vcpu); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 313 | return 0; |
| 314 | } |
| 315 | |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 316 | static int handle_stidp(struct kvm_vcpu *vcpu) |
| 317 | { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 318 | u64 operand2; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 319 | |
| 320 | vcpu->stat.instruction_stidp++; |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 321 | |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 322 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 323 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 324 | |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 325 | operand2 = kvm_s390_get_base_disp_s(vcpu); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 326 | |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 327 | if (operand2 & 7) |
| 328 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 329 | |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 330 | if (put_guest(vcpu, vcpu->arch.stidp_data, (u64 __user *)operand2)) |
| 331 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 332 | |
| 333 | VCPU_EVENT(vcpu, 5, "%s", "store cpu id"); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 334 | return 0; |
| 335 | } |
| 336 | |
| 337 | static void handle_stsi_3_2_2(struct kvm_vcpu *vcpu, struct sysinfo_3_2_2 *mem) |
| 338 | { |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 339 | struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 340 | int cpus = 0; |
| 341 | int n; |
| 342 | |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 343 | spin_lock(&fi->lock); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 344 | for (n = 0; n < KVM_MAX_VCPUS; n++) |
| 345 | if (fi->local_int[n]) |
| 346 | cpus++; |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 347 | spin_unlock(&fi->lock); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 348 | |
| 349 | /* deal with other level 3 hypervisors */ |
Heiko Carstens | caf757c | 2012-09-06 14:42:13 +0200 | [diff] [blame] | 350 | if (stsi(mem, 3, 2, 2)) |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 351 | mem->count = 0; |
| 352 | if (mem->count < 8) |
| 353 | mem->count++; |
| 354 | for (n = mem->count - 1; n > 0 ; n--) |
| 355 | memcpy(&mem->vm[n], &mem->vm[n - 1], sizeof(mem->vm[0])); |
| 356 | |
| 357 | mem->vm[0].cpus_total = cpus; |
| 358 | mem->vm[0].cpus_configured = cpus; |
| 359 | mem->vm[0].cpus_standby = 0; |
| 360 | mem->vm[0].cpus_reserved = 0; |
| 361 | mem->vm[0].caf = 1000; |
| 362 | memcpy(mem->vm[0].name, "KVMguest", 8); |
| 363 | ASCEBC(mem->vm[0].name, 8); |
| 364 | memcpy(mem->vm[0].cpi, "KVM/Linux ", 16); |
| 365 | ASCEBC(mem->vm[0].cpi, 16); |
| 366 | } |
| 367 | |
| 368 | static int handle_stsi(struct kvm_vcpu *vcpu) |
| 369 | { |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 370 | int fc = (vcpu->run->s.regs.gprs[0] & 0xf0000000) >> 28; |
| 371 | int sel1 = vcpu->run->s.regs.gprs[0] & 0xff; |
| 372 | int sel2 = vcpu->run->s.regs.gprs[1] & 0xffff; |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 373 | unsigned long mem = 0; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 374 | u64 operand2; |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 375 | int rc = 0; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 376 | |
| 377 | vcpu->stat.instruction_stsi++; |
| 378 | VCPU_EVENT(vcpu, 4, "stsi: fc: %x sel1: %x sel2: %x", fc, sel1, sel2); |
| 379 | |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 380 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 381 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 382 | |
Thomas Huth | 87d41fb | 2013-06-20 17:22:05 +0200 | [diff] [blame] | 383 | if (fc > 3) { |
Thomas Huth | ea828eb | 2013-07-26 15:04:06 +0200 | [diff] [blame^] | 384 | kvm_s390_set_psw_cc(vcpu, 3); |
Thomas Huth | 87d41fb | 2013-06-20 17:22:05 +0200 | [diff] [blame] | 385 | return 0; |
| 386 | } |
| 387 | |
| 388 | if (vcpu->run->s.regs.gprs[0] & 0x0fffff00 |
| 389 | || vcpu->run->s.regs.gprs[1] & 0xffff0000) |
| 390 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 391 | |
| 392 | if (fc == 0) { |
| 393 | vcpu->run->s.regs.gprs[0] = 3 << 28; |
Thomas Huth | ea828eb | 2013-07-26 15:04:06 +0200 | [diff] [blame^] | 394 | kvm_s390_set_psw_cc(vcpu, 0); |
Thomas Huth | 87d41fb | 2013-06-20 17:22:05 +0200 | [diff] [blame] | 395 | return 0; |
| 396 | } |
| 397 | |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 398 | operand2 = kvm_s390_get_base_disp_s(vcpu); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 399 | |
Thomas Huth | 87d41fb | 2013-06-20 17:22:05 +0200 | [diff] [blame] | 400 | if (operand2 & 0xfff) |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 401 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 402 | |
| 403 | switch (fc) { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 404 | case 1: /* same handling for 1 and 2 */ |
| 405 | case 2: |
| 406 | mem = get_zeroed_page(GFP_KERNEL); |
| 407 | if (!mem) |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 408 | goto out_no_data; |
Heiko Carstens | caf757c | 2012-09-06 14:42:13 +0200 | [diff] [blame] | 409 | if (stsi((void *) mem, fc, sel1, sel2)) |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 410 | goto out_no_data; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 411 | break; |
| 412 | case 3: |
| 413 | if (sel1 != 2 || sel2 != 2) |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 414 | goto out_no_data; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 415 | mem = get_zeroed_page(GFP_KERNEL); |
| 416 | if (!mem) |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 417 | goto out_no_data; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 418 | handle_stsi_3_2_2(vcpu, (void *) mem); |
| 419 | break; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | if (copy_to_guest_absolute(vcpu, operand2, (void *) mem, PAGE_SIZE)) { |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 423 | rc = kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 424 | goto out_exception; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 425 | } |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 426 | trace_kvm_s390_handle_stsi(vcpu, fc, sel1, sel2, operand2); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 427 | free_page(mem); |
Thomas Huth | ea828eb | 2013-07-26 15:04:06 +0200 | [diff] [blame^] | 428 | kvm_s390_set_psw_cc(vcpu, 0); |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 429 | vcpu->run->s.regs.gprs[0] = 0; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 430 | return 0; |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 431 | out_no_data: |
Thomas Huth | ea828eb | 2013-07-26 15:04:06 +0200 | [diff] [blame^] | 432 | kvm_s390_set_psw_cc(vcpu, 3); |
Heiko Carstens | c51f068 | 2013-03-25 17:22:54 +0100 | [diff] [blame] | 433 | out_exception: |
| 434 | free_page(mem); |
Heiko Carstens | db4a29c | 2013-03-25 17:22:53 +0100 | [diff] [blame] | 435 | return rc; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 436 | } |
| 437 | |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 438 | static const intercept_handler_t b2_handlers[256] = { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 439 | [0x02] = handle_stidp, |
| 440 | [0x10] = handle_set_prefix, |
| 441 | [0x11] = handle_store_prefix, |
| 442 | [0x12] = handle_store_cpu_address, |
| 443 | [0x29] = handle_skey, |
| 444 | [0x2a] = handle_skey, |
| 445 | [0x2b] = handle_skey, |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 446 | [0x30] = handle_io_inst, |
| 447 | [0x31] = handle_io_inst, |
| 448 | [0x32] = handle_io_inst, |
| 449 | [0x33] = handle_io_inst, |
| 450 | [0x34] = handle_io_inst, |
| 451 | [0x35] = handle_io_inst, |
| 452 | [0x36] = handle_io_inst, |
| 453 | [0x37] = handle_io_inst, |
| 454 | [0x38] = handle_io_inst, |
| 455 | [0x39] = handle_io_inst, |
| 456 | [0x3a] = handle_io_inst, |
| 457 | [0x3b] = handle_io_inst, |
| 458 | [0x3c] = handle_io_inst, |
| 459 | [0x5f] = handle_io_inst, |
| 460 | [0x74] = handle_io_inst, |
| 461 | [0x76] = handle_io_inst, |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 462 | [0x7d] = handle_stsi, |
| 463 | [0xb1] = handle_stfl, |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 464 | [0xb2] = handle_lpswe, |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 465 | }; |
| 466 | |
Christian Borntraeger | 70455a3 | 2009-01-22 10:28:29 +0100 | [diff] [blame] | 467 | int kvm_s390_handle_b2(struct kvm_vcpu *vcpu) |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 468 | { |
| 469 | intercept_handler_t handler; |
| 470 | |
Christian Borntraeger | 70455a3 | 2009-01-22 10:28:29 +0100 | [diff] [blame] | 471 | /* |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 472 | * A lot of B2 instructions are priviledged. Here we check for |
| 473 | * the privileged ones, that we can handle in the kernel. |
| 474 | * Anything else goes to userspace. |
| 475 | */ |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 476 | handler = b2_handlers[vcpu->arch.sie_block->ipa & 0x00ff]; |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 477 | if (handler) |
| 478 | return handler(vcpu); |
| 479 | |
Heiko Carstens | b8e660b | 2010-02-26 22:37:41 +0100 | [diff] [blame] | 480 | return -EOPNOTSUPP; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 481 | } |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 482 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 483 | static int handle_epsw(struct kvm_vcpu *vcpu) |
| 484 | { |
| 485 | int reg1, reg2; |
| 486 | |
Thomas Huth | aeb87c3 | 2013-06-12 13:54:57 +0200 | [diff] [blame] | 487 | kvm_s390_get_regs_rre(vcpu, ®1, ®2); |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 488 | |
| 489 | /* This basically extracts the mask half of the psw. */ |
Thomas Huth | 843200e | 2013-07-26 15:04:05 +0200 | [diff] [blame] | 490 | vcpu->run->s.regs.gprs[reg1] &= 0xffffffff00000000UL; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 491 | vcpu->run->s.regs.gprs[reg1] |= vcpu->arch.sie_block->gpsw.mask >> 32; |
| 492 | if (reg2) { |
Thomas Huth | 843200e | 2013-07-26 15:04:05 +0200 | [diff] [blame] | 493 | vcpu->run->s.regs.gprs[reg2] &= 0xffffffff00000000UL; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 494 | vcpu->run->s.regs.gprs[reg2] |= |
Thomas Huth | 843200e | 2013-07-26 15:04:05 +0200 | [diff] [blame] | 495 | vcpu->arch.sie_block->gpsw.mask & 0x00000000ffffffffUL; |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 496 | } |
| 497 | return 0; |
| 498 | } |
| 499 | |
Christian Borntraeger | 69d0d3a | 2013-06-12 13:54:53 +0200 | [diff] [blame] | 500 | #define PFMF_RESERVED 0xfffc0101UL |
| 501 | #define PFMF_SK 0x00020000UL |
| 502 | #define PFMF_CF 0x00010000UL |
| 503 | #define PFMF_UI 0x00008000UL |
| 504 | #define PFMF_FSC 0x00007000UL |
| 505 | #define PFMF_NQ 0x00000800UL |
| 506 | #define PFMF_MR 0x00000400UL |
| 507 | #define PFMF_MC 0x00000200UL |
| 508 | #define PFMF_KEY 0x000000feUL |
| 509 | |
| 510 | static int handle_pfmf(struct kvm_vcpu *vcpu) |
| 511 | { |
| 512 | int reg1, reg2; |
| 513 | unsigned long start, end; |
| 514 | |
| 515 | vcpu->stat.instruction_pfmf++; |
| 516 | |
| 517 | kvm_s390_get_regs_rre(vcpu, ®1, ®2); |
| 518 | |
| 519 | if (!MACHINE_HAS_PFMF) |
| 520 | return kvm_s390_inject_program_int(vcpu, PGM_OPERATION); |
| 521 | |
| 522 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
Thomas Huth | 208dd75 | 2013-06-20 17:21:59 +0200 | [diff] [blame] | 523 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
Christian Borntraeger | 69d0d3a | 2013-06-12 13:54:53 +0200 | [diff] [blame] | 524 | |
| 525 | if (vcpu->run->s.regs.gprs[reg1] & PFMF_RESERVED) |
| 526 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 527 | |
| 528 | /* Only provide non-quiescing support if the host supports it */ |
| 529 | if (vcpu->run->s.regs.gprs[reg1] & PFMF_NQ && |
| 530 | S390_lowcore.stfl_fac_list & 0x00020000) |
| 531 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 532 | |
| 533 | /* No support for conditional-SSKE */ |
| 534 | if (vcpu->run->s.regs.gprs[reg1] & (PFMF_MR | PFMF_MC)) |
| 535 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 536 | |
| 537 | start = vcpu->run->s.regs.gprs[reg2] & PAGE_MASK; |
| 538 | switch (vcpu->run->s.regs.gprs[reg1] & PFMF_FSC) { |
| 539 | case 0x00000000: |
| 540 | end = (start + (1UL << 12)) & ~((1UL << 12) - 1); |
| 541 | break; |
| 542 | case 0x00001000: |
| 543 | end = (start + (1UL << 20)) & ~((1UL << 20) - 1); |
| 544 | break; |
| 545 | /* We dont support EDAT2 |
| 546 | case 0x00002000: |
| 547 | end = (start + (1UL << 31)) & ~((1UL << 31) - 1); |
| 548 | break;*/ |
| 549 | default: |
| 550 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 551 | } |
| 552 | while (start < end) { |
| 553 | unsigned long useraddr; |
| 554 | |
| 555 | useraddr = gmap_translate(start, vcpu->arch.gmap); |
| 556 | if (IS_ERR((void *)useraddr)) |
| 557 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 558 | |
| 559 | if (vcpu->run->s.regs.gprs[reg1] & PFMF_CF) { |
| 560 | if (clear_user((void __user *)useraddr, PAGE_SIZE)) |
| 561 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 562 | } |
| 563 | |
| 564 | if (vcpu->run->s.regs.gprs[reg1] & PFMF_SK) { |
| 565 | if (set_guest_storage_key(current->mm, useraddr, |
| 566 | vcpu->run->s.regs.gprs[reg1] & PFMF_KEY, |
| 567 | vcpu->run->s.regs.gprs[reg1] & PFMF_NQ)) |
| 568 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 569 | } |
| 570 | |
| 571 | start += PAGE_SIZE; |
| 572 | } |
| 573 | if (vcpu->run->s.regs.gprs[reg1] & PFMF_FSC) |
| 574 | vcpu->run->s.regs.gprs[reg2] = end; |
| 575 | return 0; |
| 576 | } |
| 577 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 578 | static const intercept_handler_t b9_handlers[256] = { |
| 579 | [0x8d] = handle_epsw, |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 580 | [0x9c] = handle_io_inst, |
Christian Borntraeger | 69d0d3a | 2013-06-12 13:54:53 +0200 | [diff] [blame] | 581 | [0xaf] = handle_pfmf, |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 582 | }; |
| 583 | |
| 584 | int kvm_s390_handle_b9(struct kvm_vcpu *vcpu) |
| 585 | { |
| 586 | intercept_handler_t handler; |
| 587 | |
| 588 | /* This is handled just as for the B2 instructions. */ |
| 589 | handler = b9_handlers[vcpu->arch.sie_block->ipa & 0x00ff]; |
Thomas Huth | 5087dfa | 2013-06-20 17:22:01 +0200 | [diff] [blame] | 590 | if (handler) |
| 591 | return handler(vcpu); |
| 592 | |
Cornelia Huck | 48a3e95 | 2012-12-20 15:32:09 +0100 | [diff] [blame] | 593 | return -EOPNOTSUPP; |
| 594 | } |
| 595 | |
Thomas Huth | 953ed88 | 2013-06-20 17:22:04 +0200 | [diff] [blame] | 596 | int kvm_s390_handle_lctl(struct kvm_vcpu *vcpu) |
| 597 | { |
| 598 | int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4; |
| 599 | int reg3 = vcpu->arch.sie_block->ipa & 0x000f; |
| 600 | u64 useraddr; |
| 601 | u32 val = 0; |
| 602 | int reg, rc; |
| 603 | |
| 604 | vcpu->stat.instruction_lctl++; |
| 605 | |
| 606 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 607 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 608 | |
| 609 | useraddr = kvm_s390_get_base_disp_rs(vcpu); |
| 610 | |
| 611 | if (useraddr & 3) |
| 612 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 613 | |
| 614 | VCPU_EVENT(vcpu, 5, "lctl r1:%x, r3:%x, addr:%llx", reg1, reg3, |
| 615 | useraddr); |
| 616 | trace_kvm_s390_handle_lctl(vcpu, 0, reg1, reg3, useraddr); |
| 617 | |
| 618 | reg = reg1; |
| 619 | do { |
| 620 | rc = get_guest(vcpu, val, (u32 __user *) useraddr); |
| 621 | if (rc) |
| 622 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 623 | vcpu->arch.sie_block->gcr[reg] &= 0xffffffff00000000ul; |
| 624 | vcpu->arch.sie_block->gcr[reg] |= val; |
| 625 | useraddr += 4; |
| 626 | if (reg == reg3) |
| 627 | break; |
| 628 | reg = (reg + 1) % 16; |
| 629 | } while (1); |
| 630 | |
| 631 | return 0; |
| 632 | } |
| 633 | |
| 634 | static int handle_lctlg(struct kvm_vcpu *vcpu) |
| 635 | { |
| 636 | int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4; |
| 637 | int reg3 = vcpu->arch.sie_block->ipa & 0x000f; |
| 638 | u64 useraddr; |
| 639 | int reg, rc; |
| 640 | |
| 641 | vcpu->stat.instruction_lctlg++; |
| 642 | |
| 643 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 644 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 645 | |
| 646 | useraddr = kvm_s390_get_base_disp_rsy(vcpu); |
| 647 | |
| 648 | if (useraddr & 7) |
| 649 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 650 | |
| 651 | reg = reg1; |
| 652 | |
| 653 | VCPU_EVENT(vcpu, 5, "lctlg r1:%x, r3:%x, addr:%llx", reg1, reg3, |
| 654 | useraddr); |
| 655 | trace_kvm_s390_handle_lctl(vcpu, 1, reg1, reg3, useraddr); |
| 656 | |
| 657 | do { |
| 658 | rc = get_guest(vcpu, vcpu->arch.sie_block->gcr[reg], |
| 659 | (u64 __user *) useraddr); |
| 660 | if (rc) |
| 661 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 662 | useraddr += 8; |
| 663 | if (reg == reg3) |
| 664 | break; |
| 665 | reg = (reg + 1) % 16; |
| 666 | } while (1); |
| 667 | |
| 668 | return 0; |
| 669 | } |
| 670 | |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 671 | static const intercept_handler_t eb_handlers[256] = { |
Thomas Huth | 953ed88 | 2013-06-20 17:22:04 +0200 | [diff] [blame] | 672 | [0x2f] = handle_lctlg, |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 673 | [0x8a] = handle_io_inst, |
| 674 | }; |
| 675 | |
Thomas Huth | 953ed88 | 2013-06-20 17:22:04 +0200 | [diff] [blame] | 676 | int kvm_s390_handle_eb(struct kvm_vcpu *vcpu) |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 677 | { |
| 678 | intercept_handler_t handler; |
| 679 | |
Cornelia Huck | f379aae | 2012-12-20 15:32:10 +0100 | [diff] [blame] | 680 | handler = eb_handlers[vcpu->arch.sie_block->ipb & 0xff]; |
| 681 | if (handler) |
| 682 | return handler(vcpu); |
| 683 | return -EOPNOTSUPP; |
| 684 | } |
| 685 | |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 686 | static int handle_tprot(struct kvm_vcpu *vcpu) |
| 687 | { |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 688 | u64 address1, address2; |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 689 | struct vm_area_struct *vma; |
Christian Borntraeger | 1eddb85 | 2011-11-17 11:00:43 +0100 | [diff] [blame] | 690 | unsigned long user_address; |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 691 | |
| 692 | vcpu->stat.instruction_tprot++; |
| 693 | |
Thomas Huth | f9f6bbc | 2013-06-20 17:22:00 +0200 | [diff] [blame] | 694 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 695 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
| 696 | |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame] | 697 | kvm_s390_get_base_disp_sse(vcpu, &address1, &address2); |
| 698 | |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 699 | /* we only handle the Linux memory detection case: |
| 700 | * access key == 0 |
| 701 | * guest DAT == off |
| 702 | * everything else goes to userspace. */ |
| 703 | if (address2 & 0xf0) |
| 704 | return -EOPNOTSUPP; |
| 705 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_DAT) |
| 706 | return -EOPNOTSUPP; |
| 707 | |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 708 | down_read(¤t->mm->mmap_sem); |
Heiko Carstens | 59a1fa2 | 2013-03-05 13:14:42 +0100 | [diff] [blame] | 709 | user_address = __gmap_translate(address1, vcpu->arch.gmap); |
| 710 | if (IS_ERR_VALUE(user_address)) |
| 711 | goto out_inject; |
Christian Borntraeger | 1eddb85 | 2011-11-17 11:00:43 +0100 | [diff] [blame] | 712 | vma = find_vma(current->mm, user_address); |
Heiko Carstens | 59a1fa2 | 2013-03-05 13:14:42 +0100 | [diff] [blame] | 713 | if (!vma) |
| 714 | goto out_inject; |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 715 | vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44); |
| 716 | if (!(vma->vm_flags & VM_WRITE) && (vma->vm_flags & VM_READ)) |
| 717 | vcpu->arch.sie_block->gpsw.mask |= (1ul << 44); |
| 718 | if (!(vma->vm_flags & VM_WRITE) && !(vma->vm_flags & VM_READ)) |
| 719 | vcpu->arch.sie_block->gpsw.mask |= (2ul << 44); |
| 720 | |
| 721 | up_read(¤t->mm->mmap_sem); |
| 722 | return 0; |
Heiko Carstens | 59a1fa2 | 2013-03-05 13:14:42 +0100 | [diff] [blame] | 723 | |
| 724 | out_inject: |
| 725 | up_read(¤t->mm->mmap_sem); |
| 726 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | int kvm_s390_handle_e5(struct kvm_vcpu *vcpu) |
| 730 | { |
| 731 | /* For e5xx... instructions we only handle TPROT */ |
| 732 | if ((vcpu->arch.sie_block->ipa & 0x00ff) == 0x01) |
| 733 | return handle_tprot(vcpu); |
| 734 | return -EOPNOTSUPP; |
| 735 | } |
| 736 | |
Cornelia Huck | 8c3f61e | 2012-04-24 09:24:44 +0200 | [diff] [blame] | 737 | static int handle_sckpf(struct kvm_vcpu *vcpu) |
| 738 | { |
| 739 | u32 value; |
| 740 | |
| 741 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
Thomas Huth | 208dd75 | 2013-06-20 17:21:59 +0200 | [diff] [blame] | 742 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
Cornelia Huck | 8c3f61e | 2012-04-24 09:24:44 +0200 | [diff] [blame] | 743 | |
| 744 | if (vcpu->run->s.regs.gprs[0] & 0x00000000ffff0000) |
| 745 | return kvm_s390_inject_program_int(vcpu, |
| 746 | PGM_SPECIFICATION); |
| 747 | |
| 748 | value = vcpu->run->s.regs.gprs[0] & 0x000000000000ffff; |
| 749 | vcpu->arch.sie_block->todpr = value; |
| 750 | |
| 751 | return 0; |
| 752 | } |
| 753 | |
Cornelia Huck | 7797535 | 2012-12-20 15:32:06 +0100 | [diff] [blame] | 754 | static const intercept_handler_t x01_handlers[256] = { |
Cornelia Huck | 8c3f61e | 2012-04-24 09:24:44 +0200 | [diff] [blame] | 755 | [0x07] = handle_sckpf, |
| 756 | }; |
| 757 | |
| 758 | int kvm_s390_handle_01(struct kvm_vcpu *vcpu) |
| 759 | { |
| 760 | intercept_handler_t handler; |
| 761 | |
| 762 | handler = x01_handlers[vcpu->arch.sie_block->ipa & 0x00ff]; |
| 763 | if (handler) |
| 764 | return handler(vcpu); |
| 765 | return -EOPNOTSUPP; |
| 766 | } |