priv.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. /*
  2. * handling privileged instructions
  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. * Christian Borntraeger <borntraeger@de.ibm.com>
  12. */
  13. #include <linux/kvm.h>
  14. #include <linux/gfp.h>
  15. #include <linux/errno.h>
  16. #include <linux/compat.h>
  17. #include <asm/asm-offsets.h>
  18. #include <asm/current.h>
  19. #include <asm/debug.h>
  20. #include <asm/ebcdic.h>
  21. #include <asm/sysinfo.h>
  22. #include <asm/ptrace.h>
  23. #include <asm/compat.h>
  24. #include "gaccess.h"
  25. #include "kvm-s390.h"
  26. #include "trace.h"
  27. static int handle_set_prefix(struct kvm_vcpu *vcpu)
  28. {
  29. u64 operand2;
  30. u32 address = 0;
  31. u8 tmp;
  32. vcpu->stat.instruction_spx++;
  33. operand2 = kvm_s390_get_base_disp_s(vcpu);
  34. /* must be word boundary */
  35. if (operand2 & 3)
  36. return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
  37. /* get the value */
  38. if (get_guest(vcpu, address, (u32 __user *) operand2))
  39. return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
  40. address = address & 0x7fffe000u;
  41. /* make sure that the new value is valid memory */
  42. if (copy_from_guest_absolute(vcpu, &tmp, address, 1) ||
  43. (copy_from_guest_absolute(vcpu, &tmp, address + PAGE_SIZE, 1)))
  44. return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
  45. kvm_s390_set_prefix(vcpu, address);
  46. VCPU_EVENT(vcpu, 5, "setting prefix to %x", address);
  47. trace_kvm_s390_handle_prefix(vcpu, 1, address);
  48. return 0;
  49. }
  50. static int handle_store_prefix(struct kvm_vcpu *vcpu)
  51. {
  52. u64 operand2;
  53. u32 address;
  54. vcpu->stat.instruction_stpx++;
  55. operand2 = kvm_s390_get_base_disp_s(vcpu);
  56. /* must be word boundary */
  57. if (operand2 & 3)
  58. return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
  59. address = vcpu->arch.sie_block->prefix;
  60. address = address & 0x7fffe000u;
  61. /* get the value */
  62. if (put_guest(vcpu, address, (u32 __user *)operand2))
  63. return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
  64. VCPU_EVENT(vcpu, 5, "storing prefix to %x", address);
  65. trace_kvm_s390_handle_prefix(vcpu, 0, address);
  66. return 0;
  67. }
  68. static int handle_store_cpu_address(struct kvm_vcpu *vcpu)
  69. {
  70. u64 useraddr;
  71. vcpu->stat.instruction_stap++;
  72. useraddr = kvm_s390_get_base_disp_s(vcpu);
  73. if (useraddr & 1)
  74. return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
  75. if (put_guest(vcpu, vcpu->vcpu_id, (u16 __user *)useraddr))
  76. return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
  77. VCPU_EVENT(vcpu, 5, "storing cpu address to %llx", useraddr);
  78. trace_kvm_s390_handle_stap(vcpu, useraddr);
  79. return 0;
  80. }
  81. static int handle_skey(struct kvm_vcpu *vcpu)
  82. {
  83. vcpu->stat.instruction_storage_key++;
  84. vcpu->arch.sie_block->gpsw.addr -= 4;
  85. VCPU_EVENT(vcpu, 4, "%s", "retrying storage key operation");
  86. return 0;
  87. }
  88. static int handle_tpi(struct kvm_vcpu *vcpu)
  89. {
  90. struct kvm_s390_interrupt_info *inti;
  91. u64 addr;
  92. int cc;
  93. addr = kvm_s390_get_base_disp_s(vcpu);
  94. if (addr & 3)
  95. return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
  96. cc = 0;
  97. inti = kvm_s390_get_io_int(vcpu->kvm, vcpu->run->s.regs.crs[6], 0);
  98. if (!inti)
  99. goto no_interrupt;
  100. cc = 1;
  101. if (addr) {
  102. /*
  103. * Store the two-word I/O interruption code into the
  104. * provided area.
  105. */
  106. put_guest(vcpu, inti->io.subchannel_id, (u16 __user *) addr);
  107. put_guest(vcpu, inti->io.subchannel_nr, (u16 __user *) (addr + 2));
  108. put_guest(vcpu, inti->io.io_int_parm, (u32 __user *) (addr + 4));
  109. } else {
  110. /*
  111. * Store the three-word I/O interruption code into
  112. * the appropriate lowcore area.
  113. */
  114. put_guest(vcpu, inti->io.subchannel_id, (u16 __user *) __LC_SUBCHANNEL_ID);
  115. put_guest(vcpu, inti->io.subchannel_nr, (u16 __user *) __LC_SUBCHANNEL_NR);
  116. put_guest(vcpu, inti->io.io_int_parm, (u32 __user *) __LC_IO_INT_PARM);
  117. put_guest(vcpu, inti->io.io_int_word, (u32 __user *) __LC_IO_INT_WORD);
  118. }
  119. kfree(inti);
  120. no_interrupt:
  121. /* Set condition code and we're done. */
  122. vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44);
  123. vcpu->arch.sie_block->gpsw.mask |= (cc & 3ul) << 44;
  124. return 0;
  125. }
  126. static int handle_tsch(struct kvm_vcpu *vcpu)
  127. {
  128. struct kvm_s390_interrupt_info *inti;
  129. inti = kvm_s390_get_io_int(vcpu->kvm, 0,
  130. vcpu->run->s.regs.gprs[1]);
  131. /*
  132. * Prepare exit to userspace.
  133. * We indicate whether we dequeued a pending I/O interrupt
  134. * so that userspace can re-inject it if the instruction gets
  135. * a program check. While this may re-order the pending I/O
  136. * interrupts, this is no problem since the priority is kept
  137. * intact.
  138. */
  139. vcpu->run->exit_reason = KVM_EXIT_S390_TSCH;
  140. vcpu->run->s390_tsch.dequeued = !!inti;
  141. if (inti) {
  142. vcpu->run->s390_tsch.subchannel_id = inti->io.subchannel_id;
  143. vcpu->run->s390_tsch.subchannel_nr = inti->io.subchannel_nr;
  144. vcpu->run->s390_tsch.io_int_parm = inti->io.io_int_parm;
  145. vcpu->run->s390_tsch.io_int_word = inti->io.io_int_word;
  146. }
  147. vcpu->run->s390_tsch.ipb = vcpu->arch.sie_block->ipb;
  148. kfree(inti);
  149. return -EREMOTE;
  150. }
  151. static int handle_io_inst(struct kvm_vcpu *vcpu)
  152. {
  153. VCPU_EVENT(vcpu, 4, "%s", "I/O instruction");
  154. if (vcpu->kvm->arch.css_support) {
  155. /*
  156. * Most I/O instructions will be handled by userspace.
  157. * Exceptions are tpi and the interrupt portion of tsch.
  158. */
  159. if (vcpu->arch.sie_block->ipa == 0xb236)
  160. return handle_tpi(vcpu);
  161. if (vcpu->arch.sie_block->ipa == 0xb235)
  162. return handle_tsch(vcpu);
  163. /* Handle in userspace. */
  164. return -EOPNOTSUPP;
  165. } else {
  166. /*
  167. * Set condition code 3 to stop the guest from issueing channel
  168. * I/O instructions.
  169. */
  170. vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44);
  171. vcpu->arch.sie_block->gpsw.mask |= (3 & 3ul) << 44;
  172. return 0;
  173. }
  174. }
  175. static int handle_stfl(struct kvm_vcpu *vcpu)
  176. {
  177. unsigned int facility_list;
  178. int rc;
  179. vcpu->stat.instruction_stfl++;
  180. /* only pass the facility bits, which we can handle */
  181. facility_list = S390_lowcore.stfl_fac_list & 0xff00fff3;
  182. rc = copy_to_guest(vcpu, offsetof(struct _lowcore, stfl_fac_list),
  183. &facility_list, sizeof(facility_list));
  184. if (rc)
  185. return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
  186. VCPU_EVENT(vcpu, 5, "store facility list value %x", facility_list);
  187. trace_kvm_s390_handle_stfl(vcpu, facility_list);
  188. return 0;
  189. }
  190. static void handle_new_psw(struct kvm_vcpu *vcpu)
  191. {
  192. /* Check whether the new psw is enabled for machine checks. */
  193. if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_MCHECK)
  194. kvm_s390_deliver_pending_machine_checks(vcpu);
  195. }
  196. #define PSW_MASK_ADDR_MODE (PSW_MASK_EA | PSW_MASK_BA)
  197. #define PSW_MASK_UNASSIGNED 0xb80800fe7fffffffUL
  198. #define PSW_ADDR_24 0x0000000000ffffffUL
  199. #define PSW_ADDR_31 0x000000007fffffffUL
  200. static int is_valid_psw(psw_t *psw) {
  201. if (psw->mask & PSW_MASK_UNASSIGNED)
  202. return 0;
  203. if ((psw->mask & PSW_MASK_ADDR_MODE) == PSW_MASK_BA) {
  204. if (psw->addr & ~PSW_ADDR_31)
  205. return 0;
  206. }
  207. if (!(psw->mask & PSW_MASK_ADDR_MODE) && (psw->addr & ~PSW_ADDR_24))
  208. return 0;
  209. if ((psw->mask & PSW_MASK_ADDR_MODE) == PSW_MASK_EA)
  210. return 0;
  211. return 1;
  212. }
  213. int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu)
  214. {
  215. psw_t *gpsw = &vcpu->arch.sie_block->gpsw;
  216. psw_compat_t new_psw;
  217. u64 addr;
  218. if (gpsw->mask & PSW_MASK_PSTATE)
  219. return kvm_s390_inject_program_int(vcpu,
  220. PGM_PRIVILEGED_OPERATION);
  221. addr = kvm_s390_get_base_disp_s(vcpu);
  222. if (addr & 7)
  223. return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
  224. if (copy_from_guest(vcpu, &new_psw, addr, sizeof(new_psw)))
  225. return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
  226. if (!(new_psw.mask & PSW32_MASK_BASE))
  227. return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
  228. gpsw->mask = (new_psw.mask & ~PSW32_MASK_BASE) << 32;
  229. gpsw->mask |= new_psw.addr & PSW32_ADDR_AMODE;
  230. gpsw->addr = new_psw.addr & ~PSW32_ADDR_AMODE;
  231. if (!is_valid_psw(gpsw))
  232. return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
  233. handle_new_psw(vcpu);
  234. return 0;
  235. }
  236. static int handle_lpswe(struct kvm_vcpu *vcpu)
  237. {
  238. psw_t new_psw;
  239. u64 addr;
  240. addr = kvm_s390_get_base_disp_s(vcpu);
  241. if (addr & 7)
  242. return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
  243. if (copy_from_guest(vcpu, &new_psw, addr, sizeof(new_psw)))
  244. return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
  245. vcpu->arch.sie_block->gpsw = new_psw;
  246. if (!is_valid_psw(&vcpu->arch.sie_block->gpsw))
  247. return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
  248. handle_new_psw(vcpu);
  249. return 0;
  250. }
  251. static int handle_stidp(struct kvm_vcpu *vcpu)
  252. {
  253. u64 operand2;
  254. vcpu->stat.instruction_stidp++;
  255. operand2 = kvm_s390_get_base_disp_s(vcpu);
  256. if (operand2 & 7)
  257. return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
  258. if (put_guest(vcpu, vcpu->arch.stidp_data, (u64 __user *)operand2))
  259. return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
  260. VCPU_EVENT(vcpu, 5, "%s", "store cpu id");
  261. return 0;
  262. }
  263. static void handle_stsi_3_2_2(struct kvm_vcpu *vcpu, struct sysinfo_3_2_2 *mem)
  264. {
  265. struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int;
  266. int cpus = 0;
  267. int n;
  268. spin_lock(&fi->lock);
  269. for (n = 0; n < KVM_MAX_VCPUS; n++)
  270. if (fi->local_int[n])
  271. cpus++;
  272. spin_unlock(&fi->lock);
  273. /* deal with other level 3 hypervisors */
  274. if (stsi(mem, 3, 2, 2))
  275. mem->count = 0;
  276. if (mem->count < 8)
  277. mem->count++;
  278. for (n = mem->count - 1; n > 0 ; n--)
  279. memcpy(&mem->vm[n], &mem->vm[n - 1], sizeof(mem->vm[0]));
  280. mem->vm[0].cpus_total = cpus;
  281. mem->vm[0].cpus_configured = cpus;
  282. mem->vm[0].cpus_standby = 0;
  283. mem->vm[0].cpus_reserved = 0;
  284. mem->vm[0].caf = 1000;
  285. memcpy(mem->vm[0].name, "KVMguest", 8);
  286. ASCEBC(mem->vm[0].name, 8);
  287. memcpy(mem->vm[0].cpi, "KVM/Linux ", 16);
  288. ASCEBC(mem->vm[0].cpi, 16);
  289. }
  290. static int handle_stsi(struct kvm_vcpu *vcpu)
  291. {
  292. int fc = (vcpu->run->s.regs.gprs[0] & 0xf0000000) >> 28;
  293. int sel1 = vcpu->run->s.regs.gprs[0] & 0xff;
  294. int sel2 = vcpu->run->s.regs.gprs[1] & 0xffff;
  295. unsigned long mem = 0;
  296. u64 operand2;
  297. int rc = 0;
  298. vcpu->stat.instruction_stsi++;
  299. VCPU_EVENT(vcpu, 4, "stsi: fc: %x sel1: %x sel2: %x", fc, sel1, sel2);
  300. operand2 = kvm_s390_get_base_disp_s(vcpu);
  301. if (operand2 & 0xfff && fc > 0)
  302. return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
  303. switch (fc) {
  304. case 0:
  305. vcpu->run->s.regs.gprs[0] = 3 << 28;
  306. vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44);
  307. return 0;
  308. case 1: /* same handling for 1 and 2 */
  309. case 2:
  310. mem = get_zeroed_page(GFP_KERNEL);
  311. if (!mem)
  312. goto out_no_data;
  313. if (stsi((void *) mem, fc, sel1, sel2))
  314. goto out_no_data;
  315. break;
  316. case 3:
  317. if (sel1 != 2 || sel2 != 2)
  318. goto out_no_data;
  319. mem = get_zeroed_page(GFP_KERNEL);
  320. if (!mem)
  321. goto out_no_data;
  322. handle_stsi_3_2_2(vcpu, (void *) mem);
  323. break;
  324. default:
  325. goto out_no_data;
  326. }
  327. if (copy_to_guest_absolute(vcpu, operand2, (void *) mem, PAGE_SIZE)) {
  328. rc = kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
  329. goto out_exception;
  330. }
  331. trace_kvm_s390_handle_stsi(vcpu, fc, sel1, sel2, operand2);
  332. free_page(mem);
  333. vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44);
  334. vcpu->run->s.regs.gprs[0] = 0;
  335. return 0;
  336. out_no_data:
  337. /* condition code 3 */
  338. vcpu->arch.sie_block->gpsw.mask |= 3ul << 44;
  339. out_exception:
  340. free_page(mem);
  341. return rc;
  342. }
  343. static const intercept_handler_t b2_handlers[256] = {
  344. [0x02] = handle_stidp,
  345. [0x10] = handle_set_prefix,
  346. [0x11] = handle_store_prefix,
  347. [0x12] = handle_store_cpu_address,
  348. [0x29] = handle_skey,
  349. [0x2a] = handle_skey,
  350. [0x2b] = handle_skey,
  351. [0x30] = handle_io_inst,
  352. [0x31] = handle_io_inst,
  353. [0x32] = handle_io_inst,
  354. [0x33] = handle_io_inst,
  355. [0x34] = handle_io_inst,
  356. [0x35] = handle_io_inst,
  357. [0x36] = handle_io_inst,
  358. [0x37] = handle_io_inst,
  359. [0x38] = handle_io_inst,
  360. [0x39] = handle_io_inst,
  361. [0x3a] = handle_io_inst,
  362. [0x3b] = handle_io_inst,
  363. [0x3c] = handle_io_inst,
  364. [0x5f] = handle_io_inst,
  365. [0x74] = handle_io_inst,
  366. [0x76] = handle_io_inst,
  367. [0x7d] = handle_stsi,
  368. [0xb1] = handle_stfl,
  369. [0xb2] = handle_lpswe,
  370. };
  371. int kvm_s390_handle_b2(struct kvm_vcpu *vcpu)
  372. {
  373. intercept_handler_t handler;
  374. /*
  375. * a lot of B2 instructions are priviledged. We first check for
  376. * the privileged ones, that we can handle in the kernel. If the
  377. * kernel can handle this instruction, we check for the problem
  378. * state bit and (a) handle the instruction or (b) send a code 2
  379. * program check.
  380. * Anything else goes to userspace.*/
  381. handler = b2_handlers[vcpu->arch.sie_block->ipa & 0x00ff];
  382. if (handler) {
  383. if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
  384. return kvm_s390_inject_program_int(vcpu,
  385. PGM_PRIVILEGED_OPERATION);
  386. else
  387. return handler(vcpu);
  388. }
  389. return -EOPNOTSUPP;
  390. }
  391. static int handle_epsw(struct kvm_vcpu *vcpu)
  392. {
  393. int reg1, reg2;
  394. reg1 = (vcpu->arch.sie_block->ipb & 0x00f00000) >> 24;
  395. reg2 = (vcpu->arch.sie_block->ipb & 0x000f0000) >> 16;
  396. /* This basically extracts the mask half of the psw. */
  397. vcpu->run->s.regs.gprs[reg1] &= 0xffffffff00000000;
  398. vcpu->run->s.regs.gprs[reg1] |= vcpu->arch.sie_block->gpsw.mask >> 32;
  399. if (reg2) {
  400. vcpu->run->s.regs.gprs[reg2] &= 0xffffffff00000000;
  401. vcpu->run->s.regs.gprs[reg2] |=
  402. vcpu->arch.sie_block->gpsw.mask & 0x00000000ffffffff;
  403. }
  404. return 0;
  405. }
  406. static const intercept_handler_t b9_handlers[256] = {
  407. [0x8d] = handle_epsw,
  408. [0x9c] = handle_io_inst,
  409. };
  410. int kvm_s390_handle_b9(struct kvm_vcpu *vcpu)
  411. {
  412. intercept_handler_t handler;
  413. /* This is handled just as for the B2 instructions. */
  414. handler = b9_handlers[vcpu->arch.sie_block->ipa & 0x00ff];
  415. if (handler) {
  416. if ((handler != handle_epsw) &&
  417. (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE))
  418. return kvm_s390_inject_program_int(vcpu,
  419. PGM_PRIVILEGED_OPERATION);
  420. else
  421. return handler(vcpu);
  422. }
  423. return -EOPNOTSUPP;
  424. }
  425. static const intercept_handler_t eb_handlers[256] = {
  426. [0x8a] = handle_io_inst,
  427. };
  428. int kvm_s390_handle_priv_eb(struct kvm_vcpu *vcpu)
  429. {
  430. intercept_handler_t handler;
  431. /* All eb instructions that end up here are privileged. */
  432. if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
  433. return kvm_s390_inject_program_int(vcpu,
  434. PGM_PRIVILEGED_OPERATION);
  435. handler = eb_handlers[vcpu->arch.sie_block->ipb & 0xff];
  436. if (handler)
  437. return handler(vcpu);
  438. return -EOPNOTSUPP;
  439. }
  440. static int handle_tprot(struct kvm_vcpu *vcpu)
  441. {
  442. u64 address1, address2;
  443. struct vm_area_struct *vma;
  444. unsigned long user_address;
  445. vcpu->stat.instruction_tprot++;
  446. kvm_s390_get_base_disp_sse(vcpu, &address1, &address2);
  447. /* we only handle the Linux memory detection case:
  448. * access key == 0
  449. * guest DAT == off
  450. * everything else goes to userspace. */
  451. if (address2 & 0xf0)
  452. return -EOPNOTSUPP;
  453. if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_DAT)
  454. return -EOPNOTSUPP;
  455. down_read(&current->mm->mmap_sem);
  456. user_address = __gmap_translate(address1, vcpu->arch.gmap);
  457. if (IS_ERR_VALUE(user_address))
  458. goto out_inject;
  459. vma = find_vma(current->mm, user_address);
  460. if (!vma)
  461. goto out_inject;
  462. vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44);
  463. if (!(vma->vm_flags & VM_WRITE) && (vma->vm_flags & VM_READ))
  464. vcpu->arch.sie_block->gpsw.mask |= (1ul << 44);
  465. if (!(vma->vm_flags & VM_WRITE) && !(vma->vm_flags & VM_READ))
  466. vcpu->arch.sie_block->gpsw.mask |= (2ul << 44);
  467. up_read(&current->mm->mmap_sem);
  468. return 0;
  469. out_inject:
  470. up_read(&current->mm->mmap_sem);
  471. return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
  472. }
  473. int kvm_s390_handle_e5(struct kvm_vcpu *vcpu)
  474. {
  475. /* For e5xx... instructions we only handle TPROT */
  476. if ((vcpu->arch.sie_block->ipa & 0x00ff) == 0x01)
  477. return handle_tprot(vcpu);
  478. return -EOPNOTSUPP;
  479. }
  480. static int handle_sckpf(struct kvm_vcpu *vcpu)
  481. {
  482. u32 value;
  483. if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
  484. return kvm_s390_inject_program_int(vcpu,
  485. PGM_PRIVILEGED_OPERATION);
  486. if (vcpu->run->s.regs.gprs[0] & 0x00000000ffff0000)
  487. return kvm_s390_inject_program_int(vcpu,
  488. PGM_SPECIFICATION);
  489. value = vcpu->run->s.regs.gprs[0] & 0x000000000000ffff;
  490. vcpu->arch.sie_block->todpr = value;
  491. return 0;
  492. }
  493. static const intercept_handler_t x01_handlers[256] = {
  494. [0x07] = handle_sckpf,
  495. };
  496. int kvm_s390_handle_01(struct kvm_vcpu *vcpu)
  497. {
  498. intercept_handler_t handler;
  499. handler = x01_handlers[vcpu->arch.sie_block->ipa & 0x00ff];
  500. if (handler)
  501. return handler(vcpu);
  502. return -EOPNOTSUPP;
  503. }