blob: f5d4416ebfed89e98e4775adc3325feff49402b5 [file] [log] [blame]
Christian Borntraegere28acfe2008-03-25 18:47:34 +01001/*
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02002 * handling diagnose instructions
Christian Borntraegere28acfe2008-03-25 18:47:34 +01003 *
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02004 * Copyright IBM Corp. 2008, 2011
Christian Borntraegere28acfe2008-03-25 18:47:34 +01005 *
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>
15#include <linux/kvm_host.h>
16#include "kvm-s390.h"
Cornelia Huck5786fff2012-07-23 17:20:29 +020017#include "trace.h"
Christian Borntraegere28acfe2008-03-25 18:47:34 +010018
Christian Borntraeger388186b2011-10-30 15:17:03 +010019static int diag_release_pages(struct kvm_vcpu *vcpu)
20{
21 unsigned long start, end;
22 unsigned long prefix = vcpu->arch.sie_block->prefix;
23
Christian Borntraeger5a32c1a2012-01-11 11:20:32 +010024 start = vcpu->run->s.regs.gprs[(vcpu->arch.sie_block->ipa & 0xf0) >> 4];
25 end = vcpu->run->s.regs.gprs[vcpu->arch.sie_block->ipa & 0xf] + 4096;
Christian Borntraeger388186b2011-10-30 15:17:03 +010026
27 if (start & ~PAGE_MASK || end & ~PAGE_MASK || start > end
28 || start < 2 * PAGE_SIZE)
29 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
30
31 VCPU_EVENT(vcpu, 5, "diag release pages %lX %lX", start, end);
32 vcpu->stat.diagnose_10++;
33
34 /* we checked for start > end above */
35 if (end < prefix || start >= prefix + 2 * PAGE_SIZE) {
36 gmap_discard(start, end, vcpu->arch.gmap);
37 } else {
38 if (start < prefix)
39 gmap_discard(start, prefix, vcpu->arch.gmap);
40 if (end >= prefix)
41 gmap_discard(prefix + 2 * PAGE_SIZE,
42 end, vcpu->arch.gmap);
43 }
44 return 0;
45}
46
Christian Borntraegere28acfe2008-03-25 18:47:34 +010047static int __diag_time_slice_end(struct kvm_vcpu *vcpu)
48{
49 VCPU_EVENT(vcpu, 5, "%s", "diag time slice end");
50 vcpu->stat.diagnose_44++;
Christian Borntraeger8733ac32012-04-25 15:30:39 +020051 kvm_vcpu_on_spin(vcpu);
Christian Borntraegere28acfe2008-03-25 18:47:34 +010052 return 0;
53}
54
Konstantin Weitz41628d32012-04-25 15:30:38 +020055static int __diag_time_slice_end_directed(struct kvm_vcpu *vcpu)
56{
57 struct kvm *kvm = vcpu->kvm;
58 struct kvm_vcpu *tcpu;
59 int tid;
60 int i;
61
62 tid = vcpu->run->s.regs.gprs[(vcpu->arch.sie_block->ipa & 0xf0) >> 4];
63 vcpu->stat.diagnose_9c++;
64 VCPU_EVENT(vcpu, 5, "diag time slice end directed to %d", tid);
65
66 if (tid == vcpu->vcpu_id)
67 return 0;
68
69 kvm_for_each_vcpu(i, tcpu, kvm)
70 if (tcpu->vcpu_id == tid) {
71 kvm_vcpu_yield_to(tcpu);
72 break;
73 }
74
75 return 0;
76}
77
Christian Borntraegere28acfe2008-03-25 18:47:34 +010078static int __diag_ipl_functions(struct kvm_vcpu *vcpu)
79{
80 unsigned int reg = vcpu->arch.sie_block->ipa & 0xf;
Christian Borntraeger5a32c1a2012-01-11 11:20:32 +010081 unsigned long subcode = vcpu->run->s.regs.gprs[reg] & 0xffff;
Christian Borntraegere28acfe2008-03-25 18:47:34 +010082
83 VCPU_EVENT(vcpu, 5, "diag ipl functions, subcode %lx", subcode);
84 switch (subcode) {
85 case 3:
86 vcpu->run->s390_reset_flags = KVM_S390_RESET_CLEAR;
87 break;
88 case 4:
89 vcpu->run->s390_reset_flags = 0;
90 break;
91 default:
Heiko Carstensb8e660b2010-02-26 22:37:41 +010092 return -EOPNOTSUPP;
Christian Borntraegere28acfe2008-03-25 18:47:34 +010093 }
94
Cornelia Huck9e6dabe2011-11-17 11:00:41 +010095 atomic_set_mask(CPUSTAT_STOPPED, &vcpu->arch.sie_block->cpuflags);
Christian Borntraegere28acfe2008-03-25 18:47:34 +010096 vcpu->run->s390_reset_flags |= KVM_S390_RESET_SUBSYSTEM;
97 vcpu->run->s390_reset_flags |= KVM_S390_RESET_IPL;
98 vcpu->run->s390_reset_flags |= KVM_S390_RESET_CPU_INIT;
99 vcpu->run->exit_reason = KVM_EXIT_S390_RESET;
Heiko Carstens33e19112009-01-09 12:14:56 +0100100 VCPU_EVENT(vcpu, 3, "requesting userspace resets %llx",
Christian Borntraegere28acfe2008-03-25 18:47:34 +0100101 vcpu->run->s390_reset_flags);
102 return -EREMOTE;
103}
104
105int kvm_s390_handle_diag(struct kvm_vcpu *vcpu)
106{
107 int code = (vcpu->arch.sie_block->ipb & 0xfff0000) >> 16;
108
Cornelia Huck5786fff2012-07-23 17:20:29 +0200109 trace_kvm_s390_handle_diag(vcpu, code);
Christian Borntraegere28acfe2008-03-25 18:47:34 +0100110 switch (code) {
Christian Borntraeger388186b2011-10-30 15:17:03 +0100111 case 0x10:
112 return diag_release_pages(vcpu);
Christian Borntraegere28acfe2008-03-25 18:47:34 +0100113 case 0x44:
114 return __diag_time_slice_end(vcpu);
Konstantin Weitz41628d32012-04-25 15:30:38 +0200115 case 0x9c:
116 return __diag_time_slice_end_directed(vcpu);
Christian Borntraegere28acfe2008-03-25 18:47:34 +0100117 case 0x308:
118 return __diag_ipl_functions(vcpu);
119 default:
Heiko Carstensb8e660b2010-02-26 22:37:41 +0100120 return -EOPNOTSUPP;
Christian Borntraegere28acfe2008-03-25 18:47:34 +0100121 }
122}