blob: 7f35cb33e5102008244b4fd1376954400f2d0009 [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 };
Heiko Carstensdc5008b2013-03-05 13:14:43 +0100183 int rc = 0;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100184
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);
Heiko Carstens0a75ca22013-03-05 13:14:47 +0100191 rc = put_guest(vcpu, 0x1201, (u16 __user *)__LC_EXT_INT_CODE);
Heiko Carstens396083a2013-03-05 13:14:44 +0100192 rc |= put_guest(vcpu, inti->emerg.code,
Heiko Carstens0a75ca22013-03-05 13:14:47 +0100193 (u16 __user *)__LC_EXT_CPU_ADDR);
Heiko Carstensdc5008b2013-03-05 13:14:43 +0100194 rc |= copy_to_guest(vcpu, __LC_EXT_OLD_PSW,
195 &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
196 rc |= copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
197 __LC_EXT_NEW_PSW, sizeof(psw_t));
Carsten Otteba5c1e92008-03-25 18:47:26 +0100198 break;
Christian Ehrhardt7697e71f2011-10-18 12:27:15 +0200199 case KVM_S390_INT_EXTERNAL_CALL:
200 VCPU_EVENT(vcpu, 4, "%s", "interrupt: sigp ext call");
201 vcpu->stat.deliver_external_call++;
Cornelia Huckade38c32012-07-23 17:20:30 +0200202 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type,
203 inti->extcall.code, 0);
Heiko Carstens0a75ca22013-03-05 13:14:47 +0100204 rc = put_guest(vcpu, 0x1202, (u16 __user *)__LC_EXT_INT_CODE);
Heiko Carstens396083a2013-03-05 13:14:44 +0100205 rc |= put_guest(vcpu, inti->extcall.code,
Heiko Carstens0a75ca22013-03-05 13:14:47 +0100206 (u16 __user *)__LC_EXT_CPU_ADDR);
Heiko Carstensdc5008b2013-03-05 13:14:43 +0100207 rc |= copy_to_guest(vcpu, __LC_EXT_OLD_PSW,
208 &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
209 rc |= copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
210 __LC_EXT_NEW_PSW, sizeof(psw_t));
Christian Ehrhardt7697e71f2011-10-18 12:27:15 +0200211 break;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100212 case KVM_S390_INT_SERVICE:
213 VCPU_EVENT(vcpu, 4, "interrupt: sclp parm:%x",
214 inti->ext.ext_params);
215 vcpu->stat.deliver_service_signal++;
Cornelia Huckade38c32012-07-23 17:20:30 +0200216 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type,
217 inti->ext.ext_params, 0);
Heiko Carstens0a75ca22013-03-05 13:14:47 +0100218 rc = put_guest(vcpu, 0x2401, (u16 __user *)__LC_EXT_INT_CODE);
Heiko Carstensdc5008b2013-03-05 13:14:43 +0100219 rc |= copy_to_guest(vcpu, __LC_EXT_OLD_PSW,
220 &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
221 rc |= copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
222 __LC_EXT_NEW_PSW, sizeof(psw_t));
Heiko Carstens396083a2013-03-05 13:14:44 +0100223 rc |= put_guest(vcpu, inti->ext.ext_params,
Heiko Carstens0a75ca22013-03-05 13:14:47 +0100224 (u32 __user *)__LC_EXT_PARAMS);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100225 break;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100226 case KVM_S390_INT_VIRTIO:
Heiko Carstens33e19112009-01-09 12:14:56 +0100227 VCPU_EVENT(vcpu, 4, "interrupt: virtio parm:%x,parm64:%llx",
Carsten Otteba5c1e92008-03-25 18:47:26 +0100228 inti->ext.ext_params, inti->ext.ext_params2);
229 vcpu->stat.deliver_virtio_interrupt++;
Cornelia Huckade38c32012-07-23 17:20:30 +0200230 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type,
231 inti->ext.ext_params,
232 inti->ext.ext_params2);
Heiko Carstens0a75ca22013-03-05 13:14:47 +0100233 rc = put_guest(vcpu, 0x2603, (u16 __user *)__LC_EXT_INT_CODE);
234 rc |= put_guest(vcpu, 0x0d00, (u16 __user *)__LC_EXT_CPU_ADDR);
Heiko Carstensdc5008b2013-03-05 13:14:43 +0100235 rc |= copy_to_guest(vcpu, __LC_EXT_OLD_PSW,
236 &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
237 rc |= copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
238 __LC_EXT_NEW_PSW, sizeof(psw_t));
Heiko Carstens396083a2013-03-05 13:14:44 +0100239 rc |= put_guest(vcpu, inti->ext.ext_params,
Heiko Carstens0a75ca22013-03-05 13:14:47 +0100240 (u32 __user *)__LC_EXT_PARAMS);
Heiko Carstens396083a2013-03-05 13:14:44 +0100241 rc |= put_guest(vcpu, inti->ext.ext_params2,
Heiko Carstens0a75ca22013-03-05 13:14:47 +0100242 (u64 __user *)__LC_EXT_PARAMS2);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100243 break;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100244 case KVM_S390_SIGP_STOP:
245 VCPU_EVENT(vcpu, 4, "%s", "interrupt: cpu stop");
246 vcpu->stat.deliver_stop_signal++;
Cornelia Huckade38c32012-07-23 17:20:30 +0200247 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type,
248 0, 0);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100249 __set_intercept_indicator(vcpu, inti);
250 break;
251
252 case KVM_S390_SIGP_SET_PREFIX:
253 VCPU_EVENT(vcpu, 4, "interrupt: set prefix to %x",
254 inti->prefix.address);
255 vcpu->stat.deliver_prefix_signal++;
Cornelia Huckade38c32012-07-23 17:20:30 +0200256 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type,
257 inti->prefix.address, 0);
Christian Borntraeger8d26cf72012-01-11 11:19:32 +0100258 kvm_s390_set_prefix(vcpu, inti->prefix.address);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100259 break;
260
261 case KVM_S390_RESTART:
262 VCPU_EVENT(vcpu, 4, "%s", "interrupt: cpu restart");
263 vcpu->stat.deliver_restart_signal++;
Cornelia Huckade38c32012-07-23 17:20:30 +0200264 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type,
265 0, 0);
Heiko Carstensdc5008b2013-03-05 13:14:43 +0100266 rc = copy_to_guest(vcpu,
267 offsetof(struct _lowcore, restart_old_psw),
268 &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
269 rc |= copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
270 offsetof(struct _lowcore, restart_psw),
271 sizeof(psw_t));
Cornelia Huck9e6dabe2011-11-17 11:00:41 +0100272 atomic_clear_mask(CPUSTAT_STOPPED, &vcpu->arch.sie_block->cpuflags);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100273 break;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100274 case KVM_S390_PROGRAM_INT:
275 VCPU_EVENT(vcpu, 4, "interrupt: pgm check code:%x, ilc:%x",
276 inti->pgm.code,
277 table[vcpu->arch.sie_block->ipa >> 14]);
278 vcpu->stat.deliver_program_int++;
Cornelia Huckade38c32012-07-23 17:20:30 +0200279 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type,
280 inti->pgm.code, 0);
Heiko Carstens0a75ca22013-03-05 13:14:47 +0100281 rc = put_guest(vcpu, inti->pgm.code, (u16 __user *)__LC_PGM_INT_CODE);
Heiko Carstens396083a2013-03-05 13:14:44 +0100282 rc |= put_guest(vcpu, table[vcpu->arch.sie_block->ipa >> 14],
Heiko Carstens0a75ca22013-03-05 13:14:47 +0100283 (u16 __user *)__LC_PGM_ILC);
Heiko Carstensdc5008b2013-03-05 13:14:43 +0100284 rc |= copy_to_guest(vcpu, __LC_PGM_OLD_PSW,
285 &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
286 rc |= copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
287 __LC_PGM_NEW_PSW, sizeof(psw_t));
Carsten Otteba5c1e92008-03-25 18:47:26 +0100288 break;
289
Cornelia Huck48a3e952012-12-20 15:32:09 +0100290 case KVM_S390_MCHK:
291 VCPU_EVENT(vcpu, 4, "interrupt: machine check mcic=%llx",
292 inti->mchk.mcic);
293 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type,
294 inti->mchk.cr14,
295 inti->mchk.mcic);
Heiko Carstensdc5008b2013-03-05 13:14:43 +0100296 rc = kvm_s390_vcpu_store_status(vcpu,
297 KVM_S390_STORE_STATUS_PREFIXED);
Heiko Carstens0a75ca22013-03-05 13:14:47 +0100298 rc |= put_guest(vcpu, inti->mchk.mcic, (u64 __user *) __LC_MCCK_CODE);
Heiko Carstensdc5008b2013-03-05 13:14:43 +0100299 rc |= copy_to_guest(vcpu, __LC_MCK_OLD_PSW,
300 &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
301 rc |= copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
302 __LC_MCK_NEW_PSW, sizeof(psw_t));
Cornelia Huck48a3e952012-12-20 15:32:09 +0100303 break;
304
Cornelia Huckd8346b72012-12-20 15:32:08 +0100305 case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX:
306 {
307 __u32 param0 = ((__u32)inti->io.subchannel_id << 16) |
308 inti->io.subchannel_nr;
309 __u64 param1 = ((__u64)inti->io.io_int_parm << 32) |
310 inti->io.io_int_word;
311 VCPU_EVENT(vcpu, 4, "interrupt: I/O %llx", inti->type);
312 vcpu->stat.deliver_io_int++;
313 trace_kvm_s390_deliver_interrupt(vcpu->vcpu_id, inti->type,
314 param0, param1);
Heiko Carstens396083a2013-03-05 13:14:44 +0100315 rc = put_guest(vcpu, inti->io.subchannel_id,
Heiko Carstens0a75ca22013-03-05 13:14:47 +0100316 (u16 __user *) __LC_SUBCHANNEL_ID);
Heiko Carstens396083a2013-03-05 13:14:44 +0100317 rc |= put_guest(vcpu, inti->io.subchannel_nr,
Heiko Carstens0a75ca22013-03-05 13:14:47 +0100318 (u16 __user *) __LC_SUBCHANNEL_NR);
Heiko Carstens396083a2013-03-05 13:14:44 +0100319 rc |= put_guest(vcpu, inti->io.io_int_parm,
Heiko Carstens0a75ca22013-03-05 13:14:47 +0100320 (u32 __user *) __LC_IO_INT_PARM);
Heiko Carstens396083a2013-03-05 13:14:44 +0100321 rc |= put_guest(vcpu, inti->io.io_int_word,
Heiko Carstens0a75ca22013-03-05 13:14:47 +0100322 (u32 __user *) __LC_IO_INT_WORD);
Heiko Carstensdc5008b2013-03-05 13:14:43 +0100323 rc |= copy_to_guest(vcpu, __LC_IO_OLD_PSW,
324 &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
325 rc |= copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
326 __LC_IO_NEW_PSW, sizeof(psw_t));
Cornelia Huckd8346b72012-12-20 15:32:08 +0100327 break;
328 }
Carsten Otteba5c1e92008-03-25 18:47:26 +0100329 default:
330 BUG();
331 }
Heiko Carstensdc5008b2013-03-05 13:14:43 +0100332 if (rc) {
Christian Borntraeger3cd61292008-07-25 15:51:54 +0200333 printk("kvm: The guest lowcore is not mapped during interrupt "
Heiko Carstensdc5008b2013-03-05 13:14:43 +0100334 "delivery, killing userspace\n");
Christian Borntraeger3cd61292008-07-25 15:51:54 +0200335 do_exit(SIGKILL);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100336 }
337}
338
339static int __try_deliver_ckc_interrupt(struct kvm_vcpu *vcpu)
340{
Heiko Carstensdc5008b2013-03-05 13:14:43 +0100341 int rc;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100342
343 if (psw_extint_disabled(vcpu))
344 return 0;
345 if (!(vcpu->arch.sie_block->gcr[0] & 0x800ul))
346 return 0;
Heiko Carstens0a75ca22013-03-05 13:14:47 +0100347 rc = put_guest(vcpu, 0x1004, (u16 __user *)__LC_EXT_INT_CODE);
Heiko Carstensdc5008b2013-03-05 13:14:43 +0100348 rc |= copy_to_guest(vcpu, __LC_EXT_OLD_PSW,
349 &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
350 rc |= copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
351 __LC_EXT_NEW_PSW, sizeof(psw_t));
352 if (rc) {
Christian Borntraeger3cd61292008-07-25 15:51:54 +0200353 printk("kvm: The guest lowcore is not mapped during interrupt "
354 "delivery, killing userspace\n");
355 do_exit(SIGKILL);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100356 }
Carsten Otteba5c1e92008-03-25 18:47:26 +0100357 return 1;
358}
359
Gleb Natapova1b37102009-07-09 15:33:52 +0300360static int kvm_cpu_has_interrupt(struct kvm_vcpu *vcpu)
Carsten Otteba5c1e92008-03-25 18:47:26 +0100361{
Christian Borntraeger180c12f2008-06-27 15:05:40 +0200362 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
363 struct kvm_s390_float_interrupt *fi = vcpu->arch.local_int.float_int;
364 struct kvm_s390_interrupt_info *inti;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100365 int rc = 0;
366
367 if (atomic_read(&li->active)) {
368 spin_lock_bh(&li->lock);
369 list_for_each_entry(inti, &li->list, list)
370 if (__interrupt_is_deliverable(vcpu, inti)) {
371 rc = 1;
372 break;
373 }
374 spin_unlock_bh(&li->lock);
375 }
376
377 if ((!rc) && atomic_read(&fi->active)) {
Christian Borntraegerb037a4f2009-05-12 17:21:50 +0200378 spin_lock(&fi->lock);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100379 list_for_each_entry(inti, &fi->list, list)
380 if (__interrupt_is_deliverable(vcpu, inti)) {
381 rc = 1;
382 break;
383 }
Christian Borntraegerb037a4f2009-05-12 17:21:50 +0200384 spin_unlock(&fi->lock);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100385 }
386
387 if ((!rc) && (vcpu->arch.sie_block->ckc <
Heiko Carstens1aae0562013-01-30 09:49:40 +0100388 get_tod_clock() + vcpu->arch.sie_block->epoch)) {
Carsten Otteba5c1e92008-03-25 18:47:26 +0100389 if ((!psw_extint_disabled(vcpu)) &&
390 (vcpu->arch.sie_block->gcr[0] & 0x800ul))
391 rc = 1;
392 }
393
394 return rc;
395}
396
Marcelo Tosatti3d808402008-04-11 14:53:26 -0300397int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu)
398{
399 return 0;
400}
401
Carsten Otteba5c1e92008-03-25 18:47:26 +0100402int kvm_s390_handle_wait(struct kvm_vcpu *vcpu)
403{
404 u64 now, sltime;
405 DECLARE_WAITQUEUE(wait, current);
406
407 vcpu->stat.exit_wait_state++;
408 if (kvm_cpu_has_interrupt(vcpu))
409 return 0;
410
Carsten Ottee52b2af2008-05-21 13:37:44 +0200411 __set_cpu_idle(vcpu);
412 spin_lock_bh(&vcpu->arch.local_int.lock);
413 vcpu->arch.local_int.timer_due = 0;
414 spin_unlock_bh(&vcpu->arch.local_int.lock);
415
Carsten Otteba5c1e92008-03-25 18:47:26 +0100416 if (psw_interrupts_disabled(vcpu)) {
417 VCPU_EVENT(vcpu, 3, "%s", "disabled wait");
418 __unset_cpu_idle(vcpu);
Heiko Carstensb8e660b2010-02-26 22:37:41 +0100419 return -EOPNOTSUPP; /* disabled wait */
Carsten Otteba5c1e92008-03-25 18:47:26 +0100420 }
421
422 if (psw_extint_disabled(vcpu) ||
423 (!(vcpu->arch.sie_block->gcr[0] & 0x800ul))) {
424 VCPU_EVENT(vcpu, 3, "%s", "enabled wait w/o timer");
425 goto no_timer;
426 }
427
Heiko Carstens1aae0562013-01-30 09:49:40 +0100428 now = get_tod_clock() + vcpu->arch.sie_block->epoch;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100429 if (vcpu->arch.sie_block->ckc < now) {
430 __unset_cpu_idle(vcpu);
431 return 0;
432 }
433
Heiko Carstensed4f2092013-01-14 16:55:55 +0100434 sltime = tod_to_ns(vcpu->arch.sie_block->ckc - now);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100435
Christian Borntraegerca872302009-05-12 17:21:49 +0200436 hrtimer_start(&vcpu->arch.ckc_timer, ktime_set (0, sltime) , HRTIMER_MODE_REL);
437 VCPU_EVENT(vcpu, 5, "enabled wait via clock comparator: %llx ns", sltime);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100438no_timer:
Christian Borntraegerb037a4f2009-05-12 17:21:50 +0200439 spin_lock(&vcpu->arch.local_int.float_int->lock);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100440 spin_lock_bh(&vcpu->arch.local_int.lock);
Christian Borntraegerd0321a22013-06-12 13:54:55 +0200441 add_wait_queue(&vcpu->wq, &wait);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100442 while (list_empty(&vcpu->arch.local_int.list) &&
443 list_empty(&vcpu->arch.local_int.float_int->list) &&
444 (!vcpu->arch.local_int.timer_due) &&
445 !signal_pending(current)) {
446 set_current_state(TASK_INTERRUPTIBLE);
447 spin_unlock_bh(&vcpu->arch.local_int.lock);
Christian Borntraegerb037a4f2009-05-12 17:21:50 +0200448 spin_unlock(&vcpu->arch.local_int.float_int->lock);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100449 schedule();
Christian Borntraegerb037a4f2009-05-12 17:21:50 +0200450 spin_lock(&vcpu->arch.local_int.float_int->lock);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100451 spin_lock_bh(&vcpu->arch.local_int.lock);
452 }
453 __unset_cpu_idle(vcpu);
454 __set_current_state(TASK_RUNNING);
Christian Borntraegerd0321a22013-06-12 13:54:55 +0200455 remove_wait_queue(&vcpu->wq, &wait);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100456 spin_unlock_bh(&vcpu->arch.local_int.lock);
Christian Borntraegerb037a4f2009-05-12 17:21:50 +0200457 spin_unlock(&vcpu->arch.local_int.float_int->lock);
Christian Borntraegerca872302009-05-12 17:21:49 +0200458 hrtimer_try_to_cancel(&vcpu->arch.ckc_timer);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100459 return 0;
460}
461
Christian Borntraegerca872302009-05-12 17:21:49 +0200462void kvm_s390_tasklet(unsigned long parm)
Carsten Otteba5c1e92008-03-25 18:47:26 +0100463{
Christian Borntraegerca872302009-05-12 17:21:49 +0200464 struct kvm_vcpu *vcpu = (struct kvm_vcpu *) parm;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100465
Christian Borntraegerca872302009-05-12 17:21:49 +0200466 spin_lock(&vcpu->arch.local_int.lock);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100467 vcpu->arch.local_int.timer_due = 1;
Christian Borntraegerd0321a22013-06-12 13:54:55 +0200468 if (waitqueue_active(&vcpu->wq))
469 wake_up_interruptible(&vcpu->wq);
Christian Borntraegerca872302009-05-12 17:21:49 +0200470 spin_unlock(&vcpu->arch.local_int.lock);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100471}
472
Christian Borntraegerca872302009-05-12 17:21:49 +0200473/*
474 * low level hrtimer wake routine. Because this runs in hardirq context
475 * we schedule a tasklet to do the real work.
476 */
477enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer)
478{
479 struct kvm_vcpu *vcpu;
480
481 vcpu = container_of(timer, struct kvm_vcpu, arch.ckc_timer);
482 tasklet_schedule(&vcpu->arch.tasklet);
483
484 return HRTIMER_NORESTART;
485}
Carsten Otteba5c1e92008-03-25 18:47:26 +0100486
487void kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu)
488{
Christian Borntraeger180c12f2008-06-27 15:05:40 +0200489 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
490 struct kvm_s390_float_interrupt *fi = vcpu->arch.local_int.float_int;
491 struct kvm_s390_interrupt_info *n, *inti = NULL;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100492 int deliver;
493
494 __reset_intercept_indicators(vcpu);
495 if (atomic_read(&li->active)) {
496 do {
497 deliver = 0;
498 spin_lock_bh(&li->lock);
499 list_for_each_entry_safe(inti, n, &li->list, list) {
500 if (__interrupt_is_deliverable(vcpu, inti)) {
501 list_del(&inti->list);
502 deliver = 1;
503 break;
504 }
505 __set_intercept_indicator(vcpu, inti);
506 }
507 if (list_empty(&li->list))
508 atomic_set(&li->active, 0);
509 spin_unlock_bh(&li->lock);
510 if (deliver) {
511 __do_deliver_interrupt(vcpu, inti);
512 kfree(inti);
513 }
514 } while (deliver);
515 }
516
517 if ((vcpu->arch.sie_block->ckc <
Heiko Carstens1aae0562013-01-30 09:49:40 +0100518 get_tod_clock() + vcpu->arch.sie_block->epoch))
Carsten Otteba5c1e92008-03-25 18:47:26 +0100519 __try_deliver_ckc_interrupt(vcpu);
520
521 if (atomic_read(&fi->active)) {
522 do {
523 deliver = 0;
Christian Borntraegerb037a4f2009-05-12 17:21:50 +0200524 spin_lock(&fi->lock);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100525 list_for_each_entry_safe(inti, n, &fi->list, list) {
526 if (__interrupt_is_deliverable(vcpu, inti)) {
527 list_del(&inti->list);
528 deliver = 1;
529 break;
530 }
531 __set_intercept_indicator(vcpu, inti);
532 }
533 if (list_empty(&fi->list))
534 atomic_set(&fi->active, 0);
Christian Borntraegerb037a4f2009-05-12 17:21:50 +0200535 spin_unlock(&fi->lock);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100536 if (deliver) {
537 __do_deliver_interrupt(vcpu, inti);
538 kfree(inti);
539 }
540 } while (deliver);
541 }
542}
543
Cornelia Huck48a3e952012-12-20 15:32:09 +0100544void kvm_s390_deliver_pending_machine_checks(struct kvm_vcpu *vcpu)
545{
546 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
547 struct kvm_s390_float_interrupt *fi = vcpu->arch.local_int.float_int;
548 struct kvm_s390_interrupt_info *n, *inti = NULL;
549 int deliver;
550
551 __reset_intercept_indicators(vcpu);
552 if (atomic_read(&li->active)) {
553 do {
554 deliver = 0;
555 spin_lock_bh(&li->lock);
556 list_for_each_entry_safe(inti, n, &li->list, list) {
557 if ((inti->type == KVM_S390_MCHK) &&
558 __interrupt_is_deliverable(vcpu, inti)) {
559 list_del(&inti->list);
560 deliver = 1;
561 break;
562 }
563 __set_intercept_indicator(vcpu, inti);
564 }
565 if (list_empty(&li->list))
566 atomic_set(&li->active, 0);
567 spin_unlock_bh(&li->lock);
568 if (deliver) {
569 __do_deliver_interrupt(vcpu, inti);
570 kfree(inti);
571 }
572 } while (deliver);
573 }
574
575 if (atomic_read(&fi->active)) {
576 do {
577 deliver = 0;
578 spin_lock(&fi->lock);
579 list_for_each_entry_safe(inti, n, &fi->list, list) {
580 if ((inti->type == KVM_S390_MCHK) &&
581 __interrupt_is_deliverable(vcpu, inti)) {
582 list_del(&inti->list);
583 deliver = 1;
584 break;
585 }
586 __set_intercept_indicator(vcpu, inti);
587 }
588 if (list_empty(&fi->list))
589 atomic_set(&fi->active, 0);
590 spin_unlock(&fi->lock);
591 if (deliver) {
592 __do_deliver_interrupt(vcpu, inti);
593 kfree(inti);
594 }
595 } while (deliver);
596 }
597}
598
Carsten Otteba5c1e92008-03-25 18:47:26 +0100599int kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code)
600{
Christian Borntraeger180c12f2008-06-27 15:05:40 +0200601 struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;
602 struct kvm_s390_interrupt_info *inti;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100603
604 inti = kzalloc(sizeof(*inti), GFP_KERNEL);
605 if (!inti)
606 return -ENOMEM;
607
Joe Perchesa419aef2009-08-18 11:18:35 -0700608 inti->type = KVM_S390_PROGRAM_INT;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100609 inti->pgm.code = code;
610
611 VCPU_EVENT(vcpu, 3, "inject: program check %d (from kernel)", code);
Cornelia Huckade38c32012-07-23 17:20:30 +0200612 trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, inti->type, code, 0, 1);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100613 spin_lock_bh(&li->lock);
614 list_add(&inti->list, &li->list);
615 atomic_set(&li->active, 1);
Christian Borntraegerd0321a22013-06-12 13:54:55 +0200616 BUG_ON(waitqueue_active(li->wq));
Carsten Otteba5c1e92008-03-25 18:47:26 +0100617 spin_unlock_bh(&li->lock);
618 return 0;
619}
620
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +0100621struct kvm_s390_interrupt_info *kvm_s390_get_io_int(struct kvm *kvm,
622 u64 cr6, u64 schid)
623{
624 struct kvm_s390_float_interrupt *fi;
625 struct kvm_s390_interrupt_info *inti, *iter;
626
627 if ((!schid && !cr6) || (schid && cr6))
628 return NULL;
629 mutex_lock(&kvm->lock);
630 fi = &kvm->arch.float_int;
631 spin_lock(&fi->lock);
632 inti = NULL;
633 list_for_each_entry(iter, &fi->list, list) {
634 if (!is_ioint(iter->type))
635 continue;
Cornelia Huck79fd50c2013-02-07 13:20:52 +0100636 if (cr6 &&
637 ((cr6 & int_word_to_isc_bits(iter->io.io_int_word)) == 0))
Cornelia Huckfa6b7fe2012-12-20 15:32:12 +0100638 continue;
639 if (schid) {
640 if (((schid & 0x00000000ffff0000) >> 16) !=
641 iter->io.subchannel_id)
642 continue;
643 if ((schid & 0x000000000000ffff) !=
644 iter->io.subchannel_nr)
645 continue;
646 }
647 inti = iter;
648 break;
649 }
650 if (inti)
651 list_del_init(&inti->list);
652 if (list_empty(&fi->list))
653 atomic_set(&fi->active, 0);
654 spin_unlock(&fi->lock);
655 mutex_unlock(&kvm->lock);
656 return inti;
657}
658
Carsten Otteba5c1e92008-03-25 18:47:26 +0100659int kvm_s390_inject_vm(struct kvm *kvm,
660 struct kvm_s390_interrupt *s390int)
661{
Christian Borntraeger180c12f2008-06-27 15:05:40 +0200662 struct kvm_s390_local_interrupt *li;
663 struct kvm_s390_float_interrupt *fi;
Cornelia Huckd8346b72012-12-20 15:32:08 +0100664 struct kvm_s390_interrupt_info *inti, *iter;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100665 int sigcpu;
666
667 inti = kzalloc(sizeof(*inti), GFP_KERNEL);
668 if (!inti)
669 return -ENOMEM;
670
671 switch (s390int->type) {
672 case KVM_S390_INT_VIRTIO:
Heiko Carstens33e19112009-01-09 12:14:56 +0100673 VM_EVENT(kvm, 5, "inject: virtio parm:%x,parm64:%llx",
Carsten Otteba5c1e92008-03-25 18:47:26 +0100674 s390int->parm, s390int->parm64);
675 inti->type = s390int->type;
676 inti->ext.ext_params = s390int->parm;
677 inti->ext.ext_params2 = s390int->parm64;
678 break;
679 case KVM_S390_INT_SERVICE:
680 VM_EVENT(kvm, 5, "inject: sclp parm:%x", s390int->parm);
681 inti->type = s390int->type;
682 inti->ext.ext_params = s390int->parm;
683 break;
684 case KVM_S390_PROGRAM_INT:
685 case KVM_S390_SIGP_STOP:
Christian Ehrhardt7697e71f2011-10-18 12:27:15 +0200686 case KVM_S390_INT_EXTERNAL_CALL:
Carsten Otteba5c1e92008-03-25 18:47:26 +0100687 case KVM_S390_INT_EMERGENCY:
Cornelia Huckd8346b72012-12-20 15:32:08 +0100688 kfree(inti);
689 return -EINVAL;
Cornelia Huck48a3e952012-12-20 15:32:09 +0100690 case KVM_S390_MCHK:
691 VM_EVENT(kvm, 5, "inject: machine check parm64:%llx",
692 s390int->parm64);
693 inti->type = s390int->type;
694 inti->mchk.cr14 = s390int->parm; /* upper bits are not used */
695 inti->mchk.mcic = s390int->parm64;
696 break;
Cornelia Huckd8346b72012-12-20 15:32:08 +0100697 case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX:
698 if (s390int->type & IOINT_AI_MASK)
699 VM_EVENT(kvm, 5, "%s", "inject: I/O (AI)");
700 else
701 VM_EVENT(kvm, 5, "inject: I/O css %x ss %x schid %04x",
702 s390int->type & IOINT_CSSID_MASK,
703 s390int->type & IOINT_SSID_MASK,
704 s390int->type & IOINT_SCHID_MASK);
705 inti->type = s390int->type;
706 inti->io.subchannel_id = s390int->parm >> 16;
707 inti->io.subchannel_nr = s390int->parm & 0x0000ffffu;
708 inti->io.io_int_parm = s390int->parm64 >> 32;
709 inti->io.io_int_word = s390int->parm64 & 0x00000000ffffffffull;
710 break;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100711 default:
712 kfree(inti);
713 return -EINVAL;
714 }
Cornelia Huckade38c32012-07-23 17:20:30 +0200715 trace_kvm_s390_inject_vm(s390int->type, s390int->parm, s390int->parm64,
716 2);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100717
718 mutex_lock(&kvm->lock);
719 fi = &kvm->arch.float_int;
Christian Borntraegerb037a4f2009-05-12 17:21:50 +0200720 spin_lock(&fi->lock);
Cornelia Huckd8346b72012-12-20 15:32:08 +0100721 if (!is_ioint(inti->type))
722 list_add_tail(&inti->list, &fi->list);
723 else {
Cornelia Huck79fd50c2013-02-07 13:20:52 +0100724 u64 isc_bits = int_word_to_isc_bits(inti->io.io_int_word);
725
Cornelia Huckd8346b72012-12-20 15:32:08 +0100726 /* Keep I/O interrupts sorted in isc order. */
727 list_for_each_entry(iter, &fi->list, list) {
728 if (!is_ioint(iter->type))
729 continue;
Cornelia Huck79fd50c2013-02-07 13:20:52 +0100730 if (int_word_to_isc_bits(iter->io.io_int_word)
731 <= isc_bits)
Cornelia Huckd8346b72012-12-20 15:32:08 +0100732 continue;
733 break;
734 }
735 list_add_tail(&inti->list, &iter->list);
736 }
Carsten Otteba5c1e92008-03-25 18:47:26 +0100737 atomic_set(&fi->active, 1);
738 sigcpu = find_first_bit(fi->idle_mask, KVM_MAX_VCPUS);
739 if (sigcpu == KVM_MAX_VCPUS) {
740 do {
741 sigcpu = fi->next_rr_cpu++;
742 if (sigcpu == KVM_MAX_VCPUS)
743 sigcpu = fi->next_rr_cpu = 0;
744 } while (fi->local_int[sigcpu] == NULL);
745 }
746 li = fi->local_int[sigcpu];
747 spin_lock_bh(&li->lock);
748 atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags);
Christian Borntraegerd0321a22013-06-12 13:54:55 +0200749 if (waitqueue_active(li->wq))
750 wake_up_interruptible(li->wq);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100751 spin_unlock_bh(&li->lock);
Christian Borntraegerb037a4f2009-05-12 17:21:50 +0200752 spin_unlock(&fi->lock);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100753 mutex_unlock(&kvm->lock);
754 return 0;
755}
756
757int kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu,
758 struct kvm_s390_interrupt *s390int)
759{
Christian Borntraeger180c12f2008-06-27 15:05:40 +0200760 struct kvm_s390_local_interrupt *li;
761 struct kvm_s390_interrupt_info *inti;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100762
763 inti = kzalloc(sizeof(*inti), GFP_KERNEL);
764 if (!inti)
765 return -ENOMEM;
766
767 switch (s390int->type) {
768 case KVM_S390_PROGRAM_INT:
769 if (s390int->parm & 0xffff0000) {
770 kfree(inti);
771 return -EINVAL;
772 }
773 inti->type = s390int->type;
774 inti->pgm.code = s390int->parm;
775 VCPU_EVENT(vcpu, 3, "inject: program check %d (from user)",
776 s390int->parm);
777 break;
Christian Borntraegerb7e6e4d2009-01-22 10:29:08 +0100778 case KVM_S390_SIGP_SET_PREFIX:
779 inti->prefix.address = s390int->parm;
780 inti->type = s390int->type;
781 VCPU_EVENT(vcpu, 3, "inject: set prefix to %x (from user)",
782 s390int->parm);
783 break;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100784 case KVM_S390_SIGP_STOP:
785 case KVM_S390_RESTART:
Carsten Otteba5c1e92008-03-25 18:47:26 +0100786 VCPU_EVENT(vcpu, 3, "inject: type %x", s390int->type);
787 inti->type = s390int->type;
788 break;
Jason J. Herne82a12732012-10-02 16:25:36 +0200789 case KVM_S390_INT_EXTERNAL_CALL:
790 if (s390int->parm & 0xffff0000) {
791 kfree(inti);
792 return -EINVAL;
793 }
794 VCPU_EVENT(vcpu, 3, "inject: external call source-cpu:%u",
795 s390int->parm);
796 inti->type = s390int->type;
797 inti->extcall.code = s390int->parm;
798 break;
799 case KVM_S390_INT_EMERGENCY:
800 if (s390int->parm & 0xffff0000) {
801 kfree(inti);
802 return -EINVAL;
803 }
804 VCPU_EVENT(vcpu, 3, "inject: emergency %u\n", s390int->parm);
805 inti->type = s390int->type;
806 inti->emerg.code = s390int->parm;
807 break;
Cornelia Huck48a3e952012-12-20 15:32:09 +0100808 case KVM_S390_MCHK:
809 VCPU_EVENT(vcpu, 5, "inject: machine check parm64:%llx",
810 s390int->parm64);
811 inti->type = s390int->type;
812 inti->mchk.mcic = s390int->parm64;
813 break;
Carsten Otteba5c1e92008-03-25 18:47:26 +0100814 case KVM_S390_INT_VIRTIO:
815 case KVM_S390_INT_SERVICE:
Cornelia Huckd8346b72012-12-20 15:32:08 +0100816 case KVM_S390_INT_IO_MIN...KVM_S390_INT_IO_MAX:
Carsten Otteba5c1e92008-03-25 18:47:26 +0100817 default:
818 kfree(inti);
819 return -EINVAL;
820 }
Cornelia Huckade38c32012-07-23 17:20:30 +0200821 trace_kvm_s390_inject_vcpu(vcpu->vcpu_id, s390int->type, s390int->parm,
822 s390int->parm64, 2);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100823
824 mutex_lock(&vcpu->kvm->lock);
825 li = &vcpu->arch.local_int;
826 spin_lock_bh(&li->lock);
827 if (inti->type == KVM_S390_PROGRAM_INT)
828 list_add(&inti->list, &li->list);
829 else
830 list_add_tail(&inti->list, &li->list);
831 atomic_set(&li->active, 1);
832 if (inti->type == KVM_S390_SIGP_STOP)
833 li->action_bits |= ACTION_STOP_ON_STOP;
834 atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags);
Christian Borntraegerd0321a22013-06-12 13:54:55 +0200835 if (waitqueue_active(&vcpu->wq))
836 wake_up_interruptible(&vcpu->wq);
Carsten Otteba5c1e92008-03-25 18:47:26 +0100837 spin_unlock_bh(&li->lock);
838 mutex_unlock(&vcpu->kvm->lock);
839 return 0;
840}