Skip to contentSkip to conversation

KVM: PPC: e500: clear up confusion between host and

PATCH Superseded Scott Wood 2 participants 4 messages Jul 7, 2011 – Jul 18, 2011

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Scott Wood

author
#0 lore raw

PATCH 4/5 KVM: PPC: e500: clear up confusion between host and

Split out the portions of tlbe_priv that should be associated with host entries into tlbe_ref. Base victim selection on the number of hardware entries, not guest entries.

For TLB1, where one guest entry can be mapped by multiple host entries, we use the host tlbe_ref for tracking page references. For the guest TLB0 entries, we still track it with gtlb_priv, to avoid having to retranslate if the entry is evicted from the host TLB but not the guest TLB.

---
 arch/powerpc/include/asm/kvm_e500.h   |   20 +++-
 arch/powerpc/include/asm/mmu-book3e.h |    1 +
 arch/powerpc/kvm/e500_tlb.c           |  265 +++++++++++++++++++++++----------
 arch/powerpc/kvm/e500_tlb.h           |   17 --
 4 files changed, 207 insertions(+), 96 deletions(-)
arch/powerpc/include/asm/kvm_e500.h +19 -1
index adbfca9..87aab98 100644
@@ -32,11 +32,15 @@ struct tlbe{
 #define E500_TLB_VALID 1
 #define E500_TLB_DIRTY 2
 
-struct tlbe_priv {
+struct tlbe_ref {
 	pfn_t pfn;
 	unsigned int flags; /* E500_TLB_* */
 };
 
+struct tlbe_priv {
+	struct tlbe_ref ref; /* TLB0 only -- TLB1 uses tlb_refs */
+};
+
 struct vcpu_id_table;
 
 struct kvmppc_vcpu_e500 {
@@ -49,6 +53,20 @@ struct kvmppc_vcpu_e500 {
 	unsigned int gtlb_size[E500_TLB_NUM];
 	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 host_pid[E500_PID_NUM];
 	u32 pid[E500_PID_NUM];
 	u32 svr;
arch/powerpc/include/asm/mmu-book3e.h +1 -0
index 3ea0f9a..4c30de3 100644
@@ -165,6 +165,7 @@
 #define TLBnCFG_MAXSIZE		0x000f0000	/* Maximum Page Size (v1.0) */
 #define TLBnCFG_MAXSIZE_SHIFT	16
 #define TLBnCFG_ASSOC		0xff000000	/* Associativity */
+#define TLBnCFG_ASSOC_SHIFT	24
 
 /* TLBnPS encoding */
 #define TLBnPS_4K		0x00000004
arch/powerpc/kvm/e500_tlb.c +181 -77

441 lines not on this page · raw message

arch/powerpc/kvm/e500_tlb.h +0 -17
index 59b88e9..b587f69 100644
@@ -155,23 +155,6 @@ static inline unsigned int get_tlb_esel_bit(
 	return (vcpu_e500->mas0 >> 16) & 0xfff;
 }
 
-static inline unsigned int get_tlb_esel(
-		const struct kvmppc_vcpu_e500 *vcpu_e500,
-		int tlbsel)
-{
-	unsigned int esel = get_tlb_esel_bit(vcpu_e500);
-
-	if (tlbsel = 0) {
-		esel &= KVM_E500_TLB0_WAY_NUM_MASK;
-		esel |= ((vcpu_e500->mas2 >> 12) & KVM_E500_TLB0_WAY_SIZE_MASK)
-				<< KVM_E500_TLB0_WAY_NUM_BIT;
-	} else {
-		esel &= KVM_E500_TLB1_SIZE - 1;
-	}
-
-	return esel;
-}
-
 static inline int tlbe_is_host_safe(const struct kvm_vcpu *vcpu,
 			const struct tlbe *tlbe)
 {
Signature · 1 line
1.7.4.1
#1 lore raw

Re: [PATCH 4/5] KVM: PPC: e500: clear up confusion between host and guest entries

Quoted 94 lines · Scott Wood

Split out the portions of tlbe_priv that should be associated with host entries into tlbe_ref. Base victim selection on the number of hardware entries, not guest entries.

For TLB1, where one guest entry can be mapped by multiple host entries, we use the host tlbe_ref for tracking page references. For the guest TLB0 entries, we still track it with gtlb_priv, to avoid having to retranslate if the entry is evicted from the host TLB but not the guest TLB.

---

arch/powerpc/include/asm/kvm_e500.h   |   20 +++-
arch/powerpc/include/asm/mmu-book3e.h |    1 +
arch/powerpc/kvm/e500_tlb.c           |  265 +++++++++++++++++++++++----------
arch/powerpc/kvm/e500_tlb.h           |   17 --
4 files changed, 207 insertions(+), 96 deletions(-)
arch/powerpc/include/asm/kvm_e500.h +19 -1
index adbfca9..87aab98 100644
@@ -32,11 +32,15 @@ struct tlbe{
 #define E500_TLB_VALID 1
 #define E500_TLB_DIRTY 2
 
-struct tlbe_priv {
+struct tlbe_ref {
 	pfn_t pfn;
 	unsigned int flags; /* E500_TLB_* */
 };
 
+struct tlbe_priv {
+	struct tlbe_ref ref; /* TLB0 only -- TLB1 uses tlb_refs */
+};
+
 struct vcpu_id_table;
 
 struct kvmppc_vcpu_e500 {
@@ -49,6 +53,20 @@ struct kvmppc_vcpu_e500 {
 	unsigned int gtlb_size[E500_TLB_NUM];
 	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 host_pid[E500_PID_NUM];
 	u32 pid[E500_PID_NUM];
 	u32 svr;
arch/powerpc/include/asm/mmu-book3e.h +1 -0
index 3ea0f9a..4c30de3 100644
@@ -165,6 +165,7 @@
 #define TLBnCFG_MAXSIZE		0x000f0000	/* Maximum Page Size (v1.0) */
 #define TLBnCFG_MAXSIZE_SHIFT	16
 #define TLBnCFG_ASSOC		0xff000000	/* Associativity */
+#define TLBnCFG_ASSOC_SHIFT	24
 
 /* TLBnPS encoding */
 #define TLBnPS_4K		0x00000004
arch/powerpc/kvm/e500_tlb.c +2 -1
index a872732..526170f 100644
@@ -12,6 +12,7 @@
 * published by the Free Software Foundation.
 */
 
+#include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/slab.h>
 #include <linux/string.h>
@@ -26,7 +27,7 @@
 #include "trace.h"
 #include "timing.h"
 
-#define to_htlb1_esel(esel) (tlb1_entry_num - (esel) - 1)
+#define to_htlb1_esel(esel) (tlb_host_entries[1] - (esel) - 1)
 
 struct id {
 	unsigned long val;

arch/powerpc/kvm/e500_tlb.c static DEFINE_PER_CPU(struct pcpu_id_table, pcpu_sids); · line 69

Quoted 7 lines
arch/powerpc/kvm/e500_tlb.c +3 -1
@@ -63,7 +64,9 @@ static DEFINE_PER_CPU(struct pcpu_id_table, pcpu_sids);
 * The valid range of shadow ID is [1..255] */
 static DEFINE_PER_CPU(unsigned long, pcpu_last_used_sid);
 
-static unsigned int tlb1_entry_num;
+static unsigned int tlb_host_entries[2];
+static unsigned int tlb_host_ways[2];
+static unsigned int tlb_host_sets[2];

The 2 probably means "number of host TLBs", right? Isn't there a #define for this? In fact, it might be even more readable if we just shoved those into a struct:
tlb_host_entries[1] would then become host_tlb[1].entries for example :). If you don't think it'd improve the code, I'd be fine without a struct too.

Also, since you're putting knowledge about the target MMU into this anyways (2 TLBs), can we prepopulate the contents of these and declare them const? The compiler should then be able to optimize the code a bit more.

In fact, reading the code a bit more, we could use the same information for the guest side, no? So we could have a host_tlb and a guest_tlb info struct and fold some of your helper functions below to merely accessing one of the two globals.

Alex

author
#2 lore raw
In reply to Scott Wood
Quoted 6 lines · On Mon, 18 Jul 2011 11:49:10 +0200 Alexander Graf <[email protected]> wrote:
Quoted 4 lines · Scott Wood
arch/powerpc/kvm/e500_tlb.c +0 -0
@@ -63,7 +64,9 @@ static DEFINE_PER_CPU(struct pcpu_id_table, pcpu_sids);
 * The valid range of shadow ID is [1..255] */
 static DEFINE_PER_CPU(unsigned long, pcpu_last_used_sid);
 
Quoted 6 lines

arch/powerpc/kvm/e500_tlb.c static DEFINE_PER_CPU(struct pcpu_id_table, pcpu_sids); · line 69

Quoted 4 lines
arch/powerpc/kvm/e500_tlb.c +3 -1
-static unsigned int tlb1_entry_num;
+static unsigned int tlb_host_entries[2];
+static unsigned int tlb_host_ways[2];
+static unsigned int tlb_host_sets[2];

The 2 probably means "number of host TLBs", right? Isn't there a #define for this?

Looks like there is.

Quoted 3 lines

In fact, it might be even more readable if we just shoved those into a struct:
tlb_host_entries[1] would then become host_tlb[1].entries for example :).

OK.

Quoted 1 line

Also, since you're putting knowledge about the target MMU into this anyways (2 TLBs),

This is the host MMU, not target.

Quoted 2 lines

can we prepopulate the contents of these and declare them const? The compiler should then be able to optimize the code a bit more.

We populate these at runtime. TLB0 ways/entries is different on e500v1 versus e500v2. TLB1 entries is different on e500mc, though we don't support a single kernel image with e500v2 and e500mc. And who knows what might happen in the future.

As far as optimization goes, we should see what the bottlenecks are first.

Quoted 1 line

In fact, reading the code a bit more, we could use the same information for the guest side, no? So we could have a host_tlb and a guest_tlb info struct and fold some of your helper > functions below to merely accessing one of the two globals.

guest tlb is not a global. We can have multiple vcpus, and their tlbs are not necessarily configured the same.

-Scott

#3 lore raw

Re: [PATCH 4/5] KVM: PPC: e500: clear up confusion between host and guest entries

In reply to Scott Wood
Quoted 22 lines · Scott Wood
Quoted 6 lines · On Mon, 18 Jul 2011 11:49:10 +0200 Alexander Graf <[email protected]> wrote:
Quoted 4 lines · Scott Wood
arch/powerpc/kvm/e500_tlb.c +0 -0
@@ -63,7 +64,9 @@ static DEFINE_PER_CPU(struct pcpu_id_table, pcpu_sids);
 * The valid range of shadow ID is [1..255] */
 static DEFINE_PER_CPU(unsigned long, pcpu_last_used_sid);
 
Quoted 6 lines

arch/powerpc/kvm/e500_tlb.c static DEFINE_PER_CPU(struct pcpu_id_table, pcpu_sids); · line 69

Quoted 4 lines
arch/powerpc/kvm/e500_tlb.c +3 -1
-static unsigned int tlb1_entry_num;
+static unsigned int tlb_host_entries[2];
+static unsigned int tlb_host_ways[2];
+static unsigned int tlb_host_sets[2];

The 2 probably means "number of host TLBs", right? Isn't there a #define for this?

Looks like there is.

Quoted 3 lines

In fact, it might be even more readable if we just shoved those into a struct:
tlb_host_entries[1] would then become host_tlb[1].entries for example :).

Quoted 5 lines

OK.

Quoted 1 line

Also, since you're putting knowledge about the target MMU into this anyways (2 TLBs),

This is the host MMU, not target.

Yes, that was my point. We're compiling the kernel for a specific CPU anyways, so it might make sense to just base on that knowledge.

Quoted 10 lines
Quoted 3 lines

can we prepopulate the contents of these and declare them const? The compiler should then be able to optimize the code a bit more.

We populate these at runtime. TLB0 ways/entries is different on e500v1 versus e500v2. TLB1 entries is different on e500mc, though we don't support a single kernel image with e500v2 and e500mc. And who knows what might happen in the future.

As far as optimization goes, we should see what the bottlenecks are first.

I agree - just fantasizing here.

Quoted 5 lines
Quoted 2 lines

In fact, reading the code a bit more, we could use the same information for the guest side, no? So we could have a host_tlb and a guest_tlb info struct and fold some of your helper > functions below to merely accessing one of the two globals.

guest tlb is not a global. We can have multiple vcpus, and their tlbs are not necessarily configured the same.

Yes, sorry for being so fuzzy in terminology here. You know what I meant :). Host info global, vcpu info local of course.

Alex