KVM: s390: interprocessor communication via sigp
[deliverable/linux.git] / arch / s390 / kvm / intercept.c
CommitLineData
8f2abe6a
CB
1/*
2 * intercept.c - in-kernel handling for sie intercepts
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_host.h>
15#include <linux/errno.h>
16#include <linux/pagemap.h>
17
18#include <asm/kvm_host.h>
19
20#include "kvm-s390.h"
ba5c1e9b
CO
21#include "gaccess.h"
22
23static int handle_lctg(struct kvm_vcpu *vcpu)
24{
25 int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4;
26 int reg3 = vcpu->arch.sie_block->ipa & 0x000f;
27 int base2 = vcpu->arch.sie_block->ipb >> 28;
28 int disp2 = ((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16) +
29 ((vcpu->arch.sie_block->ipb & 0xff00) << 4);
30 u64 useraddr;
31 int reg, rc;
32
33 vcpu->stat.instruction_lctg++;
34 if ((vcpu->arch.sie_block->ipb & 0xff) != 0x2f)
35 return -ENOTSUPP;
36
37 useraddr = disp2;
38 if (base2)
39 useraddr += vcpu->arch.guest_gprs[base2];
40
41 reg = reg1;
42
43 VCPU_EVENT(vcpu, 5, "lctg r1:%x, r3:%x,b2:%x,d2:%x", reg1, reg3, base2,
44 disp2);
45
46 do {
47 rc = get_guest_u64(vcpu, useraddr,
48 &vcpu->arch.sie_block->gcr[reg]);
49 if (rc == -EFAULT) {
50 kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
51 break;
52 }
53 useraddr += 8;
54 if (reg == reg3)
55 break;
56 reg = (reg + 1) % 16;
57 } while (1);
58 return 0;
59}
60
61static int handle_lctl(struct kvm_vcpu *vcpu)
62{
63 int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4;
64 int reg3 = vcpu->arch.sie_block->ipa & 0x000f;
65 int base2 = vcpu->arch.sie_block->ipb >> 28;
66 int disp2 = ((vcpu->arch.sie_block->ipb & 0x0fff0000) >> 16);
67 u64 useraddr;
68 u32 val = 0;
69 int reg, rc;
70
71 vcpu->stat.instruction_lctl++;
72
73 useraddr = disp2;
74 if (base2)
75 useraddr += vcpu->arch.guest_gprs[base2];
76
77 VCPU_EVENT(vcpu, 5, "lctl r1:%x, r3:%x,b2:%x,d2:%x", reg1, reg3, base2,
78 disp2);
79
80 reg = reg1;
81 do {
82 rc = get_guest_u32(vcpu, useraddr, &val);
83 if (rc == -EFAULT) {
84 kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
85 break;
86 }
87 vcpu->arch.sie_block->gcr[reg] &= 0xffffffff00000000ul;
88 vcpu->arch.sie_block->gcr[reg] |= val;
89 useraddr += 4;
90 if (reg == reg3)
91 break;
92 reg = (reg + 1) % 16;
93 } while (1);
94 return 0;
95}
96
97static intercept_handler_t instruction_handlers[256] = {
5288fbf0 98 [0xae] = kvm_s390_handle_sigp,
453423dc 99 [0xb2] = kvm_s390_handle_priv,
ba5c1e9b
CO
100 [0xb7] = handle_lctl,
101 [0xeb] = handle_lctg,
102};
8f2abe6a
CB
103
104static int handle_noop(struct kvm_vcpu *vcpu)
105{
106 switch (vcpu->arch.sie_block->icptcode) {
107 case 0x10:
108 vcpu->stat.exit_external_request++;
109 break;
110 case 0x14:
111 vcpu->stat.exit_external_interrupt++;
112 break;
113 default:
114 break; /* nothing */
115 }
116 return 0;
117}
118
119static int handle_stop(struct kvm_vcpu *vcpu)
120{
5288fbf0
CB
121 int rc;
122
8f2abe6a 123 vcpu->stat.exit_stop_request++;
8f2abe6a 124 atomic_clear_mask(CPUSTAT_RUNNING, &vcpu->arch.sie_block->cpuflags);
5288fbf0
CB
125 spin_lock_bh(&vcpu->arch.local_int.lock);
126 if (vcpu->arch.local_int.action_bits & ACTION_STORE_ON_STOP) {
127 vcpu->arch.local_int.action_bits &= ~ACTION_STORE_ON_STOP;
128 rc = __kvm_s390_vcpu_store_status(vcpu,
129 KVM_S390_STORE_STATUS_NOADDR);
130 if (rc >= 0)
131 rc = -ENOTSUPP;
132 }
133
134 if (vcpu->arch.local_int.action_bits & ACTION_STOP_ON_STOP) {
135 vcpu->arch.local_int.action_bits &= ~ACTION_STOP_ON_STOP;
136 VCPU_EVENT(vcpu, 3, "%s", "cpu stopped");
137 rc = -ENOTSUPP;
138 } else
139 rc = 0;
140 spin_unlock_bh(&vcpu->arch.local_int.lock);
141 return rc;
8f2abe6a
CB
142}
143
144static int handle_validity(struct kvm_vcpu *vcpu)
145{
146 int viwhy = vcpu->arch.sie_block->ipb >> 16;
147 vcpu->stat.exit_validity++;
148 if (viwhy == 0x37) {
149 fault_in_pages_writeable((char __user *)
150 vcpu->kvm->arch.guest_origin +
151 vcpu->arch.sie_block->prefix,
152 PAGE_SIZE);
153 return 0;
154 }
155 VCPU_EVENT(vcpu, 2, "unhandled validity intercept code %d",
156 viwhy);
157 return -ENOTSUPP;
158}
159
ba5c1e9b
CO
160static int handle_instruction(struct kvm_vcpu *vcpu)
161{
162 intercept_handler_t handler;
163
164 vcpu->stat.exit_instruction++;
165 handler = instruction_handlers[vcpu->arch.sie_block->ipa >> 8];
166 if (handler)
167 return handler(vcpu);
168 return -ENOTSUPP;
169}
170
171static int handle_prog(struct kvm_vcpu *vcpu)
172{
173 vcpu->stat.exit_program_interruption++;
174 return kvm_s390_inject_program_int(vcpu, vcpu->arch.sie_block->iprcc);
175}
176
177static int handle_instruction_and_prog(struct kvm_vcpu *vcpu)
178{
179 int rc, rc2;
180
181 vcpu->stat.exit_instr_and_program++;
182 rc = handle_instruction(vcpu);
183 rc2 = handle_prog(vcpu);
184
185 if (rc == -ENOTSUPP)
186 vcpu->arch.sie_block->icptcode = 0x04;
187 if (rc)
188 return rc;
189 return rc2;
190}
191
8f2abe6a
CB
192static const intercept_handler_t intercept_funcs[0x48 >> 2] = {
193 [0x00 >> 2] = handle_noop,
ba5c1e9b
CO
194 [0x04 >> 2] = handle_instruction,
195 [0x08 >> 2] = handle_prog,
196 [0x0C >> 2] = handle_instruction_and_prog,
8f2abe6a
CB
197 [0x10 >> 2] = handle_noop,
198 [0x14 >> 2] = handle_noop,
ba5c1e9b 199 [0x1C >> 2] = kvm_s390_handle_wait,
8f2abe6a
CB
200 [0x20 >> 2] = handle_validity,
201 [0x28 >> 2] = handle_stop,
202};
203
204int kvm_handle_sie_intercept(struct kvm_vcpu *vcpu)
205{
206 intercept_handler_t func;
207 u8 code = vcpu->arch.sie_block->icptcode;
208
209 if (code & 3 || code > 0x48)
210 return -ENOTSUPP;
211 func = intercept_funcs[code >> 2];
212 if (func)
213 return func(vcpu);
214 return -ENOTSUPP;
215}
This page took 0.032358 seconds and 5 git commands to generate.