KVM: PPC: e500: Stop keeping shadow TLB
Subsystems (2)
PATCH 10/13 KVM: PPC: e500: Stop keeping shadow TLB
From: Liu Yu <[email protected]>
Instead of a fully separate set of TLB entries, keep just the pfn and dirty status.
--- arch/powerpc/include/asm/kvm_e500.h | 20 ++- arch/powerpc/kvm/e500_tlb.c | 317 +++++++++++++++------------------- 2 files changed, 154 insertions(+), 183 deletions(-)
arch/powerpc/include/asm/kvm_e500.h +14 -6
@@ -29,15 +29,23 @@ struct tlbe{u32 mas7; }; +#define E500_TLB_VALID 1 +#define E500_TLB_DIRTY 2 + +struct tlbe_priv { +pfn_t pfn; +unsigned int flags;/* E500_TLB_* */ +}; +struct kvmppc_vcpu_e500 {/* Unmodified copy of the guest's TLB. */ -struct tlbe *guest_tlb[E500_TLB_NUM ]; -/* TLB that's actually used when the guest is running. */ -struct tlbe *shadow_tlb[E500_TLB_NUM ]; +struct tlbe *gtlb_arch[E500_TLB_NUM ]; + +/* KVM internal information associated with each guest TLB entry */ +struct tlbe_priv *gtlb_priv[E500_TLB_NUM ]; -unsigned int guest_tlb_size[E500_TLB_NUM ]; -unsigned int shadow_tlb_size[E500_TLB_NUM ]; -unsigned int guest_tlb_nv[E500_TLB_NUM ]; +unsigned int gtlb_size[E500_TLB_NUM ]; +unsigned int gtlb_nv[E500_TLB_NUM ];u32 host_pid[E500_PID_NUM ];u32 pid[E500_PID_NUM ];
arch/powerpc/kvm/e500_tlb.c +137 -174
571 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 10/13 KVM: PPC: e500: Stop keeping shadow TLB
From: Liu Yu <[email protected]>
Instead of a fully separate set of TLB entries, keep just the pfn and dirty status.
--- arch/powerpc/include/asm/kvm_e500.h | 20 ++- arch/powerpc/kvm/e500_tlb.c | 317 +++++++++++++++------------------- 2 files changed, 154 insertions(+), 183 deletions(-)
arch/powerpc/include/asm/kvm_e500.h +14 -6
@@ -29,15 +29,23 @@ struct tlbe{u32 mas7; }; +#define E500_TLB_VALID 1 +#define E500_TLB_DIRTY 2 + +struct tlbe_priv { +pfn_t pfn; +unsigned int flags;/* E500_TLB_* */ +}; +struct kvmppc_vcpu_e500 {/* Unmodified copy of the guest's TLB. */ -struct tlbe *guest_tlb[E500_TLB_NUM ]; -/* TLB that's actually used when the guest is running. */ -struct tlbe *shadow_tlb[E500_TLB_NUM ]; +struct tlbe *gtlb_arch[E500_TLB_NUM ]; + +/* KVM internal information associated with each guest TLB entry */ +struct tlbe_priv *gtlb_priv[E500_TLB_NUM ]; -unsigned int guest_tlb_size[E500_TLB_NUM ]; -unsigned int shadow_tlb_size[E500_TLB_NUM ]; -unsigned int guest_tlb_nv[E500_TLB_NUM ]; +unsigned int gtlb_size[E500_TLB_NUM ]; +unsigned int gtlb_nv[E500_TLB_NUM ];u32 host_pid[E500_PID_NUM ];u32 pid[E500_PID_NUM ];
arch/powerpc/kvm/e500_tlb.c +137 -174
571 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Quoted 51 lines · Scott Wood
From: Liu Yu <[email protected]>
Instead of a fully separate set of TLB entries, keep just the pfn and dirty status.
Signed-off-by Liu Yu <[email protected]>Signed-off-by Scott Wood <[email protected]>---
arch/powerpc/include/asm/kvm_e500.h| 20 ++-arch/powerpc/kvm/e500_tlb.c| 317 +++++++++++++++-------------------2 files changed, 154 insertions(+), 183 deletions(-)arch/powerpc/include/asm/kvm_e500.h +14
-6@@ -29,15 +29,23 @@ struct tlbe{u32 mas7; }; +#define E500_TLB_VALID 1 +#define E500_TLB_DIRTY 2 + +struct tlbe_priv { +pfn_t pfn; +unsigned int flags;/* E500_TLB_* */ +}; +struct kvmppc_vcpu_e500 {/* Unmodified copy of the guest's TLB. */ -struct tlbe *guest_tlb[E500_TLB_NUM ]; -/* TLB that's actually used when the guest is running. */ -struct tlbe *shadow_tlb[E500_TLB_NUM ]; +struct tlbe *gtlb_arch[E500_TLB_NUM ]; + +/* KVM internal information associated with each guest TLB entry */ +struct tlbe_priv *gtlb_priv[E500_TLB_NUM ]; -unsigned int guest_tlb_size[E500_TLB_NUM ]; -unsigned int shadow_tlb_size[E500_TLB_NUM ]; -unsigned int guest_tlb_nv[E500_TLB_NUM ]; +unsigned int gtlb_size[E500_TLB_NUM ]; +unsigned int gtlb_nv[E500_TLB_NUM ];u32 host_pid[E500_PID_NUM ];u32 pid[E500_PID_NUM ];arch/powerpc/kvm/e500_tlb.c +0
-0
arch/powerpc/kvm/e500_tlb.c void kvmppc_dump_tlbs(struct kvm_vcpu *vcpu) · line 42
Quoted 2 lines
arch/powerpc/kvm/e500_tlb.c +0
-0@@ -41,25 +41,14 @@ void kvmppc_dump_tlbs(struct kvm_vcpu *vcpu)for (tlbsel =0 ; tlbsel <2 ; tlbsel++) {
The 2 here should be E500_TLB_NUM
Quoted 24 lines
arch/powerpc/kvm/e500_tlb.c +2
-13printk ("Guest TLB%d:\n" , tlbsel); -for (i =0 ; i < vcpu_e500->guest_tlb_size[tlbsel]; i++) { - tlbe = &vcpu_e500->guest_tlb[tlbsel][i]; +for (i =0 ; i < vcpu_e500->gtlb_size[tlbsel]; i++) { + tlbe = &vcpu_e500->gtlb_arch[tlbsel][i];if (tlbe->mas1 &MAS1_VALID )printk (" G[%d][%3d] | %08X | %08X | %08X | %08X |\n" , tlbsel, i, tlbe->mas1, tlbe->mas2, tlbe->mas3, tlbe->mas7); } } - -for (tlbsel =0 ; tlbsel <2 ; tlbsel++) { -printk ("Shadow TLB%d:\n" , tlbsel); -for (i =0 ; i < vcpu_e500->shadow_tlb_size[tlbsel]; i++) { - tlbe = &vcpu_e500->shadow_tlb[tlbsel][i]; -if (tlbe->mas1 &MAS1_VALID ) -printk (" S[%d][%3d] | %08X | %08X | %08X | %08X |\n" , - tlbsel, i, tlbe->mas1, tlbe->mas2, - tlbe->mas3, tlbe->mas7); - } - } }
[...]
Quoted 8 lines
arch/powerpc/kvm/e500_tlb.c +6
-0+static inline void kvmppc_e500_setup_stlbe (struct kvmppc_vcpu_e500 *vcpu_e500, +struct tlbe *gtlbe,int tsize, +struct tlbe_priv *priv, +u64 gvaddr,struct tlbe *stlbe) +{ +pfn_t pfn = priv->pfn;
arch/powerpc/kvm/e500_tlb.c static inline void kvmppc_e500_deliver_tlb_miss(struct kvm_vcpu *vcpu, · line 267
Quoted 10 lines
arch/powerpc/kvm/e500_tlb.c +10
-0+ +/* Force TS=1 IPROT=0 for all guest mappings. */ + stlbe->mas1 =MAS1_TSIZE (tsize) + |MAS1_TID (get_tlb_tid (gtlbe)) |MAS1_TS |MAS1_VALID ; + stlbe->mas2 = (gvaddr &MAS2_EPN ) + |e500_shadow_mas2_attrib (gtlbe->mas2, + vcpu_e500->vcpu.arch.shared->msr &MSR_PR ); + stlbe->mas3 = ((pfn <<PAGE_SHIFT ) &MAS3_RPN ) + |e500_shadow_mas3_attrib (gtlbe->mas3, + vcpu_e500->vcpu.arch.shared->msr &MSR_PR );
This is another source of slowness. Guest PR should only be yet another bit to account for in the TID, so we can keep both active at the same time. That should be possible with the shadow PID code, right?
Alex
Quoted 9 lines · On Tue, 14 Jun 2011 12:40:22 +0200 Alexander Graf <[email protected]> wrote:
Quoted 6 lines · Scott Wood
arch/powerpc/kvm/e500_tlb.c +0
-0@@ -41,25 +41,14 @@ void kvmppc_dump_tlbs(struct kvm_vcpu *vcpu)
Quoted 3 lines
arch/powerpc/kvm/e500_tlb.c void kvmppc_dump_tlbs(struct kvm_vcpu *vcpu) · line 42
Quoted 1 line
arch/powerpc/kvm/e500_tlb.c +0
-0for (tlbsel =0 ; tlbsel <2 ; tlbsel++) {The 2 here should be
E500_TLB_NUM
This patch didn't change this line, and this whole function can come out once we can dump the TLB with qemu.
Quoted 10 lines
Quoted 10 lines
arch/powerpc/kvm/e500_tlb.c +10
-0+static inline void kvmppc_e500_setup_stlbe (struct kvmppc_vcpu_e500 *vcpu_e500, +struct tlbe *gtlbe,int tsize, +struct tlbe_priv *priv, +u64 gvaddr,struct tlbe *stlbe) +{ +pfn_t pfn = priv->pfn; + +/* Force TS=1 IPROT=0 for all guest mappings. */ + stlbe->mas1 =MAS1_TSIZE (tsize) + |MAS1_TID (get_tlb_tid (gtlbe)) |MAS1_TS |MAS1_VALID ;
Quoted 8 lines
arch/powerpc/kvm/e500_tlb.c static inline void kvmppc_e500_deliver_tlb_miss(struct kvm_vcpu *vcpu, · line 267
Quoted 6 lines
arch/powerpc/kvm/e500_tlb.c +6
-0+ stlbe->mas2 = (gvaddr &MAS2_EPN ) + |e500_shadow_mas2_attrib (gtlbe->mas2, + vcpu_e500->vcpu.arch.shared->msr &MSR_PR ); + stlbe->mas3 = ((pfn <<PAGE_SHIFT ) &MAS3_RPN ) + |e500_shadow_mas3_attrib (gtlbe->mas3, + vcpu_e500->vcpu.arch.shared->msr &MSR_PR );This is another source of slowness. Guest PR should only be yet another bit to account for in the TID, so we can keep both active at the same time. That should be possible with the shadow PID code, right?
Not sure what you mean. We do account for guest PR with a separate shadow PID. The forcing of MSR_PR here is still needed because we still always run the guest with the real MSR[PR] set.
-Scott
Quoted 38 lines · Scott Wood
Quoted 9 lines · On Tue, 14 Jun 2011 12:40:22 +0200 Alexander Graf <[email protected]> wrote:
Quoted 6 lines · Scott Wood
arch/powerpc/kvm/e500_tlb.c +0
-0@@ -41,25 +41,14 @@ void kvmppc_dump_tlbs(struct kvm_vcpu *vcpu)Quoted 3 lines
arch/powerpc/kvm/e500_tlb.c void kvmppc_dump_tlbs(struct kvm_vcpu *vcpu) · line 42
Quoted 1 line
arch/powerpc/kvm/e500_tlb.c +0
-0for (tlbsel =0 ; tlbsel <2 ; tlbsel++) {The 2 here should be
E500_TLB_NUMThis patch didn't change this line, and this whole function can come out once we can dump the TLB with qemu.
Quoted 10 lines
Quoted 10 lines
arch/powerpc/kvm/e500_tlb.c +10
-0+static inline void kvmppc_e500_setup_stlbe (struct kvmppc_vcpu_e500 *vcpu_e500, +struct tlbe *gtlbe,int tsize, +struct tlbe_priv *priv, +u64 gvaddr,struct tlbe *stlbe) +{ +pfn_t pfn = priv->pfn; + +/* Force TS=1 IPROT=0 for all guest mappings. */ + stlbe->mas1 =MAS1_TSIZE (tsize) + |MAS1_TID (get_tlb_tid (gtlbe)) |MAS1_TS |MAS1_VALID ;Quoted 8 lines
arch/powerpc/kvm/e500_tlb.c static inline void kvmppc_e500_deliver_tlb_miss(struct kvm_vcpu *vcpu, · line 267
Quoted 6 lines
arch/powerpc/kvm/e500_tlb.c +6
-0+ stlbe->mas2 = (gvaddr &MAS2_EPN ) + |e500_shadow_mas2_attrib (gtlbe->mas2, + vcpu_e500->vcpu.arch.shared->msr &MSR_PR ); + stlbe->mas3 = ((pfn <<PAGE_SHIFT ) &MAS3_RPN ) + |e500_shadow_mas3_attrib (gtlbe->mas3, + vcpu_e500->vcpu.arch.shared->msr &MSR_PR );This is another source of slowness. Guest PR should only be yet another bit to account for in the TID, so we can keep both active at the same time. That should be possible with the shadow PID code, right?
Quoted 3 lines
Not sure what you mean. We do account for guest PR with a separate shadow PID. The forcing of
MSR_PRhere is still needed because we still always run the guest with the real MSR[PR] set.
Well, I just looked at mas3_attrib:
static inline u32 e500_shadow_mas3_attrib(u32 mas3, int usermode)
{
/* Mask off reserved bits. */
mas3 &= MAS3_ATTRIB_MASK;
if (!usermode) {
/* Guest is in supervisor mode,
* so we need to translate guest
* supervisor permissions into user permissions. */
mas3 &= ~E500_TLB_USER_PERM_MASK;
mas3 |= (mas3 & E500_TLB_SUPER_PERM_MASK) << 1;
}
return mas3 | E500_TLB_SUPER_PERM_MASK;
}... and figured that it does something different depending on the guest's PR mode. I didn't quite understand what's going on here.
Looking at it again though, it seems like this goes again into the same direction as the comment above. Since we don't have a clear cut between guest TLB code and host TLB code, things just randomly get munged together :).
Either way, this code looks completely valid. Sorry for the fuss.
Alex