priv.c 16 KB

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