Skip to contentSkip to conversation

KVM: PPC: Book3S PR: Use SLB entry 0

PATCH New Alexander Graf 1 participant 2 messages May 28, 2014

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

PATCH v2 1/2 KVM: PPC: Book3S PR: Use SLB entry 0

We didn't make use of SLB entry 0 because ... of no good reason. SLB entry 0 will always be used by the Linux linear SLB entry, so the fact that slbia does not invalidate it doesn't matter as we overwrite SLB 0 on exit anyway.

Just enable use of SLB entry 0 for our shadow SLB code.

---

v1 -> v2:

- flush ERAT by writing 0 to slb0

---
 arch/powerpc/kvm/book3s_64_mmu_host.c | 11 ++++-------
 arch/powerpc/kvm/book3s_64_slb.S      |  3 ++-
 2 files changed, 6 insertions(+), 8 deletions(-)
arch/powerpc/kvm/book3s_64_mmu_host.c +4 -7
index e2efb85..0ac9839 100644
@@ -271,11 +271,8 @@ static int kvmppc_mmu_next_segment(struct kvm_vcpu *vcpu, ulong esid)
 	int found_inval = -1;
 	int r;
 
-	if (!svcpu->slb_max)
-		svcpu->slb_max = 1;
-
 	/* Are we overwriting? */
-	for (i = 1; i < svcpu->slb_max; i++) {
+	for (i = 0; i < svcpu->slb_max; i++) {
 		if (!(svcpu->slb[i].esid & SLB_ESID_V))
 			found_inval = i;
 		else if ((svcpu->slb[i].esid & ESID_MASK) == esid) {
@@ -285,7 +282,7 @@ static int kvmppc_mmu_next_segment(struct kvm_vcpu *vcpu, ulong esid)
 	}
 
 	/* Found a spare entry that was invalidated before */
-	if (found_inval > 0) {
+	if (found_inval >= 0) {
 		r = found_inval;
 		goto out;
 	}
@@ -359,7 +356,7 @@ void kvmppc_mmu_flush_segment(struct kvm_vcpu *vcpu, ulong ea, ulong seg_size)
 	ulong seg_mask = -seg_size;
 	int i;
 
-	for (i = 1; i < svcpu->slb_max; i++) {
+	for (i = 0; i < svcpu->slb_max; i++) {
 		if ((svcpu->slb[i].esid & SLB_ESID_V) &&
 		    (svcpu->slb[i].esid & seg_mask) == ea) {
 			/* Invalidate this entry */
@@ -373,7 +370,7 @@ void kvmppc_mmu_flush_segment(struct kvm_vcpu *vcpu, ulong ea, ulong seg_size)
 void kvmppc_mmu_flush_segments(struct kvm_vcpu *vcpu)
 {
 	struct kvmppc_book3s_shadow_vcpu *svcpu = svcpu_get(vcpu);
-	svcpu->slb_max = 1;
+	svcpu->slb_max = 0;
 	svcpu->slb[0].esid = 0;
 	svcpu_put(svcpu);
 }
arch/powerpc/kvm/book3s_64_slb.S +2 -1
index 596140e..84c52c6 100644
@@ -138,7 +138,8 @@ slb_do_enter:
 
 	/* Restore bolted entries from the shadow and fix it along the way */
 
-	/* We don't store anything in entry 0, so we don't need to take care of it */
+	li	r0, r0
+	slbmte	r0, r0
 	slbia
 	isync
 
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH v2 2/2 KVM: PPC: Book3S PR: Rework SLB switching code

On LPAR guest systems Linux enables the shadow SLB to indicate to the hypervisor a number of SLB entries that always have to be available.

Today we go through this shadow SLB and disable all ESID's valid bits. However, pHyp doesn't like this approach very much and honors us with fancy machine checks.

Fortunately the shadow SLB descriptor also has an entry that indicates the number of valid entries following. During the lifetime of a guest we can just swap that value to 0 and don't have to worry about the SLB restoration magic.

While we're touching the code, let's also make it more readable (get rid of rldicl), allow it to deal with a dynamic number of bolted SLB entries and only do shadow SLB swizzling on LPAR systems.

---

v1 -> v2:

- use andis.
- remove superfluous isync/sync
- add KVM warning comments in SLB bolting code

---
 arch/powerpc/kernel/paca.c       |  3 ++
 arch/powerpc/kvm/book3s_64_slb.S | 83 ++++++++++++++++++----------------------
 arch/powerpc/mm/slb.c            |  2 +-
 3 files changed, 42 insertions(+), 46 deletions(-)
arch/powerpc/kernel/paca.c +3 -0
index ad302f8..d6e195e 100644
@@ -98,6 +98,9 @@ static inline void free_lppacas(void) { }
 /*
  * 3 persistent SLBs are registered here.  The buffer will be zero
  * initially, hence will all be invaild until we actually write them.
+ *
+ * If you make the number of persistent SLB entries dynamic, please also
+ * update PR KVM to flush and restore them accordingly.
  */
 static struct slb_shadow *slb_shadow;
 
arch/powerpc/kvm/book3s_64_slb.S +38 -45

118 lines not on this page · raw message

arch/powerpc/mm/slb.c +1 -1
index 9d1d33c..964a5f6 100644
@@ -97,7 +97,7 @@ static inline void create_shadowed_slbe(unsigned long ea, int ssize,
 static void __slb_flush_and_rebolt(void)
 {
 	/* If you change this make sure you change SLB_NUM_BOLTED
-	 * appropriately too. */
+	 * and PR KVM appropriately too. */
 	unsigned long linear_llp, vmalloc_llp, lflags, vflags;
 	unsigned long ksp_esid_data, ksp_vsid_data;
 
Signature · 1 line
1.8.1.4