Commit | Line | Data |
---|---|---|
453423dc | 1 | /* |
a53c8fab | 2 | * handling privileged instructions |
453423dc | 3 | * |
69d0d3a3 | 4 | * Copyright IBM Corp. 2008, 2013 |
453423dc CB |
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> | |
5a0e3ad6 | 15 | #include <linux/gfp.h> |
453423dc | 16 | #include <linux/errno.h> |
b13b5dc7 | 17 | #include <linux/compat.h> |
7c959e82 | 18 | #include <asm/asm-offsets.h> |
e769ece3 | 19 | #include <asm/facility.h> |
453423dc CB |
20 | #include <asm/current.h> |
21 | #include <asm/debug.h> | |
22 | #include <asm/ebcdic.h> | |
23 | #include <asm/sysinfo.h> | |
69d0d3a3 CB |
24 | #include <asm/pgtable.h> |
25 | #include <asm/pgalloc.h> | |
26 | #include <asm/io.h> | |
48a3e950 CH |
27 | #include <asm/ptrace.h> |
28 | #include <asm/compat.h> | |
453423dc CB |
29 | #include "gaccess.h" |
30 | #include "kvm-s390.h" | |
5786fffa | 31 | #include "trace.h" |
453423dc | 32 | |
6a3f95a6 TH |
33 | /* Handle SCK (SET CLOCK) interception */ |
34 | static int handle_set_clock(struct kvm_vcpu *vcpu) | |
35 | { | |
36 | struct kvm_vcpu *cpup; | |
37 | s64 hostclk, val; | |
0e7a3f94 | 38 | int i, rc; |
6a3f95a6 | 39 | u64 op2; |
6a3f95a6 TH |
40 | |
41 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) | |
42 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); | |
43 | ||
44 | op2 = kvm_s390_get_base_disp_s(vcpu); | |
45 | if (op2 & 7) /* Operand must be on a doubleword boundary */ | |
46 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); | |
0e7a3f94 HC |
47 | rc = read_guest(vcpu, op2, &val, sizeof(val)); |
48 | if (rc) | |
49 | return kvm_s390_inject_prog_cond(vcpu, rc); | |
6a3f95a6 TH |
50 | |
51 | if (store_tod_clock(&hostclk)) { | |
52 | kvm_s390_set_psw_cc(vcpu, 3); | |
53 | return 0; | |
54 | } | |
55 | val = (val - hostclk) & ~0x3fUL; | |
56 | ||
57 | mutex_lock(&vcpu->kvm->lock); | |
58 | kvm_for_each_vcpu(i, cpup, vcpu->kvm) | |
59 | cpup->arch.sie_block->epoch = val; | |
60 | mutex_unlock(&vcpu->kvm->lock); | |
61 | ||
62 | kvm_s390_set_psw_cc(vcpu, 0); | |
63 | return 0; | |
64 | } | |
65 | ||
453423dc CB |
66 | static int handle_set_prefix(struct kvm_vcpu *vcpu) |
67 | { | |
453423dc | 68 | u64 operand2; |
665170cb HC |
69 | u32 address; |
70 | int rc; | |
453423dc CB |
71 | |
72 | vcpu->stat.instruction_spx++; | |
73 | ||
5087dfa6 TH |
74 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
75 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); | |
76 | ||
b1c571a5 | 77 | operand2 = kvm_s390_get_base_disp_s(vcpu); |
453423dc CB |
78 | |
79 | /* must be word boundary */ | |
db4a29cb HC |
80 | if (operand2 & 3) |
81 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); | |
453423dc CB |
82 | |
83 | /* get the value */ | |
665170cb HC |
84 | rc = read_guest(vcpu, operand2, &address, sizeof(address)); |
85 | if (rc) | |
86 | return kvm_s390_inject_prog_cond(vcpu, rc); | |
87 | ||
88 | address &= 0x7fffe000u; | |
89 | ||
90 | /* | |
91 | * Make sure the new value is valid memory. We only need to check the | |
92 | * first page, since address is 8k aligned and memory pieces are always | |
93 | * at least 1MB aligned and have at least a size of 1MB. | |
94 | */ | |
95 | if (kvm_is_error_gpa(vcpu->kvm, address)) | |
db4a29cb | 96 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
453423dc | 97 | |
8d26cf7b | 98 | kvm_s390_set_prefix(vcpu, address); |
453423dc CB |
99 | |
100 | VCPU_EVENT(vcpu, 5, "setting prefix to %x", address); | |
5786fffa | 101 | trace_kvm_s390_handle_prefix(vcpu, 1, address); |
453423dc CB |
102 | return 0; |
103 | } | |
104 | ||
105 | static int handle_store_prefix(struct kvm_vcpu *vcpu) | |
106 | { | |
453423dc CB |
107 | u64 operand2; |
108 | u32 address; | |
f748f4a7 | 109 | int rc; |
453423dc CB |
110 | |
111 | vcpu->stat.instruction_stpx++; | |
b1c571a5 | 112 | |
5087dfa6 TH |
113 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
114 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); | |
115 | ||
b1c571a5 | 116 | operand2 = kvm_s390_get_base_disp_s(vcpu); |
453423dc CB |
117 | |
118 | /* must be word boundary */ | |
db4a29cb HC |
119 | if (operand2 & 3) |
120 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); | |
453423dc CB |
121 | |
122 | address = vcpu->arch.sie_block->prefix; | |
123 | address = address & 0x7fffe000u; | |
124 | ||
125 | /* get the value */ | |
f748f4a7 HC |
126 | rc = write_guest(vcpu, operand2, &address, sizeof(address)); |
127 | if (rc) | |
128 | return kvm_s390_inject_prog_cond(vcpu, rc); | |
453423dc CB |
129 | |
130 | VCPU_EVENT(vcpu, 5, "storing prefix to %x", address); | |
5786fffa | 131 | trace_kvm_s390_handle_prefix(vcpu, 0, address); |
453423dc CB |
132 | return 0; |
133 | } | |
134 | ||
135 | static int handle_store_cpu_address(struct kvm_vcpu *vcpu) | |
136 | { | |
8b96de0e HC |
137 | u16 vcpu_id = vcpu->vcpu_id; |
138 | u64 ga; | |
139 | int rc; | |
453423dc CB |
140 | |
141 | vcpu->stat.instruction_stap++; | |
b1c571a5 | 142 | |
5087dfa6 TH |
143 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
144 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); | |
145 | ||
8b96de0e | 146 | ga = kvm_s390_get_base_disp_s(vcpu); |
453423dc | 147 | |
8b96de0e | 148 | if (ga & 1) |
db4a29cb | 149 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
453423dc | 150 | |
8b96de0e HC |
151 | rc = write_guest(vcpu, ga, &vcpu_id, sizeof(vcpu_id)); |
152 | if (rc) | |
153 | return kvm_s390_inject_prog_cond(vcpu, rc); | |
453423dc | 154 | |
8b96de0e HC |
155 | VCPU_EVENT(vcpu, 5, "storing cpu address to %llx", ga); |
156 | trace_kvm_s390_handle_stap(vcpu, ga); | |
453423dc CB |
157 | return 0; |
158 | } | |
159 | ||
693ffc08 DD |
160 | static void __skey_check_enable(struct kvm_vcpu *vcpu) |
161 | { | |
162 | if (!(vcpu->arch.sie_block->ictl & (ICTL_ISKE | ICTL_SSKE | ICTL_RRBE))) | |
163 | return; | |
164 | ||
165 | s390_enable_skey(); | |
166 | trace_kvm_s390_skey_related_inst(vcpu); | |
167 | vcpu->arch.sie_block->ictl &= ~(ICTL_ISKE | ICTL_SSKE | ICTL_RRBE); | |
168 | } | |
169 | ||
170 | ||
453423dc CB |
171 | static int handle_skey(struct kvm_vcpu *vcpu) |
172 | { | |
693ffc08 DD |
173 | __skey_check_enable(vcpu); |
174 | ||
453423dc | 175 | vcpu->stat.instruction_storage_key++; |
5087dfa6 TH |
176 | |
177 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) | |
178 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); | |
179 | ||
dfcf7dc6 MS |
180 | vcpu->arch.sie_block->gpsw.addr = |
181 | __rewind_psw(vcpu->arch.sie_block->gpsw, 4); | |
453423dc CB |
182 | VCPU_EVENT(vcpu, 4, "%s", "retrying storage key operation"); |
183 | return 0; | |
184 | } | |
185 | ||
8a242234 HC |
186 | static int handle_ipte_interlock(struct kvm_vcpu *vcpu) |
187 | { | |
188 | psw_t *psw = &vcpu->arch.sie_block->gpsw; | |
189 | ||
190 | vcpu->stat.instruction_ipte_interlock++; | |
191 | if (psw_bits(*psw).p) | |
192 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); | |
193 | wait_event(vcpu->kvm->arch.ipte_wq, !ipte_lock_held(vcpu)); | |
194 | psw->addr = __rewind_psw(*psw, 4); | |
195 | VCPU_EVENT(vcpu, 4, "%s", "retrying ipte interlock operation"); | |
196 | return 0; | |
197 | } | |
198 | ||
aca84241 TH |
199 | static int handle_test_block(struct kvm_vcpu *vcpu) |
200 | { | |
aca84241 TH |
201 | gpa_t addr; |
202 | int reg2; | |
203 | ||
204 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) | |
205 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); | |
206 | ||
207 | kvm_s390_get_regs_rre(vcpu, NULL, ®2); | |
208 | addr = vcpu->run->s.regs.gprs[reg2] & PAGE_MASK; | |
209 | addr = kvm_s390_real_to_abs(vcpu, addr); | |
210 | ||
ef23e779 | 211 | if (kvm_is_error_gpa(vcpu->kvm, addr)) |
aca84241 TH |
212 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); |
213 | /* | |
214 | * We don't expect errors on modern systems, and do not care | |
215 | * about storage keys (yet), so let's just clear the page. | |
216 | */ | |
ef23e779 | 217 | if (kvm_clear_guest(vcpu->kvm, addr, PAGE_SIZE)) |
aca84241 TH |
218 | return -EFAULT; |
219 | kvm_s390_set_psw_cc(vcpu, 0); | |
220 | vcpu->run->s.regs.gprs[0] = 0; | |
221 | return 0; | |
222 | } | |
223 | ||
fa6b7fe9 | 224 | static int handle_tpi(struct kvm_vcpu *vcpu) |
453423dc | 225 | { |
fa6b7fe9 | 226 | struct kvm_s390_interrupt_info *inti; |
4799b557 HC |
227 | unsigned long len; |
228 | u32 tpi_data[3]; | |
229 | int cc, rc; | |
7c959e82 | 230 | u64 addr; |
fa6b7fe9 | 231 | |
4799b557 | 232 | rc = 0; |
fa6b7fe9 | 233 | addr = kvm_s390_get_base_disp_s(vcpu); |
db4a29cb HC |
234 | if (addr & 3) |
235 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); | |
7c959e82 | 236 | cc = 0; |
f092669e | 237 | inti = kvm_s390_get_io_int(vcpu->kvm, vcpu->arch.sie_block->gcr[6], 0); |
7c959e82 HC |
238 | if (!inti) |
239 | goto no_interrupt; | |
240 | cc = 1; | |
4799b557 HC |
241 | tpi_data[0] = inti->io.subchannel_id << 16 | inti->io.subchannel_nr; |
242 | tpi_data[1] = inti->io.io_int_parm; | |
243 | tpi_data[2] = inti->io.io_int_word; | |
7c959e82 HC |
244 | if (addr) { |
245 | /* | |
246 | * Store the two-word I/O interruption code into the | |
247 | * provided area. | |
248 | */ | |
4799b557 HC |
249 | len = sizeof(tpi_data) - 4; |
250 | rc = write_guest(vcpu, addr, &tpi_data, len); | |
251 | if (rc) | |
252 | return kvm_s390_inject_prog_cond(vcpu, rc); | |
7c959e82 HC |
253 | } else { |
254 | /* | |
255 | * Store the three-word I/O interruption code into | |
256 | * the appropriate lowcore area. | |
257 | */ | |
4799b557 HC |
258 | len = sizeof(tpi_data); |
259 | if (write_guest_lc(vcpu, __LC_SUBCHANNEL_ID, &tpi_data, len)) | |
260 | rc = -EFAULT; | |
7c959e82 | 261 | } |
2f32d4ea CH |
262 | /* |
263 | * If we encounter a problem storing the interruption code, the | |
264 | * instruction is suppressed from the guest's view: reinject the | |
265 | * interrupt. | |
266 | */ | |
267 | if (!rc) | |
268 | kfree(inti); | |
269 | else | |
270 | kvm_s390_reinject_io_int(vcpu->kvm, inti); | |
7c959e82 | 271 | no_interrupt: |
fa6b7fe9 | 272 | /* Set condition code and we're done. */ |
4799b557 HC |
273 | if (!rc) |
274 | kvm_s390_set_psw_cc(vcpu, cc); | |
275 | return rc ? -EFAULT : 0; | |
453423dc CB |
276 | } |
277 | ||
fa6b7fe9 CH |
278 | static int handle_tsch(struct kvm_vcpu *vcpu) |
279 | { | |
280 | struct kvm_s390_interrupt_info *inti; | |
281 | ||
282 | inti = kvm_s390_get_io_int(vcpu->kvm, 0, | |
283 | vcpu->run->s.regs.gprs[1]); | |
284 | ||
285 | /* | |
286 | * Prepare exit to userspace. | |
287 | * We indicate whether we dequeued a pending I/O interrupt | |
288 | * so that userspace can re-inject it if the instruction gets | |
289 | * a program check. While this may re-order the pending I/O | |
290 | * interrupts, this is no problem since the priority is kept | |
291 | * intact. | |
292 | */ | |
293 | vcpu->run->exit_reason = KVM_EXIT_S390_TSCH; | |
294 | vcpu->run->s390_tsch.dequeued = !!inti; | |
295 | if (inti) { | |
296 | vcpu->run->s390_tsch.subchannel_id = inti->io.subchannel_id; | |
297 | vcpu->run->s390_tsch.subchannel_nr = inti->io.subchannel_nr; | |
298 | vcpu->run->s390_tsch.io_int_parm = inti->io.io_int_parm; | |
299 | vcpu->run->s390_tsch.io_int_word = inti->io.io_int_word; | |
300 | } | |
301 | vcpu->run->s390_tsch.ipb = vcpu->arch.sie_block->ipb; | |
302 | kfree(inti); | |
303 | return -EREMOTE; | |
304 | } | |
305 | ||
306 | static int handle_io_inst(struct kvm_vcpu *vcpu) | |
307 | { | |
308 | VCPU_EVENT(vcpu, 4, "%s", "I/O instruction"); | |
309 | ||
5087dfa6 TH |
310 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
311 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); | |
312 | ||
fa6b7fe9 CH |
313 | if (vcpu->kvm->arch.css_support) { |
314 | /* | |
315 | * Most I/O instructions will be handled by userspace. | |
316 | * Exceptions are tpi and the interrupt portion of tsch. | |
317 | */ | |
318 | if (vcpu->arch.sie_block->ipa == 0xb236) | |
319 | return handle_tpi(vcpu); | |
320 | if (vcpu->arch.sie_block->ipa == 0xb235) | |
321 | return handle_tsch(vcpu); | |
322 | /* Handle in userspace. */ | |
323 | return -EOPNOTSUPP; | |
324 | } else { | |
325 | /* | |
b4a96015 | 326 | * Set condition code 3 to stop the guest from issuing channel |
fa6b7fe9 CH |
327 | * I/O instructions. |
328 | */ | |
ea828ebf | 329 | kvm_s390_set_psw_cc(vcpu, 3); |
fa6b7fe9 CH |
330 | return 0; |
331 | } | |
332 | } | |
333 | ||
453423dc CB |
334 | static int handle_stfl(struct kvm_vcpu *vcpu) |
335 | { | |
453423dc CB |
336 | int rc; |
337 | ||
338 | vcpu->stat.instruction_stfl++; | |
5087dfa6 TH |
339 | |
340 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) | |
341 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); | |
342 | ||
0f9701c6 HC |
343 | rc = write_guest_lc(vcpu, offsetof(struct _lowcore, stfl_fac_list), |
344 | vfacilities, 4); | |
dc5008b9 | 345 | if (rc) |
0f9701c6 | 346 | return rc; |
78c4b59f MM |
347 | VCPU_EVENT(vcpu, 5, "store facility list value %x", |
348 | *(unsigned int *) vfacilities); | |
349 | trace_kvm_s390_handle_stfl(vcpu, *(unsigned int *) vfacilities); | |
453423dc CB |
350 | return 0; |
351 | } | |
352 | ||
48a3e950 CH |
353 | static void handle_new_psw(struct kvm_vcpu *vcpu) |
354 | { | |
355 | /* Check whether the new psw is enabled for machine checks. */ | |
356 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_MCHECK) | |
357 | kvm_s390_deliver_pending_machine_checks(vcpu); | |
358 | } | |
359 | ||
360 | #define PSW_MASK_ADDR_MODE (PSW_MASK_EA | PSW_MASK_BA) | |
361 | #define PSW_MASK_UNASSIGNED 0xb80800fe7fffffffUL | |
d21683ea | 362 | #define PSW_ADDR_24 0x0000000000ffffffUL |
48a3e950 CH |
363 | #define PSW_ADDR_31 0x000000007fffffffUL |
364 | ||
3736b874 HC |
365 | static int is_valid_psw(psw_t *psw) { |
366 | if (psw->mask & PSW_MASK_UNASSIGNED) | |
367 | return 0; | |
368 | if ((psw->mask & PSW_MASK_ADDR_MODE) == PSW_MASK_BA) { | |
369 | if (psw->addr & ~PSW_ADDR_31) | |
370 | return 0; | |
371 | } | |
372 | if (!(psw->mask & PSW_MASK_ADDR_MODE) && (psw->addr & ~PSW_ADDR_24)) | |
373 | return 0; | |
374 | if ((psw->mask & PSW_MASK_ADDR_MODE) == PSW_MASK_EA) | |
375 | return 0; | |
376 | return 1; | |
377 | } | |
378 | ||
48a3e950 CH |
379 | int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu) |
380 | { | |
3736b874 | 381 | psw_t *gpsw = &vcpu->arch.sie_block->gpsw; |
48a3e950 | 382 | psw_compat_t new_psw; |
3736b874 | 383 | u64 addr; |
2d8bcaed | 384 | int rc; |
48a3e950 | 385 | |
3736b874 | 386 | if (gpsw->mask & PSW_MASK_PSTATE) |
208dd756 TH |
387 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
388 | ||
48a3e950 | 389 | addr = kvm_s390_get_base_disp_s(vcpu); |
6fd0fcc9 HC |
390 | if (addr & 7) |
391 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); | |
2d8bcaed HC |
392 | |
393 | rc = read_guest(vcpu, addr, &new_psw, sizeof(new_psw)); | |
394 | if (rc) | |
395 | return kvm_s390_inject_prog_cond(vcpu, rc); | |
6fd0fcc9 HC |
396 | if (!(new_psw.mask & PSW32_MASK_BASE)) |
397 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); | |
3736b874 HC |
398 | gpsw->mask = (new_psw.mask & ~PSW32_MASK_BASE) << 32; |
399 | gpsw->mask |= new_psw.addr & PSW32_ADDR_AMODE; | |
400 | gpsw->addr = new_psw.addr & ~PSW32_ADDR_AMODE; | |
401 | if (!is_valid_psw(gpsw)) | |
6fd0fcc9 | 402 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
48a3e950 | 403 | handle_new_psw(vcpu); |
48a3e950 CH |
404 | return 0; |
405 | } | |
406 | ||
407 | static int handle_lpswe(struct kvm_vcpu *vcpu) | |
408 | { | |
48a3e950 | 409 | psw_t new_psw; |
3736b874 | 410 | u64 addr; |
2d8bcaed | 411 | int rc; |
48a3e950 | 412 | |
5087dfa6 TH |
413 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
414 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); | |
415 | ||
48a3e950 | 416 | addr = kvm_s390_get_base_disp_s(vcpu); |
6fd0fcc9 HC |
417 | if (addr & 7) |
418 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); | |
2d8bcaed HC |
419 | rc = read_guest(vcpu, addr, &new_psw, sizeof(new_psw)); |
420 | if (rc) | |
421 | return kvm_s390_inject_prog_cond(vcpu, rc); | |
3736b874 HC |
422 | vcpu->arch.sie_block->gpsw = new_psw; |
423 | if (!is_valid_psw(&vcpu->arch.sie_block->gpsw)) | |
6fd0fcc9 | 424 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
48a3e950 | 425 | handle_new_psw(vcpu); |
48a3e950 CH |
426 | return 0; |
427 | } | |
428 | ||
453423dc CB |
429 | static int handle_stidp(struct kvm_vcpu *vcpu) |
430 | { | |
7d777d78 | 431 | u64 stidp_data = vcpu->arch.stidp_data; |
453423dc | 432 | u64 operand2; |
7d777d78 | 433 | int rc; |
453423dc CB |
434 | |
435 | vcpu->stat.instruction_stidp++; | |
b1c571a5 | 436 | |
5087dfa6 TH |
437 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
438 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); | |
439 | ||
b1c571a5 | 440 | operand2 = kvm_s390_get_base_disp_s(vcpu); |
453423dc | 441 | |
db4a29cb HC |
442 | if (operand2 & 7) |
443 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); | |
453423dc | 444 | |
7d777d78 HC |
445 | rc = write_guest(vcpu, operand2, &stidp_data, sizeof(stidp_data)); |
446 | if (rc) | |
447 | return kvm_s390_inject_prog_cond(vcpu, rc); | |
453423dc CB |
448 | |
449 | VCPU_EVENT(vcpu, 5, "%s", "store cpu id"); | |
453423dc CB |
450 | return 0; |
451 | } | |
452 | ||
453 | static void handle_stsi_3_2_2(struct kvm_vcpu *vcpu, struct sysinfo_3_2_2 *mem) | |
454 | { | |
453423dc CB |
455 | int cpus = 0; |
456 | int n; | |
457 | ||
ff520a63 | 458 | cpus = atomic_read(&vcpu->kvm->online_vcpus); |
453423dc CB |
459 | |
460 | /* deal with other level 3 hypervisors */ | |
caf757c6 | 461 | if (stsi(mem, 3, 2, 2)) |
453423dc CB |
462 | mem->count = 0; |
463 | if (mem->count < 8) | |
464 | mem->count++; | |
465 | for (n = mem->count - 1; n > 0 ; n--) | |
466 | memcpy(&mem->vm[n], &mem->vm[n - 1], sizeof(mem->vm[0])); | |
467 | ||
468 | mem->vm[0].cpus_total = cpus; | |
469 | mem->vm[0].cpus_configured = cpus; | |
470 | mem->vm[0].cpus_standby = 0; | |
471 | mem->vm[0].cpus_reserved = 0; | |
472 | mem->vm[0].caf = 1000; | |
473 | memcpy(mem->vm[0].name, "KVMguest", 8); | |
474 | ASCEBC(mem->vm[0].name, 8); | |
475 | memcpy(mem->vm[0].cpi, "KVM/Linux ", 16); | |
476 | ASCEBC(mem->vm[0].cpi, 16); | |
477 | } | |
478 | ||
479 | static int handle_stsi(struct kvm_vcpu *vcpu) | |
480 | { | |
5a32c1af CB |
481 | int fc = (vcpu->run->s.regs.gprs[0] & 0xf0000000) >> 28; |
482 | int sel1 = vcpu->run->s.regs.gprs[0] & 0xff; | |
483 | int sel2 = vcpu->run->s.regs.gprs[1] & 0xffff; | |
c51f068c | 484 | unsigned long mem = 0; |
453423dc | 485 | u64 operand2; |
db4a29cb | 486 | int rc = 0; |
453423dc CB |
487 | |
488 | vcpu->stat.instruction_stsi++; | |
489 | VCPU_EVENT(vcpu, 4, "stsi: fc: %x sel1: %x sel2: %x", fc, sel1, sel2); | |
490 | ||
5087dfa6 TH |
491 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
492 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); | |
493 | ||
87d41fb4 | 494 | if (fc > 3) { |
ea828ebf | 495 | kvm_s390_set_psw_cc(vcpu, 3); |
87d41fb4 TH |
496 | return 0; |
497 | } | |
453423dc | 498 | |
87d41fb4 TH |
499 | if (vcpu->run->s.regs.gprs[0] & 0x0fffff00 |
500 | || vcpu->run->s.regs.gprs[1] & 0xffff0000) | |
453423dc CB |
501 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
502 | ||
87d41fb4 | 503 | if (fc == 0) { |
5a32c1af | 504 | vcpu->run->s.regs.gprs[0] = 3 << 28; |
ea828ebf | 505 | kvm_s390_set_psw_cc(vcpu, 0); |
453423dc | 506 | return 0; |
87d41fb4 TH |
507 | } |
508 | ||
509 | operand2 = kvm_s390_get_base_disp_s(vcpu); | |
510 | ||
511 | if (operand2 & 0xfff) | |
512 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); | |
513 | ||
514 | switch (fc) { | |
453423dc CB |
515 | case 1: /* same handling for 1 and 2 */ |
516 | case 2: | |
517 | mem = get_zeroed_page(GFP_KERNEL); | |
518 | if (!mem) | |
c51f068c | 519 | goto out_no_data; |
caf757c6 | 520 | if (stsi((void *) mem, fc, sel1, sel2)) |
c51f068c | 521 | goto out_no_data; |
453423dc CB |
522 | break; |
523 | case 3: | |
524 | if (sel1 != 2 || sel2 != 2) | |
c51f068c | 525 | goto out_no_data; |
453423dc CB |
526 | mem = get_zeroed_page(GFP_KERNEL); |
527 | if (!mem) | |
c51f068c | 528 | goto out_no_data; |
453423dc CB |
529 | handle_stsi_3_2_2(vcpu, (void *) mem); |
530 | break; | |
453423dc CB |
531 | } |
532 | ||
645c5bc1 HC |
533 | rc = write_guest(vcpu, operand2, (void *)mem, PAGE_SIZE); |
534 | if (rc) { | |
535 | rc = kvm_s390_inject_prog_cond(vcpu, rc); | |
536 | goto out; | |
453423dc | 537 | } |
5786fffa | 538 | trace_kvm_s390_handle_stsi(vcpu, fc, sel1, sel2, operand2); |
453423dc | 539 | free_page(mem); |
ea828ebf | 540 | kvm_s390_set_psw_cc(vcpu, 0); |
5a32c1af | 541 | vcpu->run->s.regs.gprs[0] = 0; |
453423dc | 542 | return 0; |
c51f068c | 543 | out_no_data: |
ea828ebf | 544 | kvm_s390_set_psw_cc(vcpu, 3); |
645c5bc1 | 545 | out: |
c51f068c | 546 | free_page(mem); |
db4a29cb | 547 | return rc; |
453423dc CB |
548 | } |
549 | ||
f379aae5 | 550 | static const intercept_handler_t b2_handlers[256] = { |
453423dc | 551 | [0x02] = handle_stidp, |
6a3f95a6 | 552 | [0x04] = handle_set_clock, |
453423dc CB |
553 | [0x10] = handle_set_prefix, |
554 | [0x11] = handle_store_prefix, | |
555 | [0x12] = handle_store_cpu_address, | |
8a242234 | 556 | [0x21] = handle_ipte_interlock, |
453423dc CB |
557 | [0x29] = handle_skey, |
558 | [0x2a] = handle_skey, | |
559 | [0x2b] = handle_skey, | |
aca84241 | 560 | [0x2c] = handle_test_block, |
f379aae5 CH |
561 | [0x30] = handle_io_inst, |
562 | [0x31] = handle_io_inst, | |
563 | [0x32] = handle_io_inst, | |
564 | [0x33] = handle_io_inst, | |
565 | [0x34] = handle_io_inst, | |
566 | [0x35] = handle_io_inst, | |
567 | [0x36] = handle_io_inst, | |
568 | [0x37] = handle_io_inst, | |
569 | [0x38] = handle_io_inst, | |
570 | [0x39] = handle_io_inst, | |
571 | [0x3a] = handle_io_inst, | |
572 | [0x3b] = handle_io_inst, | |
573 | [0x3c] = handle_io_inst, | |
8a242234 | 574 | [0x50] = handle_ipte_interlock, |
f379aae5 CH |
575 | [0x5f] = handle_io_inst, |
576 | [0x74] = handle_io_inst, | |
577 | [0x76] = handle_io_inst, | |
453423dc CB |
578 | [0x7d] = handle_stsi, |
579 | [0xb1] = handle_stfl, | |
48a3e950 | 580 | [0xb2] = handle_lpswe, |
453423dc CB |
581 | }; |
582 | ||
70455a36 | 583 | int kvm_s390_handle_b2(struct kvm_vcpu *vcpu) |
453423dc CB |
584 | { |
585 | intercept_handler_t handler; | |
586 | ||
70455a36 | 587 | /* |
5087dfa6 TH |
588 | * A lot of B2 instructions are priviledged. Here we check for |
589 | * the privileged ones, that we can handle in the kernel. | |
590 | * Anything else goes to userspace. | |
591 | */ | |
f379aae5 | 592 | handler = b2_handlers[vcpu->arch.sie_block->ipa & 0x00ff]; |
5087dfa6 TH |
593 | if (handler) |
594 | return handler(vcpu); | |
595 | ||
b8e660b8 | 596 | return -EOPNOTSUPP; |
453423dc | 597 | } |
bb25b9ba | 598 | |
48a3e950 CH |
599 | static int handle_epsw(struct kvm_vcpu *vcpu) |
600 | { | |
601 | int reg1, reg2; | |
602 | ||
aeb87c3c | 603 | kvm_s390_get_regs_rre(vcpu, ®1, ®2); |
48a3e950 CH |
604 | |
605 | /* This basically extracts the mask half of the psw. */ | |
843200e7 | 606 | vcpu->run->s.regs.gprs[reg1] &= 0xffffffff00000000UL; |
48a3e950 CH |
607 | vcpu->run->s.regs.gprs[reg1] |= vcpu->arch.sie_block->gpsw.mask >> 32; |
608 | if (reg2) { | |
843200e7 | 609 | vcpu->run->s.regs.gprs[reg2] &= 0xffffffff00000000UL; |
48a3e950 | 610 | vcpu->run->s.regs.gprs[reg2] |= |
843200e7 | 611 | vcpu->arch.sie_block->gpsw.mask & 0x00000000ffffffffUL; |
48a3e950 CH |
612 | } |
613 | return 0; | |
614 | } | |
615 | ||
69d0d3a3 CB |
616 | #define PFMF_RESERVED 0xfffc0101UL |
617 | #define PFMF_SK 0x00020000UL | |
618 | #define PFMF_CF 0x00010000UL | |
619 | #define PFMF_UI 0x00008000UL | |
620 | #define PFMF_FSC 0x00007000UL | |
621 | #define PFMF_NQ 0x00000800UL | |
622 | #define PFMF_MR 0x00000400UL | |
623 | #define PFMF_MC 0x00000200UL | |
624 | #define PFMF_KEY 0x000000feUL | |
625 | ||
626 | static int handle_pfmf(struct kvm_vcpu *vcpu) | |
627 | { | |
628 | int reg1, reg2; | |
629 | unsigned long start, end; | |
630 | ||
631 | vcpu->stat.instruction_pfmf++; | |
632 | ||
633 | kvm_s390_get_regs_rre(vcpu, ®1, ®2); | |
634 | ||
635 | if (!MACHINE_HAS_PFMF) | |
636 | return kvm_s390_inject_program_int(vcpu, PGM_OPERATION); | |
637 | ||
638 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) | |
208dd756 | 639 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
69d0d3a3 CB |
640 | |
641 | if (vcpu->run->s.regs.gprs[reg1] & PFMF_RESERVED) | |
642 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); | |
643 | ||
644 | /* Only provide non-quiescing support if the host supports it */ | |
e769ece3 | 645 | if (vcpu->run->s.regs.gprs[reg1] & PFMF_NQ && !test_facility(14)) |
69d0d3a3 CB |
646 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
647 | ||
648 | /* No support for conditional-SSKE */ | |
649 | if (vcpu->run->s.regs.gprs[reg1] & (PFMF_MR | PFMF_MC)) | |
650 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); | |
651 | ||
652 | start = vcpu->run->s.regs.gprs[reg2] & PAGE_MASK; | |
653 | switch (vcpu->run->s.regs.gprs[reg1] & PFMF_FSC) { | |
654 | case 0x00000000: | |
655 | end = (start + (1UL << 12)) & ~((1UL << 12) - 1); | |
656 | break; | |
657 | case 0x00001000: | |
658 | end = (start + (1UL << 20)) & ~((1UL << 20) - 1); | |
659 | break; | |
660 | /* We dont support EDAT2 | |
661 | case 0x00002000: | |
662 | end = (start + (1UL << 31)) & ~((1UL << 31) - 1); | |
663 | break;*/ | |
664 | default: | |
665 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); | |
666 | } | |
667 | while (start < end) { | |
668 | unsigned long useraddr; | |
669 | ||
670 | useraddr = gmap_translate(start, vcpu->arch.gmap); | |
671 | if (IS_ERR((void *)useraddr)) | |
672 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); | |
673 | ||
674 | if (vcpu->run->s.regs.gprs[reg1] & PFMF_CF) { | |
675 | if (clear_user((void __user *)useraddr, PAGE_SIZE)) | |
676 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); | |
677 | } | |
678 | ||
679 | if (vcpu->run->s.regs.gprs[reg1] & PFMF_SK) { | |
693ffc08 | 680 | __skey_check_enable(vcpu); |
69d0d3a3 CB |
681 | if (set_guest_storage_key(current->mm, useraddr, |
682 | vcpu->run->s.regs.gprs[reg1] & PFMF_KEY, | |
683 | vcpu->run->s.regs.gprs[reg1] & PFMF_NQ)) | |
684 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); | |
685 | } | |
686 | ||
687 | start += PAGE_SIZE; | |
688 | } | |
689 | if (vcpu->run->s.regs.gprs[reg1] & PFMF_FSC) | |
690 | vcpu->run->s.regs.gprs[reg2] = end; | |
691 | return 0; | |
692 | } | |
693 | ||
b31288fa KW |
694 | static int handle_essa(struct kvm_vcpu *vcpu) |
695 | { | |
696 | /* entries expected to be 1FF */ | |
697 | int entries = (vcpu->arch.sie_block->cbrlo & ~PAGE_MASK) >> 3; | |
698 | unsigned long *cbrlo, cbrle; | |
699 | struct gmap *gmap; | |
700 | int i; | |
701 | ||
702 | VCPU_EVENT(vcpu, 5, "cmma release %d pages", entries); | |
703 | gmap = vcpu->arch.gmap; | |
704 | vcpu->stat.instruction_essa++; | |
b31605c1 | 705 | if (!kvm_s390_cmma_enabled(vcpu->kvm)) |
b31288fa KW |
706 | return kvm_s390_inject_program_int(vcpu, PGM_OPERATION); |
707 | ||
708 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) | |
709 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); | |
710 | ||
711 | if (((vcpu->arch.sie_block->ipb & 0xf0000000) >> 28) > 6) | |
712 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); | |
713 | ||
714 | /* Rewind PSW to repeat the ESSA instruction */ | |
715 | vcpu->arch.sie_block->gpsw.addr = | |
716 | __rewind_psw(vcpu->arch.sie_block->gpsw, 4); | |
717 | vcpu->arch.sie_block->cbrlo &= PAGE_MASK; /* reset nceo */ | |
718 | cbrlo = phys_to_virt(vcpu->arch.sie_block->cbrlo); | |
719 | down_read(&gmap->mm->mmap_sem); | |
720 | for (i = 0; i < entries; ++i) { | |
721 | cbrle = cbrlo[i]; | |
722 | if (unlikely(cbrle & ~PAGE_MASK || cbrle < 2 * PAGE_SIZE)) | |
723 | /* invalid entry */ | |
724 | break; | |
725 | /* try to free backing */ | |
726 | __gmap_zap(cbrle, gmap); | |
727 | } | |
728 | up_read(&gmap->mm->mmap_sem); | |
729 | if (i < entries) | |
730 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); | |
731 | return 0; | |
732 | } | |
733 | ||
48a3e950 | 734 | static const intercept_handler_t b9_handlers[256] = { |
8a242234 | 735 | [0x8a] = handle_ipte_interlock, |
48a3e950 | 736 | [0x8d] = handle_epsw, |
8a242234 HC |
737 | [0x8e] = handle_ipte_interlock, |
738 | [0x8f] = handle_ipte_interlock, | |
b31288fa | 739 | [0xab] = handle_essa, |
69d0d3a3 | 740 | [0xaf] = handle_pfmf, |
48a3e950 CH |
741 | }; |
742 | ||
743 | int kvm_s390_handle_b9(struct kvm_vcpu *vcpu) | |
744 | { | |
745 | intercept_handler_t handler; | |
746 | ||
747 | /* This is handled just as for the B2 instructions. */ | |
748 | handler = b9_handlers[vcpu->arch.sie_block->ipa & 0x00ff]; | |
5087dfa6 TH |
749 | if (handler) |
750 | return handler(vcpu); | |
751 | ||
48a3e950 CH |
752 | return -EOPNOTSUPP; |
753 | } | |
754 | ||
953ed88d TH |
755 | int kvm_s390_handle_lctl(struct kvm_vcpu *vcpu) |
756 | { | |
757 | int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4; | |
758 | int reg3 = vcpu->arch.sie_block->ipa & 0x000f; | |
953ed88d TH |
759 | u32 val = 0; |
760 | int reg, rc; | |
f987a3ee | 761 | u64 ga; |
953ed88d TH |
762 | |
763 | vcpu->stat.instruction_lctl++; | |
764 | ||
765 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) | |
766 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); | |
767 | ||
f987a3ee | 768 | ga = kvm_s390_get_base_disp_rs(vcpu); |
953ed88d | 769 | |
f987a3ee | 770 | if (ga & 3) |
953ed88d TH |
771 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
772 | ||
f987a3ee HC |
773 | VCPU_EVENT(vcpu, 5, "lctl r1:%x, r3:%x, addr:%llx", reg1, reg3, ga); |
774 | trace_kvm_s390_handle_lctl(vcpu, 0, reg1, reg3, ga); | |
953ed88d TH |
775 | |
776 | reg = reg1; | |
777 | do { | |
f987a3ee | 778 | rc = read_guest(vcpu, ga, &val, sizeof(val)); |
953ed88d | 779 | if (rc) |
f987a3ee | 780 | return kvm_s390_inject_prog_cond(vcpu, rc); |
953ed88d TH |
781 | vcpu->arch.sie_block->gcr[reg] &= 0xffffffff00000000ul; |
782 | vcpu->arch.sie_block->gcr[reg] |= val; | |
f987a3ee | 783 | ga += 4; |
953ed88d TH |
784 | if (reg == reg3) |
785 | break; | |
786 | reg = (reg + 1) % 16; | |
787 | } while (1); | |
788 | ||
789 | return 0; | |
790 | } | |
791 | ||
792 | static int handle_lctlg(struct kvm_vcpu *vcpu) | |
793 | { | |
794 | int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4; | |
795 | int reg3 = vcpu->arch.sie_block->ipa & 0x000f; | |
f987a3ee | 796 | u64 ga, val; |
953ed88d TH |
797 | int reg, rc; |
798 | ||
799 | vcpu->stat.instruction_lctlg++; | |
800 | ||
801 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) | |
802 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); | |
803 | ||
f987a3ee | 804 | ga = kvm_s390_get_base_disp_rsy(vcpu); |
953ed88d | 805 | |
f987a3ee | 806 | if (ga & 7) |
953ed88d TH |
807 | return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION); |
808 | ||
809 | reg = reg1; | |
810 | ||
f987a3ee HC |
811 | VCPU_EVENT(vcpu, 5, "lctlg r1:%x, r3:%x, addr:%llx", reg1, reg3, ga); |
812 | trace_kvm_s390_handle_lctl(vcpu, 1, reg1, reg3, ga); | |
953ed88d TH |
813 | |
814 | do { | |
f987a3ee | 815 | rc = read_guest(vcpu, ga, &val, sizeof(val)); |
953ed88d | 816 | if (rc) |
f987a3ee HC |
817 | return kvm_s390_inject_prog_cond(vcpu, rc); |
818 | vcpu->arch.sie_block->gcr[reg] = val; | |
819 | ga += 8; | |
953ed88d TH |
820 | if (reg == reg3) |
821 | break; | |
822 | reg = (reg + 1) % 16; | |
823 | } while (1); | |
824 | ||
825 | return 0; | |
826 | } | |
827 | ||
f379aae5 | 828 | static const intercept_handler_t eb_handlers[256] = { |
953ed88d | 829 | [0x2f] = handle_lctlg, |
f379aae5 CH |
830 | }; |
831 | ||
953ed88d | 832 | int kvm_s390_handle_eb(struct kvm_vcpu *vcpu) |
f379aae5 CH |
833 | { |
834 | intercept_handler_t handler; | |
835 | ||
f379aae5 CH |
836 | handler = eb_handlers[vcpu->arch.sie_block->ipb & 0xff]; |
837 | if (handler) | |
838 | return handler(vcpu); | |
839 | return -EOPNOTSUPP; | |
840 | } | |
841 | ||
bb25b9ba CB |
842 | static int handle_tprot(struct kvm_vcpu *vcpu) |
843 | { | |
b1c571a5 | 844 | u64 address1, address2; |
bb25b9ba | 845 | struct vm_area_struct *vma; |
1eddb85f | 846 | unsigned long user_address; |
bb25b9ba CB |
847 | |
848 | vcpu->stat.instruction_tprot++; | |
849 | ||
f9f6bbc6 TH |
850 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) |
851 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); | |
852 | ||
b1c571a5 CH |
853 | kvm_s390_get_base_disp_sse(vcpu, &address1, &address2); |
854 | ||
bb25b9ba CB |
855 | /* we only handle the Linux memory detection case: |
856 | * access key == 0 | |
857 | * guest DAT == off | |
858 | * everything else goes to userspace. */ | |
859 | if (address2 & 0xf0) | |
860 | return -EOPNOTSUPP; | |
861 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_DAT) | |
862 | return -EOPNOTSUPP; | |
863 | ||
bb25b9ba | 864 | down_read(¤t->mm->mmap_sem); |
59a1fa2d HC |
865 | user_address = __gmap_translate(address1, vcpu->arch.gmap); |
866 | if (IS_ERR_VALUE(user_address)) | |
867 | goto out_inject; | |
1eddb85f | 868 | vma = find_vma(current->mm, user_address); |
59a1fa2d HC |
869 | if (!vma) |
870 | goto out_inject; | |
bb25b9ba CB |
871 | vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44); |
872 | if (!(vma->vm_flags & VM_WRITE) && (vma->vm_flags & VM_READ)) | |
873 | vcpu->arch.sie_block->gpsw.mask |= (1ul << 44); | |
874 | if (!(vma->vm_flags & VM_WRITE) && !(vma->vm_flags & VM_READ)) | |
875 | vcpu->arch.sie_block->gpsw.mask |= (2ul << 44); | |
876 | ||
877 | up_read(¤t->mm->mmap_sem); | |
878 | return 0; | |
59a1fa2d HC |
879 | |
880 | out_inject: | |
881 | up_read(¤t->mm->mmap_sem); | |
882 | return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING); | |
bb25b9ba CB |
883 | } |
884 | ||
885 | int kvm_s390_handle_e5(struct kvm_vcpu *vcpu) | |
886 | { | |
887 | /* For e5xx... instructions we only handle TPROT */ | |
888 | if ((vcpu->arch.sie_block->ipa & 0x00ff) == 0x01) | |
889 | return handle_tprot(vcpu); | |
890 | return -EOPNOTSUPP; | |
891 | } | |
892 | ||
8c3f61e2 CH |
893 | static int handle_sckpf(struct kvm_vcpu *vcpu) |
894 | { | |
895 | u32 value; | |
896 | ||
897 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) | |
208dd756 | 898 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
8c3f61e2 CH |
899 | |
900 | if (vcpu->run->s.regs.gprs[0] & 0x00000000ffff0000) | |
901 | return kvm_s390_inject_program_int(vcpu, | |
902 | PGM_SPECIFICATION); | |
903 | ||
904 | value = vcpu->run->s.regs.gprs[0] & 0x000000000000ffff; | |
905 | vcpu->arch.sie_block->todpr = value; | |
906 | ||
907 | return 0; | |
908 | } | |
909 | ||
77975357 | 910 | static const intercept_handler_t x01_handlers[256] = { |
8c3f61e2 CH |
911 | [0x07] = handle_sckpf, |
912 | }; | |
913 | ||
914 | int kvm_s390_handle_01(struct kvm_vcpu *vcpu) | |
915 | { | |
916 | intercept_handler_t handler; | |
917 | ||
918 | handler = x01_handlers[vcpu->arch.sie_block->ipa & 0x00ff]; | |
919 | if (handler) | |
920 | return handler(vcpu); | |
921 | return -EOPNOTSUPP; | |
922 | } |