Commit | Line | Data |
---|---|---|
5288fbf0 | 1 | /* |
a53c8fab | 2 | * handling interprocessor communication |
5288fbf0 | 3 | * |
b13d3580 | 4 | * Copyright IBM Corp. 2008, 2013 |
5288fbf0 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> | |
9ace903d | 12 | * Christian Ehrhardt <ehrhardt@de.ibm.com> |
5288fbf0 CB |
13 | */ |
14 | ||
15 | #include <linux/kvm.h> | |
16 | #include <linux/kvm_host.h> | |
5a0e3ad6 | 17 | #include <linux/slab.h> |
a9ae32c3 | 18 | #include <asm/sigp.h> |
5288fbf0 CB |
19 | #include "gaccess.h" |
20 | #include "kvm-s390.h" | |
5786fffa | 21 | #include "trace.h" |
5288fbf0 | 22 | |
0096369d | 23 | static int __sigp_sense(struct kvm_vcpu *vcpu, u16 cpu_addr, |
5a32c1af | 24 | u64 *reg) |
5288fbf0 | 25 | { |
1ee0bc55 JF |
26 | struct kvm_s390_local_interrupt *li; |
27 | struct kvm_vcpu *dst_vcpu = NULL; | |
28 | int cpuflags; | |
5288fbf0 CB |
29 | int rc; |
30 | ||
31 | if (cpu_addr >= KVM_MAX_VCPUS) | |
ea1918dd | 32 | return SIGP_CC_NOT_OPERATIONAL; |
5288fbf0 | 33 | |
1ee0bc55 JF |
34 | 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))) | |
21b26c08 CH |
41 | rc = SIGP_CC_ORDER_CODE_ACCEPTED; |
42 | else { | |
5288fbf0 | 43 | *reg &= 0xffffffff00000000UL; |
1ee0bc55 | 44 | if (cpuflags & CPUSTAT_ECALL_PEND) |
21b26c08 | 45 | *reg |= SIGP_STATUS_EXT_CALL_PENDING; |
1ee0bc55 | 46 | if (cpuflags & CPUSTAT_STOPPED) |
21b26c08 | 47 | *reg |= SIGP_STATUS_STOPPED; |
ea1918dd | 48 | rc = SIGP_CC_STATUS_STORED; |
5288fbf0 | 49 | } |
5288fbf0 CB |
50 | |
51 | VCPU_EVENT(vcpu, 4, "sensed status of cpu %x rc %x", cpu_addr, rc); | |
52 | return rc; | |
53 | } | |
54 | ||
55 | static int __sigp_emergency(struct kvm_vcpu *vcpu, u16 cpu_addr) | |
56 | { | |
22ff4a33 JF |
57 | struct kvm_s390_interrupt s390int = { |
58 | .type = KVM_S390_INT_EMERGENCY, | |
59 | .parm = vcpu->vcpu_id, | |
60 | }; | |
1ee0bc55 | 61 | struct kvm_vcpu *dst_vcpu = NULL; |
22ff4a33 | 62 | int rc = 0; |
5288fbf0 | 63 | |
91880d07 TH |
64 | if (cpu_addr < KVM_MAX_VCPUS) |
65 | dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr); | |
66 | if (!dst_vcpu) | |
ea1918dd | 67 | return SIGP_CC_NOT_OPERATIONAL; |
5288fbf0 | 68 | |
22ff4a33 JF |
69 | rc = kvm_s390_inject_vcpu(dst_vcpu, &s390int); |
70 | if (!rc) | |
71 | VCPU_EVENT(vcpu, 4, "sent sigp emerg to cpu %x", cpu_addr); | |
5288fbf0 | 72 | |
22ff4a33 | 73 | return rc ? rc : SIGP_CC_ORDER_CODE_ACCEPTED; |
7697e71f CE |
74 | } |
75 | ||
b13d3580 TH |
76 | static 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 | ||
7697e71f CE |
107 | static int __sigp_external_call(struct kvm_vcpu *vcpu, u16 cpu_addr) |
108 | { | |
22ff4a33 JF |
109 | struct kvm_s390_interrupt s390int = { |
110 | .type = KVM_S390_INT_EXTERNAL_CALL, | |
111 | .parm = vcpu->vcpu_id, | |
112 | }; | |
1ee0bc55 | 113 | struct kvm_vcpu *dst_vcpu = NULL; |
22ff4a33 | 114 | int rc; |
7697e71f | 115 | |
91880d07 TH |
116 | if (cpu_addr < KVM_MAX_VCPUS) |
117 | dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr); | |
118 | if (!dst_vcpu) | |
ea1918dd | 119 | return SIGP_CC_NOT_OPERATIONAL; |
7697e71f | 120 | |
22ff4a33 JF |
121 | 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); | |
7697e71f | 124 | |
22ff4a33 | 125 | return rc ? rc : SIGP_CC_ORDER_CODE_ACCEPTED; |
5288fbf0 CB |
126 | } |
127 | ||
0e9c85a5 | 128 | static int __inject_sigp_stop(struct kvm_vcpu *dst_vcpu, int action) |
5288fbf0 | 129 | { |
0e9c85a5 | 130 | struct kvm_s390_local_interrupt *li = &dst_vcpu->arch.local_int; |
180c12fb | 131 | struct kvm_s390_interrupt_info *inti; |
e879892c | 132 | int rc = SIGP_CC_ORDER_CODE_ACCEPTED; |
5288fbf0 | 133 | |
9940fa80 | 134 | inti = kzalloc(sizeof(*inti), GFP_ATOMIC); |
5288fbf0 CB |
135 | if (!inti) |
136 | return -ENOMEM; | |
5288fbf0 CB |
137 | inti->type = KVM_S390_SIGP_STOP; |
138 | ||
4ae3c081 | 139 | spin_lock(&li->lock); |
7dfc63cf DH |
140 | if (li->action_bits & ACTION_STOP_ON_STOP) { |
141 | /* another SIGP STOP is pending */ | |
d514f426 | 142 | kfree(inti); |
7dfc63cf DH |
143 | rc = SIGP_CC_BUSY; |
144 | goto out; | |
145 | } | |
a046b816 CD |
146 | if ((atomic_read(li->cpuflags) & CPUSTAT_STOPPED)) { |
147 | kfree(inti); | |
e879892c TH |
148 | if ((action & ACTION_STORE_ON_STOP) != 0) |
149 | rc = -ESHUTDOWN; | |
24a13044 | 150 | goto out; |
a046b816 | 151 | } |
5288fbf0 CB |
152 | list_add_tail(&inti->list, &li->list); |
153 | atomic_set(&li->active, 1); | |
9ace903d | 154 | li->action_bits |= action; |
7dfc63cf | 155 | atomic_set_mask(CPUSTAT_STOP_INT, li->cpuflags); |
0e9c85a5 | 156 | kvm_s390_vcpu_wakeup(dst_vcpu); |
24a13044 | 157 | out: |
4ae3c081 | 158 | spin_unlock(&li->lock); |
9ace903d | 159 | |
e879892c | 160 | return rc; |
9ace903d CE |
161 | } |
162 | ||
163 | static int __sigp_stop(struct kvm_vcpu *vcpu, u16 cpu_addr, int action) | |
164 | { | |
1ee0bc55 | 165 | struct kvm_vcpu *dst_vcpu = NULL; |
9ace903d CE |
166 | int rc; |
167 | ||
168 | if (cpu_addr >= KVM_MAX_VCPUS) | |
ea1918dd | 169 | return SIGP_CC_NOT_OPERATIONAL; |
9ace903d | 170 | |
1ee0bc55 JF |
171 | dst_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr); |
172 | if (!dst_vcpu) | |
173 | return SIGP_CC_NOT_OPERATIONAL; | |
9ace903d | 174 | |
0e9c85a5 | 175 | rc = __inject_sigp_stop(dst_vcpu, action); |
9ace903d | 176 | |
5288fbf0 | 177 | VCPU_EVENT(vcpu, 4, "sent sigp stop to cpu %x", cpu_addr); |
e879892c TH |
178 | |
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. */ | |
e879892c TH |
183 | rc = kvm_s390_store_status_unloaded(dst_vcpu, |
184 | KVM_S390_STORE_STATUS_NOADDR); | |
185 | } | |
186 | ||
5288fbf0 CB |
187 | return rc; |
188 | } | |
189 | ||
190 | static int __sigp_set_arch(struct kvm_vcpu *vcpu, u32 parameter) | |
191 | { | |
192 | int rc; | |
3c038e6b DD |
193 | unsigned int i; |
194 | struct kvm_vcpu *v; | |
5288fbf0 CB |
195 | |
196 | switch (parameter & 0xff) { | |
197 | case 0: | |
ea1918dd | 198 | rc = SIGP_CC_NOT_OPERATIONAL; |
5288fbf0 CB |
199 | break; |
200 | case 1: | |
201 | case 2: | |
3c038e6b DD |
202 | 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 | ||
ea1918dd | 207 | rc = SIGP_CC_ORDER_CODE_ACCEPTED; |
5288fbf0 CB |
208 | break; |
209 | default: | |
b8e660b8 | 210 | rc = -EOPNOTSUPP; |
5288fbf0 CB |
211 | } |
212 | return rc; | |
213 | } | |
214 | ||
215 | static int __sigp_set_prefix(struct kvm_vcpu *vcpu, u16 cpu_addr, u32 address, | |
5a32c1af | 216 | u64 *reg) |
5288fbf0 | 217 | { |
13b191ae TH |
218 | struct kvm_s390_local_interrupt *li; |
219 | struct kvm_vcpu *dst_vcpu = NULL; | |
180c12fb | 220 | struct kvm_s390_interrupt_info *inti; |
5288fbf0 | 221 | int rc; |
5288fbf0 | 222 | |
13b191ae TH |
223 | 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 | ||
665170cb HC |
229 | /* |
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)) { | |
0744426e | 236 | *reg &= 0xffffffff00000000UL; |
a9ae32c3 | 237 | *reg |= SIGP_STATUS_INVALID_PARAMETER; |
ea1918dd | 238 | return SIGP_CC_STATUS_STORED; |
5288fbf0 CB |
239 | } |
240 | ||
241 | inti = kzalloc(sizeof(*inti), GFP_KERNEL); | |
242 | if (!inti) | |
ea1918dd | 243 | return SIGP_CC_BUSY; |
5288fbf0 | 244 | |
4ae3c081 | 245 | spin_lock(&li->lock); |
5288fbf0 | 246 | /* cpu must be in stopped state */ |
9e6dabef | 247 | if (!(atomic_read(li->cpuflags) & CPUSTAT_STOPPED)) { |
0744426e HC |
248 | *reg &= 0xffffffff00000000UL; |
249 | *reg |= SIGP_STATUS_INCORRECT_STATE; | |
ea1918dd | 250 | rc = SIGP_CC_STATUS_STORED; |
5288fbf0 CB |
251 | 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); | |
0e9c85a5 | 260 | kvm_s390_vcpu_wakeup(dst_vcpu); |
ea1918dd | 261 | rc = SIGP_CC_ORDER_CODE_ACCEPTED; |
5288fbf0 CB |
262 | |
263 | VCPU_EVENT(vcpu, 4, "set prefix of cpu %02x to %x", cpu_addr, address); | |
264 | out_li: | |
4ae3c081 | 265 | spin_unlock(&li->lock); |
5288fbf0 CB |
266 | return rc; |
267 | } | |
268 | ||
00e9e435 TH |
269 | static 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 | ||
4ae3c081 | 281 | spin_lock(&dst_vcpu->arch.local_int.lock); |
00e9e435 | 282 | flags = atomic_read(dst_vcpu->arch.local_int.cpuflags); |
4ae3c081 | 283 | spin_unlock(&dst_vcpu->arch.local_int.lock); |
00e9e435 TH |
284 | 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 | ||
bd59d3a4 | 300 | static int __sigp_sense_running(struct kvm_vcpu *vcpu, u16 cpu_addr, |
5a32c1af | 301 | u64 *reg) |
bd59d3a4 | 302 | { |
1ee0bc55 JF |
303 | struct kvm_s390_local_interrupt *li; |
304 | struct kvm_vcpu *dst_vcpu = NULL; | |
bd59d3a4 | 305 | int rc; |
bd59d3a4 CH |
306 | |
307 | if (cpu_addr >= KVM_MAX_VCPUS) | |
ea1918dd | 308 | return SIGP_CC_NOT_OPERATIONAL; |
bd59d3a4 | 309 | |
1ee0bc55 JF |
310 | 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; | |
bd59d3a4 | 322 | } |
bd59d3a4 CH |
323 | |
324 | VCPU_EVENT(vcpu, 4, "sensed running status of cpu %x rc %x", cpu_addr, | |
325 | rc); | |
326 | ||
327 | return rc; | |
328 | } | |
329 | ||
cc92d6de TH |
330 | /* Test whether the destination CPU is available and not busy */ |
331 | static int sigp_check_callable(struct kvm_vcpu *vcpu, u16 cpu_addr) | |
151104a7 | 332 | { |
151104a7 | 333 | struct kvm_s390_local_interrupt *li; |
ea1918dd | 334 | int rc = SIGP_CC_ORDER_CODE_ACCEPTED; |
1ee0bc55 | 335 | struct kvm_vcpu *dst_vcpu = NULL; |
151104a7 JF |
336 | |
337 | if (cpu_addr >= KVM_MAX_VCPUS) | |
ea1918dd | 338 | return SIGP_CC_NOT_OPERATIONAL; |
151104a7 | 339 | |
1ee0bc55 JF |
340 | 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; | |
4ae3c081 | 344 | spin_lock(&li->lock); |
151104a7 | 345 | if (li->action_bits & ACTION_STOP_ON_STOP) |
ea1918dd | 346 | rc = SIGP_CC_BUSY; |
4ae3c081 | 347 | spin_unlock(&li->lock); |
1ee0bc55 | 348 | |
151104a7 JF |
349 | return rc; |
350 | } | |
351 | ||
5288fbf0 CB |
352 | int kvm_s390_handle_sigp(struct kvm_vcpu *vcpu) |
353 | { | |
354 | int r1 = (vcpu->arch.sie_block->ipa & 0x00f0) >> 4; | |
355 | int r3 = vcpu->arch.sie_block->ipa & 0x000f; | |
5288fbf0 | 356 | u32 parameter; |
5a32c1af | 357 | u16 cpu_addr = vcpu->run->s.regs.gprs[r3]; |
5288fbf0 CB |
358 | u8 order_code; |
359 | int rc; | |
360 | ||
3eb77d51 CB |
361 | /* sigp in userspace can exit */ |
362 | if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE) | |
208dd756 | 363 | return kvm_s390_inject_program_int(vcpu, PGM_PRIVILEGED_OP); |
3eb77d51 | 364 | |
b1c571a5 | 365 | order_code = kvm_s390_get_base_disp_rs(vcpu); |
5288fbf0 CB |
366 | |
367 | if (r1 % 2) | |
5a32c1af | 368 | parameter = vcpu->run->s.regs.gprs[r1]; |
5288fbf0 | 369 | else |
5a32c1af | 370 | parameter = vcpu->run->s.regs.gprs[r1 + 1]; |
5288fbf0 | 371 | |
5786fffa | 372 | trace_kvm_s390_handle_sigp(vcpu, order_code, cpu_addr, parameter); |
5288fbf0 CB |
373 | switch (order_code) { |
374 | case SIGP_SENSE: | |
375 | vcpu->stat.instruction_sigp_sense++; | |
376 | rc = __sigp_sense(vcpu, cpu_addr, | |
5a32c1af | 377 | &vcpu->run->s.regs.gprs[r1]); |
5288fbf0 | 378 | break; |
7697e71f CE |
379 | case SIGP_EXTERNAL_CALL: |
380 | vcpu->stat.instruction_sigp_external_call++; | |
381 | rc = __sigp_external_call(vcpu, cpu_addr); | |
382 | break; | |
a9ae32c3 | 383 | case SIGP_EMERGENCY_SIGNAL: |
5288fbf0 CB |
384 | vcpu->stat.instruction_sigp_emergency++; |
385 | rc = __sigp_emergency(vcpu, cpu_addr); | |
386 | break; | |
387 | case SIGP_STOP: | |
388 | vcpu->stat.instruction_sigp_stop++; | |
9ace903d | 389 | rc = __sigp_stop(vcpu, cpu_addr, ACTION_STOP_ON_STOP); |
5288fbf0 | 390 | break; |
a9ae32c3 | 391 | case SIGP_STOP_AND_STORE_STATUS: |
5288fbf0 | 392 | vcpu->stat.instruction_sigp_stop++; |
9ec2d6dc JF |
393 | rc = __sigp_stop(vcpu, cpu_addr, ACTION_STORE_ON_STOP | |
394 | ACTION_STOP_ON_STOP); | |
5288fbf0 | 395 | break; |
00e9e435 TH |
396 | case SIGP_STORE_STATUS_AT_ADDRESS: |
397 | rc = __sigp_store_status_at_addr(vcpu, cpu_addr, parameter, | |
398 | &vcpu->run->s.regs.gprs[r1]); | |
399 | break; | |
a9ae32c3 | 400 | case SIGP_SET_ARCHITECTURE: |
5288fbf0 CB |
401 | vcpu->stat.instruction_sigp_arch++; |
402 | rc = __sigp_set_arch(vcpu, parameter); | |
403 | break; | |
404 | case SIGP_SET_PREFIX: | |
405 | vcpu->stat.instruction_sigp_prefix++; | |
406 | rc = __sigp_set_prefix(vcpu, cpu_addr, parameter, | |
5a32c1af | 407 | &vcpu->run->s.regs.gprs[r1]); |
5288fbf0 | 408 | break; |
b13d3580 TH |
409 | case SIGP_COND_EMERGENCY_SIGNAL: |
410 | rc = __sigp_conditional_emergency(vcpu, cpu_addr, parameter, | |
411 | &vcpu->run->s.regs.gprs[r1]); | |
412 | break; | |
bd59d3a4 CH |
413 | case SIGP_SENSE_RUNNING: |
414 | vcpu->stat.instruction_sigp_sense_running++; | |
415 | rc = __sigp_sense_running(vcpu, cpu_addr, | |
5a32c1af | 416 | &vcpu->run->s.regs.gprs[r1]); |
bd59d3a4 | 417 | break; |
58bc33b2 TH |
418 | case SIGP_START: |
419 | rc = sigp_check_callable(vcpu, cpu_addr); | |
420 | if (rc == SIGP_CC_ORDER_CODE_ACCEPTED) | |
421 | rc = -EOPNOTSUPP; /* Handle START in user space */ | |
422 | break; | |
5288fbf0 CB |
423 | case SIGP_RESTART: |
424 | vcpu->stat.instruction_sigp_restart++; | |
cc92d6de TH |
425 | rc = sigp_check_callable(vcpu, cpu_addr); |
426 | if (rc == SIGP_CC_ORDER_CODE_ACCEPTED) { | |
427 | VCPU_EVENT(vcpu, 4, | |
428 | "sigp restart %x to handle userspace", | |
429 | cpu_addr); | |
430 | /* user space must know about restart */ | |
431 | rc = -EOPNOTSUPP; | |
432 | } | |
433 | break; | |
5288fbf0 | 434 | default: |
b8e660b8 | 435 | return -EOPNOTSUPP; |
5288fbf0 CB |
436 | } |
437 | ||
438 | if (rc < 0) | |
439 | return rc; | |
440 | ||
949c007a | 441 | kvm_s390_set_psw_cc(vcpu, rc); |
5288fbf0 CB |
442 | return 0; |
443 | } | |
4953919f DH |
444 | |
445 | /* | |
446 | * Handle SIGP partial execution interception. | |
447 | * | |
448 | * This interception will occur at the source cpu when a source cpu sends an | |
449 | * external call to a target cpu and the target cpu has the WAIT bit set in | |
450 | * its cpuflags. Interception will occurr after the interrupt indicator bits at | |
451 | * the target cpu have been set. All error cases will lead to instruction | |
452 | * interception, therefore nothing is to be checked or prepared. | |
453 | */ | |
454 | int kvm_s390_handle_sigp_pei(struct kvm_vcpu *vcpu) | |
455 | { | |
456 | int r3 = vcpu->arch.sie_block->ipa & 0x000f; | |
457 | u16 cpu_addr = vcpu->run->s.regs.gprs[r3]; | |
458 | struct kvm_vcpu *dest_vcpu; | |
459 | u8 order_code = kvm_s390_get_base_disp_rs(vcpu); | |
460 | ||
461 | trace_kvm_s390_handle_sigp_pei(vcpu, order_code, cpu_addr); | |
462 | ||
463 | if (order_code == SIGP_EXTERNAL_CALL) { | |
464 | dest_vcpu = kvm_get_vcpu(vcpu->kvm, cpu_addr); | |
465 | BUG_ON(dest_vcpu == NULL); | |
466 | ||
0e9c85a5 | 467 | kvm_s390_vcpu_wakeup(dest_vcpu); |
4953919f DH |
468 | kvm_s390_set_psw_cc(vcpu, SIGP_CC_ORDER_CODE_ACCEPTED); |
469 | return 0; | |
470 | } | |
471 | ||
472 | return -EOPNOTSUPP; | |
473 | } |