interrupt.c 15 KB

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