booke.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  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_queue_external(struct kvm_vcpu *vcpu,
  86. struct kvm_interrupt *irq)
  87. {
  88. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_EXTERNAL);
  89. }
  90. /* Deliver the interrupt of the corresponding priority, if possible. */
  91. static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu,
  92. unsigned int priority)
  93. {
  94. int allowed = 0;
  95. ulong msr_mask;
  96. switch (priority) {
  97. case BOOKE_IRQPRIO_PROGRAM:
  98. case BOOKE_IRQPRIO_DTLB_MISS:
  99. case BOOKE_IRQPRIO_ITLB_MISS:
  100. case BOOKE_IRQPRIO_SYSCALL:
  101. case BOOKE_IRQPRIO_DATA_STORAGE:
  102. case BOOKE_IRQPRIO_INST_STORAGE:
  103. case BOOKE_IRQPRIO_FP_UNAVAIL:
  104. case BOOKE_IRQPRIO_SPE_UNAVAIL:
  105. case BOOKE_IRQPRIO_SPE_FP_DATA:
  106. case BOOKE_IRQPRIO_SPE_FP_ROUND:
  107. case BOOKE_IRQPRIO_AP_UNAVAIL:
  108. case BOOKE_IRQPRIO_ALIGNMENT:
  109. allowed = 1;
  110. msr_mask = MSR_CE|MSR_ME|MSR_DE;
  111. break;
  112. case BOOKE_IRQPRIO_CRITICAL:
  113. case BOOKE_IRQPRIO_WATCHDOG:
  114. allowed = vcpu->arch.msr & MSR_CE;
  115. msr_mask = MSR_ME;
  116. break;
  117. case BOOKE_IRQPRIO_MACHINE_CHECK:
  118. allowed = vcpu->arch.msr & MSR_ME;
  119. msr_mask = 0;
  120. break;
  121. case BOOKE_IRQPRIO_EXTERNAL:
  122. case BOOKE_IRQPRIO_DECREMENTER:
  123. case BOOKE_IRQPRIO_FIT:
  124. allowed = vcpu->arch.msr & MSR_EE;
  125. msr_mask = MSR_CE|MSR_ME|MSR_DE;
  126. break;
  127. case BOOKE_IRQPRIO_DEBUG:
  128. allowed = vcpu->arch.msr & MSR_DE;
  129. msr_mask = MSR_ME;
  130. break;
  131. }
  132. if (allowed) {
  133. vcpu->arch.srr0 = vcpu->arch.pc;
  134. vcpu->arch.srr1 = vcpu->arch.msr;
  135. vcpu->arch.pc = vcpu->arch.ivpr | vcpu->arch.ivor[priority];
  136. kvmppc_set_msr(vcpu, vcpu->arch.msr & msr_mask);
  137. clear_bit(priority, &vcpu->arch.pending_exceptions);
  138. }
  139. return allowed;
  140. }
  141. /* Check pending exceptions and deliver one, if possible. */
  142. void kvmppc_core_deliver_interrupts(struct kvm_vcpu *vcpu)
  143. {
  144. unsigned long *pending = &vcpu->arch.pending_exceptions;
  145. unsigned int priority;
  146. priority = __ffs(*pending);
  147. while (priority <= BOOKE_IRQPRIO_MAX) {
  148. if (kvmppc_booke_irqprio_deliver(vcpu, priority))
  149. break;
  150. priority = find_next_bit(pending,
  151. BITS_PER_BYTE * sizeof(*pending),
  152. priority + 1);
  153. }
  154. }
  155. /**
  156. * kvmppc_handle_exit
  157. *
  158. * Return value is in the form (errcode<<2 | RESUME_FLAG_HOST | RESUME_FLAG_NV)
  159. */
  160. int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
  161. unsigned int exit_nr)
  162. {
  163. enum emulation_result er;
  164. int r = RESUME_HOST;
  165. /* update before a new last_exit_type is rewritten */
  166. kvmppc_update_timing_stats(vcpu);
  167. local_irq_enable();
  168. run->exit_reason = KVM_EXIT_UNKNOWN;
  169. run->ready_for_interrupt_injection = 1;
  170. switch (exit_nr) {
  171. case BOOKE_INTERRUPT_MACHINE_CHECK:
  172. printk("MACHINE CHECK: %lx\n", mfspr(SPRN_MCSR));
  173. kvmppc_dump_vcpu(vcpu);
  174. r = RESUME_HOST;
  175. break;
  176. case BOOKE_INTERRUPT_EXTERNAL:
  177. kvmppc_account_exit(vcpu, EXT_INTR_EXITS);
  178. if (need_resched())
  179. cond_resched();
  180. r = RESUME_GUEST;
  181. break;
  182. case BOOKE_INTERRUPT_DECREMENTER:
  183. /* Since we switched IVPR back to the host's value, the host
  184. * handled this interrupt the moment we enabled interrupts.
  185. * Now we just offer it a chance to reschedule the guest. */
  186. kvmppc_account_exit(vcpu, DEC_EXITS);
  187. if (need_resched())
  188. cond_resched();
  189. r = RESUME_GUEST;
  190. break;
  191. case BOOKE_INTERRUPT_PROGRAM:
  192. if (vcpu->arch.msr & MSR_PR) {
  193. /* Program traps generated by user-level software must be handled
  194. * by the guest kernel. */
  195. vcpu->arch.esr = vcpu->arch.fault_esr;
  196. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_PROGRAM);
  197. r = RESUME_GUEST;
  198. kvmppc_account_exit(vcpu, USR_PR_INST);
  199. break;
  200. }
  201. er = kvmppc_emulate_instruction(run, vcpu);
  202. switch (er) {
  203. case EMULATE_DONE:
  204. /* don't overwrite subtypes, just account kvm_stats */
  205. kvmppc_account_exit_stat(vcpu, EMULATED_INST_EXITS);
  206. /* Future optimization: only reload non-volatiles if
  207. * they were actually modified by emulation. */
  208. r = RESUME_GUEST_NV;
  209. break;
  210. case EMULATE_DO_DCR:
  211. run->exit_reason = KVM_EXIT_DCR;
  212. r = RESUME_HOST;
  213. break;
  214. case EMULATE_FAIL:
  215. /* XXX Deliver Program interrupt to guest. */
  216. printk(KERN_CRIT "%s: emulation at %lx failed (%08x)\n",
  217. __func__, vcpu->arch.pc, vcpu->arch.last_inst);
  218. /* For debugging, encode the failing instruction and
  219. * report it to userspace. */
  220. run->hw.hardware_exit_reason = ~0ULL << 32;
  221. run->hw.hardware_exit_reason |= vcpu->arch.last_inst;
  222. r = RESUME_HOST;
  223. break;
  224. default:
  225. BUG();
  226. }
  227. break;
  228. case BOOKE_INTERRUPT_FP_UNAVAIL:
  229. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_FP_UNAVAIL);
  230. kvmppc_account_exit(vcpu, FP_UNAVAIL);
  231. r = RESUME_GUEST;
  232. break;
  233. case BOOKE_INTERRUPT_SPE_UNAVAIL:
  234. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_UNAVAIL);
  235. r = RESUME_GUEST;
  236. break;
  237. case BOOKE_INTERRUPT_SPE_FP_DATA:
  238. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_FP_DATA);
  239. r = RESUME_GUEST;
  240. break;
  241. case BOOKE_INTERRUPT_SPE_FP_ROUND:
  242. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SPE_FP_ROUND);
  243. r = RESUME_GUEST;
  244. break;
  245. case BOOKE_INTERRUPT_DATA_STORAGE:
  246. vcpu->arch.dear = vcpu->arch.fault_dear;
  247. vcpu->arch.esr = vcpu->arch.fault_esr;
  248. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DATA_STORAGE);
  249. kvmppc_account_exit(vcpu, DSI_EXITS);
  250. r = RESUME_GUEST;
  251. break;
  252. case BOOKE_INTERRUPT_INST_STORAGE:
  253. vcpu->arch.esr = vcpu->arch.fault_esr;
  254. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_INST_STORAGE);
  255. kvmppc_account_exit(vcpu, ISI_EXITS);
  256. r = RESUME_GUEST;
  257. break;
  258. case BOOKE_INTERRUPT_SYSCALL:
  259. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_SYSCALL);
  260. kvmppc_account_exit(vcpu, SYSCALL_EXITS);
  261. r = RESUME_GUEST;
  262. break;
  263. case BOOKE_INTERRUPT_DTLB_MISS: {
  264. unsigned long eaddr = vcpu->arch.fault_dear;
  265. int gtlb_index;
  266. gpa_t gpaddr;
  267. gfn_t gfn;
  268. /* Check the guest TLB. */
  269. gtlb_index = kvmppc_mmu_dtlb_index(vcpu, eaddr);
  270. if (gtlb_index < 0) {
  271. /* The guest didn't have a mapping for it. */
  272. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DTLB_MISS);
  273. vcpu->arch.dear = vcpu->arch.fault_dear;
  274. vcpu->arch.esr = vcpu->arch.fault_esr;
  275. kvmppc_mmu_dtlb_miss(vcpu);
  276. kvmppc_account_exit(vcpu, DTLB_REAL_MISS_EXITS);
  277. r = RESUME_GUEST;
  278. break;
  279. }
  280. gpaddr = kvmppc_mmu_xlate(vcpu, gtlb_index, eaddr);
  281. gfn = gpaddr >> PAGE_SHIFT;
  282. if (kvm_is_visible_gfn(vcpu->kvm, gfn)) {
  283. /* The guest TLB had a mapping, but the shadow TLB
  284. * didn't, and it is RAM. This could be because:
  285. * a) the entry is mapping the host kernel, or
  286. * b) the guest used a large mapping which we're faking
  287. * Either way, we need to satisfy the fault without
  288. * invoking the guest. */
  289. kvmppc_mmu_map(vcpu, eaddr, gpaddr, gtlb_index);
  290. kvmppc_account_exit(vcpu, DTLB_VIRT_MISS_EXITS);
  291. r = RESUME_GUEST;
  292. } else {
  293. /* Guest has mapped and accessed a page which is not
  294. * actually RAM. */
  295. vcpu->arch.paddr_accessed = gpaddr;
  296. r = kvmppc_emulate_mmio(run, vcpu);
  297. kvmppc_account_exit(vcpu, MMIO_EXITS);
  298. }
  299. break;
  300. }
  301. case BOOKE_INTERRUPT_ITLB_MISS: {
  302. unsigned long eaddr = vcpu->arch.pc;
  303. gpa_t gpaddr;
  304. gfn_t gfn;
  305. int gtlb_index;
  306. r = RESUME_GUEST;
  307. /* Check the guest TLB. */
  308. gtlb_index = kvmppc_mmu_itlb_index(vcpu, eaddr);
  309. if (gtlb_index < 0) {
  310. /* The guest didn't have a mapping for it. */
  311. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_ITLB_MISS);
  312. kvmppc_mmu_itlb_miss(vcpu);
  313. kvmppc_account_exit(vcpu, ITLB_REAL_MISS_EXITS);
  314. break;
  315. }
  316. kvmppc_account_exit(vcpu, ITLB_VIRT_MISS_EXITS);
  317. gpaddr = kvmppc_mmu_xlate(vcpu, gtlb_index, eaddr);
  318. gfn = gpaddr >> PAGE_SHIFT;
  319. if (kvm_is_visible_gfn(vcpu->kvm, gfn)) {
  320. /* The guest TLB had a mapping, but the shadow TLB
  321. * didn't. This could be because:
  322. * a) the entry is mapping the host kernel, or
  323. * b) the guest used a large mapping which we're faking
  324. * Either way, we need to satisfy the fault without
  325. * invoking the guest. */
  326. kvmppc_mmu_map(vcpu, eaddr, gpaddr, gtlb_index);
  327. } else {
  328. /* Guest mapped and leaped at non-RAM! */
  329. kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_MACHINE_CHECK);
  330. }
  331. break;
  332. }
  333. case BOOKE_INTERRUPT_DEBUG: {
  334. u32 dbsr;
  335. vcpu->arch.pc = mfspr(SPRN_CSRR0);
  336. /* clear IAC events in DBSR register */
  337. dbsr = mfspr(SPRN_DBSR);
  338. dbsr &= DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4;
  339. mtspr(SPRN_DBSR, dbsr);
  340. run->exit_reason = KVM_EXIT_DEBUG;
  341. kvmppc_account_exit(vcpu, DEBUG_EXITS);
  342. r = RESUME_HOST;
  343. break;
  344. }
  345. default:
  346. printk(KERN_EMERG "exit_nr %d\n", exit_nr);
  347. BUG();
  348. }
  349. local_irq_disable();
  350. kvmppc_core_deliver_interrupts(vcpu);
  351. if (!(r & RESUME_HOST)) {
  352. /* To avoid clobbering exit_reason, only check for signals if
  353. * we aren't already exiting to userspace for some other
  354. * reason. */
  355. if (signal_pending(current)) {
  356. run->exit_reason = KVM_EXIT_INTR;
  357. r = (-EINTR << 2) | RESUME_HOST | (r & RESUME_FLAG_NV);
  358. kvmppc_account_exit(vcpu, SIGNAL_EXITS);
  359. }
  360. }
  361. return r;
  362. }
  363. /* Initial guest state: 16MB mapping 0 -> 0, PC = 0, MSR = 0, R1 = 16MB */
  364. int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
  365. {
  366. vcpu->arch.pc = 0;
  367. vcpu->arch.msr = 0;
  368. vcpu->arch.gpr[1] = (16<<20) - 8; /* -8 for the callee-save LR slot */
  369. vcpu->arch.shadow_pid = 1;
  370. /* Eye-catching number so we know if the guest takes an interrupt
  371. * before it's programmed its own IVPR. */
  372. vcpu->arch.ivpr = 0x55550000;
  373. kvmppc_init_timing_stats(vcpu);
  374. return kvmppc_core_vcpu_setup(vcpu);
  375. }
  376. int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
  377. {
  378. int i;
  379. regs->pc = vcpu->arch.pc;
  380. regs->cr = vcpu->arch.cr;
  381. regs->ctr = vcpu->arch.ctr;
  382. regs->lr = vcpu->arch.lr;
  383. regs->xer = vcpu->arch.xer;
  384. regs->msr = vcpu->arch.msr;
  385. regs->srr0 = vcpu->arch.srr0;
  386. regs->srr1 = vcpu->arch.srr1;
  387. regs->pid = vcpu->arch.pid;
  388. regs->sprg0 = vcpu->arch.sprg0;
  389. regs->sprg1 = vcpu->arch.sprg1;
  390. regs->sprg2 = vcpu->arch.sprg2;
  391. regs->sprg3 = vcpu->arch.sprg3;
  392. regs->sprg5 = vcpu->arch.sprg4;
  393. regs->sprg6 = vcpu->arch.sprg5;
  394. regs->sprg7 = vcpu->arch.sprg6;
  395. for (i = 0; i < ARRAY_SIZE(regs->gpr); i++)
  396. regs->gpr[i] = vcpu->arch.gpr[i];
  397. return 0;
  398. }
  399. int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
  400. {
  401. int i;
  402. vcpu->arch.pc = regs->pc;
  403. vcpu->arch.cr = regs->cr;
  404. vcpu->arch.ctr = regs->ctr;
  405. vcpu->arch.lr = regs->lr;
  406. vcpu->arch.xer = regs->xer;
  407. kvmppc_set_msr(vcpu, regs->msr);
  408. vcpu->arch.srr0 = regs->srr0;
  409. vcpu->arch.srr1 = regs->srr1;
  410. vcpu->arch.sprg0 = regs->sprg0;
  411. vcpu->arch.sprg1 = regs->sprg1;
  412. vcpu->arch.sprg2 = regs->sprg2;
  413. vcpu->arch.sprg3 = regs->sprg3;
  414. vcpu->arch.sprg5 = regs->sprg4;
  415. vcpu->arch.sprg6 = regs->sprg5;
  416. vcpu->arch.sprg7 = regs->sprg6;
  417. for (i = 0; i < ARRAY_SIZE(vcpu->arch.gpr); i++)
  418. vcpu->arch.gpr[i] = regs->gpr[i];
  419. return 0;
  420. }
  421. int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
  422. struct kvm_sregs *sregs)
  423. {
  424. return -ENOTSUPP;
  425. }
  426. int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
  427. struct kvm_sregs *sregs)
  428. {
  429. return -ENOTSUPP;
  430. }
  431. int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
  432. {
  433. return -ENOTSUPP;
  434. }
  435. int kvm_arch_vcpu_ioctl_set_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
  436. {
  437. return -ENOTSUPP;
  438. }
  439. int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
  440. struct kvm_translation *tr)
  441. {
  442. return kvmppc_core_vcpu_translate(vcpu, tr);
  443. }
  444. int kvmppc_booke_init(void)
  445. {
  446. unsigned long ivor[16];
  447. unsigned long max_ivor = 0;
  448. int i;
  449. /* We install our own exception handlers by hijacking IVPR. IVPR must
  450. * be 16-bit aligned, so we need a 64KB allocation. */
  451. kvmppc_booke_handlers = __get_free_pages(GFP_KERNEL | __GFP_ZERO,
  452. VCPU_SIZE_ORDER);
  453. if (!kvmppc_booke_handlers)
  454. return -ENOMEM;
  455. /* XXX make sure our handlers are smaller than Linux's */
  456. /* Copy our interrupt handlers to match host IVORs. That way we don't
  457. * have to swap the IVORs on every guest/host transition. */
  458. ivor[0] = mfspr(SPRN_IVOR0);
  459. ivor[1] = mfspr(SPRN_IVOR1);
  460. ivor[2] = mfspr(SPRN_IVOR2);
  461. ivor[3] = mfspr(SPRN_IVOR3);
  462. ivor[4] = mfspr(SPRN_IVOR4);
  463. ivor[5] = mfspr(SPRN_IVOR5);
  464. ivor[6] = mfspr(SPRN_IVOR6);
  465. ivor[7] = mfspr(SPRN_IVOR7);
  466. ivor[8] = mfspr(SPRN_IVOR8);
  467. ivor[9] = mfspr(SPRN_IVOR9);
  468. ivor[10] = mfspr(SPRN_IVOR10);
  469. ivor[11] = mfspr(SPRN_IVOR11);
  470. ivor[12] = mfspr(SPRN_IVOR12);
  471. ivor[13] = mfspr(SPRN_IVOR13);
  472. ivor[14] = mfspr(SPRN_IVOR14);
  473. ivor[15] = mfspr(SPRN_IVOR15);
  474. for (i = 0; i < 16; i++) {
  475. if (ivor[i] > max_ivor)
  476. max_ivor = ivor[i];
  477. memcpy((void *)kvmppc_booke_handlers + ivor[i],
  478. kvmppc_handlers_start + i * kvmppc_handler_len,
  479. kvmppc_handler_len);
  480. }
  481. flush_icache_range(kvmppc_booke_handlers,
  482. kvmppc_booke_handlers + max_ivor + kvmppc_handler_len);
  483. return 0;
  484. }
  485. void __exit kvmppc_booke_exit(void)
  486. {
  487. free_pages(kvmppc_booke_handlers, VCPU_SIZE_ORDER);
  488. kvm_exit();
  489. }