blob: 2f6ccb065c4aa47aca03c1f5276ec2b253b01f0b [file] [log] [blame]
Carsten Otteba5c1e92008-03-25 18:47:26 +01001/*
Heiko Carstensa53c8fa2012-07-20 11:15:04 +02002 * handling kvm guest interrupts
Carsten Otteba5c1e92008-03-25 18:47:26 +01003 *
4 * Copyright IBM Corp. 2008
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License (version 2 only)
8 * as published by the Free Software Foundation.
9 *
10 * Author(s): Carsten Otte <cotte@de.ibm.com>
11 */
12
Christian Borntraegerca872302009-05-12 17:21:49 +020013#include <linux/interrupt.h>
Carsten Otteba5c1e92008-03-25 18:47:26 +010014#include <linux/kvm_host.h>
Heiko Carstenscbb870c2010-02-26 22:37:43 +010015#include <linux/hrtimer.h>
Christian Borntraeger3cd61292008-07-25 15:51:54 +020016#include <linux/signal.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/slab.h>
Heiko Carstenscbb870c2010-02-26 22:37:43 +010018#include <asm/asm-offsets.h>
19#include <asm/uaccess.h>
Carsten Otteba5c1e92008-03-25 18:47:26 +010020#include "kvm-s390.h"
21#include "gaccess.h"
Cornelia Huckade38c32012-07-23 17:20:30 +020022#include "trace-s390.h"
Carsten Otteba5c1e92008-03-25 18:47:26 +010023
Cornelia Huckd8346b72012-12-20 15:32:08 +010024#define IOINT_SCHID_MASK 0x0000ffff
25#define IOINT_SSID_MASK 0x00030000
26#define IOINT_CSSID_MASK 0x03fc0000
27#define IOINT_AI_MASK 0x04000000
28
29static int is_ioint(u64 type)
30{
31 return ((type & 0xfffe0000u) != 0xfffe0000u);
32}
33
Carsten Otteba5c1e92008-03-25 18:47:26 +010034static int psw_extint_disabled(struct kvm_vcpu *vcpu)
35{
36 return !(vcpu->arch.sie_block->gpsw.mask & PSW_MASK_EXT);
37}
38
Cornelia Huckd8346b72012-12-20 15:32:08 +010039static int psw_ioint_disabled(struct kvm_vcpu *vcpu)
40{
41 return !(vcpu->arch.sie_block->gpsw.mask & PSW_MASK_IO);
42}
43
Cornelia Huck48a3e952012-12-20 15:32:09 +010044static int psw_mchk_disabled(struct kvm_vcpu *vcpu)
45{
46 return !(vcpu->arch.sie_block->gpsw.mask & PSW_MASK_MCHECK);
47}
48
Carsten Otteba5c1e92008-03-25 18:47:26 +010049static int psw_interrupts_disabled(struct kvm_vcpu *vcpu)
50{
51 if ((vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PER) ||
52 (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_IO) ||
53 (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_EXT))
54 return 0;
55 return 1;
56}
57
Cornelia Huck79fd50c2013-02-07 13:20:52 +010058static u64 int_word_to_isc_bits(u32 int_word)
59{
60 u8 isc = (int_word & 0x38000000) >> 27;
61
62 return (0x80 >> isc) << 24;
63}
64
Carsten Otteba5c1e92008-03-25 18:47:26 +010065static int __interrupt_is_deliverable(struct kvm_vcpu *vcpu,
Christian Borntraeger180c12f2008-06-27 15:05:40 +020066 struct kvm_s390_interrupt_info *inti)
Carsten Otteba5c1e92008-03-25 18:47:26 +010067{
68 switch (inti->type) {
Christian Ehrhardt7697e71f2011-10-18 12:27:15 +020069 case KVM_S390_INT_EXTERNAL_CALL:
70 if (psw_extint_disabled(vcpu))
71 return 0;
72 if (vcpu->arch.sie_block->gcr[0] & 0x2000ul)
73 return 1;
Carsten Otteba5c1e92008-03-25 18:47:26 +010074 case KVM_S390_INT_EMERGENCY:
75 if (psw_extint_disabled(vcpu))
76 return 0;
77 if (vcpu->arch.sie_block->gcr[0] & 0x4000ul)
78 return 1;
79 return 0;
80 case KVM_S390_INT_SERVICE:
81 if (psw_extint_disabled(vcpu))
82 return 0;
83 if (vcpu->arch.sie_block->gcr[0] & 0x200ul)
84 return 1;
85 return 0;
86 case KVM_S390_INT_VIRTIO:
87 if (psw_extint_disabled(vcpu))
88 return 0;
89 if (vcpu->arch.sie_block->gcr[0] & 0x200ul)
90 return 1;
91 return 0;
92 case KVM_S390_PROGRAM_INT:
93 case KVM_S390_SIGP_STOP:
94 case KVM_S390_SIGP_SET_PREFIX:
95 case KVM_S390_RESTART:
96 return 1;
Cornelia Huck48a3e952012-12-20 15:32:09 +010097 case KVM_S390_MCHK:
98 if (psw_mchk_disabled(vcpu))
99 return 0;
100 if (vcpu->arch.sie_block->gcr[14] & inti->mchk.cr14)
101 return 1;
102 return 0;
Cornelia Huckd8346b72012-12-20 15:32:08 +0100103 case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX:
104 if (psw_ioint_disabled(vcpu))
105 return 0;
Cornelia Huck79fd50c2013-02-07 13:20:52 +0100106 if (vcpu->arch.sie_block->gcr[6] &
107 int_word_to_isc_bits(inti->io.io_int_word))
Cornelia Huckd8346b72012-12-20 15:32:08 +0100108 return 1;
109 return 0;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100110 default:
Cornelia Huckd8346b72012-12-20 15:32:08 +0100111 printk(KERN_WARNING "illegal interrupt type %llx\n",
112 inti->type);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100113 BUG();
114 }
115 return 0;
116}
117
118static void __set_cpu_idle(struct kvm_vcpu *vcpu)
119{
120 BUG_ON(vcpu->vcpu_id > KVM_MAX_VCPUS - 1);
121 atomic_set_mask(CPUSTAT_WAIT, &vcpu->arch.sie_block->cpuflags);
122 set_bit(vcpu->vcpu_id, vcpu->arch.local_int.float_int->idle_mask);
123}
124
125static void __unset_cpu_idle(struct kvm_vcpu *vcpu)
126{
127 BUG_ON(vcpu->vcpu_id > KVM_MAX_VCPUS - 1);
128 atomic_clear_mask(CPUSTAT_WAIT, &vcpu->arch.sie_block->cpuflags);
129 clear_bit(vcpu->vcpu_id, vcpu->arch.local_int.float_int->idle_mask);
130}
131
132static void __reset_intercept_indicators(struct kvm_vcpu *vcpu)
133{
134 atomic_clear_mask(CPUSTAT_ECALL_PEND |
135 CPUSTAT_IO_INT | CPUSTAT_EXT_INT | CPUSTAT_STOP_INT,
136 &vcpu->arch.sie_block->cpuflags);
137 vcpu->arch.sie_block->lctl = 0x0000;
Cornelia Huck48a3e952012-12-20 15:32:09 +0100138 vcpu->arch.sie_block->ictl &= ~ICTL_LPSW;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100139}
140
141static void __set_cpuflag(struct kvm_vcpu *vcpu, u32 flag)
142{
143 atomic_set_mask(flag, &vcpu->arch.sie_block->cpuflags);
144}
145
146static void __set_intercept_indicator(struct kvm_vcpu *vcpu,
Christian Borntraeger180c12f2008-06-27 15:05:40 +0200147 struct kvm_s390_interrupt_info *inti)
Carsten Otteba5c1e92008-03-25 18:47:26 +0100148{
149 switch (inti->type) {
Christian Ehrhardt7697e71f2011-10-18 12:27:15 +0200150 case KVM_S390_INT_EXTERNAL_CALL:
Carsten Otteba5c1e92008-03-25 18:47:26 +0100151 case KVM_S390_INT_EMERGENCY:
152 case KVM_S390_INT_SERVICE:
153 case KVM_S390_INT_VIRTIO:
154 if (psw_extint_disabled(vcpu))
155 __set_cpuflag(vcpu, CPUSTAT_EXT_INT);
156 else
157 vcpu->arch.sie_block->lctl |= LCTL_CR0;
158 break;
159 case KVM_S390_SIGP_STOP:
160 __set_cpuflag(vcpu, CPUSTAT_STOP_INT);
161 break;
Cornelia Huck48a3e952012-12-20 15:32:09 +0100162 case KVM_S390_MCHK:
163 if (psw_mchk_disabled(vcpu))
164 vcpu->arch.sie_block->ictl |= ICTL_LPSW;
165 else
166 vcpu->arch.sie_block->lctl |= LCTL_CR14;
167 break;
Cornelia Huckd8346b72012-12-20 15:32:08 +0100168 case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX:
169 if (psw_ioint_disabled(vcpu))
170 __set_cpuflag(vcpu, CPUSTAT_IO_INT);
171 else
172 vcpu->arch.sie_block->lctl |= LCTL_CR6;
173 break;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100174 default:
175 BUG();
176 }
177}
178
179static void __do_deliver_interrupt(struct kvm_vcpu *vcpu,
Christian Borntraeger180c12f2008-06-27 15:05:40 +0200180 struct kvm_s390_interrupt_info *inti)
Carsten Otteba5c1e92008-03-25 18:47:26 +0100181{
182 const unsigned short table[] = { 2, 4, 4, 6 };
183 int rc, exception = 0;
184
185 switch (inti->type) {
186 case KVM_S390_INT_EMERGENCY:
187 VCPU_EVENT(vcpu, 4, "%s", "interrupt: sigp emerg");
188 vcpu->stat.deliver_emergency_signal++;
Cornelia Huckade38c32012-07-23 17:20:30 +0200189 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type,
190 inti->emerg.code, 0);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100191 rc = put_guest_u16(vcpu, __LC_EXT_INT_CODE, 0x1201);
192 if (rc == -EFAULT)
193 exception = 1;
194
Martin Schwidefsky7e180bd2012-03-11 11:59:25 -0400195 rc = put_guest_u16(vcpu, __LC_EXT_CPU_ADDR, inti->emerg.code);
Christian Ehrhardt8bb3a2e2011-07-24 10:48:31 +0200196 if (rc == -EFAULT)
197 exception = 1;
198
Carsten Otteba5c1e92008-03-25 18:47:26 +0100199 rc = copy_to_guest(vcpu, __LC_EXT_OLD_PSW,
200 &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
201 if (rc == -EFAULT)
202 exception = 1;
203
204 rc = copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
205 __LC_EXT_NEW_PSW, sizeof(psw_t));
206 if (rc == -EFAULT)
207 exception = 1;
208 break;
209
Christian Ehrhardt7697e71f2011-10-18 12:27:15 +0200210 case KVM_S390_INT_EXTERNAL_CALL:
211 VCPU_EVENT(vcpu, 4, "%s", "interrupt: sigp ext call");
212 vcpu->stat.deliver_external_call++;
Cornelia Huckade38c32012-07-23 17:20:30 +0200213 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type,
214 inti->extcall.code, 0);
Christian Ehrhardt7697e71f2011-10-18 12:27:15 +0200215 rc = put_guest_u16(vcpu, __LC_EXT_INT_CODE, 0x1202);
216 if (rc == -EFAULT)
217 exception = 1;
218
Martin Schwidefsky7e180bd2012-03-11 11:59:25 -0400219 rc = put_guest_u16(vcpu, __LC_EXT_CPU_ADDR, inti->extcall.code);
Christian Ehrhardt7697e71f2011-10-18 12:27:15 +0200220 if (rc == -EFAULT)
221 exception = 1;
222
223 rc = copy_to_guest(vcpu, __LC_EXT_OLD_PSW,
224 &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
225 if (rc == -EFAULT)
226 exception = 1;
227
228 rc = copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
229 __LC_EXT_NEW_PSW, sizeof(psw_t));
230 if (rc == -EFAULT)
231 exception = 1;
232 break;
233
Carsten Otteba5c1e92008-03-25 18:47:26 +0100234 case KVM_S390_INT_SERVICE:
235 VCPU_EVENT(vcpu, 4, "interrupt: sclp parm:%x",
236 inti->ext.ext_params);
237 vcpu->stat.deliver_service_signal++;
Cornelia Huckade38c32012-07-23 17:20:30 +0200238 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type,
239 inti->ext.ext_params, 0);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100240 rc = put_guest_u16(vcpu, __LC_EXT_INT_CODE, 0x2401);
241 if (rc == -EFAULT)
242 exception = 1;
243
244 rc = copy_to_guest(vcpu, __LC_EXT_OLD_PSW,
245 &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
246 if (rc == -EFAULT)
247 exception = 1;
248
249 rc = copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
250 __LC_EXT_NEW_PSW, sizeof(psw_t));
251 if (rc == -EFAULT)
252 exception = 1;
253
254 rc = put_guest_u32(vcpu, __LC_EXT_PARAMS, inti->ext.ext_params);
255 if (rc == -EFAULT)
256 exception = 1;
257 break;
258
259 case KVM_S390_INT_VIRTIO:
Heiko Carstens33e19112009-01-09 12:14:56 +0100260 VCPU_EVENT(vcpu, 4, "interrupt: virtio parm:%x,parm64:%llx",
Carsten Otteba5c1e92008-03-25 18:47:26 +0100261 inti->ext.ext_params, inti->ext.ext_params2);
262 vcpu->stat.deliver_virtio_interrupt++;
Cornelia Huckade38c32012-07-23 17:20:30 +0200263 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type,
264 inti->ext.ext_params,
265 inti->ext.ext_params2);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100266 rc = put_guest_u16(vcpu, __LC_EXT_INT_CODE, 0x2603);
267 if (rc == -EFAULT)
268 exception = 1;
269
Martin Schwidefsky7e180bd2012-03-11 11:59:25 -0400270 rc = put_guest_u16(vcpu, __LC_EXT_CPU_ADDR, 0x0d00);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100271 if (rc == -EFAULT)
272 exception = 1;
273
274 rc = copy_to_guest(vcpu, __LC_EXT_OLD_PSW,
275 &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
276 if (rc == -EFAULT)
277 exception = 1;
278
279 rc = copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
280 __LC_EXT_NEW_PSW, sizeof(psw_t));
281 if (rc == -EFAULT)
282 exception = 1;
283
284 rc = put_guest_u32(vcpu, __LC_EXT_PARAMS, inti->ext.ext_params);
285 if (rc == -EFAULT)
286 exception = 1;
287
Heiko Carstenscbb870c2010-02-26 22:37:43 +0100288 rc = put_guest_u64(vcpu, __LC_EXT_PARAMS2,
289 inti->ext.ext_params2);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100290 if (rc == -EFAULT)
291 exception = 1;
292 break;
293
294 case KVM_S390_SIGP_STOP:
295 VCPU_EVENT(vcpu, 4, "%s", "interrupt: cpu stop");
296 vcpu->stat.deliver_stop_signal++;
Cornelia Huckade38c32012-07-23 17:20:30 +0200297 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type,
298 0, 0);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100299 __set_intercept_indicator(vcpu, inti);
300 break;
301
302 case KVM_S390_SIGP_SET_PREFIX:
303 VCPU_EVENT(vcpu, 4, "interrupt: set prefix to %x",
304 inti->prefix.address);
305 vcpu->stat.deliver_prefix_signal++;
Cornelia Huckade38c32012-07-23 17:20:30 +0200306 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type,
307 inti->prefix.address, 0);
Christian Borntraeger8d26cf72012-01-11 11:19:32 +0100308 kvm_s390_set_prefix(vcpu, inti->prefix.address);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100309 break;
310
311 case KVM_S390_RESTART:
312 VCPU_EVENT(vcpu, 4, "%s", "interrupt: cpu restart");
313 vcpu->stat.deliver_restart_signal++;
Cornelia Huckade38c32012-07-23 17:20:30 +0200314 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type,
315 0, 0);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100316 rc = copy_to_guest(vcpu, offsetof(struct _lowcore,
317 restart_old_psw), &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
318 if (rc == -EFAULT)
319 exception = 1;
320
321 rc = copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
322 offsetof(struct _lowcore, restart_psw), sizeof(psw_t));
323 if (rc == -EFAULT)
324 exception = 1;
Cornelia Huck9e6dabe2011-11-17 11:00:41 +0100325 atomic_clear_mask(CPUSTAT_STOPPED, &vcpu->arch.sie_block->cpuflags);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100326 break;
327
328 case KVM_S390_PROGRAM_INT:
329 VCPU_EVENT(vcpu, 4, "interrupt: pgm check code:%x, ilc:%x",
330 inti->pgm.code,
331 table[vcpu->arch.sie_block->ipa >> 14]);
332 vcpu->stat.deliver_program_int++;
Cornelia Huckade38c32012-07-23 17:20:30 +0200333 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type,
334 inti->pgm.code, 0);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100335 rc = put_guest_u16(vcpu, __LC_PGM_INT_CODE, inti->pgm.code);
336 if (rc == -EFAULT)
337 exception = 1;
338
339 rc = put_guest_u16(vcpu, __LC_PGM_ILC,
340 table[vcpu->arch.sie_block->ipa >> 14]);
341 if (rc == -EFAULT)
342 exception = 1;
343
344 rc = copy_to_guest(vcpu, __LC_PGM_OLD_PSW,
345 &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
346 if (rc == -EFAULT)
347 exception = 1;
348
349 rc = copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
350 __LC_PGM_NEW_PSW, sizeof(psw_t));
351 if (rc == -EFAULT)
352 exception = 1;
353 break;
354
Cornelia Huck48a3e952012-12-20 15:32:09 +0100355 case KVM_S390_MCHK:
356 VCPU_EVENT(vcpu, 4, "interrupt: machine check mcic=%llx",
357 inti->mchk.mcic);
358 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type,
359 inti->mchk.cr14,
360 inti->mchk.mcic);
361 rc = kvm_s390_vcpu_store_status(vcpu,
362 KVM_S390_STORE_STATUS_PREFIXED);
363 if (rc == -EFAULT)
364 exception = 1;
365
366 rc = put_guest_u64(vcpu, __LC_MCCK_CODE, inti->mchk.mcic);
367 if (rc == -EFAULT)
368 exception = 1;
369
370 rc = copy_to_guest(vcpu, __LC_MCK_OLD_PSW,
371 &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
372 if (rc == -EFAULT)
373 exception = 1;
374
375 rc = copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
376 __LC_MCK_NEW_PSW, sizeof(psw_t));
377 if (rc == -EFAULT)
378 exception = 1;
379 break;
380
Cornelia Huckd8346b72012-12-20 15:32:08 +0100381 case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX:
382 {
383 __u32 param0 = ((__u32)inti->io.subchannel_id << 16) |
384 inti->io.subchannel_nr;
385 __u64 param1 = ((__u64)inti->io.io_int_parm << 32) |
386 inti->io.io_int_word;
387 VCPU_EVENT(vcpu, 4, "interrupt: I/O %llx", inti->type);
388 vcpu->stat.deliver_io_int++;
389 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type,
390 param0, param1);
391 rc = put_guest_u16(vcpu, __LC_SUBCHANNEL_ID,
392 inti->io.subchannel_id);
393 if (rc == -EFAULT)
394 exception = 1;
395
396 rc = put_guest_u16(vcpu, __LC_SUBCHANNEL_NR,
397 inti->io.subchannel_nr);
398 if (rc == -EFAULT)
399 exception = 1;
400
401 rc = put_guest_u32(vcpu, __LC_IO_INT_PARM,
402 inti->io.io_int_parm);
403 if (rc == -EFAULT)
404 exception = 1;
405
406 rc = put_guest_u32(vcpu, __LC_IO_INT_WORD,
407 inti->io.io_int_word);
408 if (rc == -EFAULT)
409 exception = 1;
410
411 rc = copy_to_guest(vcpu, __LC_IO_OLD_PSW,
412 &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
413 if (rc == -EFAULT)
414 exception = 1;
415
416 rc = copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
417 __LC_IO_NEW_PSW, sizeof(psw_t));
418 if (rc == -EFAULT)
419 exception = 1;
420 break;
421 }
Carsten Otteba5c1e92008-03-25 18:47:26 +0100422 default:
423 BUG();
424 }
Carsten Otteba5c1e92008-03-25 18:47:26 +0100425 if (exception) {
Christian Borntraeger3cd61292008-07-25 15:51:54 +0200426 printk("kvm: The guest lowcore is not mapped during interrupt "
427 "delivery, killing userspace\n");
428 do_exit(SIGKILL);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100429 }
430}
431
432static int __try_deliver_ckc_interrupt(struct kvm_vcpu *vcpu)
433{
434 int rc, exception = 0;
435
436 if (psw_extint_disabled(vcpu))
437 return 0;
438 if (!(vcpu->arch.sie_block->gcr[0] & 0x800ul))
439 return 0;
440 rc = put_guest_u16(vcpu, __LC_EXT_INT_CODE, 0x1004);
441 if (rc == -EFAULT)
442 exception = 1;
443 rc = copy_to_guest(vcpu, __LC_EXT_OLD_PSW,
444 &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
445 if (rc == -EFAULT)
446 exception = 1;
447 rc = copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
448 __LC_EXT_NEW_PSW, sizeof(psw_t));
449 if (rc == -EFAULT)
450 exception = 1;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100451 if (exception) {
Christian Borntraeger3cd61292008-07-25 15:51:54 +0200452 printk("kvm: The guest lowcore is not mapped during interrupt "
453 "delivery, killing userspace\n");
454 do_exit(SIGKILL);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100455 }
Carsten Otteba5c1e92008-03-25 18:47:26 +0100456 return 1;
457}
458
Gleb Natapova1b37102009-07-09 15:33:52 +0300459static int kvm_cpu_has_interrupt(struct kvm_vcpu *vcpu)
Carsten Otteba5c1e92008-03-25 18:47:26 +0100460{
Christian Borntraeger180c12f2008-06-27 15:05:40 +0200461 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
462 struct kvm_s390_float_interrupt *fi = vcpu->arch.local_int.float_int;
463 struct kvm_s390_interrupt_info *inti;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100464 int rc = 0;
465
466 if (atomic_read(&li->active)) {
467 spin_lock_bh(&li->lock);
468 list_for_each_entry(inti, &li->list, list)
469 if (__interrupt_is_deliverable(vcpu, inti)) {
470 rc = 1;
471 break;
472 }
473 spin_unlock_bh(&li->lock);
474 }
475
476 if ((!rc) && atomic_read(&fi->active)) {
Christian Borntraegerb037a4f2009-05-12 17:21:50 +0200477 spin_lock(&fi->lock);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100478 list_for_each_entry(inti, &fi->list, list)
479 if (__interrupt_is_deliverable(vcpu, inti)) {
480 rc = 1;
481 break;
482 }
Christian Borntraegerb037a4f2009-05-12 17:21:50 +0200483 spin_unlock(&fi->lock);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100484 }
485
486 if ((!rc) && (vcpu->arch.sie_block->ckc <
487 get_clock() + vcpu->arch.sie_block->epoch)) {
488 if ((!psw_extint_disabled(vcpu)) &&
489 (vcpu->arch.sie_block->gcr[0] & 0x800ul))
490 rc = 1;
491 }
492
493 return rc;
494}
495
Marcelo Tosatti3d808402008-04-11 14:53:26 -0300496int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu)
497{
498 return 0;
499}
500
Carsten Otteba5c1e92008-03-25 18:47:26 +0100501int kvm_s390_handle_wait(struct kvm_vcpu *vcpu)
502{
503 u64 now, sltime;
504 DECLARE_WAITQUEUE(wait, current);
505
506 vcpu->stat.exit_wait_state++;
507 if (kvm_cpu_has_interrupt(vcpu))
508 return 0;
509
Carsten Ottee52b2af2008-05-21 13:37:44 +0200510 __set_cpu_idle(vcpu);
511 spin_lock_bh(&vcpu->arch.local_int.lock);
512 vcpu->arch.local_int.timer_due = 0;
513 spin_unlock_bh(&vcpu->arch.local_int.lock);
514
Carsten Otteba5c1e92008-03-25 18:47:26 +0100515 if (psw_interrupts_disabled(vcpu)) {
516 VCPU_EVENT(vcpu, 3, "%s", "disabled wait");
517 __unset_cpu_idle(vcpu);
Heiko Carstensb8e660b2010-02-26 22:37:41 +0100518 return -EOPNOTSUPP; /* disabled wait */
Carsten Otteba5c1e92008-03-25 18:47:26 +0100519 }
520
521 if (psw_extint_disabled(vcpu) ||
522 (!(vcpu->arch.sie_block->gcr[0] & 0x800ul))) {
523 VCPU_EVENT(vcpu, 3, "%s", "enabled wait w/o timer");
524 goto no_timer;
525 }
526
527 now = get_clock() + vcpu->arch.sie_block->epoch;
528 if (vcpu->arch.sie_block->ckc < now) {
529 __unset_cpu_idle(vcpu);
530 return 0;
531 }
532
Christian Borntraegerca872302009-05-12 17:21:49 +0200533 sltime = ((vcpu->arch.sie_block->ckc - now)*125)>>9;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100534
Christian Borntraegerca872302009-05-12 17:21:49 +0200535 hrtimer_start(&vcpu->arch.ckc_timer, ktime_set (0, sltime) , HRTIMER_MODE_REL);
536 VCPU_EVENT(vcpu, 5, "enabled wait via clock comparator: %llx ns", sltime);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100537no_timer:
Christian Borntraegerb037a4f2009-05-12 17:21:50 +0200538 spin_lock(&vcpu->arch.local_int.float_int->lock);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100539 spin_lock_bh(&vcpu->arch.local_int.lock);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100540 add_wait_queue(&vcpu->arch.local_int.wq, &wait);
541 while (list_empty(&vcpu->arch.local_int.list) &&
542 list_empty(&vcpu->arch.local_int.float_int->list) &&
543 (!vcpu->arch.local_int.timer_due) &&
544 !signal_pending(current)) {
545 set_current_state(TASK_INTERRUPTIBLE);
546 spin_unlock_bh(&vcpu->arch.local_int.lock);
Christian Borntraegerb037a4f2009-05-12 17:21:50 +0200547 spin_unlock(&vcpu->arch.local_int.float_int->lock);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100548 schedule();
Christian Borntraegerb037a4f2009-05-12 17:21:50 +0200549 spin_lock(&vcpu->arch.local_int.float_int->lock);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100550 spin_lock_bh(&vcpu->arch.local_int.lock);
551 }
552 __unset_cpu_idle(vcpu);
553 __set_current_state(TASK_RUNNING);
Christian Borntraegerd3bc2f92009-07-16 17:17:37 +0200554 remove_wait_queue(&vcpu->arch.local_int.wq, &wait);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100555 spin_unlock_bh(&vcpu->arch.local_int.lock);
Christian Borntraegerb037a4f2009-05-12 17:21:50 +0200556 spin_unlock(&vcpu->arch.local_int.float_int->lock);
Christian Borntraegerca872302009-05-12 17:21:49 +0200557 hrtimer_try_to_cancel(&vcpu->arch.ckc_timer);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100558 return 0;
559}
560
Christian Borntraegerca872302009-05-12 17:21:49 +0200561void kvm_s390_tasklet(unsigned long parm)
Carsten Otteba5c1e92008-03-25 18:47:26 +0100562{
Christian Borntraegerca872302009-05-12 17:21:49 +0200563 struct kvm_vcpu *vcpu = (struct kvm_vcpu *) parm;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100564
Christian Borntraegerca872302009-05-12 17:21:49 +0200565 spin_lock(&vcpu->arch.local_int.lock);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100566 vcpu->arch.local_int.timer_due = 1;
567 if (waitqueue_active(&vcpu->arch.local_int.wq))
568 wake_up_interruptible(&vcpu->arch.local_int.wq);
Christian Borntraegerca872302009-05-12 17:21:49 +0200569 spin_unlock(&vcpu->arch.local_int.lock);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100570}
571
Christian Borntraegerca872302009-05-12 17:21:49 +0200572/*
573 * low level hrtimer wake routine. Because this runs in hardirq context
574 * we schedule a tasklet to do the real work.
575 */
576enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer)
577{
578 struct kvm_vcpu *vcpu;
579
580 vcpu = container_of(timer, struct kvm_vcpu, arch.ckc_timer);
581 tasklet_schedule(&vcpu->arch.tasklet);
582
583 return HRTIMER_NORESTART;
584}
Carsten Otteba5c1e92008-03-25 18:47:26 +0100585
586void kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu)
587{
Christian Borntraeger180c12f2008-06-27 15:05:40 +0200588 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
589 struct kvm_s390_float_interrupt *fi = vcpu->arch.local_int.float_int;
590 struct kvm_s390_interrupt_info *n, *inti = NULL;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100591 int deliver;
592
593 __reset_intercept_indicators(vcpu);
594 if (atomic_read(&li->active)) {
595 do {
596 deliver = 0;
597 spin_lock_bh(&li->lock);
598 list_for_each_entry_safe(inti, n, &li->list, list) {
599 if (__interrupt_is_deliverable(vcpu, inti)) {
600 list_del(&inti->list);
601 deliver = 1;
602 break;
603 }
604 __set_intercept_indicator(vcpu, inti);
605 }
606 if (list_empty(&li->list))
607 atomic_set(&li->active, 0);
608 spin_unlock_bh(&li->lock);
609 if (deliver) {
610 __do_deliver_interrupt(vcpu, inti);
611 kfree(inti);
612 }
613 } while (deliver);
614 }
615
616 if ((vcpu->arch.sie_block->ckc <
617 get_clock() + vcpu->arch.sie_block->epoch))
618 __try_deliver_ckc_interrupt(vcpu);
619
620 if (atomic_read(&fi->active)) {
621 do {
622 deliver = 0;
Christian Borntraegerb037a4f2009-05-12 17:21:50 +0200623 spin_lock(&fi->lock);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100624 list_for_each_entry_safe(inti, n, &fi->list, list) {
625 if (__interrupt_is_deliverable(vcpu, inti)) {
626 list_del(&inti->list);
627 deliver = 1;
628 break;
629 }
630 __set_intercept_indicator(vcpu, inti);
631 }
632 if (list_empty(&fi->list))
633 atomic_set(&fi->active, 0);
Christian Borntraegerb037a4f2009-05-12 17:21:50 +0200634 spin_unlock(&fi->lock);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100635 if (deliver) {
636 __do_deliver_interrupt(vcpu, inti);
637 kfree(inti);
638 }
639 } while (deliver);
640 }
641}
642
Cornelia Huck48a3e952012-12-20 15:32:09 +0100643void kvm_s390_deliver_pending_machine_checks(struct kvm_vcpu *vcpu)
644{
645 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
646 struct kvm_s390_float_interrupt *fi = vcpu->arch.local_int.float_int;
647 struct kvm_s390_interrupt_info *n, *inti = NULL;
648 int deliver;
649
650 __reset_intercept_indicators(vcpu);
651 if (atomic_read(&li->active)) {
652 do {
653 deliver = 0;
654 spin_lock_bh(&li->lock);
655 list_for_each_entry_safe(inti, n, &li->list, list) {
656 if ((inti->type == KVM_S390_MCHK) &&
657 __interrupt_is_deliverable(vcpu, inti)) {
658 list_del(&inti->list);
659 deliver = 1;
660 break;
661 }
662 __set_intercept_indicator(vcpu, inti);
663 }
664 if (list_empty(&li->list))
665 atomic_set(&li->active, 0);
666 spin_unlock_bh(&li->lock);
667 if (deliver) {
668 __do_deliver_interrupt(vcpu, inti);
669 kfree(inti);
670 }
671 } while (deliver);
672 }
673
674 if (atomic_read(&fi->active)) {
675 do {
676 deliver = 0;
677 spin_lock(&fi->lock);
678 list_for_each_entry_safe(inti, n, &fi->list, list) {
679 if ((inti->type == KVM_S390_MCHK) &&
680 __interrupt_is_deliverable(vcpu, inti)) {
681 list_del(&inti->list);
682 deliver = 1;
683 break;
684 }
685 __set_intercept_indicator(vcpu, inti);
686 }
687 if (list_empty(&fi->list))
688 atomic_set(&fi->active, 0);
689 spin_unlock(&fi->lock);
690 if (deliver) {
691 __do_deliver_interrupt(vcpu, inti);
692 kfree(inti);
693 }
694 } while (deliver);
695 }
696}
697
Carsten Otteba5c1e92008-03-25 18:47:26 +0100698int kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code)
699{
Christian Borntraeger180c12f2008-06-27 15:05:40 +0200700 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
701 struct kvm_s390_interrupt_info *inti;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100702
703 inti = kzalloc(sizeof(*inti), GFP_KERNEL);
704 if (!inti)
705 return -ENOMEM;
706
Joe Perchesa419aef2009-08-18 11:18:35 -0700707 inti->type = KVM_S390_PROGRAM_INT;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100708 inti->pgm.code = code;
709
710 VCPU_EVENT(vcpu, 3, "inject: program check %d (from kernel)", code);
Cornelia Huckade38c32012-07-23 17:20:30 +0200711 trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, inti->type, code, 0, 1);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100712 spin_lock_bh(&li->lock);
713 list_add(&inti->list, &li->list);
714 atomic_set(&li->active, 1);
715 BUG_ON(waitqueue_active(&li->wq));
716 spin_unlock_bh(&li->lock);
717 return 0;
718}
719
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +0100720struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm,
721 u64 cr6, u64 schid)
722{
723 struct kvm_s390_float_interrupt *fi;
724 struct kvm_s390_interrupt_info *inti, *iter;
725
726 if ((!schid && !cr6) || (schid && cr6))
727 return NULL;
728 mutex_lock(&kvm->lock);
729 fi = &kvm->arch.float_int;
730 spin_lock(&fi->lock);
731 inti = NULL;
732 list_for_each_entry(iter, &fi->list, list) {
733 if (!is_ioint(iter->type))
734 continue;
Cornelia Huck79fd50c2013-02-07 13:20:52 +0100735 if (cr6 &&
736 ((cr6 & int_word_to_isc_bits(iter->io.io_int_word)) == 0))
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +0100737 continue;
738 if (schid) {
739 if (((schid & 0x00000000ffff0000) >> 16) !=
740 iter->io.subchannel_id)
741 continue;
742 if ((schid & 0x000000000000ffff) !=
743 iter->io.subchannel_nr)
744 continue;
745 }
746 inti = iter;
747 break;
748 }
749 if (inti)
750 list_del_init(&inti->list);
751 if (list_empty(&fi->list))
752 atomic_set(&fi->active, 0);
753 spin_unlock(&fi->lock);
754 mutex_unlock(&kvm->lock);
755 return inti;
756}
757
Carsten Otteba5c1e92008-03-25 18:47:26 +0100758int kvm_s390_inject_vm(struct kvm *kvm,
759 struct kvm_s390_interrupt *s390int)
760{
Christian Borntraeger180c12f2008-06-27 15:05:40 +0200761 struct kvm_s390_local_interrupt *li;
762 struct kvm_s390_float_interrupt *fi;
Cornelia Huckd8346b72012-12-20 15:32:08 +0100763 struct kvm_s390_interrupt_info *inti, *iter;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100764 int sigcpu;
765
766 inti = kzalloc(sizeof(*inti), GFP_KERNEL);
767 if (!inti)
768 return -ENOMEM;
769
770 switch (s390int->type) {
771 case KVM_S390_INT_VIRTIO:
Heiko Carstens33e19112009-01-09 12:14:56 +0100772 VM_EVENT(kvm, 5, "inject: virtio parm:%x,parm64:%llx",
Carsten Otteba5c1e92008-03-25 18:47:26 +0100773 s390int->parm, s390int->parm64);
774 inti->type = s390int->type;
775 inti->ext.ext_params = s390int->parm;
776 inti->ext.ext_params2 = s390int->parm64;
777 break;
778 case KVM_S390_INT_SERVICE:
779 VM_EVENT(kvm, 5, "inject: sclp parm:%x", s390int->parm);
780 inti->type = s390int->type;
781 inti->ext.ext_params = s390int->parm;
782 break;
783 case KVM_S390_PROGRAM_INT:
784 case KVM_S390_SIGP_STOP:
Christian Ehrhardt7697e71f2011-10-18 12:27:15 +0200785 case KVM_S390_INT_EXTERNAL_CALL:
Carsten Otteba5c1e92008-03-25 18:47:26 +0100786 case KVM_S390_INT_EMERGENCY:
Cornelia Huckd8346b72012-12-20 15:32:08 +0100787 kfree(inti);
788 return -EINVAL;
Cornelia Huck48a3e952012-12-20 15:32:09 +0100789 case KVM_S390_MCHK:
790 VM_EVENT(kvm, 5, "inject: machine check parm64:%llx",
791 s390int->parm64);
792 inti->type = s390int->type;
793 inti->mchk.cr14 = s390int->parm; /* upper bits are not used */
794 inti->mchk.mcic = s390int->parm64;
795 break;
Cornelia Huckd8346b72012-12-20 15:32:08 +0100796 case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX:
797 if (s390int->type & IOINT_AI_MASK)
798 VM_EVENT(kvm, 5, "%s", "inject: I/O (AI)");
799 else
800 VM_EVENT(kvm, 5, "inject: I/O css %x ss %x schid %04x",
801 s390int->type & IOINT_CSSID_MASK,
802 s390int->type & IOINT_SSID_MASK,
803 s390int->type & IOINT_SCHID_MASK);
804 inti->type = s390int->type;
805 inti->io.subchannel_id = s390int->parm >> 16;
806 inti->io.subchannel_nr = s390int->parm & 0x0000ffffu;
807 inti->io.io_int_parm = s390int->parm64 >> 32;
808 inti->io.io_int_word = s390int->parm64 & 0x00000000ffffffffull;
809 break;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100810 default:
811 kfree(inti);
812 return -EINVAL;
813 }
Cornelia Huckade38c32012-07-23 17:20:30 +0200814 trace_kvm_s390_inject_vm(s390int->type, s390int->parm, s390int->parm64,
815 2);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100816
817 mutex_lock(&kvm->lock);
818 fi = &kvm->arch.float_int;
Christian Borntraegerb037a4f2009-05-12 17:21:50 +0200819 spin_lock(&fi->lock);
Cornelia Huckd8346b72012-12-20 15:32:08 +0100820 if (!is_ioint(inti->type))
821 list_add_tail(&inti->list, &fi->list);
822 else {
Cornelia Huck79fd50c2013-02-07 13:20:52 +0100823 u64 isc_bits = int_word_to_isc_bits(inti->io.io_int_word);
824
Cornelia Huckd8346b72012-12-20 15:32:08 +0100825 /* Keep I/O interrupts sorted in isc order. */
826 list_for_each_entry(iter, &fi->list, list) {
827 if (!is_ioint(iter->type))
828 continue;
Cornelia Huck79fd50c2013-02-07 13:20:52 +0100829 if (int_word_to_isc_bits(iter->io.io_int_word)
830 <= isc_bits)
Cornelia Huckd8346b72012-12-20 15:32:08 +0100831 continue;
832 break;
833 }
834 list_add_tail(&inti->list, &iter->list);
835 }
Carsten Otteba5c1e92008-03-25 18:47:26 +0100836 atomic_set(&fi->active, 1);
837 sigcpu = find_first_bit(fi->idle_mask, KVM_MAX_VCPUS);
838 if (sigcpu == KVM_MAX_VCPUS) {
839 do {
840 sigcpu = fi->next_rr_cpu++;
841 if (sigcpu == KVM_MAX_VCPUS)
842 sigcpu = fi->next_rr_cpu = 0;
843 } while (fi->local_int[sigcpu] == NULL);
844 }
845 li = fi->local_int[sigcpu];
846 spin_lock_bh(&li->lock);
847 atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags);
848 if (waitqueue_active(&li->wq))
849 wake_up_interruptible(&li->wq);
850 spin_unlock_bh(&li->lock);
Christian Borntraegerb037a4f2009-05-12 17:21:50 +0200851 spin_unlock(&fi->lock);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100852 mutex_unlock(&kvm->lock);
853 return 0;
854}
855
856int kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu,
857 struct kvm_s390_interrupt *s390int)
858{
Christian Borntraeger180c12f2008-06-27 15:05:40 +0200859 struct kvm_s390_local_interrupt *li;
860 struct kvm_s390_interrupt_info *inti;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100861
862 inti = kzalloc(sizeof(*inti), GFP_KERNEL);
863 if (!inti)
864 return -ENOMEM;
865
866 switch (s390int->type) {
867 case KVM_S390_PROGRAM_INT:
868 if (s390int->parm & 0xffff0000) {
869 kfree(inti);
870 return -EINVAL;
871 }
872 inti->type = s390int->type;
873 inti->pgm.code = s390int->parm;
874 VCPU_EVENT(vcpu, 3, "inject: program check %d (from user)",
875 s390int->parm);
876 break;
Christian Borntraegerb7e6e4d2009-01-22 10:29:08 +0100877 case KVM_S390_SIGP_SET_PREFIX:
878 inti->prefix.address = s390int->parm;
879 inti->type = s390int->type;
880 VCPU_EVENT(vcpu, 3, "inject: set prefix to %x (from user)",
881 s390int->parm);
882 break;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100883 case KVM_S390_SIGP_STOP:
884 case KVM_S390_RESTART:
Carsten Otteba5c1e92008-03-25 18:47:26 +0100885 VCPU_EVENT(vcpu, 3, "inject: type %x", s390int->type);
886 inti->type = s390int->type;
887 break;
Jason J. Herne82a12732012-10-02 16:25:36 +0200888 case KVM_S390_INT_EXTERNAL_CALL:
889 if (s390int->parm & 0xffff0000) {
890 kfree(inti);
891 return -EINVAL;
892 }
893 VCPU_EVENT(vcpu, 3, "inject: external call source-cpu:%u",
894 s390int->parm);
895 inti->type = s390int->type;
896 inti->extcall.code = s390int->parm;
897 break;
898 case KVM_S390_INT_EMERGENCY:
899 if (s390int->parm & 0xffff0000) {
900 kfree(inti);
901 return -EINVAL;
902 }
903 VCPU_EVENT(vcpu, 3, "inject: emergency %u\n", s390int->parm);
904 inti->type = s390int->type;
905 inti->emerg.code = s390int->parm;
906 break;
Cornelia Huck48a3e952012-12-20 15:32:09 +0100907 case KVM_S390_MCHK:
908 VCPU_EVENT(vcpu, 5, "inject: machine check parm64:%llx",
909 s390int->parm64);
910 inti->type = s390int->type;
911 inti->mchk.mcic = s390int->parm64;
912 break;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100913 case KVM_S390_INT_VIRTIO:
914 case KVM_S390_INT_SERVICE:
Cornelia Huckd8346b72012-12-20 15:32:08 +0100915 case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX:
Carsten Otteba5c1e92008-03-25 18:47:26 +0100916 default:
917 kfree(inti);
918 return -EINVAL;
919 }
Cornelia Huckade38c32012-07-23 17:20:30 +0200920 trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, s390int->type, s390int->parm,
921 s390int->parm64, 2);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100922
923 mutex_lock(&vcpu->kvm->lock);
924 li = &vcpu->arch.local_int;
925 spin_lock_bh(&li->lock);
926 if (inti->type == KVM_S390_PROGRAM_INT)
927 list_add(&inti->list, &li->list);
928 else
929 list_add_tail(&inti->list, &li->list);
930 atomic_set(&li->active, 1);
931 if (inti->type == KVM_S390_SIGP_STOP)
932 li->action_bits |= ACTION_STOP_ON_STOP;
933 atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags);
934 if (waitqueue_active(&li->wq))
935 wake_up_interruptible(&vcpu->arch.local_int.wq);
936 spin_unlock_bh(&li->lock);
937 mutex_unlock(&vcpu->kvm->lock);
938 return 0;
939}