priv.c 16 KB

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