KVM: PPC: e500: Shadow TLB Improvements
Subsystems (3)
cover KVM: PPC: e500: Shadow TLB Improvements
This patch set improves the shadow TLB handling of our e500 target.
The really important bit here is that with these patches applied, we can map guest TLB1 entries into the host's TLB0. This gives a significant performance improvement as you can see below.
Alex
---
without patch, using 4k backed memory:
$ time for i in {1..1000}; do /bin/echo > /dev/null; done
real 0m12.947s
user 0m1.076s
sys 0m9.720swith hugetlbfs:
$ time for i in {1..1000}; do /bin/echo > /dev/null; donereal 0m3.262s
user 0m0.464s
sys 0m0.236s
with patches applied, using 4k backed memory:
$ time for i in {1..1000}; do /bin/echo > /dev/null; donereal 0m4.446s
user 0m0.380s
sys 0m0.644s
Alexander Graf (3):
KVM: PPC: e500: Call kvmppc_mmu_map for initial mapping
KVM: PPC: E500: Split host and guest MMU parts
KVM: PPC: e500: Implement TLB1-in-TLB0 mapping
arch/powerpc/kvm/Makefile | 9 +- arch/powerpc/kvm/e500.h | 5 +- arch/powerpc/kvm/e500_mmu.c | 812 +++++++++++++++++++++ arch/powerpc/kvm/e500_mmu_host.c | 686 ++++++++++++++++++ arch/powerpc/kvm/e500_mmu_host.h | 20 + arch/powerpc/kvm/e500_tlb.c | 1430 -------------------------------------- 6 files changed, 1528 insertions(+), 1434 deletions(-) create mode 100644 arch/powerpc/kvm/e500_mmu.c create mode 100644 arch/powerpc/kvm/e500_mmu_host.c create mode 100644 arch/powerpc/kvm/e500_mmu_host.h delete mode 100644 arch/powerpc/kvm/e500_tlb.c
PATCH 1/3 KVM: PPC: e500: Call kvmppc_mmu_map for initial mapping
When emulating tlbwe, we want to automatically map the entry that just got written in our shadow TLB map, because chances are quite high that it's going to be used very soon.
Today this happens explicitly, duplicating all the logic that is in kvmppc_mmu_map() already. Just call that one instead.
--- arch/powerpc/kvm/e500.h | 4 ++- arch/powerpc/kvm/e500_tlb.c | 45 +++++++++++------------------------------- 2 files changed, 15 insertions(+), 34 deletions(-)
arch/powerpc/kvm/e500.h +3 -1
@@ -113,8 +113,10 @@ static inline struct kvmppc_vcpu_e500 *to_e500(struct kvm_vcpu *vcpu)#define KVM_E500_TLB0_SIZE (KVM_E500_TLB0_WAY_SIZE * KVM_E500_TLB0_WAY_NUM)#define KVM_E500_TLB1_SIZE 16 +#define KVM_E500_INDEX_FORCE_MAP 0x80000000 +#define index_of (tlbsel, esel) (((tlbsel) << 16) | ((esel) & 0xFFFF)) -#define tlbsel_of (index) ((index) >> 16) +#define tlbsel_of (index) (((index) >> 16) & 0x3)#define esel_of (index) ((index) & 0xFFFF)#define E500_TLB_USER_PERM_MASK (MAS3_UX|MAS3_UR|MAS3_UW)
arch/powerpc/kvm/e500_tlb.c +12 -33
76 lines not on this page · raw message
Signature · 1 line
1.6.0.2
Re: [PATCH 1/3] KVM: PPC: e500: Call kvmppc_mmu_map for initial mapping
arch/powerpc/kvm/e500_tlb.c void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 · line 1005
Quoted 7 lines · Alexander Graf
arch/powerpc/kvm/e500_tlb.c +1
-1@@ -1024,9 +1001,11 @@ void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, gpa_t gpaddr, {struct kvmppc_vcpu_e500 *vcpu_e500 =to_e500 (vcpu);struct tlbe_priv *priv; -struct kvm_book3e_206_tlb_entry *gtlbe, stlbe; +struct kvm_book3e_206_tlb_entry *gtlbe, stlbe = {};
Is there a code path in which stlbe gets used but not fully filled in without this?
Quoted 19 lines
arch/powerpc/kvm/e500_tlb.c +2
-0int tlbsel =tlbsel_of (index);int esel =esel_of (index); +/* Needed for initial map, where we can't use the cached value */ +int force_map = index &KVM_E500_INDEX_FORCE_MAP ;int stlbsel, sesel;arch/powerpc/kvm/e500_tlb.c +1
-1gtlbe =get_entry (vcpu_e500, tlbsel, esel);@@ -1038,7 +1017,7 @@ void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, gpa_t gpaddr, priv = &vcpu_e500->gtlb_priv[tlbsel][esel];/* Only triggers after clear_tlb_refs */ -if (unlikely (!(priv->ref.flags &E500_TLB_VALID ))) +if (force_map ||unlikely (!(priv->ref.flags &E500_TLB_VALID )))kvmppc_e500_tlb0_map (vcpu_e500, esel, &stlbe);(quoted diff) +0
-0else kvmppc_e500_setup_stlbe(vcpu, gtlbe,
Quoted 1 line
BOOK3E_PAGESZ_4K,
It seems a bit odd to overload index rather than adding a flags parameter...
It also seems like it would be cleaner to just invalidate the old entry in tlbwe, and then this function doesn't need to change at all. I am a bit confused by how invalidation is currently operating -- why is E500_TLB_VALID not cleared on invalidations (except for MMU API stuff and MMU notifiers)?
-Scott
Re: [PATCH 1/3] KVM: PPC: e500: Call kvmppc_mmu_map for initial mapping
Quoted 10 lines · Scott Wood
arch/powerpc/kvm/e500_tlb.c void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, gpa_t gpaddr, · line 1004
Quoted 6 lines · Alexander Graf
arch/powerpc/kvm/e500_tlb.c +1
-1@@ -1024,9 +1001,11 @@ void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, gpa_t gpaddr, {struct kvmppc_vcpu_e500 *vcpu_e500 =to_e500 (vcpu);struct tlbe_priv *priv; -struct kvm_book3e_206_tlb_entry *gtlbe, stlbe; +struct kvm_book3e_206_tlb_entry *gtlbe, stlbe = {};Is there a code path in which stlbe gets used but not fully filled in without this?
I am hoping not, but when I wrote this patch gcc suddenly jumped at me claiming that the whole struct can get used uninitialized:
arch/powerpc/kvm/e500_mmu_host.c: In function ‘kvmppc_mmu_map’:arch/powerpc/kvm/e500_mmu_host.c:533: error: ‘stlbe.mas1’ may be used uninitialized in this function arch/powerpc/kvm/e500_mmu_host.c:533: error: ‘stlbe.mas2’ may be used uninitialized in this function arch/powerpc/kvm/e500_mmu_host.c:533: error: ‘stlbe.mas7_3’ may be used uninitialized in this function arch/powerpc/kvm/e500_mmu_host.c:533: error: ‘stlbe.mas8’ may be used uninitialized in this function
If you have any idea where this could come from, please let me know :).
Quoted 10 lines
Quoted 10 lines
arch/powerpc/kvm/e500_tlb.c +2
-0int tlbsel =tlbsel_of (index);int esel =esel_of (index); +/* Needed for initial map, where we can't use the cached value */ +int force_map = index &KVM_E500_INDEX_FORCE_MAP ;int stlbsel, sesel; gtlbe =get_entry (vcpu_e500, tlbsel, esel);@@ -1038,7 +1017,7 @@ void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, gpa_t gpaddr, priv = &vcpu_e500->gtlb_priv[tlbsel][esel];/* Only triggers after clear_tlb_refs */
Quoted 8 lines
arch/powerpc/kvm/e500_tlb.c void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, gpa_t gpaddr, · line 1023
Quoted 5 lines
arch/powerpc/kvm/e500_tlb.c +1
-1-if (unlikely (!(priv->ref.flags &E500_TLB_VALID ))) +if (force_map ||unlikely (!(priv->ref.flags &E500_TLB_VALID )))kvmppc_e500_tlb0_map (vcpu_e500, esel, &stlbe);else kvmppc_e500_setup_stlbe(vcpu, gtlbe, BOOK3E_PAGESZ_4K,It seems a bit odd to overload index rather than adding a flags parameter...
Yeah, I mostly wanted to refrain from touching 440 code. But if you prefer that, I can certainly do so :).
Quoted 5 lines
It also seems like it would be cleaner to just invalidate the old entry in tlbwe, and then this function doesn't need to change at all. I am a bit confused by how invalidation is currently operating -- why is
E500_TLB_VALIDnot cleared on invalidations (except for MMU API stuff and MMU notifiers)?
Consider me as confused as you are.
Alex
Re: [PATCH 1/3] KVM: PPC: e500: Call kvmppc_mmu_map for initial mapping
Quoted 43 lines · Alexander Graf
Quoted 10 lines · Scott Wood
arch/powerpc/kvm/e500_tlb.c void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, gpa_t gpaddr, · line 1004
Quoted 6 lines · Alexander Graf
arch/powerpc/kvm/e500_tlb.c +1
-1@@ -1024,9 +1001,11 @@ void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, gpa_t gpaddr, {struct kvmppc_vcpu_e500 *vcpu_e500 =to_e500 (vcpu);struct tlbe_priv *priv; -struct kvm_book3e_206_tlb_entry *gtlbe, stlbe; +struct kvm_book3e_206_tlb_entry *gtlbe, stlbe = {};Is there a code path in which stlbe gets used but not fully filled in without this?
I am hoping not, but when I wrote this patch gcc suddenly jumped at me claiming that the whole struct can get used uninitialized:
arch/powerpc/kvm/e500_mmu_host.c: In function ‘kvmppc_mmu_map’:arch/powerpc/kvm/e500_mmu_host.c:533: error: ‘stlbe.mas1’ may be used uninitialized in this functionarch/powerpc/kvm/e500_mmu_host.c:533: error: ‘stlbe.mas2’ may be used uninitialized in this functionarch/powerpc/kvm/e500_mmu_host.c:533: error: ‘stlbe.mas7_3’ may be used uninitialized in this functionarch/powerpc/kvm/e500_mmu_host.c:533: error: ‘stlbe.mas8’ may be used uninitialized in this functionIf you have any idea where this could come from, please let me know :).
Quoted 10 lines
Quoted 10 lines
arch/powerpc/kvm/e500_tlb.c +2
-0int tlbsel =tlbsel_of (index);int esel =esel_of (index); +/* Needed for initial map, where we can't use the cached value */ +int force_map = index &KVM_E500_INDEX_FORCE_MAP ;int stlbsel, sesel; gtlbe =get_entry (vcpu_e500, tlbsel, esel);@@ -1038,7 +1017,7 @@ void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, gpa_t gpaddr, priv = &vcpu_e500->gtlb_priv[tlbsel][esel];/* Only triggers after clear_tlb_refs */ Quoted 8 lines
arch/powerpc/kvm/e500_tlb.c void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, gpa_t gpaddr, · line 1023
Quoted 5 lines
arch/powerpc/kvm/e500_tlb.c +1
-1-if (unlikely (!(priv->ref.flags &E500_TLB_VALID ))) +if (force_map ||unlikely (!(priv->ref.flags &E500_TLB_VALID )))kvmppc_e500_tlb0_map (vcpu_e500, esel, &stlbe);else kvmppc_e500_setup_stlbe(vcpu, gtlbe, BOOK3E_PAGESZ_4K,It seems a bit odd to overload index rather than adding a flags parameter...
Quoted 5 lines
Yeah, I mostly wanted to refrain from touching 440 code. But if you prefer that, I can certainly do so :).
Quoted 3 lines
It also seems like it would be cleaner to just invalidate the old entry in tlbwe, and then this function doesn't need to change at all. I am a bit confused by how invalidation is currently operating
Well, this bit is obvious. It's done by kvmppc_e500_shadow_map when it calls kvmppc_e500_ref_release(), right?
Why it's not done explicitly though is a really good question :).
Alex
Re: [PATCH 1/3] KVM: PPC: e500: Call kvmppc_mmu_map for initial mapping
Quoted 8 lines · Alexander Graf
Quoted 4 lines · Alexander Graf
Quoted 1 line · Scott Wood
It also seems like it would be cleaner to just invalidate the old
entry
Quoted 8 lines
Quoted 1 line
Quoted 1 line
in tlbwe, and then this function doesn't need to change at all. I
am a
Quoted 1 line
Quoted 1 line
bit confused by how invalidation is currently operating
Well, this bit is obvious. It's done by
kvmppc_e500_shadow_mapwhen it callskvmppc_e500_ref_release(), right?Why it's not done explicitly though is a really good question :).
Yeah, I saw that but considered it (in combination with not reaching this function if the gtlbe is invalid, and with always preloading the host entry when the guest does tlbwe) to be why we're getting away with it rather than why it was done that way.
-Scott
Re: [PATCH 1/3] KVM: PPC: e500: Call kvmppc_mmu_map for initial mapping
In reply to Alexander GrafQuoted 29 lines · Alexander Graf
Quoted 2 lines · Scott Wood
Review void kvmppc_mmu_map(struct kvm_vcpu *vcpu,
Quoted 1 line · Alexander Graf
(quoted diff) +0
-0@@ -1024,9 +1001,11 @@ void kvmppc_mmu_map(struct kvm_vcpu *vcpu,u64 eaddr,
gpa_tgpaddr,Quoted 7 lines
arch/powerpc/kvm/e500_tlb.c void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, gpa_t gpaddr, · line 1004
Quoted 5 lines
arch/powerpc/kvm/e500_tlb.c +1
-1{struct kvmppc_vcpu_e500 *vcpu_e500 =to_e500 (vcpu);struct tlbe_priv *priv; -struct kvm_book3e_206_tlb_entry *gtlbe, stlbe; +struct kvm_book3e_206_tlb_entry *gtlbe, stlbe = {};Is there a code path in which stlbe gets used but not fully filled
in
Quoted 1 line
without this?
I am hoping not, but when I wrote this patch gcc suddenly jumped at me claiming that the whole struct can get used uninitialized:
arch/powerpc/kvm/e500_mmu_host.c: In function ‘kvmppc_mmu_map’:arch/powerpc/kvm/e500_mmu_host.c:533: error: ‘stlbe.mas1’ may be used uninitialized in this functionarch/powerpc/kvm/e500_mmu_host.c:533: error: ‘stlbe.mas2’ may be used uninitialized in this functionarch/powerpc/kvm/e500_mmu_host.c:533: error: ‘stlbe.mas7_3’ may be used uninitialized in this functionarch/powerpc/kvm/e500_mmu_host.c:533: error: ‘stlbe.mas8’ may be used uninitialized in this function
Quoted 2 lines
If you have any idea where this could come from, please let me know :).
I can't reproduce with either GCC 4.5.1 or GCC 4.7.2. Maybe from a non-final version of the patch? It would be nice to not have this, and have GCC be able to detect if we're actually missing something rather than have it get zeroed.
BTW, it's "stlbe = {}" in this patch but after the file split, somehow come out as "stlbe = { }". Was that patch supposed to be just a simple cut and paste of part of the file?
-Scott
Re: [PATCH 1/3] KVM: PPC: e500: Call kvmppc_mmu_map for initial mapping
Quoted 20 lines · Scott Wood
Quoted 11 lines · Alexander Graf
Quoted 10 lines · Scott Wood
arch/powerpc/kvm/e500_tlb.c void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, gpa_t gpaddr, · line 1004
Quoted 6 lines · Alexander Graf
arch/powerpc/kvm/e500_tlb.c +1
-1@@ -1024,9 +1001,11 @@ void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, gpa_t gpaddr, {struct kvmppc_vcpu_e500 *vcpu_e500 =to_e500 (vcpu);struct tlbe_priv *priv; -struct kvm_book3e_206_tlb_entry *gtlbe, stlbe; +struct kvm_book3e_206_tlb_entry *gtlbe, stlbe = {};Is there a code path in which stlbe gets used but not fully filled in without this?
Quoted 7 lines
I am hoping not, but when I wrote this patch gcc suddenly jumped at me claiming that the whole struct can get used uninitialized:
arch/powerpc/kvm/e500_mmu_host.c: In function ‘kvmppc_mmu_map’:arch/powerpc/kvm/e500_mmu_host.c:533: error: ‘stlbe.mas1’ may be used uninitialized in this functionarch/powerpc/kvm/e500_mmu_host.c:533: error: ‘stlbe.mas2’ may be used uninitialized in this functionarch/powerpc/kvm/e500_mmu_host.c:533: error: ‘stlbe.mas7_3’ may be used uninitialized in this functionarch/powerpc/kvm/e500_mmu_host.c:533: error: ‘stlbe.mas8’ may be used uninitialized in this function
If you have any idea where this could come from, please let me know :).
Quoted 1 line
I can't reproduce with either GCC 4.5.1 or GCC 4.7.2. Maybe from a non-final version of the patch? It would be nice to not have this, and have GCC be able to detect if we're actually missing something rather than have it get zeroed.
Ok, I'll try without again :).
Quoted 1 line
BTW, it's "stlbe = {}" in this patch but after the file split, somehow come out as "stlbe = { }". Was that patch supposed to be just a simple cut and paste of part of the file?
It started off as that, but constant rebasing to fix issues I encountered might have slipped in :).
Alex
Re: [PATCH 1/3] KVM: PPC: e500: Call kvmppc_mmu_map for initial mapping
In reply to Scott WoodQuoted 20 lines · Scott Wood
Quoted 11 lines · Alexander Graf
Quoted 10 lines · Scott Wood
arch/powerpc/kvm/e500_tlb.c void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, gpa_t gpaddr, · line 1004
Quoted 6 lines · Alexander Graf
arch/powerpc/kvm/e500_tlb.c +1
-1@@ -1024,9 +1001,11 @@ void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, gpa_t gpaddr, {struct kvmppc_vcpu_e500 *vcpu_e500 =to_e500 (vcpu);struct tlbe_priv *priv; -struct kvm_book3e_206_tlb_entry *gtlbe, stlbe; +struct kvm_book3e_206_tlb_entry *gtlbe, stlbe = {};Is there a code path in which stlbe gets used but not fully filled in without this?
Quoted 7 lines
I am hoping not, but when I wrote this patch gcc suddenly jumped at me claiming that the whole struct can get used uninitialized:
arch/powerpc/kvm/e500_mmu_host.c: In function ‘kvmppc_mmu_map’:arch/powerpc/kvm/e500_mmu_host.c:533: error: ‘stlbe.mas1’ may be used uninitialized in this functionarch/powerpc/kvm/e500_mmu_host.c:533: error: ‘stlbe.mas2’ may be used uninitialized in this functionarch/powerpc/kvm/e500_mmu_host.c:533: error: ‘stlbe.mas7_3’ may be used uninitialized in this functionarch/powerpc/kvm/e500_mmu_host.c:533: error: ‘stlbe.mas8’ may be used uninitialized in this function
If you have any idea where this could come from, please let me know :).
Quoted 1 line
I can't reproduce with either GCC 4.5.1 or GCC 4.7.2. Maybe from a non-final version of the patch? It would be nice to not have this, and have GCC be able to detect if we're actually missing something rather than have it get zeroed.
Bleks - the warning was actually genuine. I have no idea why it never triggered before, but when kvmppc_e500_shadow_map errored out with if (is_error_noslot_pfn(pfn)) then the masX fields were never set in stlbe.
I've added proper error passing now. Let's see if I can still manage to split all of this into patches...
Alex
PATCH 2/3 KVM: PPC: E500: Split host and guest MMU parts
In reply to Alexander GrafThis patch splits the file e500_tlb.c into e500_mmu.c (guest TLB handling) and e500_mmu_host.c (host TLB handling).
The main benefit of this split is readability and maintainability. It's just a lot harder to write dirty code :).
--- arch/powerpc/kvm/Makefile | 9 +- arch/powerpc/kvm/e500_mmu.c | 812 ++++++++++++++++++++++ arch/powerpc/kvm/e500_mmu_host.c | 654 ++++++++++++++++++ arch/powerpc/kvm/e500_mmu_host.h | 20 + arch/powerpc/kvm/e500_tlb.c | 1409 -------------------------------------- 5 files changed, 1492 insertions(+), 1412 deletions(-) create mode 100644 arch/powerpc/kvm/e500_mmu.c create mode 100644 arch/powerpc/kvm/e500_mmu_host.c create mode 100644 arch/powerpc/kvm/e500_mmu_host.h delete mode 100644 arch/powerpc/kvm/e500_tlb.c
arch/powerpc/kvm/Makefile +6 -3
@@ -10,7 +10,8 @@ common-objs-y = $(addprefix ../../../virt/kvm/, kvm_main.o coalesced_mmio.o \ eventfd.o) CFLAGS_44x_tlb.o := -I. -CFLAGS_e500_tlb.o := -I. +CFLAGS_e500_mmu.o := -I. +CFLAGS_e500_mmu_host.o := -I. CFLAGS_emulate.o := -I. common-objs-y += powerpc.o emulate.o
@@ -35,7 +36,8 @@ kvm-e500-objs := \ booke_emulate.o \ booke_interrupts.o \ e500.o \ - e500_tlb.o \ + e500_mmu.o \ + e500_mmu_host.o \ e500_emulate.o kvm-objs-$(CONFIG_KVM_E500V2) := $(kvm-e500-objs)
@@ -45,7 +47,8 @@ kvm-e500mc-objs := \ booke_emulate.o \ bookehv_interrupts.o \ e500mc.o \ - e500_tlb.o \ + e500_mmu.o \ + e500_mmu_host.o \ e500_emulate.o kvm-objs-$(CONFIG_KVM_E500MC) := $(kvm-e500mc-objs)
arch/powerpc/kvm/e500_mmu.c new file +812 -0
812 lines not on this page · raw message
arch/powerpc/kvm/e500_mmu_host.c new file +654 -0
654 lines not on this page · raw message
arch/powerpc/kvm/e500_mmu_host.h new file +20 -0
@@ -0,0 +1,20 @@ +/* +* Copyright (C) 2008-2013 Freescale Semiconductor, Inc. All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License, version 2, as +* published by the Free Software Foundation. +*/ + +#ifndef KVM_E500_MMU_HOST_H +#define KVM_E500_MMU_HOST_H + +void inval_gtlbe_on_host (struct kvmppc_vcpu_e500 *vcpu_e500,int tlbsel, +int esel); + +void clear_tlb1_bitmap (struct kvmppc_vcpu_e500 *vcpu_e500); +void clear_tlb_refs (struct kvmppc_vcpu_e500 *vcpu_e500); +int e500_mmu_host_init (struct kvmppc_vcpu_e500 *vcpu_e500); +void e500_mmu_host_uninit (struct kvmppc_vcpu_e500 *vcpu_e500); + +#endif /* KVM_E500_MMU_HOST_H */
arch/powerpc/kvm/e500_tlb.c deleted +0 -1409
1,409 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 3/3 KVM: PPC: e500: Implement TLB1-in-TLB0 mapping
In reply to Alexander GrafWhen a host mapping fault happens in a guest TLB1 entry today, we map the translated guest entry into the host's TLB1.
This isn't particularly clever when the guest is mapped by normal 4k pages, since these would be a lot better to put into TLB0 instead.
This patch adds the required logic to map 4k TLB1 shadow maps into the host's TLB0.
--- arch/powerpc/kvm/e500.h | 1 + arch/powerpc/kvm/e500_mmu_host.c | 58 +++++++++++++++++++++++++++++-------- 2 files changed, 46 insertions(+), 13 deletions(-)
arch/powerpc/kvm/e500.h +1 -0
@@ -28,6 +28,7 @@#define E500_TLB_VALID 1#define E500_TLB_BITMAP 2 +#define E500_TLB_TLB0 (1 << 2)struct tlbe_ref {pfn_t pfn;
arch/powerpc/kvm/e500_mmu_host.c +45 -13
90 lines not on this page · raw message
Signature · 1 line
1.6.0.2
Re: [PATCH 3/3] KVM: PPC: e500: Implement TLB1-in-TLB0 mapping
Quoted 45 lines · Alexander Graf
When a host mapping fault happens in a guest TLB1 entry today, we map the translated guest entry into the host's TLB1.
This isn't particularly clever when the guest is mapped by normal 4k pages, since these would be a lot better to put into TLB0 instead.
This patch adds the required logic to map 4k TLB1 shadow maps into the host's TLB0.
Signed-off-by Alexander Graf <[email protected]>--- arch/powerpc/kvm/e500.h | 1 + arch/powerpc/kvm/e500_mmu_host.c | 58 +++++++++++++++++++++++++++++-------- 2 files changed, 46 insertions(+), 13 deletions(-)arch/powerpc/kvm/e500.h +1
-0@@ -28,6 +28,7 @@#define E500_TLB_VALID 1#define E500_TLB_BITMAP 2 +#define E500_TLB_TLB0 (1 << 2)struct tlbe_ref {pfn_t pfn;arch/powerpc/kvm/e500_mmu_host.c +5
-0@@ -198,6 +198,11 @@ void inval_gtlbe_on_host(struct kvmppc_vcpu_e500 *vcpu_e500, int tlbsel,local_irq_restore (flags);return ; + }else if (tlbsel =1 && + vcpu_e500->gtlb_priv[1 ][esel].ref.flags &E500_TLB_TLB0 ) { +/* This is a slow path, so just invalidate everything */ +kvmppc_e500_tlbil_all (vcpu_e500); + vcpu_e500->gtlb_priv[1 ][esel].ref.flags &= ~E500_TLB_TLB0 ;
Quoted 1 line
}
What if the guest TLB1 entry is backed by a mix of TLB0 and TLB1 entries on the host? I don't see checks elsewhere that would prevent this situation.
Quoted 6 lines
arch/powerpc/kvm/e500_mmu_host.c +0
-1@@ -529,9 +556,14 @@ void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 eaddr, gpa_t gpaddr, case 1: {gfn_t gfn = gpaddr >>PAGE_SHIFT ; - stlbsel =1 ;
arch/powerpc/kvm/e500_mmu_host.c void kvmppc_mmu_map(struct kvm_vcpu *vcpu, u64 · line 569
Quoted 10 lines
arch/powerpc/kvm/e500_mmu_host.c +6
-0sesel =kvmppc_e500_tlb1_map (vcpu_e500, eaddr, gfn, gtlbe, &stlbe, esel); +if (sesel <0 ) { +/* TLB0 mapping */ + sesel =0 ; + stlbsel =0 ; + }else + stlbsel =1 ;break ; }
Maybe push the call to write_tlbe() into the tlb0/1_map functions, getting rid of the need to pass sesel/stlbsel/stlbe back?
-Scott