interrupt.c 15 KB

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