blob: b253de5b894561a72c11ba4ac577049bcc60a7d6 [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 *
Christian Borntraeger69d0d3a2013-06-12 13:54:53 +02004 * Copyright IBM Corp. 2008, 2013
Christian Borntraeger453423d2008-03-25 18:47:29 +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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/gfp.h>
Christian Borntraeger453423d2008-03-25 18:47:29 +010016#include <linux/errno.h>
Heiko Carstensb13b5dc2013-03-25 17:22:55 +010017#include <linux/compat.h>
Heiko Carstens7c959e82013-03-05 13:14:46 +010018#include <asm/asm-offsets.h>
Heiko Carstense769ece2013-07-26 15:04:01 +020019#include <asm/facility.h>
Christian Borntraeger453423d2008-03-25 18:47:29 +010020#include <asm/current.h>
21#include <asm/debug.h>
22#include <asm/ebcdic.h>
23#include <asm/sysinfo.h>
Christian Borntraeger69d0d3a2013-06-12 13:54:53 +020024#include <asm/pgtable.h>
25#include <asm/pgalloc.h>
26#include <asm/io.h>
Cornelia Huck48a3e952012-12-20 15:32:09 +010027#include <asm/ptrace.h>
28#include <asm/compat.h>
Christian Borntraeger453423d2008-03-25 18:47:29 +010029#include "gaccess.h"
30#include "kvm-s390.h"
Cornelia Huck5786fff2012-07-23 17:20:29 +020031#include "trace.h"
Christian Borntraeger453423d2008-03-25 18:47:29 +010032
Thomas Huth6a3f95a2013-09-12 10:33:49 +020033/* Handle SCK (SET CLOCK) interception */
34static int handle_set_clock(struct kvm_vcpu *vcpu)
35{
36 struct kvm_vcpu *cpup;
David Hildenbrand5a3d8832015-09-29 16:27:24 +020037 s64 val;
Heiko Carstens0e7a3f92014-01-01 16:50:11 +010038 int i, rc;
Alexander Yarygin8ae04b82015-01-19 13:24:51 +030039 ar_t ar;
Thomas Huth6a3f95a2013-09-12 10:33:49 +020040 u64 op2;
Thomas Huth6a3f95a2013-09-12 10:33:49 +020041
42 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
43 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
44
Alexander Yarygin8ae04b82015-01-19 13:24:51 +030045 op2 = kvm_s390_get_base_disp_s(vcpu, &ar);
Thomas Huth6a3f95a2013-09-12 10:33:49 +020046 if (op2 & 7) /* Operand must be on a doubleword boundary */
47 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
Alexander Yarygin8ae04b82015-01-19 13:24:51 +030048 rc = read_guest(vcpu, op2, ar, &val, sizeof(val));
Heiko Carstens0e7a3f92014-01-01 16:50:11 +010049 if (rc)
50 return kvm_s390_inject_prog_cond(vcpu, rc);
Thomas Huth6a3f95a2013-09-12 10:33:49 +020051
Christian Borntraeger7cbde762015-07-21 12:44:57 +020052 VCPU_EVENT(vcpu, 3, "SCK: setting guest TOD to 0x%llx", val);
Thomas Huth6a3f95a2013-09-12 10:33:49 +020053
54 mutex_lock(&vcpu->kvm->lock);
Fan Zhangfdf03652015-05-13 10:58:41 +020055 preempt_disable();
David Hildenbrand5a3d8832015-09-29 16:27:24 +020056 val = (val - get_tod_clock()) & ~0x3fUL;
Thomas Huth6a3f95a2013-09-12 10:33:49 +020057 kvm_for_each_vcpu(i, cpup, vcpu->kvm)
58 cpup->arch.sie_block->epoch = val;
Fan Zhangfdf03652015-05-13 10:58:41 +020059 preempt_enable();
Thomas Huth6a3f95a2013-09-12 10:33:49 +020060 mutex_unlock(&vcpu->kvm->lock);
61
62 kvm_s390_set_psw_cc(vcpu, 0);
63 return 0;
64}
65
Christian Borntraeger453423d2008-03-25 18:47:29 +010066static int handle_set_prefix(struct kvm_vcpu *vcpu)
67{
Christian Borntraeger453423d2008-03-25 18:47:29 +010068 u64 operand2;
Heiko Carstens665170c2014-01-01 16:47:12 +010069 u32 address;
70 int rc;
Alexander Yarygin8ae04b82015-01-19 13:24:51 +030071 ar_t ar;
Christian Borntraeger453423d2008-03-25 18:47:29 +010072
73 vcpu->stat.instruction_spx++;
74
Thomas Huth5087dfa2013-06-20 17:22:01 +020075 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
76 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
77
Alexander Yarygin8ae04b82015-01-19 13:24:51 +030078 operand2 = kvm_s390_get_base_disp_s(vcpu, &ar);
Christian Borntraeger453423d2008-03-25 18:47:29 +010079
80 /* must be word boundary */
Heiko Carstensdb4a29c2013-03-25 17:22:53 +010081 if (operand2 & 3)
82 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
Christian Borntraeger453423d2008-03-25 18:47:29 +010083
84 /* get the value */
Alexander Yarygin8ae04b82015-01-19 13:24:51 +030085 rc = read_guest(vcpu, operand2, ar, &address, sizeof(address));
Heiko Carstens665170c2014-01-01 16:47:12 +010086 if (rc)
87 return kvm_s390_inject_prog_cond(vcpu, rc);
Christian Borntraeger453423d2008-03-25 18:47:29 +010088
Heiko Carstens665170c2014-01-01 16:47:12 +010089 address &= 0x7fffe000u;
Christian Borntraeger453423d2008-03-25 18:47:29 +010090
Heiko Carstens665170c2014-01-01 16:47:12 +010091 /*
92 * Make sure the new value is valid memory. We only need to check the
93 * first page, since address is 8k aligned and memory pieces are always
94 * at least 1MB aligned and have at least a size of 1MB.
95 */
96 if (kvm_is_error_gpa(vcpu->kvm, address))
Heiko Carstensdb4a29c2013-03-25 17:22:53 +010097 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
Christian Borntraeger453423d2008-03-25 18:47:29 +010098
Christian Borntraeger8d26cf72012-01-11 11:19:32 +010099 kvm_s390_set_prefix(vcpu, address);
Cornelia Huck5786fff2012-07-23 17:20:29 +0200100 trace_kvm_s390_handle_prefix(vcpu, 1, address);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100101 return 0;
102}
103
104static int handle_store_prefix(struct kvm_vcpu *vcpu)
105{
Christian Borntraeger453423d2008-03-25 18:47:29 +0100106 u64 operand2;
107 u32 address;
Heiko Carstensf748f4a2014-01-01 16:52:47 +0100108 int rc;
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300109 ar_t ar;
Christian Borntraeger453423d2008-03-25 18:47:29 +0100110
111 vcpu->stat.instruction_stpx++;
Cornelia Huckb1c571a2012-12-20 15:32:07 +0100112
Thomas Huth5087dfa2013-06-20 17:22:01 +0200113 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
114 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
115
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300116 operand2 = kvm_s390_get_base_disp_s(vcpu, &ar);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100117
118 /* must be word boundary */
Heiko Carstensdb4a29c2013-03-25 17:22:53 +0100119 if (operand2 & 3)
120 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100121
Michael Muellerfda902c2014-05-13 16:58:30 +0200122 address = kvm_s390_get_prefix(vcpu);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100123
124 /* get the value */
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300125 rc = write_guest(vcpu, operand2, ar, &address, sizeof(address));
Heiko Carstensf748f4a2014-01-01 16:52:47 +0100126 if (rc)
127 return kvm_s390_inject_prog_cond(vcpu, rc);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100128
Christian Borntraeger7cbde762015-07-21 12:44:57 +0200129 VCPU_EVENT(vcpu, 3, "STPX: storing prefix 0x%x into 0x%llx", address, operand2);
Cornelia Huck5786fff2012-07-23 17:20:29 +0200130 trace_kvm_s390_handle_prefix(vcpu, 0, address);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100131 return 0;
132}
133
134static int handle_store_cpu_address(struct kvm_vcpu *vcpu)
135{
Heiko Carstens8b96de02014-01-01 16:53:27 +0100136 u16 vcpu_id = vcpu->vcpu_id;
137 u64 ga;
138 int rc;
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300139 ar_t ar;
Christian Borntraeger453423d2008-03-25 18:47:29 +0100140
141 vcpu->stat.instruction_stap++;
Cornelia Huckb1c571a2012-12-20 15:32:07 +0100142
Thomas Huth5087dfa2013-06-20 17:22:01 +0200143 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
144 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
145
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300146 ga = kvm_s390_get_base_disp_s(vcpu, &ar);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100147
Heiko Carstens8b96de02014-01-01 16:53:27 +0100148 if (ga & 1)
Heiko Carstensdb4a29c2013-03-25 17:22:53 +0100149 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100150
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300151 rc = write_guest(vcpu, ga, ar, &vcpu_id, sizeof(vcpu_id));
Heiko Carstens8b96de02014-01-01 16:53:27 +0100152 if (rc)
153 return kvm_s390_inject_prog_cond(vcpu, rc);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100154
Christian Borntraeger7cbde762015-07-21 12:44:57 +0200155 VCPU_EVENT(vcpu, 3, "STAP: storing cpu address (%u) to 0x%llx", vcpu_id, ga);
Heiko Carstens8b96de02014-01-01 16:53:27 +0100156 trace_kvm_s390_handle_stap(vcpu, ga);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100157 return 0;
158}
159
Dominik Dingel3ac8e382014-10-23 12:09:17 +0200160static int __skey_check_enable(struct kvm_vcpu *vcpu)
Dominik Dingel693ffc02014-01-14 18:11:14 +0100161{
Dominik Dingel3ac8e382014-10-23 12:09:17 +0200162 int rc = 0;
Dominik Dingel693ffc02014-01-14 18:11:14 +0100163 if (!(vcpu->arch.sie_block->ictl & (ICTL_ISKE | ICTL_SSKE | ICTL_RRBE)))
Dominik Dingel3ac8e382014-10-23 12:09:17 +0200164 return rc;
Dominik Dingel693ffc02014-01-14 18:11:14 +0100165
Dominik Dingel3ac8e382014-10-23 12:09:17 +0200166 rc = s390_enable_skey();
Christian Borntraeger7cbde762015-07-21 12:44:57 +0200167 VCPU_EVENT(vcpu, 3, "%s", "enabling storage keys for guest");
Dominik Dingel693ffc02014-01-14 18:11:14 +0100168 trace_kvm_s390_skey_related_inst(vcpu);
169 vcpu->arch.sie_block->ictl &= ~(ICTL_ISKE | ICTL_SSKE | ICTL_RRBE);
Dominik Dingel3ac8e382014-10-23 12:09:17 +0200170 return rc;
Dominik Dingel693ffc02014-01-14 18:11:14 +0100171}
172
173
Christian Borntraeger453423d2008-03-25 18:47:29 +0100174static int handle_skey(struct kvm_vcpu *vcpu)
175{
Dominik Dingel3ac8e382014-10-23 12:09:17 +0200176 int rc = __skey_check_enable(vcpu);
Dominik Dingel693ffc02014-01-14 18:11:14 +0100177
Dominik Dingel3ac8e382014-10-23 12:09:17 +0200178 if (rc)
179 return rc;
Christian Borntraeger453423d2008-03-25 18:47:29 +0100180 vcpu->stat.instruction_storage_key++;
Thomas Huth5087dfa2013-06-20 17:22:01 +0200181
182 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
183 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
184
Thomas Huth04b41ac2014-11-12 17:13:29 +0100185 kvm_s390_rewind_psw(vcpu, 4);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100186 VCPU_EVENT(vcpu, 4, "%s", "retrying storage key operation");
187 return 0;
188}
189
Heiko Carstens8a2422342014-01-10 14:33:28 +0100190static int handle_ipte_interlock(struct kvm_vcpu *vcpu)
191{
Heiko Carstens8a2422342014-01-10 14:33:28 +0100192 vcpu->stat.instruction_ipte_interlock++;
Thomas Huth04b41ac2014-11-12 17:13:29 +0100193 if (psw_bits(vcpu->arch.sie_block->gpsw).p)
Heiko Carstens8a2422342014-01-10 14:33:28 +0100194 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
195 wait_event(vcpu->kvm->arch.ipte_wq, !ipte_lock_held(vcpu));
Thomas Huth04b41ac2014-11-12 17:13:29 +0100196 kvm_s390_rewind_psw(vcpu, 4);
Heiko Carstens8a2422342014-01-10 14:33:28 +0100197 VCPU_EVENT(vcpu, 4, "%s", "retrying ipte interlock operation");
198 return 0;
199}
200
Thomas Huthaca84242013-09-12 10:33:48 +0200201static int handle_test_block(struct kvm_vcpu *vcpu)
202{
Thomas Huthaca84242013-09-12 10:33:48 +0200203 gpa_t addr;
204 int reg2;
205
206 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
207 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
208
209 kvm_s390_get_regs_rre(vcpu, NULL, &reg2);
210 addr = vcpu->run->s.regs.gprs[reg2] & PAGE_MASK;
Thomas Huthe45efa22014-03-07 12:14:23 +0100211 addr = kvm_s390_logical_to_effective(vcpu, addr);
Alexander Yarygindd9e5b72015-03-03 14:26:14 +0300212 if (kvm_s390_check_low_addr_prot_real(vcpu, addr))
Thomas Huthe45efa22014-03-07 12:14:23 +0100213 return kvm_s390_inject_prog_irq(vcpu, &vcpu->arch.pgm);
Thomas Huthaca84242013-09-12 10:33:48 +0200214 addr = kvm_s390_real_to_abs(vcpu, addr);
215
Heiko Carstensef23e772014-01-01 16:53:49 +0100216 if (kvm_is_error_gpa(vcpu->kvm, addr))
Thomas Huthaca84242013-09-12 10:33:48 +0200217 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
218 /*
219 * We don't expect errors on modern systems, and do not care
220 * about storage keys (yet), so let's just clear the page.
221 */
Heiko Carstensef23e772014-01-01 16:53:49 +0100222 if (kvm_clear_guest(vcpu->kvm, addr, PAGE_SIZE))
Thomas Huthaca84242013-09-12 10:33:48 +0200223 return -EFAULT;
224 kvm_s390_set_psw_cc(vcpu, 0);
225 vcpu->run->s.regs.gprs[0] = 0;
226 return 0;
227}
228
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +0100229static int handle_tpi(struct kvm_vcpu *vcpu)
230{
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +0100231 struct kvm_s390_interrupt_info *inti;
Heiko Carstens4799b552014-01-01 16:55:48 +0100232 unsigned long len;
233 u32 tpi_data[3];
David Hildenbrand261520d2015-02-04 15:53:42 +0100234 int rc;
Heiko Carstens7c959e82013-03-05 13:14:46 +0100235 u64 addr;
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300236 ar_t ar;
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +0100237
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300238 addr = kvm_s390_get_base_disp_s(vcpu, &ar);
Heiko Carstensdb4a29c2013-03-25 17:22:53 +0100239 if (addr & 3)
240 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
David Hildenbrand261520d2015-02-04 15:53:42 +0100241
Thomas Huthf0926692013-10-09 14:15:54 +0200242 inti = kvm_s390_get_io_int(vcpu->kvm, vcpu->arch.sie_block->gcr[6], 0);
David Hildenbrand261520d2015-02-04 15:53:42 +0100243 if (!inti) {
244 kvm_s390_set_psw_cc(vcpu, 0);
245 return 0;
246 }
247
Heiko Carstens4799b552014-01-01 16:55:48 +0100248 tpi_data[0] = inti->io.subchannel_id << 16 | inti->io.subchannel_nr;
249 tpi_data[1] = inti->io.io_int_parm;
250 tpi_data[2] = inti->io.io_int_word;
Heiko Carstens7c959e82013-03-05 13:14:46 +0100251 if (addr) {
252 /*
253 * Store the two-word I/O interruption code into the
254 * provided area.
255 */
Heiko Carstens4799b552014-01-01 16:55:48 +0100256 len = sizeof(tpi_data) - 4;
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300257 rc = write_guest(vcpu, addr, ar, &tpi_data, len);
David Hildenbrand261520d2015-02-04 15:53:42 +0100258 if (rc) {
259 rc = kvm_s390_inject_prog_cond(vcpu, rc);
260 goto reinject_interrupt;
261 }
Heiko Carstens7c959e82013-03-05 13:14:46 +0100262 } else {
263 /*
264 * Store the three-word I/O interruption code into
265 * the appropriate lowcore area.
266 */
Heiko Carstens4799b552014-01-01 16:55:48 +0100267 len = sizeof(tpi_data);
David Hildenbrand261520d2015-02-04 15:53:42 +0100268 if (write_guest_lc(vcpu, __LC_SUBCHANNEL_ID, &tpi_data, len)) {
269 /* failed writes to the low core are not recoverable */
Heiko Carstens4799b552014-01-01 16:55:48 +0100270 rc = -EFAULT;
David Hildenbrand261520d2015-02-04 15:53:42 +0100271 goto reinject_interrupt;
272 }
Heiko Carstens7c959e82013-03-05 13:14:46 +0100273 }
David Hildenbrand261520d2015-02-04 15:53:42 +0100274
275 /* irq was successfully handed to the guest */
276 kfree(inti);
277 kvm_s390_set_psw_cc(vcpu, 1);
278 return 0;
279reinject_interrupt:
Cornelia Huck2f32d4e2014-01-08 18:07:54 +0100280 /*
281 * If we encounter a problem storing the interruption code, the
282 * instruction is suppressed from the guest's view: reinject the
283 * interrupt.
284 */
David Hildenbrand15462e32015-02-04 15:59:11 +0100285 if (kvm_s390_reinject_io_int(vcpu->kvm, inti)) {
286 kfree(inti);
287 rc = -EFAULT;
288 }
David Hildenbrand261520d2015-02-04 15:53:42 +0100289 /* don't set the cc, a pgm irq was injected or we drop to user space */
Heiko Carstens4799b552014-01-01 16:55:48 +0100290 return rc ? -EFAULT : 0;
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +0100291}
292
293static int handle_tsch(struct kvm_vcpu *vcpu)
294{
Jens Freimann6d3da242013-07-03 15:18:35 +0200295 struct kvm_s390_interrupt_info *inti = NULL;
296 const u64 isc_mask = 0xffUL << 24; /* all iscs set */
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +0100297
Jens Freimann6d3da242013-07-03 15:18:35 +0200298 /* a valid schid has at least one bit set */
299 if (vcpu->run->s.regs.gprs[1])
300 inti = kvm_s390_get_io_int(vcpu->kvm, isc_mask,
301 vcpu->run->s.regs.gprs[1]);
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +0100302
303 /*
304 * Prepare exit to userspace.
305 * We indicate whether we dequeued a pending I/O interrupt
306 * so that userspace can re-inject it if the instruction gets
307 * a program check. While this may re-order the pending I/O
308 * interrupts, this is no problem since the priority is kept
309 * intact.
310 */
311 vcpu->run->exit_reason = KVM_EXIT_S390_TSCH;
312 vcpu->run->s390_tsch.dequeued = !!inti;
313 if (inti) {
314 vcpu->run->s390_tsch.subchannel_id = inti->io.subchannel_id;
315 vcpu->run->s390_tsch.subchannel_nr = inti->io.subchannel_nr;
316 vcpu->run->s390_tsch.io_int_parm = inti->io.io_int_parm;
317 vcpu->run->s390_tsch.io_int_word = inti->io.io_int_word;
318 }
319 vcpu->run->s390_tsch.ipb = vcpu->arch.sie_block->ipb;
320 kfree(inti);
321 return -EREMOTE;
322}
323
Cornelia Huckf379aae2012-12-20 15:32:10 +0100324static int handle_io_inst(struct kvm_vcpu *vcpu)
Christian Borntraeger453423d2008-03-25 18:47:29 +0100325{
Cornelia Huckf379aae2012-12-20 15:32:10 +0100326 VCPU_EVENT(vcpu, 4, "%s", "I/O instruction");
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +0100327
Thomas Huth5087dfa2013-06-20 17:22:01 +0200328 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
329 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
330
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +0100331 if (vcpu->kvm->arch.css_support) {
332 /*
333 * Most I/O instructions will be handled by userspace.
334 * Exceptions are tpi and the interrupt portion of tsch.
335 */
336 if (vcpu->arch.sie_block->ipa == 0xb236)
337 return handle_tpi(vcpu);
338 if (vcpu->arch.sie_block->ipa == 0xb235)
339 return handle_tsch(vcpu);
340 /* Handle in userspace. */
341 return -EOPNOTSUPP;
342 } else {
343 /*
Hendrik Bruecknerb4a96012013-12-13 12:53:42 +0100344 * Set condition code 3 to stop the guest from issuing channel
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +0100345 * I/O instructions.
346 */
Thomas Huthea828eb2013-07-26 15:04:06 +0200347 kvm_s390_set_psw_cc(vcpu, 3);
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +0100348 return 0;
349 }
Christian Borntraeger453423d2008-03-25 18:47:29 +0100350}
351
Christian Borntraeger453423d2008-03-25 18:47:29 +0100352static int handle_stfl(struct kvm_vcpu *vcpu)
353{
Christian Borntraeger453423d2008-03-25 18:47:29 +0100354 int rc;
Michael Mueller9d8d5782015-02-02 15:42:51 +0100355 unsigned int fac;
Christian Borntraeger453423d2008-03-25 18:47:29 +0100356
357 vcpu->stat.instruction_stfl++;
Thomas Huth5087dfa2013-06-20 17:22:01 +0200358
359 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
360 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
361
Michael Mueller9d8d5782015-02-02 15:42:51 +0100362 /*
363 * We need to shift the lower 32 facility bits (bit 0-31) from a u64
364 * into a u32 memory representation. They will remain bits 0-31.
365 */
Michael Mueller981467c2015-02-24 13:51:04 +0100366 fac = *vcpu->kvm->arch.model.fac->list >> 32;
Heiko Carstens0f9701c2014-01-01 16:56:41 +0100367 rc = write_guest_lc(vcpu, offsetof(struct _lowcore, stfl_fac_list),
Michael Mueller9d8d5782015-02-02 15:42:51 +0100368 &fac, sizeof(fac));
Heiko Carstensdc5008b2013-03-05 13:14:43 +0100369 if (rc)
Heiko Carstens0f9701c2014-01-01 16:56:41 +0100370 return rc;
Christian Borntraeger7cbde762015-07-21 12:44:57 +0200371 VCPU_EVENT(vcpu, 3, "STFL: store facility list 0x%x", fac);
Michael Mueller9d8d5782015-02-02 15:42:51 +0100372 trace_kvm_s390_handle_stfl(vcpu, fac);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100373 return 0;
374}
375
Cornelia Huck48a3e952012-12-20 15:32:09 +0100376#define PSW_MASK_ADDR_MODE (PSW_MASK_EA | PSW_MASK_BA)
377#define PSW_MASK_UNASSIGNED 0xb80800fe7fffffffUL
Heiko Carstensd21683e2013-03-25 17:22:49 +0100378#define PSW_ADDR_24 0x0000000000ffffffUL
Cornelia Huck48a3e952012-12-20 15:32:09 +0100379#define PSW_ADDR_31 0x000000007fffffffUL
380
Thomas Hutha3fb5772014-04-17 09:10:40 +0200381int is_valid_psw(psw_t *psw)
382{
Heiko Carstens3736b872013-03-25 17:22:52 +0100383 if (psw->mask & PSW_MASK_UNASSIGNED)
384 return 0;
385 if ((psw->mask & PSW_MASK_ADDR_MODE) == PSW_MASK_BA) {
386 if (psw->addr & ~PSW_ADDR_31)
387 return 0;
388 }
389 if (!(psw->mask & PSW_MASK_ADDR_MODE) && (psw->addr & ~PSW_ADDR_24))
390 return 0;
391 if ((psw->mask & PSW_MASK_ADDR_MODE) == PSW_MASK_EA)
392 return 0;
Thomas Hutha3fb5772014-04-17 09:10:40 +0200393 if (psw->addr & 1)
394 return 0;
Heiko Carstens3736b872013-03-25 17:22:52 +0100395 return 1;
396}
397
Cornelia Huck48a3e952012-12-20 15:32:09 +0100398int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu)
399{
Heiko Carstens3736b872013-03-25 17:22:52 +0100400 psw_t *gpsw = &vcpu->arch.sie_block->gpsw;
Cornelia Huck48a3e952012-12-20 15:32:09 +0100401 psw_compat_t new_psw;
Heiko Carstens3736b872013-03-25 17:22:52 +0100402 u64 addr;
Heiko Carstens2d8bcae2014-01-01 16:57:42 +0100403 int rc;
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300404 ar_t ar;
Cornelia Huck48a3e952012-12-20 15:32:09 +0100405
Heiko Carstens3736b872013-03-25 17:22:52 +0100406 if (gpsw->mask & PSW_MASK_PSTATE)
Thomas Huth208dd752013-06-20 17:21:59 +0200407 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
408
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300409 addr = kvm_s390_get_base_disp_s(vcpu, &ar);
Heiko Carstens6fd0fcc2013-03-25 17:22:51 +0100410 if (addr & 7)
411 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
Heiko Carstens2d8bcae2014-01-01 16:57:42 +0100412
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300413 rc = read_guest(vcpu, addr, ar, &new_psw, sizeof(new_psw));
Heiko Carstens2d8bcae2014-01-01 16:57:42 +0100414 if (rc)
415 return kvm_s390_inject_prog_cond(vcpu, rc);
Heiko Carstens6fd0fcc2013-03-25 17:22:51 +0100416 if (!(new_psw.mask & PSW32_MASK_BASE))
417 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
Heiko Carstens3736b872013-03-25 17:22:52 +0100418 gpsw->mask = (new_psw.mask & ~PSW32_MASK_BASE) << 32;
419 gpsw->mask |= new_psw.addr & PSW32_ADDR_AMODE;
420 gpsw->addr = new_psw.addr & ~PSW32_ADDR_AMODE;
421 if (!is_valid_psw(gpsw))
Heiko Carstens6fd0fcc2013-03-25 17:22:51 +0100422 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
Cornelia Huck48a3e952012-12-20 15:32:09 +0100423 return 0;
424}
425
426static int handle_lpswe(struct kvm_vcpu *vcpu)
427{
Cornelia Huck48a3e952012-12-20 15:32:09 +0100428 psw_t new_psw;
Heiko Carstens3736b872013-03-25 17:22:52 +0100429 u64 addr;
Heiko Carstens2d8bcae2014-01-01 16:57:42 +0100430 int rc;
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300431 ar_t ar;
Cornelia Huck48a3e952012-12-20 15:32:09 +0100432
Thomas Huth5087dfa2013-06-20 17:22:01 +0200433 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
434 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
435
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300436 addr = kvm_s390_get_base_disp_s(vcpu, &ar);
Heiko Carstens6fd0fcc2013-03-25 17:22:51 +0100437 if (addr & 7)
438 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300439 rc = read_guest(vcpu, addr, ar, &new_psw, sizeof(new_psw));
Heiko Carstens2d8bcae2014-01-01 16:57:42 +0100440 if (rc)
441 return kvm_s390_inject_prog_cond(vcpu, rc);
Heiko Carstens3736b872013-03-25 17:22:52 +0100442 vcpu->arch.sie_block->gpsw = new_psw;
443 if (!is_valid_psw(&vcpu->arch.sie_block->gpsw))
Heiko Carstens6fd0fcc2013-03-25 17:22:51 +0100444 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
Cornelia Huck48a3e952012-12-20 15:32:09 +0100445 return 0;
446}
447
Christian Borntraeger453423d2008-03-25 18:47:29 +0100448static int handle_stidp(struct kvm_vcpu *vcpu)
449{
Heiko Carstens7d777d72014-01-01 16:58:16 +0100450 u64 stidp_data = vcpu->arch.stidp_data;
Christian Borntraeger453423d2008-03-25 18:47:29 +0100451 u64 operand2;
Heiko Carstens7d777d72014-01-01 16:58:16 +0100452 int rc;
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300453 ar_t ar;
Christian Borntraeger453423d2008-03-25 18:47:29 +0100454
455 vcpu->stat.instruction_stidp++;
Cornelia Huckb1c571a2012-12-20 15:32:07 +0100456
Thomas Huth5087dfa2013-06-20 17:22:01 +0200457 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
458 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
459
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300460 operand2 = kvm_s390_get_base_disp_s(vcpu, &ar);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100461
Heiko Carstensdb4a29c2013-03-25 17:22:53 +0100462 if (operand2 & 7)
463 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100464
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300465 rc = write_guest(vcpu, operand2, ar, &stidp_data, sizeof(stidp_data));
Heiko Carstens7d777d72014-01-01 16:58:16 +0100466 if (rc)
467 return kvm_s390_inject_prog_cond(vcpu, rc);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100468
Christian Borntraeger7cbde762015-07-21 12:44:57 +0200469 VCPU_EVENT(vcpu, 3, "STIDP: store cpu id 0x%llx", stidp_data);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100470 return 0;
471}
472
473static void handle_stsi_3_2_2(struct kvm_vcpu *vcpu, struct sysinfo_3_2_2 *mem)
474{
Christian Borntraeger453423d2008-03-25 18:47:29 +0100475 int cpus = 0;
476 int n;
477
Jens Freimannff520a62014-02-24 10:11:41 +0100478 cpus = atomic_read(&vcpu->kvm->online_vcpus);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100479
480 /* deal with other level 3 hypervisors */
Heiko Carstenscaf757c2012-09-06 14:42:13 +0200481 if (stsi(mem, 3, 2, 2))
Christian Borntraeger453423d2008-03-25 18:47:29 +0100482 mem->count = 0;
483 if (mem->count < 8)
484 mem->count++;
485 for (n = mem->count - 1; n > 0 ; n--)
486 memcpy(&mem->vm[n], &mem->vm[n - 1], sizeof(mem->vm[0]));
487
Ekaterina Tumanovab75f4c92015-03-03 09:54:41 +0100488 memset(&mem->vm[0], 0, sizeof(mem->vm[0]));
Christian Borntraeger453423d2008-03-25 18:47:29 +0100489 mem->vm[0].cpus_total = cpus;
490 mem->vm[0].cpus_configured = cpus;
491 mem->vm[0].cpus_standby = 0;
492 mem->vm[0].cpus_reserved = 0;
493 mem->vm[0].caf = 1000;
494 memcpy(mem->vm[0].name, "KVMguest", 8);
495 ASCEBC(mem->vm[0].name, 8);
496 memcpy(mem->vm[0].cpi, "KVM/Linux ", 16);
497 ASCEBC(mem->vm[0].cpi, 16);
498}
499
Ekaterina Tumanovae44fc8c2015-01-30 16:55:56 +0100500static void insert_stsi_usr_data(struct kvm_vcpu *vcpu, u64 addr, ar_t ar,
501 u8 fc, u8 sel1, u16 sel2)
502{
503 vcpu->run->exit_reason = KVM_EXIT_S390_STSI;
504 vcpu->run->s390_stsi.addr = addr;
505 vcpu->run->s390_stsi.ar = ar;
506 vcpu->run->s390_stsi.fc = fc;
507 vcpu->run->s390_stsi.sel1 = sel1;
508 vcpu->run->s390_stsi.sel2 = sel2;
509}
510
Christian Borntraeger453423d2008-03-25 18:47:29 +0100511static int handle_stsi(struct kvm_vcpu *vcpu)
512{
Christian Borntraeger5a32c1a2012-01-11 11:20:32 +0100513 int fc = (vcpu->run->s.regs.gprs[0] & 0xf0000000) >> 28;
514 int sel1 = vcpu->run->s.regs.gprs[0] & 0xff;
515 int sel2 = vcpu->run->s.regs.gprs[1] & 0xffff;
Heiko Carstensc51f0682013-03-25 17:22:54 +0100516 unsigned long mem = 0;
Christian Borntraeger453423d2008-03-25 18:47:29 +0100517 u64 operand2;
Heiko Carstensdb4a29c2013-03-25 17:22:53 +0100518 int rc = 0;
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300519 ar_t ar;
Christian Borntraeger453423d2008-03-25 18:47:29 +0100520
521 vcpu->stat.instruction_stsi++;
Christian Borntraeger7cbde762015-07-21 12:44:57 +0200522 VCPU_EVENT(vcpu, 3, "STSI: fc: %u sel1: %u sel2: %u", fc, sel1, sel2);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100523
Thomas Huth5087dfa2013-06-20 17:22:01 +0200524 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
525 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
526
Thomas Huth87d41fb2013-06-20 17:22:05 +0200527 if (fc > 3) {
Thomas Huthea828eb2013-07-26 15:04:06 +0200528 kvm_s390_set_psw_cc(vcpu, 3);
Thomas Huth87d41fb2013-06-20 17:22:05 +0200529 return 0;
530 }
531
532 if (vcpu->run->s.regs.gprs[0] & 0x0fffff00
533 || vcpu->run->s.regs.gprs[1] & 0xffff0000)
534 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
535
536 if (fc == 0) {
537 vcpu->run->s.regs.gprs[0] = 3 << 28;
Thomas Huthea828eb2013-07-26 15:04:06 +0200538 kvm_s390_set_psw_cc(vcpu, 0);
Thomas Huth87d41fb2013-06-20 17:22:05 +0200539 return 0;
540 }
541
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300542 operand2 = kvm_s390_get_base_disp_s(vcpu, &ar);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100543
Thomas Huth87d41fb2013-06-20 17:22:05 +0200544 if (operand2 & 0xfff)
Christian Borntraeger453423d2008-03-25 18:47:29 +0100545 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
546
547 switch (fc) {
Christian Borntraeger453423d2008-03-25 18:47:29 +0100548 case 1: /* same handling for 1 and 2 */
549 case 2:
550 mem = get_zeroed_page(GFP_KERNEL);
551 if (!mem)
Heiko Carstensc51f0682013-03-25 17:22:54 +0100552 goto out_no_data;
Heiko Carstenscaf757c2012-09-06 14:42:13 +0200553 if (stsi((void *) mem, fc, sel1, sel2))
Heiko Carstensc51f0682013-03-25 17:22:54 +0100554 goto out_no_data;
Christian Borntraeger453423d2008-03-25 18:47:29 +0100555 break;
556 case 3:
557 if (sel1 != 2 || sel2 != 2)
Heiko Carstensc51f0682013-03-25 17:22:54 +0100558 goto out_no_data;
Christian Borntraeger453423d2008-03-25 18:47:29 +0100559 mem = get_zeroed_page(GFP_KERNEL);
560 if (!mem)
Heiko Carstensc51f0682013-03-25 17:22:54 +0100561 goto out_no_data;
Christian Borntraeger453423d2008-03-25 18:47:29 +0100562 handle_stsi_3_2_2(vcpu, (void *) mem);
563 break;
Christian Borntraeger453423d2008-03-25 18:47:29 +0100564 }
565
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300566 rc = write_guest(vcpu, operand2, ar, (void *)mem, PAGE_SIZE);
Heiko Carstens645c5bc2014-01-01 16:58:59 +0100567 if (rc) {
568 rc = kvm_s390_inject_prog_cond(vcpu, rc);
569 goto out;
Christian Borntraeger453423d2008-03-25 18:47:29 +0100570 }
Ekaterina Tumanovae44fc8c2015-01-30 16:55:56 +0100571 if (vcpu->kvm->arch.user_stsi) {
572 insert_stsi_usr_data(vcpu, operand2, ar, fc, sel1, sel2);
573 rc = -EREMOTE;
574 }
Cornelia Huck5786fff2012-07-23 17:20:29 +0200575 trace_kvm_s390_handle_stsi(vcpu, fc, sel1, sel2, operand2);
Christian Borntraeger453423d2008-03-25 18:47:29 +0100576 free_page(mem);
Thomas Huthea828eb2013-07-26 15:04:06 +0200577 kvm_s390_set_psw_cc(vcpu, 0);
Christian Borntraeger5a32c1a2012-01-11 11:20:32 +0100578 vcpu->run->s.regs.gprs[0] = 0;
Ekaterina Tumanovae44fc8c2015-01-30 16:55:56 +0100579 return rc;
Heiko Carstensc51f0682013-03-25 17:22:54 +0100580out_no_data:
Thomas Huthea828eb2013-07-26 15:04:06 +0200581 kvm_s390_set_psw_cc(vcpu, 3);
Heiko Carstens645c5bc2014-01-01 16:58:59 +0100582out:
Heiko Carstensc51f0682013-03-25 17:22:54 +0100583 free_page(mem);
Heiko Carstensdb4a29c2013-03-25 17:22:53 +0100584 return rc;
Christian Borntraeger453423d2008-03-25 18:47:29 +0100585}
586
Cornelia Huckf379aae2012-12-20 15:32:10 +0100587static const intercept_handler_t b2_handlers[256] = {
Christian Borntraeger453423d2008-03-25 18:47:29 +0100588 [0x02] = handle_stidp,
Thomas Huth6a3f95a2013-09-12 10:33:49 +0200589 [0x04] = handle_set_clock,
Christian Borntraeger453423d2008-03-25 18:47:29 +0100590 [0x10] = handle_set_prefix,
591 [0x11] = handle_store_prefix,
592 [0x12] = handle_store_cpu_address,
Heiko Carstens8a2422342014-01-10 14:33:28 +0100593 [0x21] = handle_ipte_interlock,
Christian Borntraeger453423d2008-03-25 18:47:29 +0100594 [0x29] = handle_skey,
595 [0x2a] = handle_skey,
596 [0x2b] = handle_skey,
Thomas Huthaca84242013-09-12 10:33:48 +0200597 [0x2c] = handle_test_block,
Cornelia Huckf379aae2012-12-20 15:32:10 +0100598 [0x30] = handle_io_inst,
599 [0x31] = handle_io_inst,
600 [0x32] = handle_io_inst,
601 [0x33] = handle_io_inst,
602 [0x34] = handle_io_inst,
603 [0x35] = handle_io_inst,
604 [0x36] = handle_io_inst,
605 [0x37] = handle_io_inst,
606 [0x38] = handle_io_inst,
607 [0x39] = handle_io_inst,
608 [0x3a] = handle_io_inst,
609 [0x3b] = handle_io_inst,
610 [0x3c] = handle_io_inst,
Heiko Carstens8a2422342014-01-10 14:33:28 +0100611 [0x50] = handle_ipte_interlock,
Cornelia Huckf379aae2012-12-20 15:32:10 +0100612 [0x5f] = handle_io_inst,
613 [0x74] = handle_io_inst,
614 [0x76] = handle_io_inst,
Christian Borntraeger453423d2008-03-25 18:47:29 +0100615 [0x7d] = handle_stsi,
616 [0xb1] = handle_stfl,
Cornelia Huck48a3e952012-12-20 15:32:09 +0100617 [0xb2] = handle_lpswe,
Christian Borntraeger453423d2008-03-25 18:47:29 +0100618};
619
Christian Borntraeger70455a32009-01-22 10:28:29 +0100620int kvm_s390_handle_b2(struct kvm_vcpu *vcpu)
Christian Borntraeger453423d2008-03-25 18:47:29 +0100621{
622 intercept_handler_t handler;
623
Christian Borntraeger70455a32009-01-22 10:28:29 +0100624 /*
Thomas Huth5087dfa2013-06-20 17:22:01 +0200625 * A lot of B2 instructions are priviledged. Here we check for
626 * the privileged ones, that we can handle in the kernel.
627 * Anything else goes to userspace.
628 */
Cornelia Huckf379aae2012-12-20 15:32:10 +0100629 handler = b2_handlers[vcpu->arch.sie_block->ipa & 0x00ff];
Thomas Huth5087dfa2013-06-20 17:22:01 +0200630 if (handler)
631 return handler(vcpu);
632
Heiko Carstensb8e660b2010-02-26 22:37:41 +0100633 return -EOPNOTSUPP;
Christian Borntraeger453423d2008-03-25 18:47:29 +0100634}
Christian Borntraegerbb25b9b2011-07-24 10:48:17 +0200635
Cornelia Huck48a3e952012-12-20 15:32:09 +0100636static int handle_epsw(struct kvm_vcpu *vcpu)
637{
638 int reg1, reg2;
639
Thomas Huthaeb87c32013-06-12 13:54:57 +0200640 kvm_s390_get_regs_rre(vcpu, &reg1, &reg2);
Cornelia Huck48a3e952012-12-20 15:32:09 +0100641
642 /* This basically extracts the mask half of the psw. */
Thomas Huth843200e2013-07-26 15:04:05 +0200643 vcpu->run->s.regs.gprs[reg1] &= 0xffffffff00000000UL;
Cornelia Huck48a3e952012-12-20 15:32:09 +0100644 vcpu->run->s.regs.gprs[reg1] |= vcpu->arch.sie_block->gpsw.mask >> 32;
645 if (reg2) {
Thomas Huth843200e2013-07-26 15:04:05 +0200646 vcpu->run->s.regs.gprs[reg2] &= 0xffffffff00000000UL;
Cornelia Huck48a3e952012-12-20 15:32:09 +0100647 vcpu->run->s.regs.gprs[reg2] |=
Thomas Huth843200e2013-07-26 15:04:05 +0200648 vcpu->arch.sie_block->gpsw.mask & 0x00000000ffffffffUL;
Cornelia Huck48a3e952012-12-20 15:32:09 +0100649 }
650 return 0;
651}
652
Christian Borntraeger69d0d3a2013-06-12 13:54:53 +0200653#define PFMF_RESERVED 0xfffc0101UL
654#define PFMF_SK 0x00020000UL
655#define PFMF_CF 0x00010000UL
656#define PFMF_UI 0x00008000UL
657#define PFMF_FSC 0x00007000UL
658#define PFMF_NQ 0x00000800UL
659#define PFMF_MR 0x00000400UL
660#define PFMF_MC 0x00000200UL
661#define PFMF_KEY 0x000000feUL
662
663static int handle_pfmf(struct kvm_vcpu *vcpu)
664{
665 int reg1, reg2;
666 unsigned long start, end;
667
668 vcpu->stat.instruction_pfmf++;
669
670 kvm_s390_get_regs_rre(vcpu, &reg1, &reg2);
671
672 if (!MACHINE_HAS_PFMF)
673 return kvm_s390_inject_program_int(vcpu, PGM_OPERATION);
674
675 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
Thomas Huth208dd752013-06-20 17:21:59 +0200676 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
Christian Borntraeger69d0d3a2013-06-12 13:54:53 +0200677
678 if (vcpu->run->s.regs.gprs[reg1] & PFMF_RESERVED)
679 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
680
681 /* Only provide non-quiescing support if the host supports it */
Heiko Carstense769ece2013-07-26 15:04:01 +0200682 if (vcpu->run->s.regs.gprs[reg1] & PFMF_NQ && !test_facility(14))
Christian Borntraeger69d0d3a2013-06-12 13:54:53 +0200683 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
684
685 /* No support for conditional-SSKE */
686 if (vcpu->run->s.regs.gprs[reg1] & (PFMF_MR | PFMF_MC))
687 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
688
689 start = vcpu->run->s.regs.gprs[reg2] & PAGE_MASK;
Thomas Hutha02689f2014-11-10 15:59:32 +0100690 start = kvm_s390_logical_to_effective(vcpu, start);
Thomas Huthfb34c6032013-09-09 17:58:38 +0200691
Christian Borntraeger69d0d3a2013-06-12 13:54:53 +0200692 switch (vcpu->run->s.regs.gprs[reg1] & PFMF_FSC) {
693 case 0x00000000:
694 end = (start + (1UL << 12)) & ~((1UL << 12) - 1);
695 break;
696 case 0x00001000:
697 end = (start + (1UL << 20)) & ~((1UL << 20) - 1);
698 break;
Christian Borntraeger69d0d3a2013-06-12 13:54:53 +0200699 case 0x00002000:
Guenther Hutzl53df84f2015-02-18 11:13:03 +0100700 /* only support 2G frame size if EDAT2 is available and we are
701 not in 24-bit addressing mode */
702 if (!test_kvm_facility(vcpu->kvm, 78) ||
703 psw_bits(vcpu->arch.sie_block->gpsw).eaba == PSW_AMODE_24BIT)
704 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
Christian Borntraeger69d0d3a2013-06-12 13:54:53 +0200705 end = (start + (1UL << 31)) & ~((1UL << 31) - 1);
Guenther Hutzl53df84f2015-02-18 11:13:03 +0100706 break;
Christian Borntraeger69d0d3a2013-06-12 13:54:53 +0200707 default:
708 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
709 }
Thomas Hutha02689f2014-11-10 15:59:32 +0100710
711 if (vcpu->run->s.regs.gprs[reg1] & PFMF_CF) {
Alexander Yarygindd9e5b72015-03-03 14:26:14 +0300712 if (kvm_s390_check_low_addr_prot_real(vcpu, start))
Thomas Hutha02689f2014-11-10 15:59:32 +0100713 return kvm_s390_inject_prog_irq(vcpu, &vcpu->arch.pgm);
714 }
715
Christian Borntraeger69d0d3a2013-06-12 13:54:53 +0200716 while (start < end) {
Thomas Huthfb34c6032013-09-09 17:58:38 +0200717 unsigned long useraddr, abs_addr;
Christian Borntraeger69d0d3a2013-06-12 13:54:53 +0200718
Thomas Huthfb34c6032013-09-09 17:58:38 +0200719 /* Translate guest address to host address */
720 if ((vcpu->run->s.regs.gprs[reg1] & PFMF_FSC) == 0)
721 abs_addr = kvm_s390_real_to_abs(vcpu, start);
722 else
723 abs_addr = start;
724 useraddr = gfn_to_hva(vcpu->kvm, gpa_to_gfn(abs_addr));
725 if (kvm_is_error_hva(useraddr))
Christian Borntraeger69d0d3a2013-06-12 13:54:53 +0200726 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
727
728 if (vcpu->run->s.regs.gprs[reg1] & PFMF_CF) {
729 if (clear_user((void __user *)useraddr, PAGE_SIZE))
730 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
731 }
732
733 if (vcpu->run->s.regs.gprs[reg1] & PFMF_SK) {
Dominik Dingel3ac8e382014-10-23 12:09:17 +0200734 int rc = __skey_check_enable(vcpu);
735
736 if (rc)
737 return rc;
Christian Borntraeger69d0d3a2013-06-12 13:54:53 +0200738 if (set_guest_storage_key(current->mm, useraddr,
739 vcpu->run->s.regs.gprs[reg1] & PFMF_KEY,
740 vcpu->run->s.regs.gprs[reg1] & PFMF_NQ))
741 return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
742 }
743
744 start += PAGE_SIZE;
745 }
746 if (vcpu->run->s.regs.gprs[reg1] & PFMF_FSC)
747 vcpu->run->s.regs.gprs[reg2] = end;
748 return 0;
749}
750
Konstantin Weitzb31288f2013-04-17 17:36:29 +0200751static int handle_essa(struct kvm_vcpu *vcpu)
752{
753 /* entries expected to be 1FF */
754 int entries = (vcpu->arch.sie_block->cbrlo & ~PAGE_MASK) >> 3;
755 unsigned long *cbrlo, cbrle;
756 struct gmap *gmap;
757 int i;
758
Christian Borntraeger7cbde762015-07-21 12:44:57 +0200759 VCPU_EVENT(vcpu, 4, "ESSA: release %d pages", entries);
Konstantin Weitzb31288f2013-04-17 17:36:29 +0200760 gmap = vcpu->arch.gmap;
761 vcpu->stat.instruction_essa++;
Dominik Dingele6db1d62015-05-07 15:41:57 +0200762 if (!vcpu->kvm->arch.use_cmma)
Konstantin Weitzb31288f2013-04-17 17:36:29 +0200763 return kvm_s390_inject_program_int(vcpu, PGM_OPERATION);
764
765 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
766 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
767
768 if (((vcpu->arch.sie_block->ipb & 0xf0000000) >> 28) > 6)
769 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
770
771 /* Rewind PSW to repeat the ESSA instruction */
Thomas Huth04b41ac2014-11-12 17:13:29 +0100772 kvm_s390_rewind_psw(vcpu, 4);
Konstantin Weitzb31288f2013-04-17 17:36:29 +0200773 vcpu->arch.sie_block->cbrlo &= PAGE_MASK; /* reset nceo */
774 cbrlo = phys_to_virt(vcpu->arch.sie_block->cbrlo);
775 down_read(&gmap->mm->mmap_sem);
776 for (i = 0; i < entries; ++i) {
777 cbrle = cbrlo[i];
778 if (unlikely(cbrle & ~PAGE_MASK || cbrle < 2 * PAGE_SIZE))
779 /* invalid entry */
780 break;
781 /* try to free backing */
Martin Schwidefsky6e0a0432014-04-29 09:34:41 +0200782 __gmap_zap(gmap, cbrle);
Konstantin Weitzb31288f2013-04-17 17:36:29 +0200783 }
784 up_read(&gmap->mm->mmap_sem);
785 if (i < entries)
786 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
787 return 0;
788}
789
Cornelia Huck48a3e952012-12-20 15:32:09 +0100790static const intercept_handler_t b9_handlers[256] = {
Heiko Carstens8a2422342014-01-10 14:33:28 +0100791 [0x8a] = handle_ipte_interlock,
Cornelia Huck48a3e952012-12-20 15:32:09 +0100792 [0x8d] = handle_epsw,
Heiko Carstens8a2422342014-01-10 14:33:28 +0100793 [0x8e] = handle_ipte_interlock,
794 [0x8f] = handle_ipte_interlock,
Konstantin Weitzb31288f2013-04-17 17:36:29 +0200795 [0xab] = handle_essa,
Christian Borntraeger69d0d3a2013-06-12 13:54:53 +0200796 [0xaf] = handle_pfmf,
Cornelia Huck48a3e952012-12-20 15:32:09 +0100797};
798
799int kvm_s390_handle_b9(struct kvm_vcpu *vcpu)
800{
801 intercept_handler_t handler;
802
803 /* This is handled just as for the B2 instructions. */
804 handler = b9_handlers[vcpu->arch.sie_block->ipa & 0x00ff];
Thomas Huth5087dfa2013-06-20 17:22:01 +0200805 if (handler)
806 return handler(vcpu);
807
Cornelia Huck48a3e952012-12-20 15:32:09 +0100808 return -EOPNOTSUPP;
809}
810
Thomas Huth953ed882013-06-20 17:22:04 +0200811int kvm_s390_handle_lctl(struct kvm_vcpu *vcpu)
812{
813 int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4;
814 int reg3 = vcpu->arch.sie_block->ipa & 0x000f;
Heiko Carstensfc56eb62014-10-29 10:07:16 +0100815 int reg, rc, nr_regs;
816 u32 ctl_array[16];
Heiko Carstensf987a3e2014-01-01 16:59:21 +0100817 u64 ga;
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300818 ar_t ar;
Thomas Huth953ed882013-06-20 17:22:04 +0200819
820 vcpu->stat.instruction_lctl++;
821
822 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
823 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
824
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300825 ga = kvm_s390_get_base_disp_rs(vcpu, &ar);
Thomas Huth953ed882013-06-20 17:22:04 +0200826
Heiko Carstensf987a3e2014-01-01 16:59:21 +0100827 if (ga & 3)
Thomas Huth953ed882013-06-20 17:22:04 +0200828 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
829
Christian Borntraeger7cbde762015-07-21 12:44:57 +0200830 VCPU_EVENT(vcpu, 4, "LCTL: r1:%d, r3:%d, addr: 0x%llx", reg1, reg3, ga);
Heiko Carstensf987a3e2014-01-01 16:59:21 +0100831 trace_kvm_s390_handle_lctl(vcpu, 0, reg1, reg3, ga);
Thomas Huth953ed882013-06-20 17:22:04 +0200832
Heiko Carstensfc56eb62014-10-29 10:07:16 +0100833 nr_regs = ((reg3 - reg1) & 0xf) + 1;
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300834 rc = read_guest(vcpu, ga, ar, ctl_array, nr_regs * sizeof(u32));
Heiko Carstensfc56eb62014-10-29 10:07:16 +0100835 if (rc)
836 return kvm_s390_inject_prog_cond(vcpu, rc);
Thomas Huth953ed882013-06-20 17:22:04 +0200837 reg = reg1;
Heiko Carstensfc56eb62014-10-29 10:07:16 +0100838 nr_regs = 0;
Thomas Huth953ed882013-06-20 17:22:04 +0200839 do {
Thomas Huth953ed882013-06-20 17:22:04 +0200840 vcpu->arch.sie_block->gcr[reg] &= 0xffffffff00000000ul;
Heiko Carstensfc56eb62014-10-29 10:07:16 +0100841 vcpu->arch.sie_block->gcr[reg] |= ctl_array[nr_regs++];
Thomas Huth953ed882013-06-20 17:22:04 +0200842 if (reg == reg3)
843 break;
844 reg = (reg + 1) % 16;
845 } while (1);
Christian Borntraeger2dca4852014-10-31 09:24:20 +0100846 kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
Thomas Huth953ed882013-06-20 17:22:04 +0200847 return 0;
848}
849
David Hildenbrandaba07502014-01-23 10:47:13 +0100850int kvm_s390_handle_stctl(struct kvm_vcpu *vcpu)
851{
852 int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4;
853 int reg3 = vcpu->arch.sie_block->ipa & 0x000f;
Heiko Carstensfc56eb62014-10-29 10:07:16 +0100854 int reg, rc, nr_regs;
855 u32 ctl_array[16];
David Hildenbrandaba07502014-01-23 10:47:13 +0100856 u64 ga;
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300857 ar_t ar;
David Hildenbrandaba07502014-01-23 10:47:13 +0100858
859 vcpu->stat.instruction_stctl++;
860
861 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
862 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
863
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300864 ga = kvm_s390_get_base_disp_rs(vcpu, &ar);
David Hildenbrandaba07502014-01-23 10:47:13 +0100865
866 if (ga & 3)
867 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
868
Christian Borntraeger7cbde762015-07-21 12:44:57 +0200869 VCPU_EVENT(vcpu, 4, "STCTL r1:%d, r3:%d, addr: 0x%llx", reg1, reg3, ga);
David Hildenbrandaba07502014-01-23 10:47:13 +0100870 trace_kvm_s390_handle_stctl(vcpu, 0, reg1, reg3, ga);
871
872 reg = reg1;
Heiko Carstensfc56eb62014-10-29 10:07:16 +0100873 nr_regs = 0;
David Hildenbrandaba07502014-01-23 10:47:13 +0100874 do {
Heiko Carstensfc56eb62014-10-29 10:07:16 +0100875 ctl_array[nr_regs++] = vcpu->arch.sie_block->gcr[reg];
David Hildenbrandaba07502014-01-23 10:47:13 +0100876 if (reg == reg3)
877 break;
878 reg = (reg + 1) % 16;
879 } while (1);
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300880 rc = write_guest(vcpu, ga, ar, ctl_array, nr_regs * sizeof(u32));
Heiko Carstensfc56eb62014-10-29 10:07:16 +0100881 return rc ? kvm_s390_inject_prog_cond(vcpu, rc) : 0;
David Hildenbrandaba07502014-01-23 10:47:13 +0100882}
883
Thomas Huth953ed882013-06-20 17:22:04 +0200884static int handle_lctlg(struct kvm_vcpu *vcpu)
885{
886 int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4;
887 int reg3 = vcpu->arch.sie_block->ipa & 0x000f;
Heiko Carstensfc56eb62014-10-29 10:07:16 +0100888 int reg, rc, nr_regs;
889 u64 ctl_array[16];
890 u64 ga;
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300891 ar_t ar;
Thomas Huth953ed882013-06-20 17:22:04 +0200892
893 vcpu->stat.instruction_lctlg++;
894
895 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
896 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
897
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300898 ga = kvm_s390_get_base_disp_rsy(vcpu, &ar);
Thomas Huth953ed882013-06-20 17:22:04 +0200899
Heiko Carstensf987a3e2014-01-01 16:59:21 +0100900 if (ga & 7)
Thomas Huth953ed882013-06-20 17:22:04 +0200901 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
902
Christian Borntraeger7cbde762015-07-21 12:44:57 +0200903 VCPU_EVENT(vcpu, 4, "LCTLG: r1:%d, r3:%d, addr: 0x%llx", reg1, reg3, ga);
Heiko Carstensf987a3e2014-01-01 16:59:21 +0100904 trace_kvm_s390_handle_lctl(vcpu, 1, reg1, reg3, ga);
Thomas Huth953ed882013-06-20 17:22:04 +0200905
Heiko Carstensfc56eb62014-10-29 10:07:16 +0100906 nr_regs = ((reg3 - reg1) & 0xf) + 1;
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300907 rc = read_guest(vcpu, ga, ar, ctl_array, nr_regs * sizeof(u64));
Heiko Carstensfc56eb62014-10-29 10:07:16 +0100908 if (rc)
909 return kvm_s390_inject_prog_cond(vcpu, rc);
910 reg = reg1;
911 nr_regs = 0;
Thomas Huth953ed882013-06-20 17:22:04 +0200912 do {
Heiko Carstensfc56eb62014-10-29 10:07:16 +0100913 vcpu->arch.sie_block->gcr[reg] = ctl_array[nr_regs++];
Thomas Huth953ed882013-06-20 17:22:04 +0200914 if (reg == reg3)
915 break;
916 reg = (reg + 1) % 16;
917 } while (1);
Christian Borntraeger2dca4852014-10-31 09:24:20 +0100918 kvm_make_request(KVM_REQ_TLB_FLUSH, vcpu);
Thomas Huth953ed882013-06-20 17:22:04 +0200919 return 0;
920}
921
David Hildenbrandaba07502014-01-23 10:47:13 +0100922static int handle_stctg(struct kvm_vcpu *vcpu)
923{
924 int reg1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4;
925 int reg3 = vcpu->arch.sie_block->ipa & 0x000f;
Heiko Carstensfc56eb62014-10-29 10:07:16 +0100926 int reg, rc, nr_regs;
927 u64 ctl_array[16];
928 u64 ga;
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300929 ar_t ar;
David Hildenbrandaba07502014-01-23 10:47:13 +0100930
931 vcpu->stat.instruction_stctg++;
932
933 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
934 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
935
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300936 ga = kvm_s390_get_base_disp_rsy(vcpu, &ar);
David Hildenbrandaba07502014-01-23 10:47:13 +0100937
938 if (ga & 7)
939 return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
940
Christian Borntraeger7cbde762015-07-21 12:44:57 +0200941 VCPU_EVENT(vcpu, 4, "STCTG r1:%d, r3:%d, addr: 0x%llx", reg1, reg3, ga);
David Hildenbrandaba07502014-01-23 10:47:13 +0100942 trace_kvm_s390_handle_stctl(vcpu, 1, reg1, reg3, ga);
943
Heiko Carstensfc56eb62014-10-29 10:07:16 +0100944 reg = reg1;
945 nr_regs = 0;
David Hildenbrandaba07502014-01-23 10:47:13 +0100946 do {
Heiko Carstensfc56eb62014-10-29 10:07:16 +0100947 ctl_array[nr_regs++] = vcpu->arch.sie_block->gcr[reg];
David Hildenbrandaba07502014-01-23 10:47:13 +0100948 if (reg == reg3)
949 break;
950 reg = (reg + 1) % 16;
951 } while (1);
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300952 rc = write_guest(vcpu, ga, ar, ctl_array, nr_regs * sizeof(u64));
Heiko Carstensfc56eb62014-10-29 10:07:16 +0100953 return rc ? kvm_s390_inject_prog_cond(vcpu, rc) : 0;
David Hildenbrandaba07502014-01-23 10:47:13 +0100954}
955
Cornelia Huckf379aae2012-12-20 15:32:10 +0100956static const intercept_handler_t eb_handlers[256] = {
Thomas Huth953ed882013-06-20 17:22:04 +0200957 [0x2f] = handle_lctlg,
David Hildenbrandaba07502014-01-23 10:47:13 +0100958 [0x25] = handle_stctg,
Cornelia Huckf379aae2012-12-20 15:32:10 +0100959};
960
Thomas Huth953ed882013-06-20 17:22:04 +0200961int kvm_s390_handle_eb(struct kvm_vcpu *vcpu)
Cornelia Huckf379aae2012-12-20 15:32:10 +0100962{
963 intercept_handler_t handler;
964
Cornelia Huckf379aae2012-12-20 15:32:10 +0100965 handler = eb_handlers[vcpu->arch.sie_block->ipb & 0xff];
966 if (handler)
967 return handler(vcpu);
968 return -EOPNOTSUPP;
969}
970
Christian Borntraegerbb25b9b2011-07-24 10:48:17 +0200971static int handle_tprot(struct kvm_vcpu *vcpu)
972{
Cornelia Huckb1c571a2012-12-20 15:32:07 +0100973 u64 address1, address2;
Thomas Hutha0465f92014-02-04 14:48:07 +0100974 unsigned long hva, gpa;
975 int ret = 0, cc = 0;
976 bool writable;
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300977 ar_t ar;
Christian Borntraegerbb25b9b2011-07-24 10:48:17 +0200978
979 vcpu->stat.instruction_tprot++;
980
Thomas Huthf9f6bbc2013-06-20 17:22:00 +0200981 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
982 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
983
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300984 kvm_s390_get_base_disp_sse(vcpu, &address1, &address2, &ar, NULL);
Cornelia Huckb1c571a2012-12-20 15:32:07 +0100985
Christian Borntraegerbb25b9b2011-07-24 10:48:17 +0200986 /* we only handle the Linux memory detection case:
987 * access key == 0
Christian Borntraegerbb25b9b2011-07-24 10:48:17 +0200988 * everything else goes to userspace. */
989 if (address2 & 0xf0)
990 return -EOPNOTSUPP;
991 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_DAT)
Thomas Hutha0465f92014-02-04 14:48:07 +0100992 ipte_lock(vcpu);
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300993 ret = guest_translate_address(vcpu, address1, ar, &gpa, 1);
Thomas Hutha0465f92014-02-04 14:48:07 +0100994 if (ret == PGM_PROTECTION) {
995 /* Write protected? Try again with read-only... */
996 cc = 1;
Alexander Yarygin8ae04b82015-01-19 13:24:51 +0300997 ret = guest_translate_address(vcpu, address1, ar, &gpa, 0);
Thomas Hutha0465f92014-02-04 14:48:07 +0100998 }
999 if (ret) {
1000 if (ret == PGM_ADDRESSING || ret == PGM_TRANSLATION_SPEC) {
1001 ret = kvm_s390_inject_program_int(vcpu, ret);
1002 } else if (ret > 0) {
1003 /* Translation not available */
1004 kvm_s390_set_psw_cc(vcpu, 3);
1005 ret = 0;
1006 }
1007 goto out_unlock;
1008 }
Christian Borntraegerbb25b9b2011-07-24 10:48:17 +02001009
Thomas Hutha0465f92014-02-04 14:48:07 +01001010 hva = gfn_to_hva_prot(vcpu->kvm, gpa_to_gfn(gpa), &writable);
1011 if (kvm_is_error_hva(hva)) {
1012 ret = kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
1013 } else {
1014 if (!writable)
1015 cc = 1; /* Write not permitted ==> read-only */
1016 kvm_s390_set_psw_cc(vcpu, cc);
1017 /* Note: CC2 only occurs for storage keys (not supported yet) */
1018 }
1019out_unlock:
1020 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_DAT)
1021 ipte_unlock(vcpu);
1022 return ret;
Christian Borntraegerbb25b9b2011-07-24 10:48:17 +02001023}
1024
1025int kvm_s390_handle_e5(struct kvm_vcpu *vcpu)
1026{
1027 /* For e5xx... instructions we only handle TPROT */
1028 if ((vcpu->arch.sie_block->ipa & 0x00ff) == 0x01)
1029 return handle_tprot(vcpu);
1030 return -EOPNOTSUPP;
1031}
1032
Cornelia Huck8c3f61e2012-04-24 09:24:44 +02001033static int handle_sckpf(struct kvm_vcpu *vcpu)
1034{
1035 u32 value;
1036
1037 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
Thomas Huth208dd752013-06-20 17:21:59 +02001038 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
Cornelia Huck8c3f61e2012-04-24 09:24:44 +02001039
1040 if (vcpu->run->s.regs.gprs[0] & 0x00000000ffff0000)
1041 return kvm_s390_inject_program_int(vcpu,
1042 PGM_SPECIFICATION);
1043
1044 value = vcpu->run->s.regs.gprs[0] & 0x000000000000ffff;
1045 vcpu->arch.sie_block->todpr = value;
1046
1047 return 0;
1048}
1049
Cornelia Huck77975352012-12-20 15:32:06 +01001050static const intercept_handler_t x01_handlers[256] = {
Cornelia Huck8c3f61e2012-04-24 09:24:44 +02001051 [0x07] = handle_sckpf,
1052};
1053
1054int kvm_s390_handle_01(struct kvm_vcpu *vcpu)
1055{
1056 intercept_handler_t handler;
1057
1058 handler = x01_handlers[vcpu->arch.sie_block->ipa & 0x00ff];
1059 if (handler)
1060 return handler(vcpu);
1061 return -EOPNOTSUPP;
1062}