2 * Copyright (C) 2008 Freescale Semiconductor, Inc. All rights reserved.
4 * Author: Yu Liu, yu.liu@freescale.com
7 * This file is based on arch/powerpc/kvm/44x_tlb.c,
8 * by Hollis Blanchard <hollisb@us.ibm.com>.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License, version 2, as
12 * published by the Free Software Foundation.
15 #include <linux/types.h>
16 #include <linux/string.h>
17 #include <linux/kvm.h>
18 #include <linux/kvm_host.h>
19 #include <linux/highmem.h>
20 #include <asm/kvm_ppc.h>
21 #include <asm/kvm_e500.h>
25 #define to_htlb1_esel(esel) (tlb1_entry_num - (esel) - 1)
27 static unsigned int tlb1_entry_num;
29 void kvmppc_dump_tlbs(struct kvm_vcpu *vcpu)
31 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
35 printk("| %8s | %8s | %8s | %8s | %8s |\n",
36 "nr", "mas1", "mas2", "mas3", "mas7");
38 for (tlbsel = 0; tlbsel < 2; tlbsel++) {
39 printk("Guest TLB%d:\n", tlbsel);
40 for (i = 0; i < vcpu_e500->guest_tlb_size[tlbsel]; i++) {
41 tlbe = &vcpu_e500->guest_tlb[tlbsel][i];
42 if (tlbe->mas1 & MAS1_VALID)
43 printk(" G[%d][%3d] | %08X | %08X | %08X | %08X |\n",
44 tlbsel, i, tlbe->mas1, tlbe->mas2,
45 tlbe->mas3, tlbe->mas7);
49 for (tlbsel = 0; tlbsel < 2; tlbsel++) {
50 printk("Shadow TLB%d:\n", tlbsel);
51 for (i = 0; i < vcpu_e500->shadow_tlb_size[tlbsel]; i++) {
52 tlbe = &vcpu_e500->shadow_tlb[tlbsel][i];
53 if (tlbe->mas1 & MAS1_VALID)
54 printk(" S[%d][%3d] | %08X | %08X | %08X | %08X |\n",
55 tlbsel, i, tlbe->mas1, tlbe->mas2,
56 tlbe->mas3, tlbe->mas7);
61 static inline unsigned int tlb0_get_next_victim(
62 struct kvmppc_vcpu_e500 *vcpu_e500)
66 victim = vcpu_e500->guest_tlb_nv[0]++;
67 if (unlikely(vcpu_e500->guest_tlb_nv[0] >= KVM_E500_TLB0_WAY_NUM))
68 vcpu_e500->guest_tlb_nv[0] = 0;
73 static inline unsigned int tlb1_max_shadow_size(void)
75 return tlb1_entry_num - tlbcam_index;
78 static inline int tlbe_is_writable(struct tlbe *tlbe)
80 return tlbe->mas3 & (MAS3_SW|MAS3_UW);
83 static inline u32 e500_shadow_mas3_attrib(u32 mas3, int usermode)
85 /* Mask off reserved bits. */
86 mas3 &= MAS3_ATTRIB_MASK;
89 /* Guest is in supervisor mode,
90 * so we need to translate guest
91 * supervisor permissions into user permissions. */
92 mas3 &= ~E500_TLB_USER_PERM_MASK;
93 mas3 |= (mas3 & E500_TLB_SUPER_PERM_MASK) << 1;
96 return mas3 | E500_TLB_SUPER_PERM_MASK;
99 static inline u32 e500_shadow_mas2_attrib(u32 mas2, int usermode)
101 return mas2 & MAS2_ATTRIB_MASK;
105 * writing shadow tlb entry to host TLB
107 static inline void __write_host_tlbe(struct tlbe *stlbe)
109 mtspr(SPRN_MAS1, stlbe->mas1);
110 mtspr(SPRN_MAS2, stlbe->mas2);
111 mtspr(SPRN_MAS3, stlbe->mas3);
112 mtspr(SPRN_MAS7, stlbe->mas7);
113 __asm__ __volatile__ ("tlbwe\n" : : );
116 static inline void write_host_tlbe(struct kvmppc_vcpu_e500 *vcpu_e500,
117 int tlbsel, int esel)
119 struct tlbe *stlbe = &vcpu_e500->shadow_tlb[tlbsel][esel];
123 __write_host_tlbe(stlbe);
125 unsigned register mas0;
127 mas0 = mfspr(SPRN_MAS0);
129 mtspr(SPRN_MAS0, MAS0_TLBSEL(1) | MAS0_ESEL(to_htlb1_esel(esel)));
130 __write_host_tlbe(stlbe);
132 mtspr(SPRN_MAS0, mas0);
137 void kvmppc_e500_tlb_load(struct kvm_vcpu *vcpu, int cpu)
139 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
141 unsigned register mas0;
143 /* Load all valid TLB1 entries to reduce guest tlb miss fault */
145 mas0 = mfspr(SPRN_MAS0);
146 for (i = 0; i < tlb1_max_shadow_size(); i++) {
147 struct tlbe *stlbe = &vcpu_e500->shadow_tlb[1][i];
149 if (get_tlb_v(stlbe)) {
150 mtspr(SPRN_MAS0, MAS0_TLBSEL(1)
151 | MAS0_ESEL(to_htlb1_esel(i)));
152 __write_host_tlbe(stlbe);
155 mtspr(SPRN_MAS0, mas0);
159 void kvmppc_e500_tlb_put(struct kvm_vcpu *vcpu)
164 /* Search the guest TLB for a matching entry. */
165 static int kvmppc_e500_tlb_index(struct kvmppc_vcpu_e500 *vcpu_e500,
166 gva_t eaddr, int tlbsel, unsigned int pid, int as)
170 /* XXX Replace loop with fancy data structures. */
171 for (i = 0; i < vcpu_e500->guest_tlb_size[tlbsel]; i++) {
172 struct tlbe *tlbe = &vcpu_e500->guest_tlb[tlbsel][i];
175 if (eaddr < get_tlb_eaddr(tlbe))
178 if (eaddr > get_tlb_end(tlbe))
181 tid = get_tlb_tid(tlbe);
182 if (tid && (tid != pid))
185 if (!get_tlb_v(tlbe))
188 if (get_tlb_ts(tlbe) != as && as != -1)
197 static void kvmppc_e500_shadow_release(struct kvmppc_vcpu_e500 *vcpu_e500,
198 int tlbsel, int esel)
200 struct tlbe *stlbe = &vcpu_e500->shadow_tlb[tlbsel][esel];
201 struct page *page = vcpu_e500->shadow_pages[tlbsel][esel];
204 vcpu_e500->shadow_pages[tlbsel][esel] = NULL;
206 if (get_tlb_v(stlbe)) {
207 if (tlbe_is_writable(stlbe))
208 kvm_release_page_dirty(page);
210 kvm_release_page_clean(page);
215 static void kvmppc_e500_stlbe_invalidate(struct kvmppc_vcpu_e500 *vcpu_e500,
216 int tlbsel, int esel)
218 struct tlbe *stlbe = &vcpu_e500->shadow_tlb[tlbsel][esel];
220 kvmppc_e500_shadow_release(vcpu_e500, tlbsel, esel);
222 KVMTRACE_5D(STLB_INVAL, &vcpu_e500->vcpu, index_of(tlbsel, esel),
223 stlbe->mas1, stlbe->mas2, stlbe->mas3, stlbe->mas7,
227 static void kvmppc_e500_tlb1_invalidate(struct kvmppc_vcpu_e500 *vcpu_e500,
228 gva_t eaddr, gva_t eend, u32 tid)
230 unsigned int pid = tid & 0xff;
233 /* XXX Replace loop with fancy data structures. */
234 for (i = 0; i < vcpu_e500->guest_tlb_size[1]; i++) {
235 struct tlbe *stlbe = &vcpu_e500->shadow_tlb[1][i];
238 if (!get_tlb_v(stlbe))
241 if (eend < get_tlb_eaddr(stlbe))
244 if (eaddr > get_tlb_end(stlbe))
247 tid = get_tlb_tid(stlbe);
248 if (tid && (tid != pid))
251 kvmppc_e500_stlbe_invalidate(vcpu_e500, 1, i);
252 write_host_tlbe(vcpu_e500, 1, i);
256 static inline void kvmppc_e500_deliver_tlb_miss(struct kvm_vcpu *vcpu,
257 unsigned int eaddr, int as)
259 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
260 unsigned int victim, pidsel, tsized;
263 /* since we only have two TLBs, only lower bit is used. */
264 tlbsel = (vcpu_e500->mas4 >> 28) & 0x1;
265 victim = (tlbsel == 0) ? tlb0_get_next_victim(vcpu_e500) : 0;
266 pidsel = (vcpu_e500->mas4 >> 16) & 0xf;
267 tsized = (vcpu_e500->mas4 >> 8) & 0xf;
269 vcpu_e500->mas0 = MAS0_TLBSEL(tlbsel) | MAS0_ESEL(victim)
270 | MAS0_NV(vcpu_e500->guest_tlb_nv[tlbsel]);
271 vcpu_e500->mas1 = MAS1_VALID | (as ? MAS1_TS : 0)
272 | MAS1_TID(vcpu_e500->pid[pidsel])
273 | MAS1_TSIZE(tsized);
274 vcpu_e500->mas2 = (eaddr & MAS2_EPN)
275 | (vcpu_e500->mas4 & MAS2_ATTRIB_MASK);
276 vcpu_e500->mas3 &= MAS3_U0 | MAS3_U1 | MAS3_U2 | MAS3_U3;
277 vcpu_e500->mas6 = (vcpu_e500->mas6 & MAS6_SPID1)
278 | (get_cur_pid(vcpu) << 16)
279 | (as ? MAS6_SAS : 0);
283 static inline void kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500,
284 u64 gvaddr, gfn_t gfn, struct tlbe *gtlbe, int tlbsel, int esel)
286 struct page *new_page;
290 stlbe = &vcpu_e500->shadow_tlb[tlbsel][esel];
292 /* Get reference to new page. */
293 new_page = gfn_to_page(vcpu_e500->vcpu.kvm, gfn);
294 if (is_error_page(new_page)) {
295 printk(KERN_ERR "Couldn't get guest page for gfn %lx!\n", gfn);
296 kvm_release_page_clean(new_page);
299 hpaddr = page_to_phys(new_page);
301 /* Drop reference to old page. */
302 kvmppc_e500_shadow_release(vcpu_e500, tlbsel, esel);
304 vcpu_e500->shadow_pages[tlbsel][esel] = new_page;
306 /* Force TS=1 IPROT=0 TSIZE=4KB for all guest mappings. */
307 stlbe->mas1 = MAS1_TSIZE(BOOKE_PAGESZ_4K)
308 | MAS1_TID(get_tlb_tid(gtlbe)) | MAS1_TS | MAS1_VALID;
309 stlbe->mas2 = (gvaddr & MAS2_EPN)
310 | e500_shadow_mas2_attrib(gtlbe->mas2,
311 vcpu_e500->vcpu.arch.msr & MSR_PR);
312 stlbe->mas3 = (hpaddr & MAS3_RPN)
313 | e500_shadow_mas3_attrib(gtlbe->mas3,
314 vcpu_e500->vcpu.arch.msr & MSR_PR);
315 stlbe->mas7 = (hpaddr >> 32) & MAS7_RPN;
317 KVMTRACE_5D(STLB_WRITE, &vcpu_e500->vcpu, index_of(tlbsel, esel),
318 stlbe->mas1, stlbe->mas2, stlbe->mas3, stlbe->mas7,
322 /* XXX only map the one-one case, for now use TLB0 */
323 static int kvmppc_e500_stlbe_map(struct kvmppc_vcpu_e500 *vcpu_e500,
324 int tlbsel, int esel)
328 gtlbe = &vcpu_e500->guest_tlb[tlbsel][esel];
330 kvmppc_e500_shadow_map(vcpu_e500, get_tlb_eaddr(gtlbe),
331 get_tlb_raddr(gtlbe) >> PAGE_SHIFT,
332 gtlbe, tlbsel, esel);
337 /* Caller must ensure that the specified guest TLB entry is safe to insert into
339 /* XXX for both one-one and one-to-many , for now use TLB1 */
340 static int kvmppc_e500_tlb1_map(struct kvmppc_vcpu_e500 *vcpu_e500,
341 u64 gvaddr, gfn_t gfn, struct tlbe *gtlbe)
345 victim = vcpu_e500->guest_tlb_nv[1]++;
347 if (unlikely(vcpu_e500->guest_tlb_nv[1] >= tlb1_max_shadow_size()))
348 vcpu_e500->guest_tlb_nv[1] = 0;
350 kvmppc_e500_shadow_map(vcpu_e500, gvaddr, gfn, gtlbe, 1, victim);
355 /* Invalidate all guest kernel mappings when enter usermode,
356 * so that when they fault back in they will get the
357 * proper permission bits. */
358 void kvmppc_mmu_priv_switch(struct kvm_vcpu *vcpu, int usermode)
361 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
364 /* XXX Replace loop with fancy data structures. */
365 /* needn't set modified since tlbia will make TLB1 coherent */
366 for (i = 0; i < tlb1_max_shadow_size(); i++)
367 kvmppc_e500_stlbe_invalidate(vcpu_e500, 1, i);
373 static int kvmppc_e500_gtlbe_invalidate(struct kvmppc_vcpu_e500 *vcpu_e500,
374 int tlbsel, int esel)
376 struct tlbe *gtlbe = &vcpu_e500->guest_tlb[tlbsel][esel];
378 if (unlikely(get_tlb_iprot(gtlbe)))
382 kvmppc_e500_tlb1_invalidate(vcpu_e500, get_tlb_eaddr(gtlbe),
386 kvmppc_e500_stlbe_invalidate(vcpu_e500, tlbsel, esel);
394 int kvmppc_e500_emul_tlbivax(struct kvm_vcpu *vcpu, int ra, int rb)
396 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
401 ea = ((ra) ? vcpu->arch.gpr[ra] : 0) + vcpu->arch.gpr[rb];
403 ia = (ea >> 2) & 0x1;
405 /* since we only have two TLBs, only lower bit is used. */
406 tlbsel = (ea >> 3) & 0x1;
409 /* invalidate all entries */
410 for (esel = 0; esel < vcpu_e500->guest_tlb_size[tlbsel]; esel++)
411 kvmppc_e500_gtlbe_invalidate(vcpu_e500, tlbsel, esel);
414 esel = kvmppc_e500_tlb_index(vcpu_e500, ea, tlbsel,
415 get_cur_pid(vcpu), -1);
417 kvmppc_e500_gtlbe_invalidate(vcpu_e500, tlbsel, esel);
425 int kvmppc_e500_emul_tlbre(struct kvm_vcpu *vcpu)
427 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
431 tlbsel = get_tlb_tlbsel(vcpu_e500);
432 esel = get_tlb_esel(vcpu_e500, tlbsel);
434 gtlbe = &vcpu_e500->guest_tlb[tlbsel][esel];
435 vcpu_e500->mas0 &= MAS0_NV(0);
436 vcpu_e500->mas0 |= MAS0_NV(vcpu_e500->guest_tlb_nv[tlbsel]);
437 vcpu_e500->mas1 = gtlbe->mas1;
438 vcpu_e500->mas2 = gtlbe->mas2;
439 vcpu_e500->mas3 = gtlbe->mas3;
440 vcpu_e500->mas7 = gtlbe->mas7;
445 int kvmppc_e500_emul_tlbsx(struct kvm_vcpu *vcpu, int rb)
447 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
448 int as = !!get_cur_sas(vcpu_e500);
449 unsigned int pid = get_cur_spid(vcpu_e500);
451 struct tlbe *gtlbe = NULL;
454 ea = vcpu->arch.gpr[rb];
456 for (tlbsel = 0; tlbsel < 2; tlbsel++) {
457 esel = kvmppc_e500_tlb_index(vcpu_e500, ea, tlbsel, pid, as);
459 gtlbe = &vcpu_e500->guest_tlb[tlbsel][esel];
465 vcpu_e500->mas0 = MAS0_TLBSEL(tlbsel) | MAS0_ESEL(esel)
466 | MAS0_NV(vcpu_e500->guest_tlb_nv[tlbsel]);
467 vcpu_e500->mas1 = gtlbe->mas1;
468 vcpu_e500->mas2 = gtlbe->mas2;
469 vcpu_e500->mas3 = gtlbe->mas3;
470 vcpu_e500->mas7 = gtlbe->mas7;
474 /* since we only have two TLBs, only lower bit is used. */
475 tlbsel = vcpu_e500->mas4 >> 28 & 0x1;
476 victim = (tlbsel == 0) ? tlb0_get_next_victim(vcpu_e500) : 0;
478 vcpu_e500->mas0 = MAS0_TLBSEL(tlbsel) | MAS0_ESEL(victim)
479 | MAS0_NV(vcpu_e500->guest_tlb_nv[tlbsel]);
480 vcpu_e500->mas1 = (vcpu_e500->mas6 & MAS6_SPID0)
481 | (vcpu_e500->mas6 & (MAS6_SAS ? MAS1_TS : 0))
482 | (vcpu_e500->mas4 & MAS4_TSIZED(~0));
483 vcpu_e500->mas2 &= MAS2_EPN;
484 vcpu_e500->mas2 |= vcpu_e500->mas4 & MAS2_ATTRIB_MASK;
485 vcpu_e500->mas3 &= MAS3_U0 | MAS3_U1 | MAS3_U2 | MAS3_U3;
492 int kvmppc_e500_emul_tlbwe(struct kvm_vcpu *vcpu)
494 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
499 int tlbsel, esel, stlbsel, sesel;
501 tlbsel = get_tlb_tlbsel(vcpu_e500);
502 esel = get_tlb_esel(vcpu_e500, tlbsel);
504 gtlbe = &vcpu_e500->guest_tlb[tlbsel][esel];
506 if (get_tlb_v(gtlbe) && tlbsel == 1) {
507 eaddr = get_tlb_eaddr(gtlbe);
508 tid = get_tlb_tid(gtlbe);
509 kvmppc_e500_tlb1_invalidate(vcpu_e500, eaddr,
510 get_tlb_end(gtlbe), tid);
513 gtlbe->mas1 = vcpu_e500->mas1;
514 gtlbe->mas2 = vcpu_e500->mas2;
515 gtlbe->mas3 = vcpu_e500->mas3;
516 gtlbe->mas7 = vcpu_e500->mas7;
518 KVMTRACE_5D(GTLB_WRITE, vcpu, vcpu_e500->mas0,
519 gtlbe->mas1, gtlbe->mas2, gtlbe->mas3, gtlbe->mas7,
522 /* Invalidate shadow mappings for the about-to-be-clobbered TLBE. */
523 if (tlbe_is_host_safe(vcpu, gtlbe)) {
527 gtlbe->mas1 &= ~MAS1_TSIZE(~0);
528 gtlbe->mas1 |= MAS1_TSIZE(BOOKE_PAGESZ_4K);
531 sesel = kvmppc_e500_stlbe_map(vcpu_e500, 0, esel);
537 eaddr = get_tlb_eaddr(gtlbe);
538 raddr = get_tlb_raddr(gtlbe);
540 /* Create a 4KB mapping on the host.
541 * If the guest wanted a large page,
542 * only the first 4KB is mapped here and the rest
543 * are mapped on the fly. */
545 sesel = kvmppc_e500_tlb1_map(vcpu_e500, eaddr,
546 raddr >> PAGE_SHIFT, gtlbe);
552 write_host_tlbe(vcpu_e500, stlbsel, sesel);
558 int kvmppc_mmu_itlb_index(struct kvm_vcpu *vcpu, gva_t eaddr)
560 unsigned int as = !!(vcpu->arch.msr & MSR_IS);
562 return kvmppc_e500_tlb_search(vcpu, eaddr, get_cur_pid(vcpu), as);
565 int kvmppc_mmu_dtlb_index(struct kvm_vcpu *vcpu, gva_t eaddr)
567 unsigned int as = !!(vcpu->arch.msr & MSR_DS);
569 return kvmppc_e500_tlb_search(vcpu, eaddr, get_cur_pid(vcpu), as);
572 void kvmppc_mmu_itlb_miss(struct kvm_vcpu *vcpu)
574 unsigned int as = !!(vcpu->arch.msr & MSR_IS);
576 kvmppc_e500_deliver_tlb_miss(vcpu, vcpu->arch.pc, as);
579 void kvmppc_mmu_dtlb_miss(struct kvm_vcpu *vcpu)
581 unsigned int as = !!(vcpu->arch.msr & MSR_DS);
583 kvmppc_e500_deliver_tlb_miss(vcpu, vcpu->arch.fault_dear, as);
586 gpa_t kvmppc_mmu_xlate(struct kvm_vcpu *vcpu, unsigned int index,
589 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
591 &vcpu_e500->guest_tlb[tlbsel_of(index)][esel_of(index)];
592 u64 pgmask = get_tlb_bytes(gtlbe) - 1;
594 return get_tlb_raddr(gtlbe) | (eaddr & pgmask);
597 void kvmppc_mmu_destroy(struct kvm_vcpu *vcpu)
599 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
602 for (tlbsel = 0; tlbsel < 2; tlbsel++)
603 for (i = 0; i < vcpu_e500->guest_tlb_size[tlbsel]; i++)
604 kvmppc_e500_shadow_release(vcpu_e500, tlbsel, i);
606 /* discard all guest mapping */
610 void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, gpa_t gpaddr,
613 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
614 int tlbsel = tlbsel_of(index);
615 int esel = esel_of(index);
625 gfn_t gfn = gpaddr >> PAGE_SHIFT;
627 = &vcpu_e500->guest_tlb[tlbsel][esel];
630 sesel = kvmppc_e500_tlb1_map(vcpu_e500, eaddr, gfn, gtlbe);
638 write_host_tlbe(vcpu_e500, stlbsel, sesel);
641 int kvmppc_e500_tlb_search(struct kvm_vcpu *vcpu,
642 gva_t eaddr, unsigned int pid, int as)
644 struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
647 for (tlbsel = 0; tlbsel < 2; tlbsel++) {
648 esel = kvmppc_e500_tlb_index(vcpu_e500, eaddr, tlbsel, pid, as);
650 return index_of(tlbsel, esel);
656 void kvmppc_e500_tlb_setup(struct kvmppc_vcpu_e500 *vcpu_e500)
660 /* Insert large initial mapping for guest. */
661 tlbe = &vcpu_e500->guest_tlb[1][0];
662 tlbe->mas1 = MAS1_VALID | MAS1_TSIZE(BOOKE_PAGESZ_256M);
664 tlbe->mas3 = E500_TLB_SUPER_PERM_MASK;
667 /* 4K map for serial output. Used by kernel wrapper. */
668 tlbe = &vcpu_e500->guest_tlb[1][1];
669 tlbe->mas1 = MAS1_VALID | MAS1_TSIZE(BOOKE_PAGESZ_4K);
670 tlbe->mas2 = (0xe0004500 & 0xFFFFF000) | MAS2_I | MAS2_G;
671 tlbe->mas3 = (0xe0004500 & 0xFFFFF000) | E500_TLB_SUPER_PERM_MASK;
675 int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
677 tlb1_entry_num = mfspr(SPRN_TLB1CFG) & 0xFFF;
679 vcpu_e500->guest_tlb_size[0] = KVM_E500_TLB0_SIZE;
680 vcpu_e500->guest_tlb[0] =
681 kzalloc(sizeof(struct tlbe) * KVM_E500_TLB0_SIZE, GFP_KERNEL);
682 if (vcpu_e500->guest_tlb[0] == NULL)
685 vcpu_e500->shadow_tlb_size[0] = KVM_E500_TLB0_SIZE;
686 vcpu_e500->shadow_tlb[0] =
687 kzalloc(sizeof(struct tlbe) * KVM_E500_TLB0_SIZE, GFP_KERNEL);
688 if (vcpu_e500->shadow_tlb[0] == NULL)
691 vcpu_e500->guest_tlb_size[1] = KVM_E500_TLB1_SIZE;
692 vcpu_e500->guest_tlb[1] =
693 kzalloc(sizeof(struct tlbe) * KVM_E500_TLB1_SIZE, GFP_KERNEL);
694 if (vcpu_e500->guest_tlb[1] == NULL)
695 goto err_out_shadow0;
697 vcpu_e500->shadow_tlb_size[1] = tlb1_entry_num;
698 vcpu_e500->shadow_tlb[1] =
699 kzalloc(sizeof(struct tlbe) * tlb1_entry_num, GFP_KERNEL);
700 if (vcpu_e500->shadow_tlb[1] == NULL)
703 vcpu_e500->shadow_pages[0] = (struct page **)
704 kzalloc(sizeof(struct page *) * KVM_E500_TLB0_SIZE, GFP_KERNEL);
705 if (vcpu_e500->shadow_pages[0] == NULL)
706 goto err_out_shadow1;
708 vcpu_e500->shadow_pages[1] = (struct page **)
709 kzalloc(sizeof(struct page *) * tlb1_entry_num, GFP_KERNEL);
710 if (vcpu_e500->shadow_pages[1] == NULL)
716 kfree(vcpu_e500->shadow_pages[0]);
718 kfree(vcpu_e500->shadow_tlb[1]);
720 kfree(vcpu_e500->guest_tlb[1]);
722 kfree(vcpu_e500->shadow_tlb[0]);
724 kfree(vcpu_e500->guest_tlb[0]);
729 void kvmppc_e500_tlb_uninit(struct kvmppc_vcpu_e500 *vcpu_e500)
731 kfree(vcpu_e500->shadow_pages[1]);
732 kfree(vcpu_e500->shadow_pages[0]);
733 kfree(vcpu_e500->shadow_tlb[1]);
734 kfree(vcpu_e500->guest_tlb[1]);
735 kfree(vcpu_e500->shadow_tlb[0]);
736 kfree(vcpu_e500->guest_tlb[0]);