KVM: PPC: e500: enable magic page
Subsystems (3)
PATCH v3 9/13 KVM: PPC: e500: enable magic page
This is a shared page used for paravirtualization. It is always present in the guest kernel's effective address space at the address indicated by the hypercall that enables it.
The physical address specified by the hypercall is not used, as e500 does not have real mode.
---
v3: Removed unnecessary preloading of magic page TLB entry in the hcall
Documentation/virtual/kvm/ppc-pv.txt | 8 +++++--- arch/powerpc/include/asm/kvm_ppc.h | 1 + arch/powerpc/kvm/booke.c | 11 +++++++++++ arch/powerpc/kvm/e500_tlb.c | 22 +++++++++++++++++++++- arch/powerpc/kvm/powerpc.c | 3 ++- 5 files changed, 40 insertions(+), 5 deletions(-)
Documentation/virtual/kvm/ppc-pv.txt +5 -3
@@ -68,9 +68,11 @@ page that contains parts of supervisor visible register state. The guest can map this shared page using the KVM hypercall KVM_HC_PPC_MAP_MAGIC_PAGE. With this hypercall issued the guest always gets the magic page mapped at the -desired location in effective and physical address space. For now, we always -map the page to -4096. This way we can access it using absolute load and store -functions. The following instruction reads the first field of the magic page: +desired location. The first parameter indicates the effective address when the +MMU is enabled. The second parameter indicates the address in real mode, if +applicable to the target. For now, we always map the page to -4096. This way we +can access it using absolute load and store functions. The following +instruction reads the first field of the magic page: ld rX, -4096(0)
arch/powerpc/include/asm/kvm_ppc.h +1 -0
@@ -109,6 +109,7 @@ extern void kvmppc_booke_exit(void);extern void kvmppc_core_destroy_mmu (struct kvm_vcpu *vcpu);extern int kvmppc_kvm_pv (struct kvm_vcpu *vcpu); +extern void kvmppc_map_magic (struct kvm_vcpu *vcpu);/* * Cuts out inst bits with ordering according to spec.
arch/powerpc/kvm/booke.c +11 -0
@@ -472,6 +472,17 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,gpa_t gpaddr;gfn_t gfn; +#ifdef CONFIG_KVM_E500 +if (!(vcpu->arch.shared->msr &MSR_PR ) && + (eaddr &PAGE_MASK ) = vcpu->arch.magic_page_ea) { +kvmppc_map_magic (vcpu); +kvmppc_account_exit (vcpu,DTLB_VIRT_MISS_EXITS ); + r =RESUME_GUEST ; + +break ; + } +#endif +/* Check the guest TLB. */ gtlb_index =kvmppc_mmu_dtlb_index (vcpu, eaddr);if (gtlb_index <0 ) {
arch/powerpc/kvm/e500_tlb.c +21 -1
@@ -76,7 +76,8 @@ static inline unsigned int tlb0_get_next_victim(static inline unsigned int tlb1_max_shadow_size (void ) { -return tlb1_entry_num - tlbcam_index; +/* reserve one entry for magic page */ +return tlb1_entry_num - tlbcam_index -1 ; }static inline int tlbe_is_writable (struct tlbe *tlbe)
@@ -142,6 +143,25 @@ static inline void write_host_tlbe(struct kvmppc_vcpu_e500 *vcpu_e500, } } +void kvmppc_map_magic (struct kvm_vcpu *vcpu) +{ +struct tlbe magic; +ulong shared_page = ((ulong )vcpu->arch.shared) &PAGE_MASK ; +pfn_t pfn; + + pfn = (pfn_t )virt_to_phys ((void *)shared_page) >>PAGE_SHIFT ; +get_page (pfn_to_page (pfn)); + + magic.mas1 =MAS1_VALID |MAS1_TS | +MAS1_TSIZE (BOOK3E_PAGESZ_4K ); + magic.mas2 = vcpu->arch.magic_page_ea |MAS2_M ; + magic.mas3 = (pfn <<PAGE_SHIFT ) | +MAS3_SW |MAS3_SR |MAS3_UW |MAS3_UR ; + magic.mas7 = pfn >> (32 -PAGE_SHIFT ); + +__write_host_tlbe (&magic,MAS0_TLBSEL (1 ) |MAS0_ESEL (tlbcam_index)); +} +void kvmppc_e500_tlb_load (struct kvm_vcpu *vcpu,int cpu) { }
arch/powerpc/kvm/powerpc.c +2 -1
@@ -73,7 +73,8 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu) }case HC_VENDOR_KVM |KVM_HC_FEATURES : r =HC_EV_SUCCESS ; -#if defined(CONFIG_PPC_BOOK3S )/* XXX Missing magic page on BookE */ +#if defined(CONFIG_PPC_BOOK3S ) || defined(CONFIG_KVM_E500 ) +/* XXX Missing magic page on 44x */ r2 |= (1 <<KVM_FEATURE_MAGIC_PAGE );#endif
Signature · 1 line
1.7.4.1
Quoted 6 lines · Scott Wood
This is a shared page used for paravirtualization. It is always present in the guest kernel's effective address space at the address indicated by the hypercall that enables it.
The physical address specified by the hypercall is not used, as e500 does not have real mode.
What are your results when using the magic page? I have the following numbers with your patches applied:
= bare metal =
root@e500:~/kvm# time for i in {1..1000}; do /bin/echo > /dev/null; donereal 0m5.445s
user 0m0.204s
sys 0m0.572s
= no hypervisor node (magic page not used) =
debian-powerpc:~# time for i in {1..1000}; do /bin/echo > /dev/null; donereal 1m36.362s
user 0m13.224s
sys 1m11.084s
= with hypervisor node (magic page used) =
debian-powerpc:~# time for i in {1..1000}; do /bin/echo > /dev/null; donereal 2m28.888s
user 0m9.248s
sys 1m4.016s
This seems rather irritating to me. I haven't tried to trace what's going on, but trapping instructions really shouldn't be much better than mapping the magic page, plus the magic page should stay in memory.
... unless of course we're in the dynamically generated code paths. Then we get plenty of TLB misses instead of instruction emulation traps.
Either way, certainly something to check before we enable the magic page in Qemu.
Alex
Quoted 30 lines · Alexander Graf
Quoted 6 lines · Scott Wood
This is a shared page used for paravirtualization. It is always present in the guest kernel's effective address space at the address indicated by the hypercall that enables it.
The physical address specified by the hypercall is not used, as e500 does not have real mode.
What are your results when using the magic page? I have the following numbers with your patches applied:
= bare metal =
root@e500:~/kvm# time for i in {1..1000}; do /bin/echo > /dev/null; donereal 0m5.445s
user 0m0.204s
sys 0m0.572s= no hypervisor node (magic page not used) =
debian-powerpc:~# time for i in {1..1000}; do /bin/echo > /dev/null; donereal 1m36.362s
user 0m13.224s
sys 1m11.084s
Quoted 7 lines
= with hypervisor node (magic page used) =
debian-powerpc:~# time for i in {1..1000}; do /bin/echo > /dev/null; donereal 2m28.888s
user 0m9.248s
sys 1m4.016s
Interesting - now I'm down to:
debian-powerpc:~# time for i in {1..1000}; do /bin/echo > /dev/null; donereal 1m25.008s
user 0m9.224s
sys 1m5.720s
Oh well, let's hope I did something wrong before :).
Alex
Quoted 32 lines · On Wed, 15 Jun 2011 13:34:06 +0200 Alexander Graf <[email protected]> wrote:
Quoted 20 lines · Alexander Graf
What are your results when using the magic page? I have the following numbers with your patches applied:
= bare metal =
root@e500:~/kvm# time for i in {1..1000}; do /bin/echo > /dev/null; donereal 0m5.445s
user 0m0.204s
sys 0m0.572s= no hypervisor node (magic page not used) =
debian-powerpc:~# time for i in {1..1000}; do /bin/echo > /dev/null; donereal 1m36.362s
user 0m13.224s
sys 1m11.084sQuoted 7 lines
= with hypervisor node (magic page used) =
debian-powerpc:~# time for i in {1..1000}; do /bin/echo > /dev/null; donereal 2m28.888s
user 0m9.248s
sys 1m4.016sInteresting - now I'm down to:
Quoted 8 lines
debian-powerpc:~# time for i in {1..1000}; do /bin/echo > /dev/null; donereal 1m25.008s
user 0m9.224s
sys 1m5.720sOh well, let's hope I did something wrong before :).
Remember, I have more paravirt patches coming after this (wanted to get the MMU stuff dealt with first), and the kernel is still using 4K TLB1 pages in the default qemu config. We should probably use TLB0 when large pages aren't available.
Without paravirt, no large pages:
sh-2.05b# time for i in $(seq 1000); do /bin/echo > /dev/null ; done
real 0m42.769s user 0m3.256s sys 0m34.988s
With paravirt including my local patches (but still no large pages):
sh-2.05b# time for i in $(seq 1000); do /bin/echo > /dev/null ; done
real 0m40.339s user 0m1.560s sys 0m32.652s
With large pages and no paravirt:
sh-2.05b# time for i in $(seq 1000); do /bin/echo > /dev/null ;done
real 0m7.986s user 0m2.528s sys 0m3.232s
With large pages and paravirt, but just this patchset (no further paravirt patches):
sh-2.05b# time for i in $(seq 1000); do /bin/echo > /dev/null ; done
real 0m6.067s user 0m3.068s sys 0m2.332s
With large pages and all my paravirt patches:
sh-2.05b# time for i in $(seq 1000); do /bin/echo > /dev/null ;done
real 0m3.837s user 0m0.604s sys 0m0.316s
On the host (different rfs, but I think similar in relevant ways, except that the host rfs has SPE and guest rfs is soft-float):
# time for i in $(seq 1000); do /bin/echo > /dev/null ; done
real 0m1.850s user 0m0.028s sys 0m0.236s
I used seq because my rfs is using an older bash that doesn't seem to understand the range expression.
-Scott
Quoted 51 lines · Scott Wood
Quoted 32 lines · On Wed, 15 Jun 2011 13:34:06 +0200 Alexander Graf <[email protected]> wrote:
Quoted 20 lines · Alexander Graf
What are your results when using the magic page? I have the following numbers with your patches applied:
= bare metal =
root@e500:~/kvm# time for i in {1..1000}; do /bin/echo > /dev/null; donereal 0m5.445s
user 0m0.204s
sys 0m0.572s= no hypervisor node (magic page not used) =
debian-powerpc:~# time for i in {1..1000}; do /bin/echo > /dev/null; donereal 1m36.362s
user 0m13.224s
sys 1m11.084sQuoted 7 lines
= with hypervisor node (magic page used) =
debian-powerpc:~# time for i in {1..1000}; do /bin/echo > /dev/null; donereal 2m28.888s
user 0m9.248s
sys 1m4.016sInteresting - now I'm down to:
Quoted 8 lines
debian-powerpc:~# time for i in {1..1000}; do /bin/echo > /dev/null; donereal 1m25.008s
user 0m9.224s
sys 1m5.720sOh well, let's hope I did something wrong before :).
Remember, I have more paravirt patches coming after this (wanted to get the MMU stuff dealt with first), and the kernel is still using 4K TLB1 pages in the default qemu config. We should probably use TLB0 when large pages aren't available.
Without paravirt, no large pages:
Quoted 7 lines
sh-2.05b# time for i in $(seq 1000); do
/bin/echo>/dev/null; donereal 0m42.769s user 0m3.256s sys 0m34.988sWith paravirt including my local patches (but still no large pages):
Do these include patches to move the MAS registers to the shared page? That should reduce the instruction traps by a significant number.
Quoted 7 lines
sh-2.05b# time for i in $(seq 1000); do
/bin/echo>/dev/null; donereal 0m40.339s user 0m1.560s sys 0m32.652s
Quoted 5 lines
With large pages and no paravirt:
sh-2.05b# time for i in $(seq 1000); do
/bin/echo>/dev/null;donereal 0m7.986s
Wow, so this is where all the time gets wasted. Sounds like the guest's kernel eats up all of it. I assume "large pages" means direct map?
Quoted 6 lines
user 0m2.528s
sys 0m3.232sWith large pages and paravirt, but just this patchset (no further paravirt patches):
Quoted 7 lines
sh-2.05b# time for i in $(seq 1000); do
/bin/echo>/dev/null; donereal 0m6.067s user 0m3.068s sys 0m2.332sWith large pages and all my paravirt patches:
Mind to give me a list of patches that you have in the queue? Nothing fancy, just the instructions that you're already looking at.
Quoted 9 lines
sh-2.05b# time for i in $(seq 1000); do
/bin/echo>/dev/null;donereal 0m3.837s user 0m0.604s sys 0m0.316sOn the host (different rfs, but I think similar in relevant ways, except that the host rfs has SPE and guest rfs is soft-float):
Quoted 8 lines
# time for i in $(seq 1000); do /bin/echo > /dev/null ; donereal 0m1.850s user 0m0.028s sys 0m0.236sI used seq because my rfs is using an older bash that doesn't seem to understand the range expression.
Sure, it's very valuable benchmarking data nevertheless! I just use the bash range thing because it's easier to type - and slightly faster.
Thanks a lot for these numbers.
Alex
Quoted 6 lines · On Wed, 15 Jun 2011 23:21:37 +0200 Alexander Graf <[email protected]> wrote:
Quoted 1 line · Scott Wood
With paravirt including my local patches (but still no large pages):
Do these include patches to move the MAS registers to the shared page? That should reduce the instruction traps by a significant number.
Yes.
Quoted 3 lines
Quoted 1 line
With large pages and all my paravirt patches:
Mind to give me a list of patches that you have in the queue? Nothing fancy, just the instructions that you're already looking at.
- MASn
- wrtee/wrteei
- SPRG4-7 (guest not allowed to write to paravirt SPRG and read from real and expect it to match)
- ESR
- PIR
- a fix to int_pending (wasn't getting cleared on IACK)
- elimination of a trap on guest entry by using mtmsr instead of rfi in a case where it doesn't need to be atomic
- Elimination of the need to write to HID0 before MSR[WE] if running under KVM (helps when frequently blocking on I/O).
Then there are timer fixes, interrupt stuff, e500mc, etc.
-Scott