priv.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  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. int kvm_s390_handle_lpsw(struct kvm_vcpu *vcpu)
  225. {
  226. u64 addr;
  227. psw_compat_t new_psw;
  228. if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
  229. return kvm_s390_inject_program_int(vcpu,
  230. PGM_PRIVILEGED_OPERATION);
  231. addr = kvm_s390_get_base_disp_s(vcpu);
  232. if (addr & 7)
  233. return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
  234. if (copy_from_guest(vcpu, &new_psw, addr, sizeof(new_psw)))
  235. return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
  236. if (!(new_psw.mask & PSW32_MASK_BASE))
  237. return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
  238. vcpu->arch.sie_block->gpsw.mask =
  239. (new_psw.mask & ~PSW32_MASK_BASE) << 32;
  240. vcpu->arch.sie_block->gpsw.mask |= new_psw.addr & PSW32_ADDR_AMODE;
  241. vcpu->arch.sie_block->gpsw.addr = new_psw.addr & ~PSW32_ADDR_AMODE;
  242. if ((vcpu->arch.sie_block->gpsw.mask & PSW_MASK_UNASSIGNED) ||
  243. (!(vcpu->arch.sie_block->gpsw.mask & PSW_MASK_ADDR_MODE) &&
  244. (vcpu->arch.sie_block->gpsw.addr & ~PSW_ADDR_24)) ||
  245. ((vcpu->arch.sie_block->gpsw.mask & PSW_MASK_ADDR_MODE) ==
  246. PSW_MASK_EA))
  247. return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
  248. handle_new_psw(vcpu);
  249. return 0;
  250. }
  251. static int handle_lpswe(struct kvm_vcpu *vcpu)
  252. {
  253. u64 addr;
  254. psw_t new_psw;
  255. addr = kvm_s390_get_base_disp_s(vcpu);
  256. if (addr & 7)
  257. return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
  258. if (copy_from_guest(vcpu, &new_psw, addr, sizeof(new_psw)))
  259. return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
  260. vcpu->arch.sie_block->gpsw.mask = new_psw.mask;
  261. vcpu->arch.sie_block->gpsw.addr = new_psw.addr;
  262. if ((vcpu->arch.sie_block->gpsw.mask & PSW_MASK_UNASSIGNED) ||
  263. (((vcpu->arch.sie_block->gpsw.mask & PSW_MASK_ADDR_MODE) ==
  264. PSW_MASK_BA) &&
  265. (vcpu->arch.sie_block->gpsw.addr & ~PSW_ADDR_31)) ||
  266. (!(vcpu->arch.sie_block->gpsw.mask & PSW_MASK_ADDR_MODE) &&
  267. (vcpu->arch.sie_block->gpsw.addr & ~PSW_ADDR_24)) ||
  268. ((vcpu->arch.sie_block->gpsw.mask & PSW_MASK_ADDR_MODE) ==
  269. PSW_MASK_EA))
  270. return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
  271. handle_new_psw(vcpu);
  272. return 0;
  273. }
  274. static int handle_stidp(struct kvm_vcpu *vcpu)
  275. {
  276. u64 operand2;
  277. int rc;
  278. vcpu->stat.instruction_stidp++;
  279. operand2 = kvm_s390_get_base_disp_s(vcpu);
  280. if (operand2 & 7) {
  281. kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
  282. goto out;
  283. }
  284. rc = put_guest(vcpu, vcpu->arch.stidp_data, (u64 __user *)operand2);
  285. if (rc) {
  286. kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
  287. goto out;
  288. }
  289. VCPU_EVENT(vcpu, 5, "%s", "store cpu id");
  290. out:
  291. return 0;
  292. }
  293. static void handle_stsi_3_2_2(struct kvm_vcpu *vcpu, struct sysinfo_3_2_2 *mem)
  294. {
  295. struct kvm_s390_float_interrupt *fi = &vcpu->kvm->arch.float_int;
  296. int cpus = 0;
  297. int n;
  298. spin_lock(&fi->lock);
  299. for (n = 0; n < KVM_MAX_VCPUS; n++)
  300. if (fi->local_int[n])
  301. cpus++;
  302. spin_unlock(&fi->lock);
  303. /* deal with other level 3 hypervisors */
  304. if (stsi(mem, 3, 2, 2))
  305. mem->count = 0;
  306. if (mem->count < 8)
  307. mem->count++;
  308. for (n = mem->count - 1; n > 0 ; n--)
  309. memcpy(&mem->vm[n], &mem->vm[n - 1], sizeof(mem->vm[0]));
  310. mem->vm[0].cpus_total = cpus;
  311. mem->vm[0].cpus_configured = cpus;
  312. mem->vm[0].cpus_standby = 0;
  313. mem->vm[0].cpus_reserved = 0;
  314. mem->vm[0].caf = 1000;
  315. memcpy(mem->vm[0].name, "KVMguest", 8);
  316. ASCEBC(mem->vm[0].name, 8);
  317. memcpy(mem->vm[0].cpi, "KVM/Linux ", 16);
  318. ASCEBC(mem->vm[0].cpi, 16);
  319. }
  320. static int handle_stsi(struct kvm_vcpu *vcpu)
  321. {
  322. int fc = (vcpu->run->s.regs.gprs[0] & 0xf0000000) >> 28;
  323. int sel1 = vcpu->run->s.regs.gprs[0] & 0xff;
  324. int sel2 = vcpu->run->s.regs.gprs[1] & 0xffff;
  325. u64 operand2;
  326. unsigned long mem;
  327. vcpu->stat.instruction_stsi++;
  328. VCPU_EVENT(vcpu, 4, "stsi: fc: %x sel1: %x sel2: %x", fc, sel1, sel2);
  329. operand2 = kvm_s390_get_base_disp_s(vcpu);
  330. if (operand2 & 0xfff && fc > 0)
  331. return kvm_s390_inject_program_int(vcpu, PGM_SPECIFICATION);
  332. switch (fc) {
  333. case 0:
  334. vcpu->run->s.regs.gprs[0] = 3 << 28;
  335. vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44);
  336. return 0;
  337. case 1: /* same handling for 1 and 2 */
  338. case 2:
  339. mem = get_zeroed_page(GFP_KERNEL);
  340. if (!mem)
  341. goto out_fail;
  342. if (stsi((void *) mem, fc, sel1, sel2))
  343. goto out_mem;
  344. break;
  345. case 3:
  346. if (sel1 != 2 || sel2 != 2)
  347. goto out_fail;
  348. mem = get_zeroed_page(GFP_KERNEL);
  349. if (!mem)
  350. goto out_fail;
  351. handle_stsi_3_2_2(vcpu, (void *) mem);
  352. break;
  353. default:
  354. goto out_fail;
  355. }
  356. if (copy_to_guest_absolute(vcpu, operand2, (void *) mem, PAGE_SIZE)) {
  357. kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
  358. goto out_mem;
  359. }
  360. trace_kvm_s390_handle_stsi(vcpu, fc, sel1, sel2, operand2);
  361. free_page(mem);
  362. vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44);
  363. vcpu->run->s.regs.gprs[0] = 0;
  364. return 0;
  365. out_mem:
  366. free_page(mem);
  367. out_fail:
  368. /* condition code 3 */
  369. vcpu->arch.sie_block->gpsw.mask |= 3ul << 44;
  370. return 0;
  371. }
  372. static const intercept_handler_t b2_handlers[256] = {
  373. [0x02] = handle_stidp,
  374. [0x10] = handle_set_prefix,
  375. [0x11] = handle_store_prefix,
  376. [0x12] = handle_store_cpu_address,
  377. [0x29] = handle_skey,
  378. [0x2a] = handle_skey,
  379. [0x2b] = handle_skey,
  380. [0x30] = handle_io_inst,
  381. [0x31] = handle_io_inst,
  382. [0x32] = handle_io_inst,
  383. [0x33] = handle_io_inst,
  384. [0x34] = handle_io_inst,
  385. [0x35] = handle_io_inst,
  386. [0x36] = handle_io_inst,
  387. [0x37] = handle_io_inst,
  388. [0x38] = handle_io_inst,
  389. [0x39] = handle_io_inst,
  390. [0x3a] = handle_io_inst,
  391. [0x3b] = handle_io_inst,
  392. [0x3c] = handle_io_inst,
  393. [0x5f] = handle_io_inst,
  394. [0x74] = handle_io_inst,
  395. [0x76] = handle_io_inst,
  396. [0x7d] = handle_stsi,
  397. [0xb1] = handle_stfl,
  398. [0xb2] = handle_lpswe,
  399. };
  400. int kvm_s390_handle_b2(struct kvm_vcpu *vcpu)
  401. {
  402. intercept_handler_t handler;
  403. /*
  404. * a lot of B2 instructions are priviledged. We first check for
  405. * the privileged ones, that we can handle in the kernel. If the
  406. * kernel can handle this instruction, we check for the problem
  407. * state bit and (a) handle the instruction or (b) send a code 2
  408. * program check.
  409. * Anything else goes to userspace.*/
  410. handler = b2_handlers[vcpu->arch.sie_block->ipa & 0x00ff];
  411. if (handler) {
  412. if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
  413. return kvm_s390_inject_program_int(vcpu,
  414. PGM_PRIVILEGED_OPERATION);
  415. else
  416. return handler(vcpu);
  417. }
  418. return -EOPNOTSUPP;
  419. }
  420. static int handle_epsw(struct kvm_vcpu *vcpu)
  421. {
  422. int reg1, reg2;
  423. reg1 = (vcpu->arch.sie_block->ipb & 0x00f00000) >> 24;
  424. reg2 = (vcpu->arch.sie_block->ipb & 0x000f0000) >> 16;
  425. /* This basically extracts the mask half of the psw. */
  426. vcpu->run->s.regs.gprs[reg1] &= 0xffffffff00000000;
  427. vcpu->run->s.regs.gprs[reg1] |= vcpu->arch.sie_block->gpsw.mask >> 32;
  428. if (reg2) {
  429. vcpu->run->s.regs.gprs[reg2] &= 0xffffffff00000000;
  430. vcpu->run->s.regs.gprs[reg2] |=
  431. vcpu->arch.sie_block->gpsw.mask & 0x00000000ffffffff;
  432. }
  433. return 0;
  434. }
  435. static const intercept_handler_t b9_handlers[256] = {
  436. [0x8d] = handle_epsw,
  437. [0x9c] = handle_io_inst,
  438. };
  439. int kvm_s390_handle_b9(struct kvm_vcpu *vcpu)
  440. {
  441. intercept_handler_t handler;
  442. /* This is handled just as for the B2 instructions. */
  443. handler = b9_handlers[vcpu->arch.sie_block->ipa & 0x00ff];
  444. if (handler) {
  445. if ((handler != handle_epsw) &&
  446. (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE))
  447. return kvm_s390_inject_program_int(vcpu,
  448. PGM_PRIVILEGED_OPERATION);
  449. else
  450. return handler(vcpu);
  451. }
  452. return -EOPNOTSUPP;
  453. }
  454. static const intercept_handler_t eb_handlers[256] = {
  455. [0x8a] = handle_io_inst,
  456. };
  457. int kvm_s390_handle_priv_eb(struct kvm_vcpu *vcpu)
  458. {
  459. intercept_handler_t handler;
  460. /* All eb instructions that end up here are privileged. */
  461. if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
  462. return kvm_s390_inject_program_int(vcpu,
  463. PGM_PRIVILEGED_OPERATION);
  464. handler = eb_handlers[vcpu->arch.sie_block->ipb & 0xff];
  465. if (handler)
  466. return handler(vcpu);
  467. return -EOPNOTSUPP;
  468. }
  469. static int handle_tprot(struct kvm_vcpu *vcpu)
  470. {
  471. u64 address1, address2;
  472. struct vm_area_struct *vma;
  473. unsigned long user_address;
  474. vcpu->stat.instruction_tprot++;
  475. kvm_s390_get_base_disp_sse(vcpu, &address1, &address2);
  476. /* we only handle the Linux memory detection case:
  477. * access key == 0
  478. * guest DAT == off
  479. * everything else goes to userspace. */
  480. if (address2 & 0xf0)
  481. return -EOPNOTSUPP;
  482. if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_DAT)
  483. return -EOPNOTSUPP;
  484. down_read(&current->mm->mmap_sem);
  485. user_address = __gmap_translate(address1, vcpu->arch.gmap);
  486. if (IS_ERR_VALUE(user_address))
  487. goto out_inject;
  488. vma = find_vma(current->mm, user_address);
  489. if (!vma)
  490. goto out_inject;
  491. vcpu->arch.sie_block->gpsw.mask &= ~(3ul << 44);
  492. if (!(vma->vm_flags & VM_WRITE) && (vma->vm_flags & VM_READ))
  493. vcpu->arch.sie_block->gpsw.mask |= (1ul << 44);
  494. if (!(vma->vm_flags & VM_WRITE) && !(vma->vm_flags & VM_READ))
  495. vcpu->arch.sie_block->gpsw.mask |= (2ul << 44);
  496. up_read(&current->mm->mmap_sem);
  497. return 0;
  498. out_inject:
  499. up_read(&current->mm->mmap_sem);
  500. return kvm_s390_inject_program_int(vcpu, PGM_ADDRESSING);
  501. }
  502. int kvm_s390_handle_e5(struct kvm_vcpu *vcpu)
  503. {
  504. /* For e5xx... instructions we only handle TPROT */
  505. if ((vcpu->arch.sie_block->ipa & 0x00ff) == 0x01)
  506. return handle_tprot(vcpu);
  507. return -EOPNOTSUPP;
  508. }
  509. static int handle_sckpf(struct kvm_vcpu *vcpu)
  510. {
  511. u32 value;
  512. if (vcpu->arch.sie_block->gpsw.mask & PSW_MASK_PSTATE)
  513. return kvm_s390_inject_program_int(vcpu,
  514. PGM_PRIVILEGED_OPERATION);
  515. if (vcpu->run->s.regs.gprs[0] & 0x00000000ffff0000)
  516. return kvm_s390_inject_program_int(vcpu,
  517. PGM_SPECIFICATION);
  518. value = vcpu->run->s.regs.gprs[0] & 0x000000000000ffff;
  519. vcpu->arch.sie_block->todpr = value;
  520. return 0;
  521. }
  522. static const intercept_handler_t x01_handlers[256] = {
  523. [0x07] = handle_sckpf,
  524. };
  525. int kvm_s390_handle_01(struct kvm_vcpu *vcpu)
  526. {
  527. intercept_handler_t handler;
  528. handler = x01_handlers[vcpu->arch.sie_block->ipa & 0x00ff];
  529. if (handler)
  530. return handler(vcpu);
  531. return -EOPNOTSUPP;
  532. }