blob: 8ad776f8785660f9edad604feb8dba598d18de44 [file] [log] [blame]
Christian Borntraeger453423d2008-03-25 18:47:29 +01001/*
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02002 * handling privileged instructions
Christian Borntraeger453423d2008-03-25 18:47:29 +01003 *
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 Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/gfp.h>
Christian Borntraeger453423d2008-03-25 18:47:29 +010016#include <linux/errno.h>
17#include <asm/current.h>
18#include <asm/debug.h>
19#include <asm/ebcdic.h>
20#include <asm/sysinfo.h>
Cornelia Huck48a3e952012-12-20 15:32:09 +010021#include <asm/ptrace.h>
22#include <asm/compat.h>
Christian Borntraeger453423d2008-03-25 18:47:29 +010023#include "gaccess.h"
24#include "kvm-s390.h"
Cornelia Huck5786fff2012-07-23 17:20:29 +020025#include "trace.h"
Christian Borntraeger453423d2008-03-25 18:47:29 +010026
27static int handle_set_prefix(struct kvm_vcpu *vcpu)
28{
Christian Borntraeger453423d2008-03-25 18:47:29 +010029 u64 operand2;
30 u32 address = 0;
31 u8 tmp;
32
33 vcpu->stat.instruction_spx++;
34
Cornelia Huckb1c571a2012-12-20 15:32:07 +010035 operand2 = kvm_s390_get_base_disp_s(vcpu);
Christian Borntraeger453423d2008-03-25 18:47:29 +010036
37 /* must be word boundary */
38 if (operand2 & 3) {
39 kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
40 goto out;
41 }
42
43 /* get the value */
44 if (get_guest_u32(vcpu, operand2, &address)) {
45 kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
46 goto out;
47 }
48
49 address = address & 0x7fffe000u;
50
51 /* make sure that the new value is valid memory */
52 if (copy_from_guest_absolute(vcpu, &tmp, address, 1) ||
53 (copy_from_guest_absolute(vcpu, &tmp, address + PAGE_SIZE, 1))) {
54 kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
55 goto out;
56 }
57
Christian Borntraeger8d26cf72012-01-11 11:19:32 +010058 kvm_s390_set_prefix(vcpu, address);
Christian Borntraeger453423d2008-03-25 18:47:29 +010059
60 VCPU_EVENT(vcpu, 5, "setting prefix to %x", address);
Cornelia Huck5786fff2012-07-23 17:20:29 +020061 trace_kvm_s390_handle_prefix(vcpu, 1, address);
Christian Borntraeger453423d2008-03-25 18:47:29 +010062out:
63 return 0;
64}
65
66static int handle_store_prefix(struct kvm_vcpu *vcpu)
67{
Christian Borntraeger453423d2008-03-25 18:47:29 +010068 u64 operand2;
69 u32 address;
70
71 vcpu->stat.instruction_stpx++;
Cornelia Huckb1c571a2012-12-20 15:32:07 +010072
73 operand2 = kvm_s390_get_base_disp_s(vcpu);
Christian Borntraeger453423d2008-03-25 18:47:29 +010074
75 /* must be word boundary */
76 if (operand2 & 3) {
77 kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
78 goto out;
79 }
80
81 address = vcpu->arch.sie_block->prefix;
82 address = address & 0x7fffe000u;
83
84 /* get the value */
85 if (put_guest_u32(vcpu, operand2, address)) {
86 kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
87 goto out;
88 }
89
90 VCPU_EVENT(vcpu, 5, "storing prefix to %x", address);
Cornelia Huck5786fff2012-07-23 17:20:29 +020091 trace_kvm_s390_handle_prefix(vcpu, 0, address);
Christian Borntraeger453423d2008-03-25 18:47:29 +010092out:
93 return 0;
94}
95
96static int handle_store_cpu_address(struct kvm_vcpu *vcpu)
97{
Christian Borntraeger453423d2008-03-25 18:47:29 +010098 u64 useraddr;
99 int rc;
100
101 vcpu->stat.instruction_stap++;
Cornelia Huckb1c571a2012-12-20 15:32:07 +0100102
103 useraddr = kvm_s390_get_base_disp_s(vcpu);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100104
105 if (useraddr & 1) {
106 kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
107 goto out;
108 }
109
110 rc = put_guest_u16(vcpu, useraddr, vcpu->vcpu_id);
111 if (rc == -EFAULT) {
112 kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
113 goto out;
114 }
115
Heiko Carstens33e19112009-01-09 12:14:56 +0100116 VCPU_EVENT(vcpu, 5, "storing cpu address to %llx", useraddr);
Cornelia Huck5786fff2012-07-23 17:20:29 +0200117 trace_kvm_s390_handle_stap(vcpu, useraddr);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100118out:
119 return 0;
120}
121
122static int handle_skey(struct kvm_vcpu *vcpu)
123{
124 vcpu->stat.instruction_storage_key++;
125 vcpu->arch.sie_block->gpsw.addr -= 4;
126 VCPU_EVENT(vcpu, 4, "%s", "retrying storage key operation");
127 return 0;
128}
129
Cornelia Huckf379aae2012-12-20 15:32:10 +0100130static int handle_io_inst(struct kvm_vcpu *vcpu)
Christian Borntraeger453423d2008-03-25 18:47:29 +0100131{
Cornelia Huckf379aae2012-12-20 15:32:10 +0100132 VCPU_EVENT(vcpu, 4, "%s", "I/O instruction");
Christian Borntraeger453423d2008-03-25 18:47:29 +0100133 /* condition code 3 */
134 vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44);
135 vcpu->arch.sie_block->gpsw.mask |= (3 & 3ul) << 44;
136 return 0;
137}
138
Christian Borntraeger453423d2008-03-25 18:47:29 +0100139static int handle_stfl(struct kvm_vcpu *vcpu)
140{
Martin Schwidefsky14375bc2010-10-25 16:10:51 +0200141 unsigned int facility_list;
Christian Borntraeger453423d2008-03-25 18:47:29 +0100142 int rc;
143
144 vcpu->stat.instruction_stfl++;
Christian Borntraegera0046b62008-08-29 13:29:45 +0200145 /* only pass the facility bits, which we can handle */
Martin Schwidefsky14375bc2010-10-25 16:10:51 +0200146 facility_list = S390_lowcore.stfl_fac_list & 0xff00fff3;
Christian Borntraeger453423d2008-03-25 18:47:29 +0100147
148 rc = copy_to_guest(vcpu, offsetof(struct _lowcore, stfl_fac_list),
149 &facility_list, sizeof(facility_list));
150 if (rc == -EFAULT)
151 kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
Cornelia Huck5786fff2012-07-23 17:20:29 +0200152 else {
Christian Borntraeger453423d2008-03-25 18:47:29 +0100153 VCPU_EVENT(vcpu, 5, "store facility list value %x",
154 facility_list);
Cornelia Huck5786fff2012-07-23 17:20:29 +0200155 trace_kvm_s390_handle_stfl(vcpu, facility_list);
156 }
Christian Borntraeger453423d2008-03-25 18:47:29 +0100157 return 0;
158}
159
Cornelia Huck48a3e952012-12-20 15:32:09 +0100160static void handle_new_psw(struct kvm_vcpu *vcpu)
161{
162 /* Check whether the new psw is enabled for machine checks. */
163 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_MCHECK)
164 kvm_s390_deliver_pending_machine_checks(vcpu);
165}
166
167#define PSW_MASK_ADDR_MODE (PSW_MASK_EA | PSW_MASK_BA)
168#define PSW_MASK_UNASSIGNED 0xb80800fe7fffffffUL
169#define PSW_ADDR_24 0x00000000000fffffUL
170#define PSW_ADDR_31 0x000000007fffffffUL
171
172int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu)
173{
174 u64 addr;
175 psw_compat_t new_psw;
176
177 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
178 return kvm_s390_inject_program_int(vcpu,
179 PGM_PRIVILEGED_OPERATION);
180
181 addr = kvm_s390_get_base_disp_s(vcpu);
182
183 if (addr & 7) {
184 kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
185 goto out;
186 }
187
188 if (copy_from_guest(vcpu, &new_psw, addr, sizeof(new_psw))) {
189 kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
190 goto out;
191 }
192
193 if (!(new_psw.mask & PSW32_MASK_BASE)) {
194 kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
195 goto out;
196 }
197
198 vcpu->arch.sie_block->gpsw.mask =
199 (new_psw.mask & ~PSW32_MASK_BASE) << 32;
200 vcpu->arch.sie_block->gpsw.addr = new_psw.addr;
201
202 if ((vcpu->arch.sie_block->gpsw.mask & PSW_MASK_UNASSIGNED) ||
203 (!(vcpu->arch.sie_block->gpsw.mask & PSW_MASK_ADDR_MODE) &&
204 (vcpu->arch.sie_block->gpsw.addr & ~PSW_ADDR_24)) ||
205 ((vcpu->arch.sie_block->gpsw.mask & PSW_MASK_ADDR_MODE) ==
206 PSW_MASK_EA)) {
207 kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
208 goto out;
209 }
210
211 handle_new_psw(vcpu);
212out:
213 return 0;
214}
215
216static int handle_lpswe(struct kvm_vcpu *vcpu)
217{
218 u64 addr;
219 psw_t new_psw;
220
221 addr = kvm_s390_get_base_disp_s(vcpu);
222
223 if (addr & 7) {
224 kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
225 goto out;
226 }
227
228 if (copy_from_guest(vcpu, &new_psw, addr, sizeof(new_psw))) {
229 kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
230 goto out;
231 }
232
233 vcpu->arch.sie_block->gpsw.mask = new_psw.mask;
234 vcpu->arch.sie_block->gpsw.addr = new_psw.addr;
235
236 if ((vcpu->arch.sie_block->gpsw.mask & PSW_MASK_UNASSIGNED) ||
237 (((vcpu->arch.sie_block->gpsw.mask & PSW_MASK_ADDR_MODE) ==
238 PSW_MASK_BA) &&
239 (vcpu->arch.sie_block->gpsw.addr & ~PSW_ADDR_31)) ||
240 (!(vcpu->arch.sie_block->gpsw.mask & PSW_MASK_ADDR_MODE) &&
241 (vcpu->arch.sie_block->gpsw.addr & ~PSW_ADDR_24)) ||
242 ((vcpu->arch.sie_block->gpsw.mask & PSW_MASK_ADDR_MODE) ==
243 PSW_MASK_EA)) {
244 kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
245 goto out;
246 }
247
248 handle_new_psw(vcpu);
249out:
250 return 0;
251}
252
Christian Borntraeger453423d2008-03-25 18:47:29 +0100253static int handle_stidp(struct kvm_vcpu *vcpu)
254{
Christian Borntraeger453423d2008-03-25 18:47:29 +0100255 u64 operand2;
256 int rc;
257
258 vcpu->stat.instruction_stidp++;
Cornelia Huckb1c571a2012-12-20 15:32:07 +0100259
260 operand2 = kvm_s390_get_base_disp_s(vcpu);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100261
262 if (operand2 & 7) {
263 kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
264 goto out;
265 }
266
267 rc = put_guest_u64(vcpu, operand2, vcpu->arch.stidp_data);
268 if (rc == -EFAULT) {
269 kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
270 goto out;
271 }
272
273 VCPU_EVENT(vcpu, 5, "%s", "store cpu id");
274out:
275 return 0;
276}
277
278static void handle_stsi_3_2_2(struct kvm_vcpu *vcpu, struct sysinfo_3_2_2 *mem)
279{
Christian Borntraeger180c12f2008-06-27 15:05:40 +0200280 struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int;
Christian Borntraeger453423d2008-03-25 18:47:29 +0100281 int cpus = 0;
282 int n;
283
Christian Borntraegerb037a4f2009-05-12 17:21:50 +0200284 spin_lock(&fi->lock);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100285 for (n = 0; n < KVM_MAX_VCPUS; n++)
286 if (fi->local_int[n])
287 cpus++;
Christian Borntraegerb037a4f2009-05-12 17:21:50 +0200288 spin_unlock(&fi->lock);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100289
290 /* deal with other level 3 hypervisors */
Heiko Carstenscaf757c2012-09-06 14:42:13 +0200291 if (stsi(mem, 3, 2, 2))
Christian Borntraeger453423d2008-03-25 18:47:29 +0100292 mem->count = 0;
293 if (mem->count < 8)
294 mem->count++;
295 for (n = mem->count - 1; n > 0 ; n--)
296 memcpy(&mem->vm[n], &mem->vm[n - 1], sizeof(mem->vm[0]));
297
298 mem->vm[0].cpus_total = cpus;
299 mem->vm[0].cpus_configured = cpus;
300 mem->vm[0].cpus_standby = 0;
301 mem->vm[0].cpus_reserved = 0;
302 mem->vm[0].caf = 1000;
303 memcpy(mem->vm[0].name, "KVMguest", 8);
304 ASCEBC(mem->vm[0].name, 8);
305 memcpy(mem->vm[0].cpi, "KVM/Linux ", 16);
306 ASCEBC(mem->vm[0].cpi, 16);
307}
308
309static int handle_stsi(struct kvm_vcpu *vcpu)
310{
Christian Borntraeger5a32c1a2012-01-11 11:20:32 +0100311 int fc = (vcpu->run->s.regs.gprs[0] & 0xf0000000) >> 28;
312 int sel1 = vcpu->run->s.regs.gprs[0] & 0xff;
313 int sel2 = vcpu->run->s.regs.gprs[1] & 0xffff;
Christian Borntraeger453423d2008-03-25 18:47:29 +0100314 u64 operand2;
315 unsigned long mem;
316
317 vcpu->stat.instruction_stsi++;
318 VCPU_EVENT(vcpu, 4, "stsi: fc: %x sel1: %x sel2: %x", fc, sel1, sel2);
319
Cornelia Huckb1c571a2012-12-20 15:32:07 +0100320 operand2 = kvm_s390_get_base_disp_s(vcpu);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100321
322 if (operand2 & 0xfff && fc > 0)
323 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
324
325 switch (fc) {
326 case 0:
Christian Borntraeger5a32c1a2012-01-11 11:20:32 +0100327 vcpu->run->s.regs.gprs[0] = 3 << 28;
Christian Borntraeger453423d2008-03-25 18:47:29 +0100328 vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44);
329 return 0;
330 case 1: /* same handling for 1 and 2 */
331 case 2:
332 mem = get_zeroed_page(GFP_KERNEL);
333 if (!mem)
334 goto out_fail;
Heiko Carstenscaf757c2012-09-06 14:42:13 +0200335 if (stsi((void *) mem, fc, sel1, sel2))
Christian Borntraeger453423d2008-03-25 18:47:29 +0100336 goto out_mem;
337 break;
338 case 3:
339 if (sel1 != 2 || sel2 != 2)
340 goto out_fail;
341 mem = get_zeroed_page(GFP_KERNEL);
342 if (!mem)
343 goto out_fail;
344 handle_stsi_3_2_2(vcpu, (void *) mem);
345 break;
346 default:
347 goto out_fail;
348 }
349
350 if (copy_to_guest_absolute(vcpu, operand2, (void *) mem, PAGE_SIZE)) {
351 kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
352 goto out_mem;
353 }
Cornelia Huck5786fff2012-07-23 17:20:29 +0200354 trace_kvm_s390_handle_stsi(vcpu, fc, sel1, sel2, operand2);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100355 free_page(mem);
356 vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44);
Christian Borntraeger5a32c1a2012-01-11 11:20:32 +0100357 vcpu->run->s.regs.gprs[0] = 0;
Christian Borntraeger453423d2008-03-25 18:47:29 +0100358 return 0;
359out_mem:
360 free_page(mem);
361out_fail:
362 /* condition code 3 */
363 vcpu->arch.sie_block->gpsw.mask |= 3ul << 44;
364 return 0;
365}
366
Cornelia Huckf379aae2012-12-20 15:32:10 +0100367static const intercept_handler_t b2_handlers[256] = {
Christian Borntraeger453423d2008-03-25 18:47:29 +0100368 [0x02] = handle_stidp,
369 [0x10] = handle_set_prefix,
370 [0x11] = handle_store_prefix,
371 [0x12] = handle_store_cpu_address,
372 [0x29] = handle_skey,
373 [0x2a] = handle_skey,
374 [0x2b] = handle_skey,
Cornelia Huckf379aae2012-12-20 15:32:10 +0100375 [0x30] = handle_io_inst,
376 [0x31] = handle_io_inst,
377 [0x32] = handle_io_inst,
378 [0x33] = handle_io_inst,
379 [0x34] = handle_io_inst,
380 [0x35] = handle_io_inst,
381 [0x36] = handle_io_inst,
382 [0x37] = handle_io_inst,
383 [0x38] = handle_io_inst,
384 [0x39] = handle_io_inst,
385 [0x3a] = handle_io_inst,
386 [0x3b] = handle_io_inst,
387 [0x3c] = handle_io_inst,
388 [0x5f] = handle_io_inst,
389 [0x74] = handle_io_inst,
390 [0x76] = handle_io_inst,
Christian Borntraeger453423d2008-03-25 18:47:29 +0100391 [0x7d] = handle_stsi,
392 [0xb1] = handle_stfl,
Cornelia Huck48a3e952012-12-20 15:32:09 +0100393 [0xb2] = handle_lpswe,
Christian Borntraeger453423d2008-03-25 18:47:29 +0100394};
395
Christian Borntraeger70455a32009-01-22 10:28:29 +0100396int kvm_s390_handle_b2(struct kvm_vcpu *vcpu)
Christian Borntraeger453423d2008-03-25 18:47:29 +0100397{
398 intercept_handler_t handler;
399
Christian Borntraeger70455a32009-01-22 10:28:29 +0100400 /*
401 * a lot of B2 instructions are priviledged. We first check for
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300402 * the privileged ones, that we can handle in the kernel. If the
Christian Borntraeger70455a32009-01-22 10:28:29 +0100403 * kernel can handle this instruction, we check for the problem
404 * state bit and (a) handle the instruction or (b) send a code 2
405 * program check.
406 * Anything else goes to userspace.*/
Cornelia Huckf379aae2012-12-20 15:32:10 +0100407 handler = b2_handlers[vcpu->arch.sie_block->ipa & 0x00ff];
Christian Borntraeger70455a32009-01-22 10:28:29 +0100408 if (handler) {
409 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
410 return kvm_s390_inject_program_int(vcpu,
411 PGM_PRIVILEGED_OPERATION);
412 else
413 return handler(vcpu);
414 }
Heiko Carstensb8e660b2010-02-26 22:37:41 +0100415 return -EOPNOTSUPP;
Christian Borntraeger453423d2008-03-25 18:47:29 +0100416}
Christian Borntraegerbb25b9b2011-07-24 10:48:17 +0200417
Cornelia Huck48a3e952012-12-20 15:32:09 +0100418static int handle_epsw(struct kvm_vcpu *vcpu)
419{
420 int reg1, reg2;
421
422 reg1 = (vcpu->arch.sie_block->ipb & 0x00f00000) >> 24;
423 reg2 = (vcpu->arch.sie_block->ipb & 0x000f0000) >> 16;
424
425 /* This basically extracts the mask half of the psw. */
426 vcpu->run->s.regs.gprs[reg1] &= 0xffffffff00000000;
427 vcpu->run->s.regs.gprs[reg1] |= vcpu->arch.sie_block->gpsw.mask >> 32;
428 if (reg2) {
429 vcpu->run->s.regs.gprs[reg2] &= 0xffffffff00000000;
430 vcpu->run->s.regs.gprs[reg2] |=
431 vcpu->arch.sie_block->gpsw.mask & 0x00000000ffffffff;
432 }
433 return 0;
434}
435
436static const intercept_handler_t b9_handlers[256] = {
437 [0x8d] = handle_epsw,
Cornelia Huckf379aae2012-12-20 15:32:10 +0100438 [0x9c] = handle_io_inst,
Cornelia Huck48a3e952012-12-20 15:32:09 +0100439};
440
441int kvm_s390_handle_b9(struct kvm_vcpu *vcpu)
442{
443 intercept_handler_t handler;
444
445 /* This is handled just as for the B2 instructions. */
446 handler = b9_handlers[vcpu->arch.sie_block->ipa & 0x00ff];
447 if (handler) {
448 if ((handler != handle_epsw) &&
449 (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE))
450 return kvm_s390_inject_program_int(vcpu,
451 PGM_PRIVILEGED_OPERATION);
452 else
453 return handler(vcpu);
454 }
455 return -EOPNOTSUPP;
456}
457
Cornelia Huckf379aae2012-12-20 15:32:10 +0100458static const intercept_handler_t eb_handlers[256] = {
459 [0x8a] = handle_io_inst,
460};
461
462int kvm_s390_handle_priv_eb(struct kvm_vcpu *vcpu)
463{
464 intercept_handler_t handler;
465
466 /* All eb instructions that end up here are privileged. */
467 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
468 return kvm_s390_inject_program_int(vcpu,
469 PGM_PRIVILEGED_OPERATION);
470 handler = eb_handlers[vcpu->arch.sie_block->ipb & 0xff];
471 if (handler)
472 return handler(vcpu);
473 return -EOPNOTSUPP;
474}
475
Christian Borntraegerbb25b9b2011-07-24 10:48:17 +0200476static int handle_tprot(struct kvm_vcpu *vcpu)
477{
Cornelia Huckb1c571a2012-12-20 15:32:07 +0100478 u64 address1, address2;
Christian Borntraegerbb25b9b2011-07-24 10:48:17 +0200479 struct vm_area_struct *vma;
Christian Borntraeger1eddb852011-11-17 11:00:43 +0100480 unsigned long user_address;
Christian Borntraegerbb25b9b2011-07-24 10:48:17 +0200481
482 vcpu->stat.instruction_tprot++;
483
Cornelia Huckb1c571a2012-12-20 15:32:07 +0100484 kvm_s390_get_base_disp_sse(vcpu, &address1, &address2);
485
Christian Borntraegerbb25b9b2011-07-24 10:48:17 +0200486 /* we only handle the Linux memory detection case:
487 * access key == 0
488 * guest DAT == off
489 * everything else goes to userspace. */
490 if (address2 & 0xf0)
491 return -EOPNOTSUPP;
492 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_DAT)
493 return -EOPNOTSUPP;
494
495
Christian Borntraeger1eddb852011-11-17 11:00:43 +0100496 /* we must resolve the address without holding the mmap semaphore.
497 * This is ok since the userspace hypervisor is not supposed to change
498 * the mapping while the guest queries the memory. Otherwise the guest
499 * might crash or get wrong info anyway. */
500 user_address = (unsigned long) __guestaddr_to_user(vcpu, address1);
501
Christian Borntraegerbb25b9b2011-07-24 10:48:17 +0200502 down_read(&current->mm->mmap_sem);
Christian Borntraeger1eddb852011-11-17 11:00:43 +0100503 vma = find_vma(current->mm, user_address);
Christian Borntraegerbb25b9b2011-07-24 10:48:17 +0200504 if (!vma) {
505 up_read(&current->mm->mmap_sem);
506 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
507 }
508
509 vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44);
510 if (!(vma->vm_flags & VM_WRITE) && (vma->vm_flags & VM_READ))
511 vcpu->arch.sie_block->gpsw.mask |= (1ul << 44);
512 if (!(vma->vm_flags & VM_WRITE) && !(vma->vm_flags & VM_READ))
513 vcpu->arch.sie_block->gpsw.mask |= (2ul << 44);
514
515 up_read(&current->mm->mmap_sem);
516 return 0;
517}
518
519int kvm_s390_handle_e5(struct kvm_vcpu *vcpu)
520{
521 /* For e5xx... instructions we only handle TPROT */
522 if ((vcpu->arch.sie_block->ipa & 0x00ff) == 0x01)
523 return handle_tprot(vcpu);
524 return -EOPNOTSUPP;
525}
526
Cornelia Huck8c3f61e2012-04-24 09:24:44 +0200527static int handle_sckpf(struct kvm_vcpu *vcpu)
528{
529 u32 value;
530
531 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
532 return kvm_s390_inject_program_int(vcpu,
533 PGM_PRIVILEGED_OPERATION);
534
535 if (vcpu->run->s.regs.gprs[0] & 0x00000000ffff0000)
536 return kvm_s390_inject_program_int(vcpu,
537 PGM_SPECIFICATION);
538
539 value = vcpu->run->s.regs.gprs[0] & 0x000000000000ffff;
540 vcpu->arch.sie_block->todpr = value;
541
542 return 0;
543}
544
Cornelia Huck77975352012-12-20 15:32:06 +0100545static const intercept_handler_t x01_handlers[256] = {
Cornelia Huck8c3f61e2012-04-24 09:24:44 +0200546 [0x07] = handle_sckpf,
547};
548
549int kvm_s390_handle_01(struct kvm_vcpu *vcpu)
550{
551 intercept_handler_t handler;
552
553 handler = x01_handlers[vcpu->arch.sie_block->ipa & 0x00ff];
554 if (handler)
555 return handler(vcpu);
556 return -EOPNOTSUPP;
557}