priv.c 16 KB

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