Skip to contentSkip to conversation

KVM: PPC: e6500: TLB emulation for IND entries

PATCH In review Laurentiu Tudor 1 participant 1 message Sep 24, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 KVM: PPC: e6500: TLB emulation for IND entries

Handle indirect entries (IND) in TLB emulation code. Translation size of IND entries differs from the size of referred Page Tables (Linux guests now use IND of 2MB for 4KB PTs) and this requires careful tweaking of the existing logic.

TLB search emulation requires additional search in HW TLB0 (since entries might be directly added by HTW) and found entries should be presented to the guest with RPN changed from PFN to GFN. There might be more GFNs pointing to the same PFN so the only way to get the corresponding GFN is to search it in guest's PTE. If the IND entry for the corresponding PT is not available just invalidate guest's ea and report a tlbsx miss. This patch only implements the invalidation and lets a TODO note for searching HW TLB0.

[[email protected]: addressed review feedback,
refactoring, cleanup & other fixes]

---
 arch/powerpc/include/asm/mmu-book3e.h |  2 +
 arch/powerpc/kvm/e500.h               | 93 +++++++++++++++++++++++++++++------
 arch/powerpc/kvm/e500_mmu.c           | 92 ++++++++++++++++++++++++++--------
 arch/powerpc/kvm/e500_mmu_host.c      | 30 ++++++++++-
 arch/powerpc/kvm/e500mc.c             | 45 +++++++++++++++--
 5 files changed, 222 insertions(+), 40 deletions(-)
arch/powerpc/include/asm/mmu-book3e.h +2 -0
index 9dbad3c..c8a1518 100644
@@ -61,6 +61,7 @@
 #define MAS1_IPROT		0x40000000
 #define MAS1_TID(x)		(((x) << 16) & 0x3FFF0000)
 #define MAS1_IND		0x00002000
+#define MAS1_IND_SHIFT		13
 #define MAS1_TS			0x00001000
 #define MAS1_TSIZE_MASK		0x00000f80
 #define MAS1_TSIZE_SHIFT	7
@@ -97,6 +98,7 @@
 #define MAS4_TLBSEL_MASK	MAS0_TLBSEL_MASK
 #define MAS4_TLBSELD(x) 	MAS0_TLBSEL(x)
 #define MAS4_INDD		0x00008000	/* Default IND */
+#define MAS4_INDD_SHIFT		15
 #define MAS4_TSIZED(x)		MAS1_TSIZE(x)
 #define MAS4_X0D		0x00000040
 #define MAS4_X1D		0x00000020
arch/powerpc/kvm/e500.h +78 -15

121 lines not on this page · raw message

arch/powerpc/kvm/e500_mmu.c +72 -20

209 lines not on this page · raw message

arch/powerpc/kvm/e500_mmu_host.c +29 -1
index 99ad88a..aafa864 100644
@@ -421,7 +421,8 @@ static void kvmppc_e500_setup_stlbe(
 	BUG_ON(!(ref->flags & E500_TLB_VALID));
 
 	/* Force IPROT=0 for all guest mappings. */
-	stlbe->mas1 = MAS1_TSIZE(tsize) | get_tlb_sts(gtlbe) | MAS1_VALID;
+	stlbe->mas1 = MAS1_TSIZE(tsize) | get_tlb_sts(gtlbe) | MAS1_VALID |
+		      (get_tlb_ind(vcpu, gtlbe) << MAS1_IND_SHIFT);
 	stlbe->mas2 = (gvaddr & MAS2_EPN) | (ref->flags & E500_TLB_MAS2_ATTR);
 	stlbe->mas7_3 = ((u64)pfn << PAGE_SHIFT) |
 			e500_shadow_mas3_attrib(gtlbe->mas7_3, pr);
@@ -444,6 +445,7 @@ static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500,
 	pte_t *ptep;
 	unsigned int wimg = 0;
 	pgd_t *pgdir;
+	int ind;
 	unsigned long flags;
 
 	/* used to check for invalidations in progress */
@@ -461,6 +463,15 @@ static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500,
 	slot = gfn_to_memslot(vcpu_e500->vcpu.kvm, gfn);
 	hva = gfn_to_hva_memslot(slot, gfn);
 
+	/*
+	 * An IND entry points to a Page Table which has a different size
+	 * compared to the translation size that it covers:
+	 *	page size bytes = (tsize bytes / 4KB) * 8 bytes
+	 * this gives:
+	 *	psize = tsize - BOOK3E_PAGESZ_4K - 7;
+	 */
+	ind = get_tlb_ind(&vcpu_e500->vcpu, gtlbe);
+
 	if (tlbsel = 1) {
 		struct vm_area_struct *vma;
 		down_read(&current->mm->mmap_sem);
@@ -497,6 +508,8 @@ static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500,
 
 			tsize = (gtlbe->mas1 & MAS1_TSIZE_MASK) >>
 				MAS1_TSIZE_SHIFT;
+			if (ind)
+				tsize -= BOOK3E_PAGESZ_4K + 7;
 
 			/*
 			 * MMUv1 doesn't implement the lowest tsize bit,
@@ -507,6 +520,15 @@ static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500,
 			tsize = max(BOOK3E_PAGESZ_4K, tsize);
 
 			/*
+			 * On MMUv2 IND case, the TSIZE just calculated above
+			 * (size of the actual page table, not the translation
+			 * size) may end up smaller than 4K, so don't
+			 * touch it in this case.
+			 */
+			if (!ind)
+				tsize = max(BOOK3E_PAGESZ_4K, tsize);
+
+			/*
 			 * Calculate TSIZE increment. MMUv2 supports
 			 * power of 2K translations while MMUv1 is limited
 			 * to power of 4K sizes.
@@ -547,6 +569,8 @@ static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500,
 
 			tsize = (gtlbe->mas1 & MAS1_TSIZE_MASK) >>
 				MAS1_TSIZE_SHIFT;
+			if (ind)
+				tsize -= BOOK3E_PAGESZ_4K + 7;
 
 			/*
 			 * Take the largest page size that satisfies both host
@@ -614,6 +638,10 @@ static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500,
 	}
 	kvmppc_e500_ref_setup(ref, gtlbe, pfn, wimg);
 
+	/* Restore translation size for indirect entries */
+	if (ind)
+		tsize += BOOK3E_PAGESZ_4K + 7;
+
 	kvmppc_e500_setup_stlbe(&vcpu_e500->vcpu, gtlbe, tsize,
 				ref, gvaddr, stlbe);
 
arch/powerpc/kvm/e500mc.c +41 -4

73 lines not on this page · raw message

Signature · 1 line
1.8.3.1