interrupt.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. /*
  2. * interrupt.c - handling kvm guest interrupts
  3. *
  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. #include <asm/lowcore.h>
  13. #include <asm/uaccess.h>
  14. #include <linux/kvm_host.h>
  15. #include "kvm-s390.h"
  16. #include "gaccess.h"
  17. static int psw_extint_disabled(struct kvm_vcpu *vcpu)
  18. {
  19. return !(vcpu->arch.sie_block->gpsw.mask & PSW_MASK_EXT);
  20. }
  21. static int psw_interrupts_disabled(struct kvm_vcpu *vcpu)
  22. {
  23. if ((vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PER) ||
  24. (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_IO) ||
  25. (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_EXT))
  26. return 0;
  27. return 1;
  28. }
  29. static int __interrupt_is_deliverable(struct kvm_vcpu *vcpu,
  30. struct interrupt_info *inti)
  31. {
  32. switch (inti->type) {
  33. case KVM_S390_INT_EMERGENCY:
  34. if (psw_extint_disabled(vcpu))
  35. return 0;
  36. if (vcpu->arch.sie_block->gcr[0] & 0x4000ul)
  37. return 1;
  38. return 0;
  39. case KVM_S390_INT_SERVICE:
  40. if (psw_extint_disabled(vcpu))
  41. return 0;
  42. if (vcpu->arch.sie_block->gcr[0] & 0x200ul)
  43. return 1;
  44. return 0;
  45. case KVM_S390_INT_VIRTIO:
  46. if (psw_extint_disabled(vcpu))
  47. return 0;
  48. if (vcpu->arch.sie_block->gcr[0] & 0x200ul)
  49. return 1;
  50. return 0;
  51. case KVM_S390_PROGRAM_INT:
  52. case KVM_S390_SIGP_STOP:
  53. case KVM_S390_SIGP_SET_PREFIX:
  54. case KVM_S390_RESTART:
  55. return 1;
  56. default:
  57. BUG();
  58. }
  59. return 0;
  60. }
  61. static void __set_cpu_idle(struct kvm_vcpu *vcpu)
  62. {
  63. BUG_ON(vcpu->vcpu_id > KVM_MAX_VCPUS - 1);
  64. atomic_set_mask(CPUSTAT_WAIT, &vcpu->arch.sie_block->cpuflags);
  65. set_bit(vcpu->vcpu_id, vcpu->arch.local_int.float_int->idle_mask);
  66. }
  67. static void __unset_cpu_idle(struct kvm_vcpu *vcpu)
  68. {
  69. BUG_ON(vcpu->vcpu_id > KVM_MAX_VCPUS - 1);
  70. atomic_clear_mask(CPUSTAT_WAIT, &vcpu->arch.sie_block->cpuflags);
  71. clear_bit(vcpu->vcpu_id, vcpu->arch.local_int.float_int->idle_mask);
  72. }
  73. static void __reset_intercept_indicators(struct kvm_vcpu *vcpu)
  74. {
  75. atomic_clear_mask(CPUSTAT_ECALL_PEND |
  76. CPUSTAT_IO_INT | CPUSTAT_EXT_INT | CPUSTAT_STOP_INT,
  77. &vcpu->arch.sie_block->cpuflags);
  78. vcpu->arch.sie_block->lctl = 0x0000;
  79. }
  80. static void __set_cpuflag(struct kvm_vcpu *vcpu, u32 flag)
  81. {
  82. atomic_set_mask(flag, &vcpu->arch.sie_block->cpuflags);
  83. }
  84. static void __set_intercept_indicator(struct kvm_vcpu *vcpu,
  85. struct interrupt_info *inti)
  86. {
  87. switch (inti->type) {
  88. case KVM_S390_INT_EMERGENCY:
  89. case KVM_S390_INT_SERVICE:
  90. case KVM_S390_INT_VIRTIO:
  91. if (psw_extint_disabled(vcpu))
  92. __set_cpuflag(vcpu, CPUSTAT_EXT_INT);
  93. else
  94. vcpu->arch.sie_block->lctl |= LCTL_CR0;
  95. break;
  96. case KVM_S390_SIGP_STOP:
  97. __set_cpuflag(vcpu, CPUSTAT_STOP_INT);
  98. break;
  99. default:
  100. BUG();
  101. }
  102. }
  103. static void __do_deliver_interrupt(struct kvm_vcpu *vcpu,
  104. struct interrupt_info *inti)
  105. {
  106. const unsigned short table[] = { 2, 4, 4, 6 };
  107. int rc, exception = 0;
  108. switch (inti->type) {
  109. case KVM_S390_INT_EMERGENCY:
  110. VCPU_EVENT(vcpu, 4, "%s", "interrupt: sigp emerg");
  111. vcpu->stat.deliver_emergency_signal++;
  112. rc = put_guest_u16(vcpu, __LC_EXT_INT_CODE, 0x1201);
  113. if (rc == -EFAULT)
  114. exception = 1;
  115. rc = copy_to_guest(vcpu, __LC_EXT_OLD_PSW,
  116. &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
  117. if (rc == -EFAULT)
  118. exception = 1;
  119. rc = copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
  120. __LC_EXT_NEW_PSW, sizeof(psw_t));
  121. if (rc == -EFAULT)
  122. exception = 1;
  123. break;
  124. case KVM_S390_INT_SERVICE:
  125. VCPU_EVENT(vcpu, 4, "interrupt: sclp parm:%x",
  126. inti->ext.ext_params);
  127. vcpu->stat.deliver_service_signal++;
  128. rc = put_guest_u16(vcpu, __LC_EXT_INT_CODE, 0x2401);
  129. if (rc == -EFAULT)
  130. exception = 1;
  131. rc = copy_to_guest(vcpu, __LC_EXT_OLD_PSW,
  132. &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
  133. if (rc == -EFAULT)
  134. exception = 1;
  135. rc = copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
  136. __LC_EXT_NEW_PSW, sizeof(psw_t));
  137. if (rc == -EFAULT)
  138. exception = 1;
  139. rc = put_guest_u32(vcpu, __LC_EXT_PARAMS, inti->ext.ext_params);
  140. if (rc == -EFAULT)
  141. exception = 1;
  142. break;
  143. case KVM_S390_INT_VIRTIO:
  144. VCPU_EVENT(vcpu, 4, "interrupt: virtio parm:%x,parm64:%lx",
  145. inti->ext.ext_params, inti->ext.ext_params2);
  146. vcpu->stat.deliver_virtio_interrupt++;
  147. rc = put_guest_u16(vcpu, __LC_EXT_INT_CODE, 0x2603);
  148. if (rc == -EFAULT)
  149. exception = 1;
  150. rc = put_guest_u16(vcpu, __LC_CPU_ADDRESS, 0x0d00);
  151. if (rc == -EFAULT)
  152. exception = 1;
  153. rc = copy_to_guest(vcpu, __LC_EXT_OLD_PSW,
  154. &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
  155. if (rc == -EFAULT)
  156. exception = 1;
  157. rc = copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
  158. __LC_EXT_NEW_PSW, sizeof(psw_t));
  159. if (rc == -EFAULT)
  160. exception = 1;
  161. rc = put_guest_u32(vcpu, __LC_EXT_PARAMS, inti->ext.ext_params);
  162. if (rc == -EFAULT)
  163. exception = 1;
  164. rc = put_guest_u64(vcpu, __LC_PFAULT_INTPARM,
  165. inti->ext.ext_params2);
  166. if (rc == -EFAULT)
  167. exception = 1;
  168. break;
  169. case KVM_S390_SIGP_STOP:
  170. VCPU_EVENT(vcpu, 4, "%s", "interrupt: cpu stop");
  171. vcpu->stat.deliver_stop_signal++;
  172. __set_intercept_indicator(vcpu, inti);
  173. break;
  174. case KVM_S390_SIGP_SET_PREFIX:
  175. VCPU_EVENT(vcpu, 4, "interrupt: set prefix to %x",
  176. inti->prefix.address);
  177. vcpu->stat.deliver_prefix_signal++;
  178. vcpu->arch.sie_block->prefix = inti->prefix.address;
  179. vcpu->arch.sie_block->ihcpu = 0xffff;
  180. break;
  181. case KVM_S390_RESTART:
  182. VCPU_EVENT(vcpu, 4, "%s", "interrupt: cpu restart");
  183. vcpu->stat.deliver_restart_signal++;
  184. rc = copy_to_guest(vcpu, offsetof(struct _lowcore,
  185. restart_old_psw), &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
  186. if (rc == -EFAULT)
  187. exception = 1;
  188. rc = copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
  189. offsetof(struct _lowcore, restart_psw), sizeof(psw_t));
  190. if (rc == -EFAULT)
  191. exception = 1;
  192. break;
  193. case KVM_S390_PROGRAM_INT:
  194. VCPU_EVENT(vcpu, 4, "interrupt: pgm check code:%x, ilc:%x",
  195. inti->pgm.code,
  196. table[vcpu->arch.sie_block->ipa >> 14]);
  197. vcpu->stat.deliver_program_int++;
  198. rc = put_guest_u16(vcpu, __LC_PGM_INT_CODE, inti->pgm.code);
  199. if (rc == -EFAULT)
  200. exception = 1;
  201. rc = put_guest_u16(vcpu, __LC_PGM_ILC,
  202. table[vcpu->arch.sie_block->ipa >> 14]);
  203. if (rc == -EFAULT)
  204. exception = 1;
  205. rc = copy_to_guest(vcpu, __LC_PGM_OLD_PSW,
  206. &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
  207. if (rc == -EFAULT)
  208. exception = 1;
  209. rc = copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
  210. __LC_PGM_NEW_PSW, sizeof(psw_t));
  211. if (rc == -EFAULT)
  212. exception = 1;
  213. break;
  214. default:
  215. BUG();
  216. }
  217. if (exception) {
  218. VCPU_EVENT(vcpu, 1, "%s", "program exception while delivering"
  219. " interrupt");
  220. kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
  221. if (inti->type == KVM_S390_PROGRAM_INT) {
  222. printk(KERN_WARNING "kvm: recursive program check\n");
  223. BUG();
  224. }
  225. }
  226. }
  227. static int __try_deliver_ckc_interrupt(struct kvm_vcpu *vcpu)
  228. {
  229. int rc, exception = 0;
  230. if (psw_extint_disabled(vcpu))
  231. return 0;
  232. if (!(vcpu->arch.sie_block->gcr[0] & 0x800ul))
  233. return 0;
  234. rc = put_guest_u16(vcpu, __LC_EXT_INT_CODE, 0x1004);
  235. if (rc == -EFAULT)
  236. exception = 1;
  237. rc = copy_to_guest(vcpu, __LC_EXT_OLD_PSW,
  238. &vcpu->arch.sie_block->gpsw, sizeof(psw_t));
  239. if (rc == -EFAULT)
  240. exception = 1;
  241. rc = copy_from_guest(vcpu, &vcpu->arch.sie_block->gpsw,
  242. __LC_EXT_NEW_PSW, sizeof(psw_t));
  243. if (rc == -EFAULT)
  244. exception = 1;
  245. if (exception) {
  246. VCPU_EVENT(vcpu, 1, "%s", "program exception while delivering" \
  247. " ckc interrupt");
  248. kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
  249. return 0;
  250. }
  251. return 1;
  252. }
  253. int kvm_cpu_has_interrupt(struct kvm_vcpu *vcpu)
  254. {
  255. struct local_interrupt *li = &vcpu->arch.local_int;
  256. struct float_interrupt *fi = vcpu->arch.local_int.float_int;
  257. struct interrupt_info *inti;
  258. int rc = 0;
  259. if (atomic_read(&li->active)) {
  260. spin_lock_bh(&li->lock);
  261. list_for_each_entry(inti, &li->list, list)
  262. if (__interrupt_is_deliverable(vcpu, inti)) {
  263. rc = 1;
  264. break;
  265. }
  266. spin_unlock_bh(&li->lock);
  267. }
  268. if ((!rc) && atomic_read(&fi->active)) {
  269. spin_lock_bh(&fi->lock);
  270. list_for_each_entry(inti, &fi->list, list)
  271. if (__interrupt_is_deliverable(vcpu, inti)) {
  272. rc = 1;
  273. break;
  274. }
  275. spin_unlock_bh(&fi->lock);
  276. }
  277. if ((!rc) && (vcpu->arch.sie_block->ckc <
  278. get_clock() + vcpu->arch.sie_block->epoch)) {
  279. if ((!psw_extint_disabled(vcpu)) &&
  280. (vcpu->arch.sie_block->gcr[0] & 0x800ul))
  281. rc = 1;
  282. }
  283. return rc;
  284. }
  285. int kvm_s390_handle_wait(struct kvm_vcpu *vcpu)
  286. {
  287. u64 now, sltime;
  288. DECLARE_WAITQUEUE(wait, current);
  289. vcpu->stat.exit_wait_state++;
  290. if (kvm_cpu_has_interrupt(vcpu))
  291. return 0;
  292. if (psw_interrupts_disabled(vcpu)) {
  293. VCPU_EVENT(vcpu, 3, "%s", "disabled wait");
  294. __unset_cpu_idle(vcpu);
  295. return -ENOTSUPP; /* disabled wait */
  296. }
  297. if (psw_extint_disabled(vcpu) ||
  298. (!(vcpu->arch.sie_block->gcr[0] & 0x800ul))) {
  299. VCPU_EVENT(vcpu, 3, "%s", "enabled wait w/o timer");
  300. goto no_timer;
  301. }
  302. now = get_clock() + vcpu->arch.sie_block->epoch;
  303. if (vcpu->arch.sie_block->ckc < now) {
  304. __unset_cpu_idle(vcpu);
  305. return 0;
  306. }
  307. sltime = (vcpu->arch.sie_block->ckc - now) / (0xf4240000ul / HZ) + 1;
  308. vcpu->arch.ckc_timer.expires = jiffies + sltime;
  309. add_timer(&vcpu->arch.ckc_timer);
  310. VCPU_EVENT(vcpu, 5, "enabled wait timer:%lx jiffies", sltime);
  311. no_timer:
  312. spin_lock_bh(&vcpu->arch.local_int.float_int->lock);
  313. spin_lock_bh(&vcpu->arch.local_int.lock);
  314. __set_cpu_idle(vcpu);
  315. vcpu->arch.local_int.timer_due = 0;
  316. add_wait_queue(&vcpu->arch.local_int.wq, &wait);
  317. while (list_empty(&vcpu->arch.local_int.list) &&
  318. list_empty(&vcpu->arch.local_int.float_int->list) &&
  319. (!vcpu->arch.local_int.timer_due) &&
  320. !signal_pending(current)) {
  321. set_current_state(TASK_INTERRUPTIBLE);
  322. spin_unlock_bh(&vcpu->arch.local_int.lock);
  323. spin_unlock_bh(&vcpu->arch.local_int.float_int->lock);
  324. vcpu_put(vcpu);
  325. schedule();
  326. vcpu_load(vcpu);
  327. spin_lock_bh(&vcpu->arch.local_int.float_int->lock);
  328. spin_lock_bh(&vcpu->arch.local_int.lock);
  329. }
  330. __unset_cpu_idle(vcpu);
  331. __set_current_state(TASK_RUNNING);
  332. remove_wait_queue(&vcpu->wq, &wait);
  333. spin_unlock_bh(&vcpu->arch.local_int.lock);
  334. spin_unlock_bh(&vcpu->arch.local_int.float_int->lock);
  335. del_timer(&vcpu->arch.ckc_timer);
  336. return 0;
  337. }
  338. void kvm_s390_idle_wakeup(unsigned long data)
  339. {
  340. struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data;
  341. spin_lock_bh(&vcpu->arch.local_int.lock);
  342. vcpu->arch.local_int.timer_due = 1;
  343. if (waitqueue_active(&vcpu->arch.local_int.wq))
  344. wake_up_interruptible(&vcpu->arch.local_int.wq);
  345. spin_unlock_bh(&vcpu->arch.local_int.lock);
  346. }
  347. void kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu)
  348. {
  349. struct local_interrupt *li = &vcpu->arch.local_int;
  350. struct float_interrupt *fi = vcpu->arch.local_int.float_int;
  351. struct interrupt_info *n, *inti = NULL;
  352. int deliver;
  353. __reset_intercept_indicators(vcpu);
  354. if (atomic_read(&li->active)) {
  355. do {
  356. deliver = 0;
  357. spin_lock_bh(&li->lock);
  358. list_for_each_entry_safe(inti, n, &li->list, list) {
  359. if (__interrupt_is_deliverable(vcpu, inti)) {
  360. list_del(&inti->list);
  361. deliver = 1;
  362. break;
  363. }
  364. __set_intercept_indicator(vcpu, inti);
  365. }
  366. if (list_empty(&li->list))
  367. atomic_set(&li->active, 0);
  368. spin_unlock_bh(&li->lock);
  369. if (deliver) {
  370. __do_deliver_interrupt(vcpu, inti);
  371. kfree(inti);
  372. }
  373. } while (deliver);
  374. }
  375. if ((vcpu->arch.sie_block->ckc <
  376. get_clock() + vcpu->arch.sie_block->epoch))
  377. __try_deliver_ckc_interrupt(vcpu);
  378. if (atomic_read(&fi->active)) {
  379. do {
  380. deliver = 0;
  381. spin_lock_bh(&fi->lock);
  382. list_for_each_entry_safe(inti, n, &fi->list, list) {
  383. if (__interrupt_is_deliverable(vcpu, inti)) {
  384. list_del(&inti->list);
  385. deliver = 1;
  386. break;
  387. }
  388. __set_intercept_indicator(vcpu, inti);
  389. }
  390. if (list_empty(&fi->list))
  391. atomic_set(&fi->active, 0);
  392. spin_unlock_bh(&fi->lock);
  393. if (deliver) {
  394. __do_deliver_interrupt(vcpu, inti);
  395. kfree(inti);
  396. }
  397. } while (deliver);
  398. }
  399. }
  400. int kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code)
  401. {
  402. struct local_interrupt *li = &vcpu->arch.local_int;
  403. struct interrupt_info *inti;
  404. inti = kzalloc(sizeof(*inti), GFP_KERNEL);
  405. if (!inti)
  406. return -ENOMEM;
  407. inti->type = KVM_S390_PROGRAM_INT;;
  408. inti->pgm.code = code;
  409. VCPU_EVENT(vcpu, 3, "inject: program check %d (from kernel)", code);
  410. spin_lock_bh(&li->lock);
  411. list_add(&inti->list, &li->list);
  412. atomic_set(&li->active, 1);
  413. BUG_ON(waitqueue_active(&li->wq));
  414. spin_unlock_bh(&li->lock);
  415. return 0;
  416. }
  417. int kvm_s390_inject_vm(struct kvm *kvm,
  418. struct kvm_s390_interrupt *s390int)
  419. {
  420. struct local_interrupt *li;
  421. struct float_interrupt *fi;
  422. struct interrupt_info *inti;
  423. int sigcpu;
  424. inti = kzalloc(sizeof(*inti), GFP_KERNEL);
  425. if (!inti)
  426. return -ENOMEM;
  427. switch (s390int->type) {
  428. case KVM_S390_INT_VIRTIO:
  429. VM_EVENT(kvm, 5, "inject: virtio parm:%x,parm64:%lx",
  430. s390int->parm, s390int->parm64);
  431. inti->type = s390int->type;
  432. inti->ext.ext_params = s390int->parm;
  433. inti->ext.ext_params2 = s390int->parm64;
  434. break;
  435. case KVM_S390_INT_SERVICE:
  436. VM_EVENT(kvm, 5, "inject: sclp parm:%x", s390int->parm);
  437. inti->type = s390int->type;
  438. inti->ext.ext_params = s390int->parm;
  439. break;
  440. case KVM_S390_PROGRAM_INT:
  441. case KVM_S390_SIGP_STOP:
  442. case KVM_S390_INT_EMERGENCY:
  443. default:
  444. kfree(inti);
  445. return -EINVAL;
  446. }
  447. mutex_lock(&kvm->lock);
  448. fi = &kvm->arch.float_int;
  449. spin_lock_bh(&fi->lock);
  450. list_add_tail(&inti->list, &fi->list);
  451. atomic_set(&fi->active, 1);
  452. sigcpu = find_first_bit(fi->idle_mask, KVM_MAX_VCPUS);
  453. if (sigcpu == KVM_MAX_VCPUS) {
  454. do {
  455. sigcpu = fi->next_rr_cpu++;
  456. if (sigcpu == KVM_MAX_VCPUS)
  457. sigcpu = fi->next_rr_cpu = 0;
  458. } while (fi->local_int[sigcpu] == NULL);
  459. }
  460. li = fi->local_int[sigcpu];
  461. spin_lock_bh(&li->lock);
  462. atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags);
  463. if (waitqueue_active(&li->wq))
  464. wake_up_interruptible(&li->wq);
  465. spin_unlock_bh(&li->lock);
  466. spin_unlock_bh(&fi->lock);
  467. mutex_unlock(&kvm->lock);
  468. return 0;
  469. }
  470. int kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu,
  471. struct kvm_s390_interrupt *s390int)
  472. {
  473. struct local_interrupt *li;
  474. struct interrupt_info *inti;
  475. inti = kzalloc(sizeof(*inti), GFP_KERNEL);
  476. if (!inti)
  477. return -ENOMEM;
  478. switch (s390int->type) {
  479. case KVM_S390_PROGRAM_INT:
  480. if (s390int->parm & 0xffff0000) {
  481. kfree(inti);
  482. return -EINVAL;
  483. }
  484. inti->type = s390int->type;
  485. inti->pgm.code = s390int->parm;
  486. VCPU_EVENT(vcpu, 3, "inject: program check %d (from user)",
  487. s390int->parm);
  488. break;
  489. case KVM_S390_SIGP_STOP:
  490. case KVM_S390_RESTART:
  491. case KVM_S390_SIGP_SET_PREFIX:
  492. case KVM_S390_INT_EMERGENCY:
  493. VCPU_EVENT(vcpu, 3, "inject: type %x", s390int->type);
  494. inti->type = s390int->type;
  495. break;
  496. case KVM_S390_INT_VIRTIO:
  497. case KVM_S390_INT_SERVICE:
  498. default:
  499. kfree(inti);
  500. return -EINVAL;
  501. }
  502. mutex_lock(&vcpu->kvm->lock);
  503. li = &vcpu->arch.local_int;
  504. spin_lock_bh(&li->lock);
  505. if (inti->type == KVM_S390_PROGRAM_INT)
  506. list_add(&inti->list, &li->list);
  507. else
  508. list_add_tail(&inti->list, &li->list);
  509. atomic_set(&li->active, 1);
  510. if (inti->type == KVM_S390_SIGP_STOP)
  511. li->action_bits |= ACTION_STOP_ON_STOP;
  512. atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags);
  513. if (waitqueue_active(&li->wq))
  514. wake_up_interruptible(&vcpu->arch.local_int.wq);
  515. spin_unlock_bh(&li->lock);
  516. mutex_unlock(&vcpu->kvm->lock);
  517. return 0;
  518. }