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 | * |
| 4 | * Copyright IBM Corp. 2008 |
| 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> |
| 17 | #include <asm/current.h> |
| 18 | #include <asm/debug.h> |
| 19 | #include <asm/ebcdic.h> |
| 20 | #include <asm/sysinfo.h> |
| 21 | #include "gaccess.h" |
| 22 | #include "kvm-s390.h" |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 23 | #include "trace.h" |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 24 | |
| 25 | static int handle_set_prefix(struct kvm_vcpu *vcpu) |
| 26 | { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 27 | u64 operand2; |
| 28 | u32 address = 0; |
| 29 | u8 tmp; |
| 30 | |
| 31 | vcpu->stat.instruction_spx++; |
| 32 | |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame^] | 33 | operand2 = kvm_s390_get_base_disp_s(vcpu); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 34 | |
| 35 | /* must be word boundary */ |
| 36 | if (operand2 & 3) { |
| 37 | kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 38 | goto out; |
| 39 | } |
| 40 | |
| 41 | /* get the value */ |
| 42 | if (get_guest_u32(vcpu, operand2, &address)) { |
| 43 | kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 44 | goto out; |
| 45 | } |
| 46 | |
| 47 | address = address & 0x7fffe000u; |
| 48 | |
| 49 | /* make sure that the new value is valid memory */ |
| 50 | if (copy_from_guest_absolute(vcpu, &tmp, address, 1) || |
| 51 | (copy_from_guest_absolute(vcpu, &tmp, address + PAGE_SIZE, 1))) { |
| 52 | kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 53 | goto out; |
| 54 | } |
| 55 | |
Christian Borntraeger | 8d26cf7 | 2012-01-11 11:19:32 +0100 | [diff] [blame] | 56 | kvm_s390_set_prefix(vcpu, address); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 57 | |
| 58 | VCPU_EVENT(vcpu, 5, "setting prefix to %x", address); |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 59 | trace_kvm_s390_handle_prefix(vcpu, 1, address); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 60 | out: |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static int handle_store_prefix(struct kvm_vcpu *vcpu) |
| 65 | { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 66 | u64 operand2; |
| 67 | u32 address; |
| 68 | |
| 69 | vcpu->stat.instruction_stpx++; |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame^] | 70 | |
| 71 | operand2 = kvm_s390_get_base_disp_s(vcpu); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 72 | |
| 73 | /* must be word boundary */ |
| 74 | if (operand2 & 3) { |
| 75 | kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 76 | goto out; |
| 77 | } |
| 78 | |
| 79 | address = vcpu->arch.sie_block->prefix; |
| 80 | address = address & 0x7fffe000u; |
| 81 | |
| 82 | /* get the value */ |
| 83 | if (put_guest_u32(vcpu, operand2, address)) { |
| 84 | kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 85 | goto out; |
| 86 | } |
| 87 | |
| 88 | VCPU_EVENT(vcpu, 5, "storing prefix to %x", address); |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 89 | trace_kvm_s390_handle_prefix(vcpu, 0, address); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 90 | out: |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | static int handle_store_cpu_address(struct kvm_vcpu *vcpu) |
| 95 | { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 96 | u64 useraddr; |
| 97 | int rc; |
| 98 | |
| 99 | vcpu->stat.instruction_stap++; |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame^] | 100 | |
| 101 | useraddr = kvm_s390_get_base_disp_s(vcpu); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 102 | |
| 103 | if (useraddr & 1) { |
| 104 | kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 105 | goto out; |
| 106 | } |
| 107 | |
| 108 | rc = put_guest_u16(vcpu, useraddr, vcpu->vcpu_id); |
| 109 | if (rc == -EFAULT) { |
| 110 | kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 111 | goto out; |
| 112 | } |
| 113 | |
Heiko Carstens | 33e1911 | 2009-01-09 12:14:56 +0100 | [diff] [blame] | 114 | VCPU_EVENT(vcpu, 5, "storing cpu address to %llx", useraddr); |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 115 | trace_kvm_s390_handle_stap(vcpu, useraddr); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 116 | out: |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | static int handle_skey(struct kvm_vcpu *vcpu) |
| 121 | { |
| 122 | vcpu->stat.instruction_storage_key++; |
| 123 | vcpu->arch.sie_block->gpsw.addr -= 4; |
| 124 | VCPU_EVENT(vcpu, 4, "%s", "retrying storage key operation"); |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | static int handle_stsch(struct kvm_vcpu *vcpu) |
| 129 | { |
| 130 | vcpu->stat.instruction_stsch++; |
| 131 | VCPU_EVENT(vcpu, 4, "%s", "store subchannel - CC3"); |
| 132 | /* condition code 3 */ |
| 133 | vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44); |
| 134 | vcpu->arch.sie_block->gpsw.mask |= (3 & 3ul) << 44; |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | static int handle_chsc(struct kvm_vcpu *vcpu) |
| 139 | { |
| 140 | vcpu->stat.instruction_chsc++; |
| 141 | VCPU_EVENT(vcpu, 4, "%s", "channel subsystem call - CC3"); |
| 142 | /* condition code 3 */ |
| 143 | vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44); |
| 144 | vcpu->arch.sie_block->gpsw.mask |= (3 & 3ul) << 44; |
| 145 | return 0; |
| 146 | } |
| 147 | |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 148 | static int handle_stfl(struct kvm_vcpu *vcpu) |
| 149 | { |
Martin Schwidefsky | 14375bc | 2010-10-25 16:10:51 +0200 | [diff] [blame] | 150 | unsigned int facility_list; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 151 | int rc; |
| 152 | |
| 153 | vcpu->stat.instruction_stfl++; |
Christian Borntraeger | a0046b6 | 2008-08-29 13:29:45 +0200 | [diff] [blame] | 154 | /* only pass the facility bits, which we can handle */ |
Martin Schwidefsky | 14375bc | 2010-10-25 16:10:51 +0200 | [diff] [blame] | 155 | facility_list = S390_lowcore.stfl_fac_list & 0xff00fff3; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 156 | |
| 157 | rc = copy_to_guest(vcpu, offsetof(struct _lowcore, stfl_fac_list), |
| 158 | &facility_list, sizeof(facility_list)); |
| 159 | if (rc == -EFAULT) |
| 160 | kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 161 | else { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 162 | VCPU_EVENT(vcpu, 5, "store facility list value %x", |
| 163 | facility_list); |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 164 | trace_kvm_s390_handle_stfl(vcpu, facility_list); |
| 165 | } |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | static int handle_stidp(struct kvm_vcpu *vcpu) |
| 170 | { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 171 | u64 operand2; |
| 172 | int rc; |
| 173 | |
| 174 | vcpu->stat.instruction_stidp++; |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame^] | 175 | |
| 176 | operand2 = kvm_s390_get_base_disp_s(vcpu); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 177 | |
| 178 | if (operand2 & 7) { |
| 179 | kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 180 | goto out; |
| 181 | } |
| 182 | |
| 183 | rc = put_guest_u64(vcpu, operand2, vcpu->arch.stidp_data); |
| 184 | if (rc == -EFAULT) { |
| 185 | kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 186 | goto out; |
| 187 | } |
| 188 | |
| 189 | VCPU_EVENT(vcpu, 5, "%s", "store cpu id"); |
| 190 | out: |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | static void handle_stsi_3_2_2(struct kvm_vcpu *vcpu, struct sysinfo_3_2_2 *mem) |
| 195 | { |
Christian Borntraeger | 180c12f | 2008-06-27 15:05:40 +0200 | [diff] [blame] | 196 | struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 197 | int cpus = 0; |
| 198 | int n; |
| 199 | |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 200 | spin_lock(&fi->lock); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 201 | for (n = 0; n < KVM_MAX_VCPUS; n++) |
| 202 | if (fi->local_int[n]) |
| 203 | cpus++; |
Christian Borntraeger | b037a4f | 2009-05-12 17:21:50 +0200 | [diff] [blame] | 204 | spin_unlock(&fi->lock); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 205 | |
| 206 | /* deal with other level 3 hypervisors */ |
Heiko Carstens | caf757c | 2012-09-06 14:42:13 +0200 | [diff] [blame] | 207 | if (stsi(mem, 3, 2, 2)) |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 208 | mem->count = 0; |
| 209 | if (mem->count < 8) |
| 210 | mem->count++; |
| 211 | for (n = mem->count - 1; n > 0 ; n--) |
| 212 | memcpy(&mem->vm[n], &mem->vm[n - 1], sizeof(mem->vm[0])); |
| 213 | |
| 214 | mem->vm[0].cpus_total = cpus; |
| 215 | mem->vm[0].cpus_configured = cpus; |
| 216 | mem->vm[0].cpus_standby = 0; |
| 217 | mem->vm[0].cpus_reserved = 0; |
| 218 | mem->vm[0].caf = 1000; |
| 219 | memcpy(mem->vm[0].name, "KVMguest", 8); |
| 220 | ASCEBC(mem->vm[0].name, 8); |
| 221 | memcpy(mem->vm[0].cpi, "KVM/Linux ", 16); |
| 222 | ASCEBC(mem->vm[0].cpi, 16); |
| 223 | } |
| 224 | |
| 225 | static int handle_stsi(struct kvm_vcpu *vcpu) |
| 226 | { |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 227 | int fc = (vcpu->run->s.regs.gprs[0] & 0xf0000000) >> 28; |
| 228 | int sel1 = vcpu->run->s.regs.gprs[0] & 0xff; |
| 229 | int sel2 = vcpu->run->s.regs.gprs[1] & 0xffff; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 230 | u64 operand2; |
| 231 | unsigned long mem; |
| 232 | |
| 233 | vcpu->stat.instruction_stsi++; |
| 234 | VCPU_EVENT(vcpu, 4, "stsi: fc: %x sel1: %x sel2: %x", fc, sel1, sel2); |
| 235 | |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame^] | 236 | operand2 = kvm_s390_get_base_disp_s(vcpu); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 237 | |
| 238 | if (operand2 & 0xfff && fc > 0) |
| 239 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
| 240 | |
| 241 | switch (fc) { |
| 242 | case 0: |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 243 | vcpu->run->s.regs.gprs[0] = 3 << 28; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 244 | vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44); |
| 245 | return 0; |
| 246 | case 1: /* same handling for 1 and 2 */ |
| 247 | case 2: |
| 248 | mem = get_zeroed_page(GFP_KERNEL); |
| 249 | if (!mem) |
| 250 | goto out_fail; |
Heiko Carstens | caf757c | 2012-09-06 14:42:13 +0200 | [diff] [blame] | 251 | if (stsi((void *) mem, fc, sel1, sel2)) |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 252 | goto out_mem; |
| 253 | break; |
| 254 | case 3: |
| 255 | if (sel1 != 2 || sel2 != 2) |
| 256 | goto out_fail; |
| 257 | mem = get_zeroed_page(GFP_KERNEL); |
| 258 | if (!mem) |
| 259 | goto out_fail; |
| 260 | handle_stsi_3_2_2(vcpu, (void *) mem); |
| 261 | break; |
| 262 | default: |
| 263 | goto out_fail; |
| 264 | } |
| 265 | |
| 266 | if (copy_to_guest_absolute(vcpu, operand2, (void *) mem, PAGE_SIZE)) { |
| 267 | kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 268 | goto out_mem; |
| 269 | } |
Cornelia Huck | 5786fff | 2012-07-23 17:20:29 +0200 | [diff] [blame] | 270 | trace_kvm_s390_handle_stsi(vcpu, fc, sel1, sel2, operand2); |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 271 | free_page(mem); |
| 272 | vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44); |
Christian Borntraeger | 5a32c1a | 2012-01-11 11:20:32 +0100 | [diff] [blame] | 273 | vcpu->run->s.regs.gprs[0] = 0; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 274 | return 0; |
| 275 | out_mem: |
| 276 | free_page(mem); |
| 277 | out_fail: |
| 278 | /* condition code 3 */ |
| 279 | vcpu->arch.sie_block->gpsw.mask |= 3ul << 44; |
| 280 | return 0; |
| 281 | } |
| 282 | |
Cornelia Huck | 7797535 | 2012-12-20 15:32:06 +0100 | [diff] [blame] | 283 | static const intercept_handler_t priv_handlers[256] = { |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 284 | [0x02] = handle_stidp, |
| 285 | [0x10] = handle_set_prefix, |
| 286 | [0x11] = handle_store_prefix, |
| 287 | [0x12] = handle_store_cpu_address, |
| 288 | [0x29] = handle_skey, |
| 289 | [0x2a] = handle_skey, |
| 290 | [0x2b] = handle_skey, |
| 291 | [0x34] = handle_stsch, |
| 292 | [0x5f] = handle_chsc, |
| 293 | [0x7d] = handle_stsi, |
| 294 | [0xb1] = handle_stfl, |
| 295 | }; |
| 296 | |
Christian Borntraeger | 70455a3 | 2009-01-22 10:28:29 +0100 | [diff] [blame] | 297 | int kvm_s390_handle_b2(struct kvm_vcpu *vcpu) |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 298 | { |
| 299 | intercept_handler_t handler; |
| 300 | |
Christian Borntraeger | 70455a3 | 2009-01-22 10:28:29 +0100 | [diff] [blame] | 301 | /* |
| 302 | * a lot of B2 instructions are priviledged. We first check for |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 303 | * the privileged ones, that we can handle in the kernel. If the |
Christian Borntraeger | 70455a3 | 2009-01-22 10:28:29 +0100 | [diff] [blame] | 304 | * kernel can handle this instruction, we check for the problem |
| 305 | * state bit and (a) handle the instruction or (b) send a code 2 |
| 306 | * program check. |
| 307 | * Anything else goes to userspace.*/ |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 308 | handler = priv_handlers[vcpu->arch.sie_block->ipa & 0x00ff]; |
Christian Borntraeger | 70455a3 | 2009-01-22 10:28:29 +0100 | [diff] [blame] | 309 | if (handler) { |
| 310 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 311 | return kvm_s390_inject_program_int(vcpu, |
| 312 | PGM_PRIVILEGED_OPERATION); |
| 313 | else |
| 314 | return handler(vcpu); |
| 315 | } |
Heiko Carstens | b8e660b | 2010-02-26 22:37:41 +0100 | [diff] [blame] | 316 | return -EOPNOTSUPP; |
Christian Borntraeger | 453423d | 2008-03-25 18:47:29 +0100 | [diff] [blame] | 317 | } |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 318 | |
| 319 | static int handle_tprot(struct kvm_vcpu *vcpu) |
| 320 | { |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame^] | 321 | u64 address1, address2; |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 322 | struct vm_area_struct *vma; |
Christian Borntraeger | 1eddb85 | 2011-11-17 11:00:43 +0100 | [diff] [blame] | 323 | unsigned long user_address; |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 324 | |
| 325 | vcpu->stat.instruction_tprot++; |
| 326 | |
Cornelia Huck | b1c571a | 2012-12-20 15:32:07 +0100 | [diff] [blame^] | 327 | kvm_s390_get_base_disp_sse(vcpu, &address1, &address2); |
| 328 | |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 329 | /* we only handle the Linux memory detection case: |
| 330 | * access key == 0 |
| 331 | * guest DAT == off |
| 332 | * everything else goes to userspace. */ |
| 333 | if (address2 & 0xf0) |
| 334 | return -EOPNOTSUPP; |
| 335 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_DAT) |
| 336 | return -EOPNOTSUPP; |
| 337 | |
| 338 | |
Christian Borntraeger | 1eddb85 | 2011-11-17 11:00:43 +0100 | [diff] [blame] | 339 | /* we must resolve the address without holding the mmap semaphore. |
| 340 | * This is ok since the userspace hypervisor is not supposed to change |
| 341 | * the mapping while the guest queries the memory. Otherwise the guest |
| 342 | * might crash or get wrong info anyway. */ |
| 343 | user_address = (unsigned long) __guestaddr_to_user(vcpu, address1); |
| 344 | |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 345 | down_read(¤t->mm->mmap_sem); |
Christian Borntraeger | 1eddb85 | 2011-11-17 11:00:43 +0100 | [diff] [blame] | 346 | vma = find_vma(current->mm, user_address); |
Christian Borntraeger | bb25b9b | 2011-07-24 10:48:17 +0200 | [diff] [blame] | 347 | if (!vma) { |
| 348 | up_read(¤t->mm->mmap_sem); |
| 349 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
| 350 | } |
| 351 | |
| 352 | vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44); |
| 353 | if (!(vma->vm_flags & VM_WRITE) && (vma->vm_flags & VM_READ)) |
| 354 | vcpu->arch.sie_block->gpsw.mask |= (1ul << 44); |
| 355 | if (!(vma->vm_flags & VM_WRITE) && !(vma->vm_flags & VM_READ)) |
| 356 | vcpu->arch.sie_block->gpsw.mask |= (2ul << 44); |
| 357 | |
| 358 | up_read(¤t->mm->mmap_sem); |
| 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | int kvm_s390_handle_e5(struct kvm_vcpu *vcpu) |
| 363 | { |
| 364 | /* For e5xx... instructions we only handle TPROT */ |
| 365 | if ((vcpu->arch.sie_block->ipa & 0x00ff) == 0x01) |
| 366 | return handle_tprot(vcpu); |
| 367 | return -EOPNOTSUPP; |
| 368 | } |
| 369 | |
Cornelia Huck | 8c3f61e | 2012-04-24 09:24:44 +0200 | [diff] [blame] | 370 | static int handle_sckpf(struct kvm_vcpu *vcpu) |
| 371 | { |
| 372 | u32 value; |
| 373 | |
| 374 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
| 375 | return kvm_s390_inject_program_int(vcpu, |
| 376 | PGM_PRIVILEGED_OPERATION); |
| 377 | |
| 378 | if (vcpu->run->s.regs.gprs[0] & 0x00000000ffff0000) |
| 379 | return kvm_s390_inject_program_int(vcpu, |
| 380 | PGM_SPECIFICATION); |
| 381 | |
| 382 | value = vcpu->run->s.regs.gprs[0] & 0x000000000000ffff; |
| 383 | vcpu->arch.sie_block->todpr = value; |
| 384 | |
| 385 | return 0; |
| 386 | } |
| 387 | |
Cornelia Huck | 7797535 | 2012-12-20 15:32:06 +0100 | [diff] [blame] | 388 | static const intercept_handler_t x01_handlers[256] = { |
Cornelia Huck | 8c3f61e | 2012-04-24 09:24:44 +0200 | [diff] [blame] | 389 | [0x07] = handle_sckpf, |
| 390 | }; |
| 391 | |
| 392 | int kvm_s390_handle_01(struct kvm_vcpu *vcpu) |
| 393 | { |
| 394 | intercept_handler_t handler; |
| 395 | |
| 396 | handler = x01_handlers[vcpu->arch.sie_block->ipa & 0x00ff]; |
| 397 | if (handler) |
| 398 | return handler(vcpu); |
| 399 | return -EOPNOTSUPP; |
| 400 | } |