booke.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License, version 2, as
  4. * published by the Free Software Foundation.
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. * GNU General Public License for more details.
  10. *
  11. * You should have received a copy of the GNU General Public License
  12. * along with this program; if not, write to the Free Software
  13. * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  14. *
  15. * Copyright IBM Corp. 2007
  16. *
  17. * Authors: Hollis Blanchard <hollisb@us.ibm.com>
  18. * Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
  19. */
  20. #include <linux/errno.h>
  21. #include <linux/err.h>
  22. #include <linux/kvm_host.h>
  23. #include <linux/module.h>
  24. #include <linux/vmalloc.h>
  25. #include <linux/fs.h>
  26. #include <asm/cputable.h>
  27. #include <asm/uaccess.h>
  28. #include <asm/kvm_ppc.h>
  29. #include "timing.h"
  30. #include <asm/cacheflush.h>
  31. #include "booke.h"
  32. unsigned long kvmppc_booke_handlers;
  33. #define VM_STAT(x) offsetof(struct kvm, stat.x), KVM_STAT_VM
  34. #define VCPU_STAT(x) offsetof(struct kvm_vcpu, stat.x), KVM_STAT_VCPU
  35. struct kvm_stats_debugfs_item debugfs_entries[] = {
  36. { "mmio", VCPU_STAT(mmio_exits) },
  37. { "dcr", VCPU_STAT(dcr_exits) },
  38. { "sig", VCPU_STAT(signal_exits) },
  39. { "itlb_r", VCPU_STAT(itlb_real_miss_exits) },
  40. { "itlb_v", VCPU_STAT(itlb_virt_miss_exits) },
  41. { "dtlb_r", VCPU_STAT(dtlb_real_miss_exits) },
  42. { "dtlb_v", VCPU_STAT(dtlb_virt_miss_exits) },
  43. { "sysc", VCPU_STAT(syscall_exits) },
  44. { "isi", VCPU_STAT(isi_exits) },
  45. { "dsi", VCPU_STAT(dsi_exits) },
  46. { "inst_emu", VCPU_STAT(emulated_inst_exits) },
  47. { "dec", VCPU_STAT(dec_exits) },
  48. { "ext_intr", VCPU_STAT(ext_intr_exits) },
  49. { "halt_wakeup", VCPU_STAT(halt_wakeup) },
  50. { NULL }
  51. };
  52. /* TODO: use vcpu_printf() */
  53. void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu)
  54. {
  55. int i;
  56. printk("pc: %08lx msr: %08lx\n", vcpu->arch.pc, vcpu->arch.msr);
  57. printk("lr: %08lx ctr: %08lx\n", vcpu->arch.lr, vcpu->arch.ctr);
  58. printk("srr0: %08lx srr1: %08lx\n", vcpu->arch.srr0, vcpu->arch.srr1);
  59. printk("exceptions: %08lx\n", vcpu->arch.pending_exceptions);
  60. for (i = 0; i < 32; i += 4) {
  61. printk("gpr%02d: %08lx %08lx %08lx %08lx\n", i,
  62. vcpu->arch.gpr[i],
  63. vcpu->arch.gpr[i+1],
  64. vcpu->arch.gpr[i+2],
  65. vcpu->arch.gpr[i+3]);
  66. }
  67. }
  68. static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu,
  69. unsigned int priority)
  70. {
  71. set_bit(priority, &vcpu->arch.pending_exceptions);
  72. }
  73. void kvmppc_core_queue_program(struct kvm_vcpu *vcpu)
  74. {
  75. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_PROGRAM);
  76. }
  77. void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu)
  78. {
  79. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DECREMENTER);
  80. }
  81. int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu)
  82. {
  83. return test_bit(BOOKE_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions);
  84. }
  85. void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu)
  86. {
  87. clear_bit(BOOKE_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions);
  88. }
  89. void kvmppc_core_queue_external(struct kvm_vcpu *vcpu,
  90. struct kvm_interrupt *irq)
  91. {
  92. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_EXTERNAL);
  93. }
  94. /* Deliver the interrupt of the corresponding priority, if possible. */
  95. static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu,
  96. unsigned int priority)
  97. {
  98. int allowed = 0;
  99. ulong msr_mask;
  100. switch (priority) {
  101. case BOOKE_IRQPRIO_PROGRAM:
  102. case BOOKE_IRQPRIO_DTLB_MISS:
  103. case BOOKE_IRQPRIO_ITLB_MISS:
  104. case BOOKE_IRQPRIO_SYSCALL:
  105. case BOOKE_IRQPRIO_DATA_STORAGE:
  106. case BOOKE_IRQPRIO_INST_STORAGE:
  107. case BOOKE_IRQPRIO_FP_UNAVAIL:
  108. case BOOKE_IRQPRIO_SPE_UNAVAIL:
  109. case BOOKE_IRQPRIO_SPE_FP_DATA:
  110. case BOOKE_IRQPRIO_SPE_FP_ROUND:
  111. case BOOKE_IRQPRIO_AP_UNAVAIL:
  112. case BOOKE_IRQPRIO_ALIGNMENT:
  113. allowed = 1;
  114. msr_mask = MSR_CE|MSR_ME|MSR_DE;
  115. break;
  116. case BOOKE_IRQPRIO_CRITICAL:
  117. case BOOKE_IRQPRIO_WATCHDOG:
  118. allowed = vcpu->arch.msr & MSR_CE;
  119. msr_mask = MSR_ME;
  120. break;
  121. case BOOKE_IRQPRIO_MACHINE_CHECK:
  122. allowed = vcpu->arch.msr & MSR_ME;
  123. msr_mask = 0;
  124. break;
  125. case BOOKE_IRQPRIO_EXTERNAL:
  126. case BOOKE_IRQPRIO_DECREMENTER:
  127. case BOOKE_IRQPRIO_FIT:
  128. allowed = vcpu->arch.msr & MSR_EE;
  129. msr_mask = MSR_CE|MSR_ME|MSR_DE;
  130. break;
  131. case BOOKE_IRQPRIO_DEBUG:
  132. allowed = vcpu->arch.msr & MSR_DE;
  133. msr_mask = MSR_ME;
  134. break;
  135. }
  136. if (allowed) {
  137. vcpu->arch.srr0 = vcpu->arch.pc;
  138. vcpu->arch.srr1 = vcpu->arch.msr;
  139. vcpu->arch.pc = vcpu->arch.ivpr | vcpu->arch.ivor[priority];
  140. kvmppc_set_msr(vcpu, vcpu->arch.msr & msr_mask);
  141. clear_bit(priority, &vcpu->arch.pending_exceptions);
  142. }
  143. return allowed;
  144. }
  145. /* Check pending exceptions and deliver one, if possible. */
  146. void kvmppc_core_deliver_interrupts(struct kvm_vcpu *vcpu)
  147. {
  148. unsigned long *pending = &vcpu->arch.pending_exceptions;
  149. unsigned int priority;
  150. priority = __ffs(*pending);
  151. while (priority <= BOOKE_IRQPRIO_MAX) {
  152. if (kvmppc_booke_irqprio_deliver(vcpu, priority))
  153. break;
  154. priority = find_next_bit(pending,
  155. BITS_PER_BYTE * sizeof(*pending),
  156. priority + 1);
  157. }
  158. }
  159. /**
  160. * kvmppc_handle_exit
  161. *
  162. * Return value is in the form (errcode<<2 | RESUME_FLAG_HOST | RESUME_FLAG_NV)
  163. */
  164. int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
  165. unsigned int exit_nr)
  166. {
  167. enum emulation_result er;
  168. int r = RESUME_HOST;
  169. /* update before a new last_exit_type is rewritten */
  170. kvmppc_update_timing_stats(vcpu);
  171. local_irq_enable();
  172. run->exit_reason = KVM_EXIT_UNKNOWN;
  173. run->ready_for_interrupt_injection = 1;
  174. switch (exit_nr) {
  175. case BOOKE_INTERRUPT_MACHINE_CHECK:
  176. printk("MACHINE CHECK: %lx\n", mfspr(SPRN_MCSR));
  177. kvmppc_dump_vcpu(vcpu);
  178. r = RESUME_HOST;
  179. break;
  180. case BOOKE_INTERRUPT_EXTERNAL:
  181. kvmppc_account_exit(vcpu, EXT_INTR_EXITS);
  182. if (need_resched())
  183. cond_resched();
  184. r = RESUME_GUEST;
  185. break;
  186. case BOOKE_INTERRUPT_DECREMENTER:
  187. /* Since we switched IVPR back to the host's value, the host
  188. * handled this interrupt the moment we enabled interrupts.
  189. * Now we just offer it a chance to reschedule the guest. */
  190. kvmppc_account_exit(vcpu, DEC_EXITS);
  191. if (need_resched())
  192. cond_resched();
  193. r = RESUME_GUEST;
  194. break;
  195. case BOOKE_INTERRUPT_PROGRAM:
  196. if (vcpu->arch.msr & MSR_PR) {
  197. /* Program traps generated by user-level software must be handled
  198. * by the guest kernel. */
  199. vcpu->arch.esr = vcpu->arch.fault_esr;
  200. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_PROGRAM);
  201. r = RESUME_GUEST;
  202. kvmppc_account_exit(vcpu, USR_PR_INST);
  203. break;
  204. }
  205. er = kvmppc_emulate_instruction(run, vcpu);
  206. switch (er) {
  207. case EMULATE_DONE:
  208. /* don't overwrite subtypes, just account kvm_stats */
  209. kvmppc_account_exit_stat(vcpu, EMULATED_INST_EXITS);
  210. /* Future optimization: only reload non-volatiles if
  211. * they were actually modified by emulation. */
  212. r = RESUME_GUEST_NV;
  213. break;
  214. case EMULATE_DO_DCR:
  215. run->exit_reason = KVM_EXIT_DCR;
  216. r = RESUME_HOST;
  217. break;
  218. case EMULATE_FAIL:
  219. /* XXX Deliver Program interrupt to guest. */
  220. printk(KERN_CRIT "%s: emulation at %lx failed (%08x)\n",
  221. __func__, vcpu->arch.pc, vcpu->arch.last_inst);
  222. /* For debugging, encode the failing instruction and
  223. * report it to userspace. */
  224. run->hw.hardware_exit_reason = ~0ULL << 32;
  225. run->hw.hardware_exit_reason |= vcpu->arch.last_inst;
  226. r = RESUME_HOST;
  227. break;
  228. default:
  229. BUG();
  230. }
  231. break;
  232. case BOOKE_INTERRUPT_FP_UNAVAIL:
  233. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_FP_UNAVAIL);
  234. kvmppc_account_exit(vcpu, FP_UNAVAIL);
  235. r = RESUME_GUEST;
  236. break;
  237. case BOOKE_INTERRUPT_SPE_UNAVAIL:
  238. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_UNAVAIL);
  239. r = RESUME_GUEST;
  240. break;
  241. case BOOKE_INTERRUPT_SPE_FP_DATA:
  242. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_FP_DATA);
  243. r = RESUME_GUEST;
  244. break;
  245. case BOOKE_INTERRUPT_SPE_FP_ROUND:
  246. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_FP_ROUND);
  247. r = RESUME_GUEST;
  248. break;
  249. case BOOKE_INTERRUPT_DATA_STORAGE:
  250. vcpu->arch.dear = vcpu->arch.fault_dear;
  251. vcpu->arch.esr = vcpu->arch.fault_esr;
  252. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DATA_STORAGE);
  253. kvmppc_account_exit(vcpu, DSI_EXITS);
  254. r = RESUME_GUEST;
  255. break;
  256. case BOOKE_INTERRUPT_INST_STORAGE:
  257. vcpu->arch.esr = vcpu->arch.fault_esr;
  258. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_INST_STORAGE);
  259. kvmppc_account_exit(vcpu, ISI_EXITS);
  260. r = RESUME_GUEST;
  261. break;
  262. case BOOKE_INTERRUPT_SYSCALL:
  263. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SYSCALL);
  264. kvmppc_account_exit(vcpu, SYSCALL_EXITS);
  265. r = RESUME_GUEST;
  266. break;
  267. case BOOKE_INTERRUPT_DTLB_MISS: {
  268. unsigned long eaddr = vcpu->arch.fault_dear;
  269. int gtlb_index;
  270. gpa_t gpaddr;
  271. gfn_t gfn;
  272. /* Check the guest TLB. */
  273. gtlb_index = kvmppc_mmu_dtlb_index(vcpu, eaddr);
  274. if (gtlb_index < 0) {
  275. /* The guest didn't have a mapping for it. */
  276. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DTLB_MISS);
  277. vcpu->arch.dear = vcpu->arch.fault_dear;
  278. vcpu->arch.esr = vcpu->arch.fault_esr;
  279. kvmppc_mmu_dtlb_miss(vcpu);
  280. kvmppc_account_exit(vcpu, DTLB_REAL_MISS_EXITS);
  281. r = RESUME_GUEST;
  282. break;
  283. }
  284. gpaddr = kvmppc_mmu_xlate(vcpu, gtlb_index, eaddr);
  285. gfn = gpaddr >> PAGE_SHIFT;
  286. if (kvm_is_visible_gfn(vcpu->kvm, gfn)) {
  287. /* The guest TLB had a mapping, but the shadow TLB
  288. * didn't, and it is RAM. This could be because:
  289. * a) the entry is mapping the host kernel, or
  290. * b) the guest used a large mapping which we're faking
  291. * Either way, we need to satisfy the fault without
  292. * invoking the guest. */
  293. kvmppc_mmu_map(vcpu, eaddr, gpaddr, gtlb_index);
  294. kvmppc_account_exit(vcpu, DTLB_VIRT_MISS_EXITS);
  295. r = RESUME_GUEST;
  296. } else {
  297. /* Guest has mapped and accessed a page which is not
  298. * actually RAM. */
  299. vcpu->arch.paddr_accessed = gpaddr;
  300. r = kvmppc_emulate_mmio(run, vcpu);
  301. kvmppc_account_exit(vcpu, MMIO_EXITS);
  302. }
  303. break;
  304. }
  305. case BOOKE_INTERRUPT_ITLB_MISS: {
  306. unsigned long eaddr = vcpu->arch.pc;
  307. gpa_t gpaddr;
  308. gfn_t gfn;
  309. int gtlb_index;
  310. r = RESUME_GUEST;
  311. /* Check the guest TLB. */
  312. gtlb_index = kvmppc_mmu_itlb_index(vcpu, eaddr);
  313. if (gtlb_index < 0) {
  314. /* The guest didn't have a mapping for it. */
  315. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_ITLB_MISS);
  316. kvmppc_mmu_itlb_miss(vcpu);
  317. kvmppc_account_exit(vcpu, ITLB_REAL_MISS_EXITS);
  318. break;
  319. }
  320. kvmppc_account_exit(vcpu, ITLB_VIRT_MISS_EXITS);
  321. gpaddr = kvmppc_mmu_xlate(vcpu, gtlb_index, eaddr);
  322. gfn = gpaddr >> PAGE_SHIFT;
  323. if (kvm_is_visible_gfn(vcpu->kvm, gfn)) {
  324. /* The guest TLB had a mapping, but the shadow TLB
  325. * didn't. This could be because:
  326. * a) the entry is mapping the host kernel, or
  327. * b) the guest used a large mapping which we're faking
  328. * Either way, we need to satisfy the fault without
  329. * invoking the guest. */
  330. kvmppc_mmu_map(vcpu, eaddr, gpaddr, gtlb_index);
  331. } else {
  332. /* Guest mapped and leaped at non-RAM! */
  333. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_MACHINE_CHECK);
  334. }
  335. break;
  336. }
  337. case BOOKE_INTERRUPT_DEBUG: {
  338. u32 dbsr;
  339. vcpu->arch.pc = mfspr(SPRN_CSRR0);
  340. /* clear IAC events in DBSR register */
  341. dbsr = mfspr(SPRN_DBSR);
  342. dbsr &= DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4;
  343. mtspr(SPRN_DBSR, dbsr);
  344. run->exit_reason = KVM_EXIT_DEBUG;
  345. kvmppc_account_exit(vcpu, DEBUG_EXITS);
  346. r = RESUME_HOST;
  347. break;
  348. }
  349. default:
  350. printk(KERN_EMERG "exit_nr %d\n", exit_nr);
  351. BUG();
  352. }
  353. local_irq_disable();
  354. kvmppc_core_deliver_interrupts(vcpu);
  355. if (!(r & RESUME_HOST)) {
  356. /* To avoid clobbering exit_reason, only check for signals if
  357. * we aren't already exiting to userspace for some other
  358. * reason. */
  359. if (signal_pending(current)) {
  360. run->exit_reason = KVM_EXIT_INTR;
  361. r = (-EINTR << 2) | RESUME_HOST | (r & RESUME_FLAG_NV);
  362. kvmppc_account_exit(vcpu, SIGNAL_EXITS);
  363. }
  364. }
  365. return r;
  366. }
  367. /* Initial guest state: 16MB mapping 0 -> 0, PC = 0, MSR = 0, R1 = 16MB */
  368. int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
  369. {
  370. vcpu->arch.pc = 0;
  371. vcpu->arch.msr = 0;
  372. vcpu->arch.gpr[1] = (16<<20) - 8; /* -8 for the callee-save LR slot */
  373. vcpu->arch.shadow_pid = 1;
  374. /* Eye-catching number so we know if the guest takes an interrupt
  375. * before it's programmed its own IVPR. */
  376. vcpu->arch.ivpr = 0x55550000;
  377. kvmppc_init_timing_stats(vcpu);
  378. return kvmppc_core_vcpu_setup(vcpu);
  379. }
  380. int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
  381. {
  382. int i;
  383. regs->pc = vcpu->arch.pc;
  384. regs->cr = vcpu->arch.cr;
  385. regs->ctr = vcpu->arch.ctr;
  386. regs->lr = vcpu->arch.lr;
  387. regs->xer = vcpu->arch.xer;
  388. regs->msr = vcpu->arch.msr;
  389. regs->srr0 = vcpu->arch.srr0;
  390. regs->srr1 = vcpu->arch.srr1;
  391. regs->pid = vcpu->arch.pid;
  392. regs->sprg0 = vcpu->arch.sprg0;
  393. regs->sprg1 = vcpu->arch.sprg1;
  394. regs->sprg2 = vcpu->arch.sprg2;
  395. regs->sprg3 = vcpu->arch.sprg3;
  396. regs->sprg5 = vcpu->arch.sprg4;
  397. regs->sprg6 = vcpu->arch.sprg5;
  398. regs->sprg7 = vcpu->arch.sprg6;
  399. for (i = 0; i < ARRAY_SIZE(regs->gpr); i++)
  400. regs->gpr[i] = vcpu->arch.gpr[i];
  401. return 0;
  402. }
  403. int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
  404. {
  405. int i;
  406. vcpu->arch.pc = regs->pc;
  407. vcpu->arch.cr = regs->cr;
  408. vcpu->arch.ctr = regs->ctr;
  409. vcpu->arch.lr = regs->lr;
  410. vcpu->arch.xer = regs->xer;
  411. kvmppc_set_msr(vcpu, regs->msr);
  412. vcpu->arch.srr0 = regs->srr0;
  413. vcpu->arch.srr1 = regs->srr1;
  414. vcpu->arch.sprg0 = regs->sprg0;
  415. vcpu->arch.sprg1 = regs->sprg1;
  416. vcpu->arch.sprg2 = regs->sprg2;
  417. vcpu->arch.sprg3 = regs->sprg3;
  418. vcpu->arch.sprg5 = regs->sprg4;
  419. vcpu->arch.sprg6 = regs->sprg5;
  420. vcpu->arch.sprg7 = regs->sprg6;
  421. for (i = 0; i < ARRAY_SIZE(vcpu->arch.gpr); i++)
  422. vcpu->arch.gpr[i] = regs->gpr[i];
  423. return 0;
  424. }
  425. int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
  426. struct kvm_sregs *sregs)
  427. {
  428. return -ENOTSUPP;
  429. }
  430. int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
  431. struct kvm_sregs *sregs)
  432. {
  433. return -ENOTSUPP;
  434. }
  435. int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
  436. {
  437. return -ENOTSUPP;
  438. }
  439. int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
  440. {
  441. return -ENOTSUPP;
  442. }
  443. int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
  444. struct kvm_translation *tr)
  445. {
  446. return kvmppc_core_vcpu_translate(vcpu, tr);
  447. }
  448. int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log)
  449. {
  450. return -ENOTSUPP;
  451. }
  452. int __init kvmppc_booke_init(void)
  453. {
  454. unsigned long ivor[16];
  455. unsigned long max_ivor = 0;
  456. int i;
  457. /* We install our own exception handlers by hijacking IVPR. IVPR must
  458. * be 16-bit aligned, so we need a 64KB allocation. */
  459. kvmppc_booke_handlers = __get_free_pages(GFP_KERNEL | __GFP_ZERO,
  460. VCPU_SIZE_ORDER);
  461. if (!kvmppc_booke_handlers)
  462. return -ENOMEM;
  463. /* XXX make sure our handlers are smaller than Linux's */
  464. /* Copy our interrupt handlers to match host IVORs. That way we don't
  465. * have to swap the IVORs on every guest/host transition. */
  466. ivor[0] = mfspr(SPRN_IVOR0);
  467. ivor[1] = mfspr(SPRN_IVOR1);
  468. ivor[2] = mfspr(SPRN_IVOR2);
  469. ivor[3] = mfspr(SPRN_IVOR3);
  470. ivor[4] = mfspr(SPRN_IVOR4);
  471. ivor[5] = mfspr(SPRN_IVOR5);
  472. ivor[6] = mfspr(SPRN_IVOR6);
  473. ivor[7] = mfspr(SPRN_IVOR7);
  474. ivor[8] = mfspr(SPRN_IVOR8);
  475. ivor[9] = mfspr(SPRN_IVOR9);
  476. ivor[10] = mfspr(SPRN_IVOR10);
  477. ivor[11] = mfspr(SPRN_IVOR11);
  478. ivor[12] = mfspr(SPRN_IVOR12);
  479. ivor[13] = mfspr(SPRN_IVOR13);
  480. ivor[14] = mfspr(SPRN_IVOR14);
  481. ivor[15] = mfspr(SPRN_IVOR15);
  482. for (i = 0; i < 16; i++) {
  483. if (ivor[i] > max_ivor)
  484. max_ivor = ivor[i];
  485. memcpy((void *)kvmppc_booke_handlers + ivor[i],
  486. kvmppc_handlers_start + i * kvmppc_handler_len,
  487. kvmppc_handler_len);
  488. }
  489. flush_icache_range(kvmppc_booke_handlers,
  490. kvmppc_booke_handlers + max_ivor + kvmppc_handler_len);
  491. return 0;
  492. }
  493. void __exit kvmppc_booke_exit(void)
  494. {
  495. free_pages(kvmppc_booke_handlers, VCPU_SIZE_ORDER);
  496. kvm_exit();
  497. }