interrupt.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  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_cpu_has_pending_timer(struct kvm_vcpu *vcpu)
  286. {
  287. return 0;
  288. }
  289. int kvm_s390_handle_wait(struct kvm_vcpu *vcpu)
  290. {
  291. u64 now, sltime;
  292. DECLARE_WAITQUEUE(wait, current);
  293. vcpu->stat.exit_wait_state++;
  294. if (kvm_cpu_has_interrupt(vcpu))
  295. return 0;
  296. if (psw_interrupts_disabled(vcpu)) {
  297. VCPU_EVENT(vcpu, 3, "%s", "disabled wait");
  298. __unset_cpu_idle(vcpu);
  299. return -ENOTSUPP; /* disabled wait */
  300. }
  301. if (psw_extint_disabled(vcpu) ||
  302. (!(vcpu->arch.sie_block->gcr[0] & 0x800ul))) {
  303. VCPU_EVENT(vcpu, 3, "%s", "enabled wait w/o timer");
  304. goto no_timer;
  305. }
  306. now = get_clock() + vcpu->arch.sie_block->epoch;
  307. if (vcpu->arch.sie_block->ckc < now) {
  308. __unset_cpu_idle(vcpu);
  309. return 0;
  310. }
  311. sltime = (vcpu->arch.sie_block->ckc - now) / (0xf4240000ul / HZ) + 1;
  312. vcpu->arch.ckc_timer.expires = jiffies + sltime;
  313. add_timer(&vcpu->arch.ckc_timer);
  314. VCPU_EVENT(vcpu, 5, "enabled wait timer:%lx jiffies", sltime);
  315. no_timer:
  316. spin_lock_bh(&vcpu->arch.local_int.float_int->lock);
  317. spin_lock_bh(&vcpu->arch.local_int.lock);
  318. __set_cpu_idle(vcpu);
  319. vcpu->arch.local_int.timer_due = 0;
  320. add_wait_queue(&vcpu->arch.local_int.wq, &wait);
  321. while (list_empty(&vcpu->arch.local_int.list) &&
  322. list_empty(&vcpu->arch.local_int.float_int->list) &&
  323. (!vcpu->arch.local_int.timer_due) &&
  324. !signal_pending(current)) {
  325. set_current_state(TASK_INTERRUPTIBLE);
  326. spin_unlock_bh(&vcpu->arch.local_int.lock);
  327. spin_unlock_bh(&vcpu->arch.local_int.float_int->lock);
  328. vcpu_put(vcpu);
  329. schedule();
  330. vcpu_load(vcpu);
  331. spin_lock_bh(&vcpu->arch.local_int.float_int->lock);
  332. spin_lock_bh(&vcpu->arch.local_int.lock);
  333. }
  334. __unset_cpu_idle(vcpu);
  335. __set_current_state(TASK_RUNNING);
  336. remove_wait_queue(&vcpu->wq, &wait);
  337. spin_unlock_bh(&vcpu->arch.local_int.lock);
  338. spin_unlock_bh(&vcpu->arch.local_int.float_int->lock);
  339. del_timer(&vcpu->arch.ckc_timer);
  340. return 0;
  341. }
  342. void kvm_s390_idle_wakeup(unsigned long data)
  343. {
  344. struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data;
  345. spin_lock_bh(&vcpu->arch.local_int.lock);
  346. vcpu->arch.local_int.timer_due = 1;
  347. if (waitqueue_active(&vcpu->arch.local_int.wq))
  348. wake_up_interruptible(&vcpu->arch.local_int.wq);
  349. spin_unlock_bh(&vcpu->arch.local_int.lock);
  350. }
  351. void kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu)
  352. {
  353. struct local_interrupt *li = &vcpu->arch.local_int;
  354. struct float_interrupt *fi = vcpu->arch.local_int.float_int;
  355. struct interrupt_info *n, *inti = NULL;
  356. int deliver;
  357. __reset_intercept_indicators(vcpu);
  358. if (atomic_read(&li->active)) {
  359. do {
  360. deliver = 0;
  361. spin_lock_bh(&li->lock);
  362. list_for_each_entry_safe(inti, n, &li->list, list) {
  363. if (__interrupt_is_deliverable(vcpu, inti)) {
  364. list_del(&inti->list);
  365. deliver = 1;
  366. break;
  367. }
  368. __set_intercept_indicator(vcpu, inti);
  369. }
  370. if (list_empty(&li->list))
  371. atomic_set(&li->active, 0);
  372. spin_unlock_bh(&li->lock);
  373. if (deliver) {
  374. __do_deliver_interrupt(vcpu, inti);
  375. kfree(inti);
  376. }
  377. } while (deliver);
  378. }
  379. if ((vcpu->arch.sie_block->ckc <
  380. get_clock() + vcpu->arch.sie_block->epoch))
  381. __try_deliver_ckc_interrupt(vcpu);
  382. if (atomic_read(&fi->active)) {
  383. do {
  384. deliver = 0;
  385. spin_lock_bh(&fi->lock);
  386. list_for_each_entry_safe(inti, n, &fi->list, list) {
  387. if (__interrupt_is_deliverable(vcpu, inti)) {
  388. list_del(&inti->list);
  389. deliver = 1;
  390. break;
  391. }
  392. __set_intercept_indicator(vcpu, inti);
  393. }
  394. if (list_empty(&fi->list))
  395. atomic_set(&fi->active, 0);
  396. spin_unlock_bh(&fi->lock);
  397. if (deliver) {
  398. __do_deliver_interrupt(vcpu, inti);
  399. kfree(inti);
  400. }
  401. } while (deliver);
  402. }
  403. }
  404. int kvm_s390_inject_program_int(struct kvm_vcpu *vcpu, u16 code)
  405. {
  406. struct local_interrupt *li = &vcpu->arch.local_int;
  407. struct interrupt_info *inti;
  408. inti = kzalloc(sizeof(*inti), GFP_KERNEL);
  409. if (!inti)
  410. return -ENOMEM;
  411. inti->type = KVM_S390_PROGRAM_INT;;
  412. inti->pgm.code = code;
  413. VCPU_EVENT(vcpu, 3, "inject: program check %d (from kernel)", code);
  414. spin_lock_bh(&li->lock);
  415. list_add(&inti->list, &li->list);
  416. atomic_set(&li->active, 1);
  417. BUG_ON(waitqueue_active(&li->wq));
  418. spin_unlock_bh(&li->lock);
  419. return 0;
  420. }
  421. int kvm_s390_inject_vm(struct kvm *kvm,
  422. struct kvm_s390_interrupt *s390int)
  423. {
  424. struct local_interrupt *li;
  425. struct float_interrupt *fi;
  426. struct interrupt_info *inti;
  427. int sigcpu;
  428. inti = kzalloc(sizeof(*inti), GFP_KERNEL);
  429. if (!inti)
  430. return -ENOMEM;
  431. switch (s390int->type) {
  432. case KVM_S390_INT_VIRTIO:
  433. VM_EVENT(kvm, 5, "inject: virtio parm:%x,parm64:%lx",
  434. s390int->parm, s390int->parm64);
  435. inti->type = s390int->type;
  436. inti->ext.ext_params = s390int->parm;
  437. inti->ext.ext_params2 = s390int->parm64;
  438. break;
  439. case KVM_S390_INT_SERVICE:
  440. VM_EVENT(kvm, 5, "inject: sclp parm:%x", s390int->parm);
  441. inti->type = s390int->type;
  442. inti->ext.ext_params = s390int->parm;
  443. break;
  444. case KVM_S390_PROGRAM_INT:
  445. case KVM_S390_SIGP_STOP:
  446. case KVM_S390_INT_EMERGENCY:
  447. default:
  448. kfree(inti);
  449. return -EINVAL;
  450. }
  451. mutex_lock(&kvm->lock);
  452. fi = &kvm->arch.float_int;
  453. spin_lock_bh(&fi->lock);
  454. list_add_tail(&inti->list, &fi->list);
  455. atomic_set(&fi->active, 1);
  456. sigcpu = find_first_bit(fi->idle_mask, KVM_MAX_VCPUS);
  457. if (sigcpu == KVM_MAX_VCPUS) {
  458. do {
  459. sigcpu = fi->next_rr_cpu++;
  460. if (sigcpu == KVM_MAX_VCPUS)
  461. sigcpu = fi->next_rr_cpu = 0;
  462. } while (fi->local_int[sigcpu] == NULL);
  463. }
  464. li = fi->local_int[sigcpu];
  465. spin_lock_bh(&li->lock);
  466. atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags);
  467. if (waitqueue_active(&li->wq))
  468. wake_up_interruptible(&li->wq);
  469. spin_unlock_bh(&li->lock);
  470. spin_unlock_bh(&fi->lock);
  471. mutex_unlock(&kvm->lock);
  472. return 0;
  473. }
  474. int kvm_s390_inject_vcpu(struct kvm_vcpu *vcpu,
  475. struct kvm_s390_interrupt *s390int)
  476. {
  477. struct local_interrupt *li;
  478. struct interrupt_info *inti;
  479. inti = kzalloc(sizeof(*inti), GFP_KERNEL);
  480. if (!inti)
  481. return -ENOMEM;
  482. switch (s390int->type) {
  483. case KVM_S390_PROGRAM_INT:
  484. if (s390int->parm & 0xffff0000) {
  485. kfree(inti);
  486. return -EINVAL;
  487. }
  488. inti->type = s390int->type;
  489. inti->pgm.code = s390int->parm;
  490. VCPU_EVENT(vcpu, 3, "inject: program check %d (from user)",
  491. s390int->parm);
  492. break;
  493. case KVM_S390_SIGP_STOP:
  494. case KVM_S390_RESTART:
  495. case KVM_S390_SIGP_SET_PREFIX:
  496. case KVM_S390_INT_EMERGENCY:
  497. VCPU_EVENT(vcpu, 3, "inject: type %x", s390int->type);
  498. inti->type = s390int->type;
  499. break;
  500. case KVM_S390_INT_VIRTIO:
  501. case KVM_S390_INT_SERVICE:
  502. default:
  503. kfree(inti);
  504. return -EINVAL;
  505. }
  506. mutex_lock(&vcpu->kvm->lock);
  507. li = &vcpu->arch.local_int;
  508. spin_lock_bh(&li->lock);
  509. if (inti->type == KVM_S390_PROGRAM_INT)
  510. list_add(&inti->list, &li->list);
  511. else
  512. list_add_tail(&inti->list, &li->list);
  513. atomic_set(&li->active, 1);
  514. if (inti->type == KVM_S390_SIGP_STOP)
  515. li->action_bits |= ACTION_STOP_ON_STOP;
  516. atomic_set_mask(CPUSTAT_EXT_INT, li->cpuflags);
  517. if (waitqueue_active(&li->wq))
  518. wake_up_interruptible(&vcpu->arch.local_int.wq);
  519. spin_unlock_bh(&li->lock);
  520. mutex_unlock(&vcpu->kvm->lock);
  521. return 0;
  522. }