blob: 5e259bd62515178fa8087c17a8c1d9a5e994ecb4 [file] [log] [blame]
Christian Borntraeger5288fbf2008-03-25 18:47:31 +01001/*
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02002 * handling interprocessor communication
Christian Borntraeger5288fbf2008-03-25 18:47:31 +01003 *
Thomas Huthb13d3582013-11-21 16:01:48 +01004 * Copyright IBM Corp. 2008, 2013
Christian Borntraeger5288fbf2008-03-25 18:47:31 +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>
Christian Ehrhardt9ace9032009-05-20 15:34:55 +020012 * Christian Ehrhardt <ehrhardt@de.ibm.com>
Christian Borntraeger5288fbf2008-03-25 18:47:31 +010013 */
14
15#include <linux/kvm.h>
16#include <linux/kvm_host.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/slab.h>
Heiko Carstensa9ae32c2012-06-04 12:55:15 +020018#include <asm/sigp.h>
Christian Borntraeger5288fbf2008-03-25 18:47:31 +010019#include "gaccess.h"
20#include "kvm-s390.h"
Cornelia Huck5786fff2012-07-23 17:20:29 +020021#include "trace.h"
Christian Borntraeger5288fbf2008-03-25 18:47:31 +010022
Martin Schwidefsky00963692008-07-25 15:51:00 +020023static int __sigp_sense(struct kvm_vcpu *vcpu, u16 cpu_addr,
Christian Borntraeger5a32c1a2012-01-11 11:20:32 +010024 u64 *reg)
Christian Borntraeger5288fbf2008-03-25 18:47:31 +010025{
Jens Freimann1ee0bc52014-02-25 15:36:45 +010026 struct kvm_s390_local_interrupt *li;
27 struct kvm_vcpu *dst_vcpu = NULL;
28 int cpuflags;
Christian Borntraeger5288fbf2008-03-25 18:47:31 +010029 int rc;
30
31 if (cpu_addr >= KVM_MAX_VCPUS)
Heiko Carstensea1918d2012-06-26 16:06:40 +020032 return SIGP_CC_NOT_OPERATIONAL;
Christian Borntraeger5288fbf2008-03-25 18:47:31 +010033
Jens Freimann1ee0bc52014-02-25 15:36:45 +010034 dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr);
35 if (!dst_vcpu)
36 return SIGP_CC_NOT_OPERATIONAL;
37 li = &dst_vcpu->arch.local_int;
38
39 cpuflags = atomic_read(li->cpuflags);
40 if (!(cpuflags & (CPUSTAT_ECALL_PEND | CPUSTAT_STOPPED)))
Cornelia Huck21b26c02012-06-26 16:06:41 +020041 rc = SIGP_CC_ORDER_CODE_ACCEPTED;
42 else {
Christian Borntraeger5288fbf2008-03-25 18:47:31 +010043 *reg &= 0xffffffff00000000UL;
Jens Freimann1ee0bc52014-02-25 15:36:45 +010044 if (cpuflags & CPUSTAT_ECALL_PEND)
Cornelia Huck21b26c02012-06-26 16:06:41 +020045 *reg |= SIGP_STATUS_EXT_CALL_PENDING;
Jens Freimann1ee0bc52014-02-25 15:36:45 +010046 if (cpuflags & CPUSTAT_STOPPED)
Cornelia Huck21b26c02012-06-26 16:06:41 +020047 *reg |= SIGP_STATUS_STOPPED;
Heiko Carstensea1918d2012-06-26 16:06:40 +020048 rc = SIGP_CC_STATUS_STORED;
Christian Borntraeger5288fbf2008-03-25 18:47:31 +010049 }
Christian Borntraeger5288fbf2008-03-25 18:47:31 +010050
51 VCPU_EVENT(vcpu, 4, "sensed status of cpu %x rc %x", cpu_addr, rc);
52 return rc;
53}
54
55static int __sigp_emergency(struct kvm_vcpu *vcpu, u16 cpu_addr)
56{
Jens Freimann22ff4a32014-05-14 17:14:46 +020057 struct kvm_s390_interrupt s390int = {
58 .type = KVM_S390_INT_EMERGENCY,
59 .parm = vcpu->vcpu_id,
60 };
Jens Freimann1ee0bc52014-02-25 15:36:45 +010061 struct kvm_vcpu *dst_vcpu = NULL;
Jens Freimann22ff4a32014-05-14 17:14:46 +020062 int rc = 0;
Christian Borntraeger5288fbf2008-03-25 18:47:31 +010063
Thomas Huth91880d02014-03-20 13:20:46 +010064 if (cpu_addr < KVM_MAX_VCPUS)
65 dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr);
66 if (!dst_vcpu)
Heiko Carstensea1918d2012-06-26 16:06:40 +020067 return SIGP_CC_NOT_OPERATIONAL;
Christian Borntraeger5288fbf2008-03-25 18:47:31 +010068
Jens Freimann22ff4a32014-05-14 17:14:46 +020069 rc = kvm_s390_inject_vcpu(dst_vcpu, &s390int);
70 if (!rc)
71 VCPU_EVENT(vcpu, 4, "sent sigp emerg to cpu %x", cpu_addr);
Christian Borntraeger5288fbf2008-03-25 18:47:31 +010072
Jens Freimann22ff4a32014-05-14 17:14:46 +020073 return rc ? rc : SIGP_CC_ORDER_CODE_ACCEPTED;
Christian Ehrhardt7697e71f2011-10-18 12:27:15 +020074}
75
Thomas Huthb13d3582013-11-21 16:01:48 +010076static int __sigp_conditional_emergency(struct kvm_vcpu *vcpu, u16 cpu_addr,
77 u16 asn, u64 *reg)
78{
79 struct kvm_vcpu *dst_vcpu = NULL;
80 const u64 psw_int_mask = PSW_MASK_IO | PSW_MASK_EXT;
81 u16 p_asn, s_asn;
82 psw_t *psw;
83 u32 flags;
84
85 if (cpu_addr < KVM_MAX_VCPUS)
86 dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr);
87 if (!dst_vcpu)
88 return SIGP_CC_NOT_OPERATIONAL;
89 flags = atomic_read(&dst_vcpu->arch.sie_block->cpuflags);
90 psw = &dst_vcpu->arch.sie_block->gpsw;
91 p_asn = dst_vcpu->arch.sie_block->gcr[4] & 0xffff; /* Primary ASN */
92 s_asn = dst_vcpu->arch.sie_block->gcr[3] & 0xffff; /* Secondary ASN */
93
94 /* Deliver the emergency signal? */
95 if (!(flags & CPUSTAT_STOPPED)
96 || (psw->mask & psw_int_mask) != psw_int_mask
97 || ((flags & CPUSTAT_WAIT) && psw->addr != 0)
98 || (!(flags & CPUSTAT_WAIT) && (asn == p_asn || asn == s_asn))) {
99 return __sigp_emergency(vcpu, cpu_addr);
100 } else {
101 *reg &= 0xffffffff00000000UL;
102 *reg |= SIGP_STATUS_INCORRECT_STATE;
103 return SIGP_CC_STATUS_STORED;
104 }
105}
106
Christian Ehrhardt7697e71f2011-10-18 12:27:15 +0200107static int __sigp_external_call(struct kvm_vcpu *vcpu, u16 cpu_addr)
108{
Jens Freimann22ff4a32014-05-14 17:14:46 +0200109 struct kvm_s390_interrupt s390int = {
110 .type = KVM_S390_INT_EXTERNAL_CALL,
111 .parm = vcpu->vcpu_id,
112 };
Jens Freimann1ee0bc52014-02-25 15:36:45 +0100113 struct kvm_vcpu *dst_vcpu = NULL;
Jens Freimann22ff4a32014-05-14 17:14:46 +0200114 int rc;
Christian Ehrhardt7697e71f2011-10-18 12:27:15 +0200115
Thomas Huth91880d02014-03-20 13:20:46 +0100116 if (cpu_addr < KVM_MAX_VCPUS)
117 dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr);
118 if (!dst_vcpu)
Heiko Carstensea1918d2012-06-26 16:06:40 +0200119 return SIGP_CC_NOT_OPERATIONAL;
Christian Ehrhardt7697e71f2011-10-18 12:27:15 +0200120
Jens Freimann22ff4a32014-05-14 17:14:46 +0200121 rc = kvm_s390_inject_vcpu(dst_vcpu, &s390int);
122 if (!rc)
123 VCPU_EVENT(vcpu, 4, "sent sigp ext call to cpu %x", cpu_addr);
Christian Ehrhardt7697e71f2011-10-18 12:27:15 +0200124
Jens Freimann22ff4a32014-05-14 17:14:46 +0200125 return rc ? rc : SIGP_CC_ORDER_CODE_ACCEPTED;
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100126}
127
David Hildenbrand0e9c85a2014-05-16 11:59:46 +0200128static int __inject_sigp_stop(struct kvm_vcpu *dst_vcpu, int action)
Christian Ehrhardt9ace9032009-05-20 15:34:55 +0200129{
David Hildenbrand0e9c85a2014-05-16 11:59:46 +0200130 struct kvm_s390_local_interrupt *li = &dst_vcpu->arch.local_int;
Christian Ehrhardt9ace9032009-05-20 15:34:55 +0200131 struct kvm_s390_interrupt_info *inti;
Thomas Huthe8798922013-11-06 15:46:33 +0100132 int rc = SIGP_CC_ORDER_CODE_ACCEPTED;
Christian Ehrhardt9ace9032009-05-20 15:34:55 +0200133
Julia Lawall9940fa82010-06-08 18:58:11 +0200134 inti = kzalloc(sizeof(*inti), GFP_ATOMIC);
Christian Ehrhardt9ace9032009-05-20 15:34:55 +0200135 if (!inti)
136 return -ENOMEM;
137 inti->type = KVM_S390_SIGP_STOP;
138
David Hildenbrand4ae3c082014-05-16 10:23:53 +0200139 spin_lock(&li->lock);
David Hildenbrand7dfc63c2014-05-15 14:25:25 +0200140 if (li->action_bits & ACTION_STOP_ON_STOP) {
141 /* another SIGP STOP is pending */
Christian Borntraegerd514f422014-07-28 11:52:02 +0200142 kfree(inti);
David Hildenbrand7dfc63c2014-05-15 14:25:25 +0200143 rc = SIGP_CC_BUSY;
144 goto out;
145 }
Cong Dinga046b812013-01-15 11:17:29 +0100146 if ((atomic_read(li->cpuflags) & CPUSTAT_STOPPED)) {
147 kfree(inti);
Thomas Huthe8798922013-11-06 15:46:33 +0100148 if ((action & ACTION_STORE_ON_STOP) != 0)
149 rc = -ESHUTDOWN;
Jens Freimann24a13042012-02-06 10:59:05 +0100150 goto out;
Cong Dinga046b812013-01-15 11:17:29 +0100151 }
Christian Ehrhardt9ace9032009-05-20 15:34:55 +0200152 list_add_tail(&inti->list, &li->list);
153 atomic_set(&li->active, 1);
Christian Ehrhardt9ace9032009-05-20 15:34:55 +0200154 li->action_bits |= action;
David Hildenbrand7dfc63c2014-05-15 14:25:25 +0200155 atomic_set_mask(CPUSTAT_STOP_INT, li->cpuflags);
David Hildenbrand0e9c85a2014-05-16 11:59:46 +0200156 kvm_s390_vcpu_wakeup(dst_vcpu);
Jens Freimann24a13042012-02-06 10:59:05 +0100157out:
David Hildenbrand4ae3c082014-05-16 10:23:53 +0200158 spin_unlock(&li->lock);
Christian Ehrhardt9ace9032009-05-20 15:34:55 +0200159
Thomas Huthe8798922013-11-06 15:46:33 +0100160 return rc;
Christian Ehrhardt9ace9032009-05-20 15:34:55 +0200161}
162
163static int __sigp_stop(struct kvm_vcpu *vcpu, u16 cpu_addr, int action)
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100164{
Jens Freimann1ee0bc52014-02-25 15:36:45 +0100165 struct kvm_vcpu *dst_vcpu = NULL;
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100166 int rc;
167
168 if (cpu_addr >= KVM_MAX_VCPUS)
Heiko Carstensea1918d2012-06-26 16:06:40 +0200169 return SIGP_CC_NOT_OPERATIONAL;
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100170
Jens Freimann1ee0bc52014-02-25 15:36:45 +0100171 dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr);
172 if (!dst_vcpu)
173 return SIGP_CC_NOT_OPERATIONAL;
Christian Ehrhardt9ace9032009-05-20 15:34:55 +0200174
David Hildenbrand0e9c85a2014-05-16 11:59:46 +0200175 rc = __inject_sigp_stop(dst_vcpu, action);
Christian Ehrhardt9ace9032009-05-20 15:34:55 +0200176
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100177 VCPU_EVENT(vcpu, 4, "sent sigp stop to cpu %x", cpu_addr);
Thomas Huthe8798922013-11-06 15:46:33 +0100178
179 if ((action & ACTION_STORE_ON_STOP) != 0 && rc == -ESHUTDOWN) {
180 /* If the CPU has already been stopped, we still have
181 * to save the status when doing stop-and-store. This
182 * has to be done after unlocking all spinlocks. */
Thomas Huthe8798922013-11-06 15:46:33 +0100183 rc = kvm_s390_store_status_unloaded(dst_vcpu,
184 KVM_S390_STORE_STATUS_NOADDR);
185 }
186
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100187 return rc;
188}
189
190static int __sigp_set_arch(struct kvm_vcpu *vcpu, u32 parameter)
191{
192 int rc;
Dominik Dingel3c038e62013-10-07 17:11:48 +0200193 unsigned int i;
194 struct kvm_vcpu *v;
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100195
196 switch (parameter & 0xff) {
197 case 0:
Heiko Carstensea1918d2012-06-26 16:06:40 +0200198 rc = SIGP_CC_NOT_OPERATIONAL;
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100199 break;
200 case 1:
201 case 2:
Dominik Dingel3c038e62013-10-07 17:11:48 +0200202 kvm_for_each_vcpu(i, v, vcpu->kvm) {
203 v->arch.pfault_token = KVM_S390_PFAULT_TOKEN_INVALID;
204 kvm_clear_async_pf_completion_queue(v);
205 }
206
Heiko Carstensea1918d2012-06-26 16:06:40 +0200207 rc = SIGP_CC_ORDER_CODE_ACCEPTED;
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100208 break;
209 default:
Heiko Carstensb8e660b2010-02-26 22:37:41 +0100210 rc = -EOPNOTSUPP;
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100211 }
212 return rc;
213}
214
215static int __sigp_set_prefix(struct kvm_vcpu *vcpu, u16 cpu_addr, u32 address,
Christian Borntraeger5a32c1a2012-01-11 11:20:32 +0100216 u64 *reg)
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100217{
Thomas Huth13b191a2014-01-27 12:06:19 +0100218 struct kvm_s390_local_interrupt *li;
219 struct kvm_vcpu *dst_vcpu = NULL;
Christian Borntraeger180c12f2008-06-27 15:05:40 +0200220 struct kvm_s390_interrupt_info *inti;
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100221 int rc;
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100222
Thomas Huth13b191a2014-01-27 12:06:19 +0100223 if (cpu_addr < KVM_MAX_VCPUS)
224 dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr);
225 if (!dst_vcpu)
226 return SIGP_CC_NOT_OPERATIONAL;
227 li = &dst_vcpu->arch.local_int;
228
Heiko Carstens665170c2014-01-01 16:47:12 +0100229 /*
230 * Make sure the new value is valid memory. We only need to check the
231 * first page, since address is 8k aligned and memory pieces are always
232 * at least 1MB aligned and have at least a size of 1MB.
233 */
234 address &= 0x7fffe000u;
235 if (kvm_is_error_gpa(vcpu->kvm, address)) {
Heiko Carstens07444262012-06-26 16:06:39 +0200236 *reg &= 0xffffffff00000000UL;
Heiko Carstensa9ae32c2012-06-04 12:55:15 +0200237 *reg |= SIGP_STATUS_INVALID_PARAMETER;
Heiko Carstensea1918d2012-06-26 16:06:40 +0200238 return SIGP_CC_STATUS_STORED;
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100239 }
240
241 inti = kzalloc(sizeof(*inti), GFP_KERNEL);
242 if (!inti)
Heiko Carstensea1918d2012-06-26 16:06:40 +0200243 return SIGP_CC_BUSY;
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100244
David Hildenbrand4ae3c082014-05-16 10:23:53 +0200245 spin_lock(&li->lock);
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100246 /* cpu must be in stopped state */
Cornelia Huck9e6dabe2011-11-17 11:00:41 +0100247 if (!(atomic_read(li->cpuflags) & CPUSTAT_STOPPED)) {
Heiko Carstens07444262012-06-26 16:06:39 +0200248 *reg &= 0xffffffff00000000UL;
249 *reg |= SIGP_STATUS_INCORRECT_STATE;
Heiko Carstensea1918d2012-06-26 16:06:40 +0200250 rc = SIGP_CC_STATUS_STORED;
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100251 kfree(inti);
252 goto out_li;
253 }
254
255 inti->type = KVM_S390_SIGP_SET_PREFIX;
256 inti->prefix.address = address;
257
258 list_add_tail(&inti->list, &li->list);
259 atomic_set(&li->active, 1);
David Hildenbrand0e9c85a2014-05-16 11:59:46 +0200260 kvm_s390_vcpu_wakeup(dst_vcpu);
Heiko Carstensea1918d2012-06-26 16:06:40 +0200261 rc = SIGP_CC_ORDER_CODE_ACCEPTED;
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100262
263 VCPU_EVENT(vcpu, 4, "set prefix of cpu %02x to %x", cpu_addr, address);
264out_li:
David Hildenbrand4ae3c082014-05-16 10:23:53 +0200265 spin_unlock(&li->lock);
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100266 return rc;
267}
268
Thomas Huth00e9e432013-11-13 20:48:51 +0100269static int __sigp_store_status_at_addr(struct kvm_vcpu *vcpu, u16 cpu_id,
270 u32 addr, u64 *reg)
271{
272 struct kvm_vcpu *dst_vcpu = NULL;
273 int flags;
274 int rc;
275
276 if (cpu_id < KVM_MAX_VCPUS)
277 dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_id);
278 if (!dst_vcpu)
279 return SIGP_CC_NOT_OPERATIONAL;
280
David Hildenbrand4ae3c082014-05-16 10:23:53 +0200281 spin_lock(&dst_vcpu->arch.local_int.lock);
Thomas Huth00e9e432013-11-13 20:48:51 +0100282 flags = atomic_read(dst_vcpu->arch.local_int.cpuflags);
David Hildenbrand4ae3c082014-05-16 10:23:53 +0200283 spin_unlock(&dst_vcpu->arch.local_int.lock);
Thomas Huth00e9e432013-11-13 20:48:51 +0100284 if (!(flags & CPUSTAT_STOPPED)) {
285 *reg &= 0xffffffff00000000UL;
286 *reg |= SIGP_STATUS_INCORRECT_STATE;
287 return SIGP_CC_STATUS_STORED;
288 }
289
290 addr &= 0x7ffffe00;
291 rc = kvm_s390_store_status_unloaded(dst_vcpu, addr);
292 if (rc == -EFAULT) {
293 *reg &= 0xffffffff00000000UL;
294 *reg |= SIGP_STATUS_INVALID_PARAMETER;
295 rc = SIGP_CC_STATUS_STORED;
296 }
297 return rc;
298}
299
Cornelia Huckbd59d3a2011-11-17 11:00:42 +0100300static int __sigp_sense_running(struct kvm_vcpu *vcpu, u16 cpu_addr,
Christian Borntraeger5a32c1a2012-01-11 11:20:32 +0100301 u64 *reg)
Cornelia Huckbd59d3a2011-11-17 11:00:42 +0100302{
Jens Freimann1ee0bc52014-02-25 15:36:45 +0100303 struct kvm_s390_local_interrupt *li;
304 struct kvm_vcpu *dst_vcpu = NULL;
Cornelia Huckbd59d3a2011-11-17 11:00:42 +0100305 int rc;
Cornelia Huckbd59d3a2011-11-17 11:00:42 +0100306
307 if (cpu_addr >= KVM_MAX_VCPUS)
Heiko Carstensea1918d2012-06-26 16:06:40 +0200308 return SIGP_CC_NOT_OPERATIONAL;
Cornelia Huckbd59d3a2011-11-17 11:00:42 +0100309
Jens Freimann1ee0bc52014-02-25 15:36:45 +0100310 dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr);
311 if (!dst_vcpu)
312 return SIGP_CC_NOT_OPERATIONAL;
313 li = &dst_vcpu->arch.local_int;
314 if (atomic_read(li->cpuflags) & CPUSTAT_RUNNING) {
315 /* running */
316 rc = SIGP_CC_ORDER_CODE_ACCEPTED;
317 } else {
318 /* not running */
319 *reg &= 0xffffffff00000000UL;
320 *reg |= SIGP_STATUS_NOT_RUNNING;
321 rc = SIGP_CC_STATUS_STORED;
Cornelia Huckbd59d3a2011-11-17 11:00:42 +0100322 }
Cornelia Huckbd59d3a2011-11-17 11:00:42 +0100323
324 VCPU_EVENT(vcpu, 4, "sensed running status of cpu %x rc %x", cpu_addr,
325 rc);
326
327 return rc;
328}
329
Thomas Huthcc92d6d2013-11-27 11:47:10 +0100330/* Test whether the destination CPU is available and not busy */
331static int sigp_check_callable(struct kvm_vcpu *vcpu, u16 cpu_addr)
Jens Freimann151104a2012-02-08 08:28:29 +0100332{
Jens Freimann151104a2012-02-08 08:28:29 +0100333 struct kvm_s390_local_interrupt *li;
Heiko Carstensea1918d2012-06-26 16:06:40 +0200334 int rc = SIGP_CC_ORDER_CODE_ACCEPTED;
Jens Freimann1ee0bc52014-02-25 15:36:45 +0100335 struct kvm_vcpu *dst_vcpu = NULL;
Jens Freimann151104a2012-02-08 08:28:29 +0100336
337 if (cpu_addr >= KVM_MAX_VCPUS)
Heiko Carstensea1918d2012-06-26 16:06:40 +0200338 return SIGP_CC_NOT_OPERATIONAL;
Jens Freimann151104a2012-02-08 08:28:29 +0100339
Jens Freimann1ee0bc52014-02-25 15:36:45 +0100340 dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr);
341 if (!dst_vcpu)
342 return SIGP_CC_NOT_OPERATIONAL;
343 li = &dst_vcpu->arch.local_int;
David Hildenbrand4ae3c082014-05-16 10:23:53 +0200344 spin_lock(&li->lock);
Jens Freimann151104a2012-02-08 08:28:29 +0100345 if (li->action_bits & ACTION_STOP_ON_STOP)
Heiko Carstensea1918d2012-06-26 16:06:40 +0200346 rc = SIGP_CC_BUSY;
David Hildenbrand4ae3c082014-05-16 10:23:53 +0200347 spin_unlock(&li->lock);
Jens Freimann1ee0bc52014-02-25 15:36:45 +0100348
Jens Freimann151104a2012-02-08 08:28:29 +0100349 return rc;
350}
351
David Hildenbrand3526a662014-03-19 14:57:49 +0100352static int handle_sigp_dst(struct kvm_vcpu *vcpu, u8 order_code,
353 u16 cpu_addr, u32 parameter, u64 *status_reg)
354{
355 int rc;
356
357 switch (order_code) {
358 case SIGP_SENSE:
359 vcpu->stat.instruction_sigp_sense++;
360 rc = __sigp_sense(vcpu, cpu_addr, status_reg);
361 break;
362 case SIGP_EXTERNAL_CALL:
363 vcpu->stat.instruction_sigp_external_call++;
364 rc = __sigp_external_call(vcpu, cpu_addr);
365 break;
366 case SIGP_EMERGENCY_SIGNAL:
367 vcpu->stat.instruction_sigp_emergency++;
368 rc = __sigp_emergency(vcpu, cpu_addr);
369 break;
370 case SIGP_STOP:
371 vcpu->stat.instruction_sigp_stop++;
372 rc = __sigp_stop(vcpu, cpu_addr, ACTION_STOP_ON_STOP);
373 break;
374 case SIGP_STOP_AND_STORE_STATUS:
375 vcpu->stat.instruction_sigp_stop++;
376 rc = __sigp_stop(vcpu, cpu_addr, ACTION_STORE_ON_STOP |
377 ACTION_STOP_ON_STOP);
378 break;
379 case SIGP_STORE_STATUS_AT_ADDRESS:
380 rc = __sigp_store_status_at_addr(vcpu, cpu_addr, parameter,
381 status_reg);
382 break;
383 case SIGP_SET_PREFIX:
384 vcpu->stat.instruction_sigp_prefix++;
385 rc = __sigp_set_prefix(vcpu, cpu_addr, parameter, status_reg);
386 break;
387 case SIGP_COND_EMERGENCY_SIGNAL:
388 rc = __sigp_conditional_emergency(vcpu, cpu_addr, parameter,
389 status_reg);
390 break;
391 case SIGP_SENSE_RUNNING:
392 vcpu->stat.instruction_sigp_sense_running++;
393 rc = __sigp_sense_running(vcpu, cpu_addr, status_reg);
394 break;
395 case SIGP_START:
396 rc = sigp_check_callable(vcpu, cpu_addr);
397 if (rc == SIGP_CC_ORDER_CODE_ACCEPTED)
398 rc = -EOPNOTSUPP; /* Handle START in user space */
399 break;
400 case SIGP_RESTART:
401 vcpu->stat.instruction_sigp_restart++;
402 rc = sigp_check_callable(vcpu, cpu_addr);
403 if (rc == SIGP_CC_ORDER_CODE_ACCEPTED) {
404 VCPU_EVENT(vcpu, 4,
405 "sigp restart %x to handle userspace",
406 cpu_addr);
407 /* user space must know about restart */
408 rc = -EOPNOTSUPP;
409 }
410 break;
411 default:
412 rc = -EOPNOTSUPP;
413 }
414
415 return rc;
416}
417
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100418int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu)
419{
420 int r1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4;
421 int r3 = vcpu->arch.sie_block->ipa & 0x000f;
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100422 u32 parameter;
Christian Borntraeger5a32c1a2012-01-11 11:20:32 +0100423 u16 cpu_addr = vcpu->run->s.regs.gprs[r3];
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100424 u8 order_code;
425 int rc;
426
Christian Borntraeger3eb77d52008-11-17 14:50:35 +0100427 /* sigp in userspace can exit */
428 if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
Thomas Huth208dd752013-06-20 17:21:59 +0200429 return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP);
Christian Borntraeger3eb77d52008-11-17 14:50:35 +0100430
Cornelia Huckb1c571a2012-12-20 15:32:07 +0100431 order_code = kvm_s390_get_base_disp_rs(vcpu);
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100432
433 if (r1 % 2)
Christian Borntraeger5a32c1a2012-01-11 11:20:32 +0100434 parameter = vcpu->run->s.regs.gprs[r1];
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100435 else
Christian Borntraeger5a32c1a2012-01-11 11:20:32 +0100436 parameter = vcpu->run->s.regs.gprs[r1 + 1];
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100437
Cornelia Huck5786fff2012-07-23 17:20:29 +0200438 trace_kvm_s390_handle_sigp(vcpu, order_code, cpu_addr, parameter);
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100439 switch (order_code) {
Heiko Carstensa9ae32c2012-06-04 12:55:15 +0200440 case SIGP_SET_ARCHITECTURE:
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100441 vcpu->stat.instruction_sigp_arch++;
442 rc = __sigp_set_arch(vcpu, parameter);
443 break;
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100444 default:
David Hildenbrand3526a662014-03-19 14:57:49 +0100445 rc = handle_sigp_dst(vcpu, order_code, cpu_addr,
446 parameter,
447 &vcpu->run->s.regs.gprs[r1]);
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100448 }
449
450 if (rc < 0)
451 return rc;
452
Thomas Huth949c0072013-11-26 12:27:16 +0100453 kvm_s390_set_psw_cc(vcpu, rc);
Christian Borntraeger5288fbf2008-03-25 18:47:31 +0100454 return 0;
455}
David Hildenbrand49539192014-02-21 08:59:59 +0100456
457/*
458 * Handle SIGP partial execution interception.
459 *
460 * This interception will occur at the source cpu when a source cpu sends an
461 * external call to a target cpu and the target cpu has the WAIT bit set in
462 * its cpuflags. Interception will occurr after the interrupt indicator bits at
463 * the target cpu have been set. All error cases will lead to instruction
464 * interception, therefore nothing is to be checked or prepared.
465 */
466int kvm_s390_handle_sigp_pei(struct kvm_vcpu *vcpu)
467{
468 int r3 = vcpu->arch.sie_block->ipa & 0x000f;
469 u16 cpu_addr = vcpu->run->s.regs.gprs[r3];
470 struct kvm_vcpu *dest_vcpu;
471 u8 order_code = kvm_s390_get_base_disp_rs(vcpu);
472
473 trace_kvm_s390_handle_sigp_pei(vcpu, order_code, cpu_addr);
474
475 if (order_code == SIGP_EXTERNAL_CALL) {
476 dest_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr);
477 BUG_ON(dest_vcpu == NULL);
478
David Hildenbrand0e9c85a2014-05-16 11:59:46 +0200479 kvm_s390_vcpu_wakeup(dest_vcpu);
David Hildenbrand49539192014-02-21 08:59:59 +0100480 kvm_s390_set_psw_cc(vcpu, SIGP_CC_ORDER_CODE_ACCEPTED);
481 return 0;
482 }
483
484 return -EOPNOTSUPP;
485}