2 * handling privileged instructions
4 * Copyright IBM Corp. 2008, 2013
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.
10 * Author(s): Carsten Otte <cotte@de.ibm.com>
11 * Christian Borntraeger <borntraeger@de.ibm.com>
14 #include <linux/kvm.h>
15 #include <linux/gfp.h>
16 #include <linux/errno.h>
17 #include <linux/compat.h>
18 #include <asm/asm-offsets.h>
19 #include <asm/current.h>
20 #include <asm/debug.h>
21 #include <asm/ebcdic.h>
22 #include <asm/sysinfo.h>
23 #include <asm/pgtable.h>
24 #include <asm/pgalloc.h>
26 #include <asm/ptrace.h>
27 #include <asm/compat.h>
32 static int handle_set_prefix(struct kvm_vcpu *vcpu)
38 vcpu->stat.instruction_spx++;
40 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
41 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
43 operand2 = kvm_s390_get_base_disp_s(vcpu);
45 /* must be word boundary */
47 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
50 if (get_guest(vcpu, address, (u32 __user *) operand2))
51 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
53 address = address & 0x7fffe000u;
55 /* make sure that the new value is valid memory */
56 if (copy_from_guest_absolute(vcpu, &tmp, address, 1) ||
57 (copy_from_guest_absolute(vcpu, &tmp, address + PAGE_SIZE, 1)))
58 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
60 kvm_s390_set_prefix(vcpu, address);
62 VCPU_EVENT(vcpu, 5, "setting prefix to %x", address);
63 trace_kvm_s390_handle_prefix(vcpu, 1, address);
67 static int handle_store_prefix(struct kvm_vcpu *vcpu)
72 vcpu->stat.instruction_stpx++;
74 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
75 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
77 operand2 = kvm_s390_get_base_disp_s(vcpu);
79 /* must be word boundary */
81 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
83 address = vcpu->arch.sie_block->prefix;
84 address = address & 0x7fffe000u;
87 if (put_guest(vcpu, address, (u32 __user *)operand2))
88 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
90 VCPU_EVENT(vcpu, 5, "storing prefix to %x", address);
91 trace_kvm_s390_handle_prefix(vcpu, 0, address);
95 static int handle_store_cpu_address(struct kvm_vcpu *vcpu)
99 vcpu->stat.instruction_stap++;
101 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
102 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
104 useraddr = kvm_s390_get_base_disp_s(vcpu);
107 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
109 if (put_guest(vcpu, vcpu->vcpu_id, (u16 __user *)useraddr))
110 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
112 VCPU_EVENT(vcpu, 5, "storing cpu address to %llx", useraddr);
113 trace_kvm_s390_handle_stap(vcpu, useraddr);
117 static int handle_skey(struct kvm_vcpu *vcpu)
119 vcpu->stat.instruction_storage_key++;
121 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
122 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
124 vcpu->arch.sie_block->gpsw.addr =
125 __rewind_psw(vcpu->arch.sie_block->gpsw, 4);
126 VCPU_EVENT(vcpu, 4, "%s", "retrying storage key operation");
130 static int handle_tpi(struct kvm_vcpu *vcpu)
132 struct kvm_s390_interrupt_info *inti;
136 addr = kvm_s390_get_base_disp_s(vcpu);
138 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
140 inti = kvm_s390_get_io_int(vcpu->kvm, vcpu->run->s.regs.crs[6], 0);
146 * Store the two-word I/O interruption code into the
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);
155 * Store the three-word I/O interruption code into
156 * the appropriate lowcore area.
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);
165 /* Set condition code and we're done. */
166 vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44);
167 vcpu->arch.sie_block->gpsw.mask |= (cc & 3ul) << 44;
171 static int handle_tsch(struct kvm_vcpu *vcpu)
173 struct kvm_s390_interrupt_info *inti;
175 inti = kvm_s390_get_io_int(vcpu->kvm, 0,
176 vcpu->run->s.regs.gprs[1]);
179 * Prepare exit to userspace.
180 * We indicate whether we dequeued a pending I/O interrupt
181 * so that userspace can re-inject it if the instruction gets
182 * a program check. While this may re-order the pending I/O
183 * interrupts, this is no problem since the priority is kept
186 vcpu->run->exit_reason = KVM_EXIT_S390_TSCH;
187 vcpu->run->s390_tsch.dequeued = !!inti;
189 vcpu->run->s390_tsch.subchannel_id = inti->io.subchannel_id;
190 vcpu->run->s390_tsch.subchannel_nr = inti->io.subchannel_nr;
191 vcpu->run->s390_tsch.io_int_parm = inti->io.io_int_parm;
192 vcpu->run->s390_tsch.io_int_word = inti->io.io_int_word;
194 vcpu->run->s390_tsch.ipb = vcpu->arch.sie_block->ipb;
199 static int handle_io_inst(struct kvm_vcpu *vcpu)
201 VCPU_EVENT(vcpu, 4, "%s", "I/O instruction");
203 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
204 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
206 if (vcpu->kvm->arch.css_support) {
208 * Most I/O instructions will be handled by userspace.
209 * Exceptions are tpi and the interrupt portion of tsch.
211 if (vcpu->arch.sie_block->ipa == 0xb236)
212 return handle_tpi(vcpu);
213 if (vcpu->arch.sie_block->ipa == 0xb235)
214 return handle_tsch(vcpu);
215 /* Handle in userspace. */
219 * Set condition code 3 to stop the guest from issueing channel
222 vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44);
223 vcpu->arch.sie_block->gpsw.mask |= (3 & 3ul) << 44;
228 static int handle_stfl(struct kvm_vcpu *vcpu)
232 vcpu->stat.instruction_stfl++;
234 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
235 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
237 rc = copy_to_guest(vcpu, offsetof(struct _lowcore, stfl_fac_list),
240 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
241 VCPU_EVENT(vcpu, 5, "store facility list value %x",
242 *(unsigned int *) vfacilities);
243 trace_kvm_s390_handle_stfl(vcpu, *(unsigned int *) vfacilities);
247 static void handle_new_psw(struct kvm_vcpu *vcpu)
249 /* Check whether the new psw is enabled for machine checks. */
250 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_MCHECK)
251 kvm_s390_deliver_pending_machine_checks(vcpu);
254 #define PSW_MASK_ADDR_MODE (PSW_MASK_EA | PSW_MASK_BA)
255 #define PSW_MASK_UNASSIGNED 0xb80800fe7fffffffUL
256 #define PSW_ADDR_24 0x0000000000ffffffUL
257 #define PSW_ADDR_31 0x000000007fffffffUL
259 static int is_valid_psw(psw_t *psw) {
260 if (psw->mask & PSW_MASK_UNASSIGNED)
262 if ((psw->mask & PSW_MASK_ADDR_MODE) == PSW_MASK_BA) {
263 if (psw->addr & ~PSW_ADDR_31)
266 if (!(psw->mask & PSW_MASK_ADDR_MODE) && (psw->addr & ~PSW_ADDR_24))
268 if ((psw->mask & PSW_MASK_ADDR_MODE) == PSW_MASK_EA)
273 int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu)
275 psw_t *gpsw = &vcpu->arch.sie_block->gpsw;
276 psw_compat_t new_psw;
279 if (gpsw->mask & PSW_MASK_PSTATE)
280 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
282 addr = kvm_s390_get_base_disp_s(vcpu);
284 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
285 if (copy_from_guest(vcpu, &new_psw, addr, sizeof(new_psw)))
286 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
287 if (!(new_psw.mask & PSW32_MASK_BASE))
288 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
289 gpsw->mask = (new_psw.mask & ~PSW32_MASK_BASE) << 32;
290 gpsw->mask |= new_psw.addr & PSW32_ADDR_AMODE;
291 gpsw->addr = new_psw.addr & ~PSW32_ADDR_AMODE;
292 if (!is_valid_psw(gpsw))
293 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
294 handle_new_psw(vcpu);
298 static int handle_lpswe(struct kvm_vcpu *vcpu)
303 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
304 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
306 addr = kvm_s390_get_base_disp_s(vcpu);
308 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
309 if (copy_from_guest(vcpu, &new_psw, addr, sizeof(new_psw)))
310 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
311 vcpu->arch.sie_block->gpsw = new_psw;
312 if (!is_valid_psw(&vcpu->arch.sie_block->gpsw))
313 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
314 handle_new_psw(vcpu);
318 static int handle_stidp(struct kvm_vcpu *vcpu)
322 vcpu->stat.instruction_stidp++;
324 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
325 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
327 operand2 = kvm_s390_get_base_disp_s(vcpu);
330 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
332 if (put_guest(vcpu, vcpu->arch.stidp_data, (u64 __user *)operand2))
333 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
335 VCPU_EVENT(vcpu, 5, "%s", "store cpu id");
339 static void handle_stsi_3_2_2(struct kvm_vcpu *vcpu, struct sysinfo_3_2_2 *mem)
341 struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int;
345 spin_lock(&fi->lock);
346 for (n = 0; n < KVM_MAX_VCPUS; n++)
347 if (fi->local_int[n])
349 spin_unlock(&fi->lock);
351 /* deal with other level 3 hypervisors */
352 if (stsi(mem, 3, 2, 2))
356 for (n = mem->count - 1; n > 0 ; n--)
357 memcpy(&mem->vm[n], &mem->vm[n - 1], sizeof(mem->vm[0]));
359 mem->vm[0].cpus_total = cpus;
360 mem->vm[0].cpus_configured = cpus;
361 mem->vm[0].cpus_standby = 0;
362 mem->vm[0].cpus_reserved = 0;
363 mem->vm[0].caf = 1000;
364 memcpy(mem->vm[0].name, "KVMguest", 8);
365 ASCEBC(mem->vm[0].name, 8);
366 memcpy(mem->vm[0].cpi, "KVM/Linux ", 16);
367 ASCEBC(mem->vm[0].cpi, 16);
370 static int handle_stsi(struct kvm_vcpu *vcpu)
372 int fc = (vcpu->run->s.regs.gprs[0] & 0xf0000000) >> 28;
373 int sel1 = vcpu->run->s.regs.gprs[0] & 0xff;
374 int sel2 = vcpu->run->s.regs.gprs[1] & 0xffff;
375 unsigned long mem = 0;
379 vcpu->stat.instruction_stsi++;
380 VCPU_EVENT(vcpu, 4, "stsi: fc: %x sel1: %x sel2: %x", fc, sel1, sel2);
382 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
383 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
386 vcpu->arch.sie_block->gpsw.mask |= 3ul << 44; /* cc 3 */
390 if (vcpu->run->s.regs.gprs[0] & 0x0fffff00
391 || vcpu->run->s.regs.gprs[1] & 0xffff0000)
392 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
395 vcpu->run->s.regs.gprs[0] = 3 << 28;
396 vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44); /* cc 0 */
400 operand2 = kvm_s390_get_base_disp_s(vcpu);
402 if (operand2 & 0xfff)
403 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
406 case 1: /* same handling for 1 and 2 */
408 mem = get_zeroed_page(GFP_KERNEL);
411 if (stsi((void *) mem, fc, sel1, sel2))
415 if (sel1 != 2 || sel2 != 2)
417 mem = get_zeroed_page(GFP_KERNEL);
420 handle_stsi_3_2_2(vcpu, (void *) mem);
424 if (copy_to_guest_absolute(vcpu, operand2, (void *) mem, PAGE_SIZE)) {
425 rc = kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
428 trace_kvm_s390_handle_stsi(vcpu, fc, sel1, sel2, operand2);
430 vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44);
431 vcpu->run->s.regs.gprs[0] = 0;
434 /* condition code 3 */
435 vcpu->arch.sie_block->gpsw.mask |= 3ul << 44;
441 static const intercept_handler_t b2_handlers[256] = {
442 [0x02] = handle_stidp,
443 [0x10] = handle_set_prefix,
444 [0x11] = handle_store_prefix,
445 [0x12] = handle_store_cpu_address,
446 [0x29] = handle_skey,
447 [0x2a] = handle_skey,
448 [0x2b] = handle_skey,
449 [0x30] = handle_io_inst,
450 [0x31] = handle_io_inst,
451 [0x32] = handle_io_inst,
452 [0x33] = handle_io_inst,
453 [0x34] = handle_io_inst,
454 [0x35] = handle_io_inst,
455 [0x36] = handle_io_inst,
456 [0x37] = handle_io_inst,
457 [0x38] = handle_io_inst,
458 [0x39] = handle_io_inst,
459 [0x3a] = handle_io_inst,
460 [0x3b] = handle_io_inst,
461 [0x3c] = handle_io_inst,
462 [0x5f] = handle_io_inst,
463 [0x74] = handle_io_inst,
464 [0x76] = handle_io_inst,
465 [0x7d] = handle_stsi,
466 [0xb1] = handle_stfl,
467 [0xb2] = handle_lpswe,
470 int kvm_s390_handle_b2(struct kvm_vcpu *vcpu)
472 intercept_handler_t handler;
475 * A lot of B2 instructions are priviledged. Here we check for
476 * the privileged ones, that we can handle in the kernel.
477 * Anything else goes to userspace.
479 handler = b2_handlers[vcpu->arch.sie_block->ipa & 0x00ff];
481 return handler(vcpu);
486 static int handle_epsw(struct kvm_vcpu *vcpu)
490 kvm_s390_get_regs_rre(vcpu, ®1, ®2);
492 /* This basically extracts the mask half of the psw. */
493 vcpu->run->s.regs.gprs[reg1] &= 0xffffffff00000000;
494 vcpu->run->s.regs.gprs[reg1] |= vcpu->arch.sie_block->gpsw.mask >> 32;
496 vcpu->run->s.regs.gprs[reg2] &= 0xffffffff00000000;
497 vcpu->run->s.regs.gprs[reg2] |=
498 vcpu->arch.sie_block->gpsw.mask & 0x00000000ffffffff;
503 #define PFMF_RESERVED 0xfffc0101UL
504 #define PFMF_SK 0x00020000UL
505 #define PFMF_CF 0x00010000UL
506 #define PFMF_UI 0x00008000UL
507 #define PFMF_FSC 0x00007000UL
508 #define PFMF_NQ 0x00000800UL
509 #define PFMF_MR 0x00000400UL
510 #define PFMF_MC 0x00000200UL
511 #define PFMF_KEY 0x000000feUL
513 static int handle_pfmf(struct kvm_vcpu *vcpu)
516 unsigned long start, end;
518 vcpu->stat.instruction_pfmf++;
520 kvm_s390_get_regs_rre(vcpu, ®1, ®2);
522 if (!MACHINE_HAS_PFMF)
523 return kvm_s390_inject_program_int(vcpu, PGM_OPERATION);
525 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
526 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
528 if (vcpu->run->s.regs.gprs[reg1] & PFMF_RESERVED)
529 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
531 /* Only provide non-quiescing support if the host supports it */
532 if (vcpu->run->s.regs.gprs[reg1] & PFMF_NQ &&
533 S390_lowcore.stfl_fac_list & 0x00020000)
534 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
536 /* No support for conditional-SSKE */
537 if (vcpu->run->s.regs.gprs[reg1] & (PFMF_MR | PFMF_MC))
538 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
540 start = vcpu->run->s.regs.gprs[reg2] & PAGE_MASK;
541 switch (vcpu->run->s.regs.gprs[reg1] & PFMF_FSC) {
543 end = (start + (1UL << 12)) & ~((1UL << 12) - 1);
546 end = (start + (1UL << 20)) & ~((1UL << 20) - 1);
548 /* We dont support EDAT2
550 end = (start + (1UL << 31)) & ~((1UL << 31) - 1);
553 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
555 while (start < end) {
556 unsigned long useraddr;
558 useraddr = gmap_translate(start, vcpu->arch.gmap);
559 if (IS_ERR((void *)useraddr))
560 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
562 if (vcpu->run->s.regs.gprs[reg1] & PFMF_CF) {
563 if (clear_user((void __user *)useraddr, PAGE_SIZE))
564 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
567 if (vcpu->run->s.regs.gprs[reg1] & PFMF_SK) {
568 if (set_guest_storage_key(current->mm, useraddr,
569 vcpu->run->s.regs.gprs[reg1] & PFMF_KEY,
570 vcpu->run->s.regs.gprs[reg1] & PFMF_NQ))
571 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
576 if (vcpu->run->s.regs.gprs[reg1] & PFMF_FSC)
577 vcpu->run->s.regs.gprs[reg2] = end;
581 static const intercept_handler_t b9_handlers[256] = {
582 [0x8d] = handle_epsw,
583 [0x9c] = handle_io_inst,
584 [0xaf] = handle_pfmf,
587 int kvm_s390_handle_b9(struct kvm_vcpu *vcpu)
589 intercept_handler_t handler;
591 /* This is handled just as for the B2 instructions. */
592 handler = b9_handlers[vcpu->arch.sie_block->ipa & 0x00ff];
594 return handler(vcpu);
599 int kvm_s390_handle_lctl(struct kvm_vcpu *vcpu)
601 int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4;
602 int reg3 = vcpu->arch.sie_block->ipa & 0x000f;
607 vcpu->stat.instruction_lctl++;
609 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
610 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
612 useraddr = kvm_s390_get_base_disp_rs(vcpu);
615 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
617 VCPU_EVENT(vcpu, 5, "lctl r1:%x, r3:%x, addr:%llx", reg1, reg3,
619 trace_kvm_s390_handle_lctl(vcpu, 0, reg1, reg3, useraddr);
623 rc = get_guest(vcpu, val, (u32 __user *) useraddr);
625 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
626 vcpu->arch.sie_block->gcr[reg] &= 0xffffffff00000000ul;
627 vcpu->arch.sie_block->gcr[reg] |= val;
631 reg = (reg + 1) % 16;
637 static int handle_lctlg(struct kvm_vcpu *vcpu)
639 int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4;
640 int reg3 = vcpu->arch.sie_block->ipa & 0x000f;
644 vcpu->stat.instruction_lctlg++;
646 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
647 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
649 useraddr = kvm_s390_get_base_disp_rsy(vcpu);
652 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
656 VCPU_EVENT(vcpu, 5, "lctlg r1:%x, r3:%x, addr:%llx", reg1, reg3,
658 trace_kvm_s390_handle_lctl(vcpu, 1, reg1, reg3, useraddr);
661 rc = get_guest(vcpu, vcpu->arch.sie_block->gcr[reg],
662 (u64 __user *) useraddr);
664 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
668 reg = (reg + 1) % 16;
674 static const intercept_handler_t eb_handlers[256] = {
675 [0x2f] = handle_lctlg,
676 [0x8a] = handle_io_inst,
679 int kvm_s390_handle_eb(struct kvm_vcpu *vcpu)
681 intercept_handler_t handler;
683 handler = eb_handlers[vcpu->arch.sie_block->ipb & 0xff];
685 return handler(vcpu);
689 static int handle_tprot(struct kvm_vcpu *vcpu)
691 u64 address1, address2;
692 struct vm_area_struct *vma;
693 unsigned long user_address;
695 vcpu->stat.instruction_tprot++;
697 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
698 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
700 kvm_s390_get_base_disp_sse(vcpu, &address1, &address2);
702 /* we only handle the Linux memory detection case:
705 * everything else goes to userspace. */
708 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_DAT)
711 down_read(¤t->mm->mmap_sem);
712 user_address = __gmap_translate(address1, vcpu->arch.gmap);
713 if (IS_ERR_VALUE(user_address))
715 vma = find_vma(current->mm, user_address);
718 vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44);
719 if (!(vma->vm_flags & VM_WRITE) && (vma->vm_flags & VM_READ))
720 vcpu->arch.sie_block->gpsw.mask |= (1ul << 44);
721 if (!(vma->vm_flags & VM_WRITE) && !(vma->vm_flags & VM_READ))
722 vcpu->arch.sie_block->gpsw.mask |= (2ul << 44);
724 up_read(¤t->mm->mmap_sem);
728 up_read(¤t->mm->mmap_sem);
729 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
732 int kvm_s390_handle_e5(struct kvm_vcpu *vcpu)
734 /* For e5xx... instructions we only handle TPROT */
735 if ((vcpu->arch.sie_block->ipa & 0x00ff) == 0x01)
736 return handle_tprot(vcpu);
740 static int handle_sckpf(struct kvm_vcpu *vcpu)
744 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
745 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
747 if (vcpu->run->s.regs.gprs[0] & 0x00000000ffff0000)
748 return kvm_s390_inject_program_int(vcpu,
751 value = vcpu->run->s.regs.gprs[0] & 0x000000000000ffff;
752 vcpu->arch.sie_block->todpr = value;
757 static const intercept_handler_t x01_handlers[256] = {
758 [0x07] = handle_sckpf,
761 int kvm_s390_handle_01(struct kvm_vcpu *vcpu)
763 intercept_handler_t handler;
765 handler = x01_handlers[vcpu->arch.sie_block->ipa & 0x00ff];
767 return handler(vcpu);