Skip to contentSkip to conversation

ppc patch queue 2013-04-11 for 3.9

GIT PULL New Alexander Graf 1 participant 5 messages Apr 11, 2013

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

Hi Marcelo / Gleb,

This is my current patch queue for ppc against master for 3.9. Please pull.

This patch set contains a number of patches fixing regressions in e500 KVM code.

Some of these patches (the top 3 ones) also went into kvm/next by accident, so there will be duplicate git commits with these later. But IMHO I'd prefer to have a working 3.9 release rather than a clean git history.

Alex

The following changes since commit 31880c37c11e28cb81c70757e38392b42e695dc6:
Linus Torvalds (1):

        Linux 3.9-rc6

are available in the git repository at:

git://github.com/agraf/linux-2.6.git kvm-ppc-3.9

Scott Wood (4):
kvm/powerpc/e500mc: fix tlb invalidation on cpu migration kvm/ppc/e500: h2g_tlb1_rmap: esel 0 is valid kvm/ppc/e500: g2h_tlb1_map: clear old bit before setting new bit kvm/ppc/e500: eliminate tlb_refs

 arch/powerpc/kvm/e500.h          |   24 ++++-------
 arch/powerpc/kvm/e500_mmu_host.c |   84 ++++++++++++-------------------------
 arch/powerpc/kvm/e500mc.c        |    7 +++-
 3 files changed, 41 insertions(+), 74 deletions(-)
#1 lore raw

PATCH 1/4 kvm/powerpc/e500mc: fix tlb invalidation on cpu migration

From: Scott Wood <[email protected]>

The existing check handles the case where we've migrated to a different core than we last ran on, but it doesn't handle the case where we're still on the same cpu we last ran on, but some other vcpu has run on this cpu in the meantime.

Without this, guest segfaults (and other misbehavior) have been seen in smp guests.

---
 arch/powerpc/kvm/e500mc.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
arch/powerpc/kvm/e500mc.c +6 -1
index 1f89d26..2f4baa0 100644
@@ -108,6 +108,8 @@ void kvmppc_mmu_msr_notify(struct kvm_vcpu *vcpu, u32 old_msr)
 {
 }
 
+static DEFINE_PER_CPU(struct kvm_vcpu *, last_vcpu_on_cpu);
+
 void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 {
 	struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
@@ -136,8 +138,11 @@ void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
 	mtspr(SPRN_GDEAR, vcpu->arch.shared->dar);
 	mtspr(SPRN_GESR, vcpu->arch.shared->esr);
 
-	if (vcpu->arch.oldpir != mfspr(SPRN_PIR))
+	if (vcpu->arch.oldpir != mfspr(SPRN_PIR) ||
+	    __get_cpu_var(last_vcpu_on_cpu) != vcpu) {
 		kvmppc_e500_tlbil_all(vcpu_e500);
+		__get_cpu_var(last_vcpu_on_cpu) = vcpu;
+	}
 
 	kvmppc_load_guest_fp(vcpu);
 }
Signature · 1 line
1.6.0.2
#2 lore raw

PATCH 2/4 kvm/ppc/e500: h2g_tlb1_rmap: esel 0 is valid

In reply to Alexander Graf

From: Scott Wood <[email protected]>

Add one to esel values in h2g_tlb1_rmap, so that "no mapping" can be distinguished from "esel 0". Note that we're not saved by the fact that host esel 0 is reserved for non-KVM use, because KVM host esel numbering is not the raw host numbering (see to_htlb1_esel).

---
 arch/powerpc/kvm/e500_mmu_host.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/kvm/e500_mmu_host.c +2 -2
index a222edf..35fb80e 100644
@@ -511,10 +511,10 @@ static int kvmppc_e500_tlb1_map_tlb1(struct kvmppc_vcpu_e500 *vcpu_e500,
 	vcpu_e500->g2h_tlb1_map[esel] |= (u64)1 << sesel;
 	vcpu_e500->gtlb_priv[1][esel].ref.flags |= E500_TLB_BITMAP;
 	if (vcpu_e500->h2g_tlb1_rmap[sesel]) {
-		unsigned int idx = vcpu_e500->h2g_tlb1_rmap[sesel];
+		unsigned int idx = vcpu_e500->h2g_tlb1_rmap[sesel] - 1;
 		vcpu_e500->g2h_tlb1_map[idx] &= ~(1ULL << sesel);
 	}
-	vcpu_e500->h2g_tlb1_rmap[sesel] = esel;
+	vcpu_e500->h2g_tlb1_rmap[sesel] = esel + 1;
 
 	return sesel;
 }
Signature · 1 line
1.6.0.2
#3 lore raw

PATCH 3/4 kvm/ppc/e500: g2h_tlb1_map: clear old bit before setting new bit

In reply to Alexander Graf

From: Scott Wood <[email protected]>

It's possible that we're using the same host TLB1 slot to map (a presumably different portion of) the same guest TLB1 entry. Clear the bit in the map before setting it, so that if the esels are the same the bit will remain set.

---
 arch/powerpc/kvm/e500_mmu_host.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
arch/powerpc/kvm/e500_mmu_host.c +4 -3
index 35fb80e..8e72b21 100644
@@ -507,13 +507,14 @@ static int kvmppc_e500_tlb1_map_tlb1(struct kvmppc_vcpu_e500 *vcpu_e500,
 	if (unlikely(vcpu_e500->host_tlb1_nv >= tlb1_max_shadow_size()))
 		vcpu_e500->host_tlb1_nv = 0;
 
-	vcpu_e500->tlb_refs[1][sesel] = *ref;
-	vcpu_e500->g2h_tlb1_map[esel] |= (u64)1 << sesel;
-	vcpu_e500->gtlb_priv[1][esel].ref.flags |= E500_TLB_BITMAP;
 	if (vcpu_e500->h2g_tlb1_rmap[sesel]) {
 		unsigned int idx = vcpu_e500->h2g_tlb1_rmap[sesel] - 1;
 		vcpu_e500->g2h_tlb1_map[idx] &= ~(1ULL << sesel);
 	}
+
+	vcpu_e500->tlb_refs[1][sesel] = *ref;
+	vcpu_e500->gtlb_priv[1][esel].ref.flags |= E500_TLB_BITMAP;
+	vcpu_e500->g2h_tlb1_map[esel] |= (u64)1 << sesel;
 	vcpu_e500->h2g_tlb1_rmap[sesel] = esel + 1;
 
 	return sesel;
Signature · 1 line
1.6.0.2
#4 lore raw

PATCH 4/4 kvm/ppc/e500: eliminate tlb_refs

In reply to Alexander Graf

From: Scott Wood <[email protected]>

Commit 523f0e5421c12610527c620b983b443f329e3a32 ("KVM: PPC: E500:
Explicitly mark shadow maps invalid") began using E500_TLB_VALID for guest TLB1 entries, and skipping invalidations if it's not set.

However, when E500_TLB_VALID was set for such entries, it was on a fake local ref, and so the invalidations never happen. gtlb_privs is documented as being only for guest TLB0, though we already violate that with E500_TLB_BITMAP.

Now that we have MMU notifiers, and thus don't need to actually retain a reference to the mapped pages, get rid of tlb_refs, and use gtlb_privs for E500_TLB_VALID in TLB1.

Since we can have more than one host TLB entry for a given tlbe_ref, be careful not to clear existing flags that are relevant to other host TLB entries when preparing a new host TLB entry.

---
 arch/powerpc/kvm/e500.h          |   24 ++++--------
 arch/powerpc/kvm/e500_mmu_host.c |   75 +++++++++++---------------------------
 2 files changed, 30 insertions(+), 69 deletions(-)
arch/powerpc/kvm/e500.h +8 -16
index 41cefd4..33db48a 100644
@@ -26,17 +26,20 @@
 #define E500_PID_NUM   3
 #define E500_TLB_NUM   2
 
-#define E500_TLB_VALID 1
-#define E500_TLB_BITMAP 2
+/* entry is mapped somewhere in host TLB */
+#define E500_TLB_VALID		(1 << 0)
+/* TLB1 entry is mapped by host TLB1, tracked by bitmaps */
+#define E500_TLB_BITMAP		(1 << 1)
+/* TLB1 entry is mapped by host TLB0 */
 #define E500_TLB_TLB0		(1 << 2)
 
 struct tlbe_ref {
-	pfn_t pfn;
-	unsigned int flags; /* E500_TLB_* */
+	pfn_t pfn;		/* valid only for TLB0, except briefly */
+	unsigned int flags;	/* E500_TLB_* */
 };
 
 struct tlbe_priv {
-	struct tlbe_ref ref; /* TLB0 only -- TLB1 uses tlb_refs */
+	struct tlbe_ref ref;
 };
 
 #ifdef CONFIG_KVM_E500V2
@@ -63,17 +66,6 @@ struct kvmppc_vcpu_e500 {
 
 	unsigned int gtlb_nv[E500_TLB_NUM];
 
-	/*
-	 * information associated with each host TLB entry --
-	 * TLB1 only for now.  If/when guest TLB1 entries can be
-	 * mapped with host TLB0, this will be used for that too.
-	 *
-	 * We don't want to use this for guest TLB0 because then we'd
-	 * have the overhead of doing the translation again even if
-	 * the entry is still in the guest TLB (e.g. we swapped out
-	 * and back, and our host TLB entries got evicted).
-	 */
-	struct tlbe_ref *tlb_refs[E500_TLB_NUM];
 	unsigned int host_tlb1_nv;
 
 	u32 svr;
arch/powerpc/kvm/e500_mmu_host.c +21 -49

154 lines not on this page · raw message

Signature · 1 line
1.6.0.2