KVM: PPC: e500: Save/restore SPE state
Subsystems (2)
PATCH v3 4/13 KVM: PPC: e500: Save/restore SPE state
This is done lazily. The SPE save will be done only if the guest has used SPE since the last preemption or heavyweight exit. Restore will be done only on demand, when enabling MSR_SPE in the shadow MSR, in response to an SPE fault or mtmsr emulation.
For SPEFSCR, Linux already switches it on context switch (non-lazily), so the only remaining bit is to save it between qemu and the guest.
Signed-off-by Liu Yu <[email protected]>
Signed-off-by Scott Wood <[email protected]>
---
v3: removed mismerge hunk that removed
kvmppc_core_load_host/guest_debugstate stubs.
arch/powerpc/include/asm/kvm_host.h | 6 ++ arch/powerpc/include/asm/reg_booke.h | 1 + arch/powerpc/kernel/asm-offsets.c | 7 +++ arch/powerpc/kvm/booke.c | 84 +++++++++++++++++++++++++++++++++- arch/powerpc/kvm/booke.h | 22 +++------ arch/powerpc/kvm/booke_interrupts.S | 38 +++++++++++++++ arch/powerpc/kvm/e500.c | 7 ++- 7 files changed, 148 insertions(+), 17 deletions(-)
arch/powerpc/include/asm/kvm_host.h +6 -0
@@ -195,6 +195,12 @@ struct kvm_vcpu_arch {u64 fpr[32 ];u64 fpscr; +#ifdef CONFIG_SPE +ulong evr[32 ]; +ulong spefscr; +ulong host_spefscr; +u64 acc; +#endif #ifdef CONFIG_ALTIVEC vector128 vr[32 ];vector128 vscr;
arch/powerpc/include/asm/reg_booke.h +1 -0
@@ -318,6 +318,7 @@#define ESR_ILK 0x00100000/* Instr. Cache Locking */ #define ESR_PUO 0x00040000/* Unimplemented Operation exception */ #define ESR_BO 0x00020000/* Byte Ordering */ +#define ESR_SPV 0x00000080/* Signal Processing operation */ /* Bit definitions related to the DBCR0. */ #if defined(CONFIG_40x)
arch/powerpc/kernel/asm-offsets.c +7 -0
@@ -497,6 +497,13 @@ int main(void)DEFINE (TLBCAM_MAS7 , offsetof(struct tlbcam , MAS7));#endif +#if defined(CONFIG_KVM ) && defined(CONFIG_SPE ) + DEFINE(VCPU_EVR, offsetof(struct kvm_vcpu, arch.evr[0])); + DEFINE(VCPU_ACC, offsetof(struct kvm_vcpu, arch.acc)); + DEFINE(VCPU_SPEFSCR, offsetof(struct kvm_vcpu, arch.spefscr)); + DEFINE(VCPU_HOST_SPEFSCR, offsetof(struct kvm_vcpu, arch.host_spefscr)); +#endif +#ifdef CONFIG_KVM_EXIT_TIMING DEFINE (VCPU_TIMING_EXIT_TBU , offsetof(struct kvm_vcpu , arch.timing_exit.tv32.tbu));
arch/powerpc/kvm/booke.c +82 -2
110 lines not on this page · raw message
arch/powerpc/kvm/booke.h +8 -14
@@ -52,24 +52,18 @@extern unsigned long kvmppc_booke_handlers; -/* Helper function for "full" MSR writes. No need to call this if only EE is -* changing. */ -static inline void kvmppc_set_msr (struct kvm_vcpu *vcpu,u32 new_msr) -{ -if ((new_msr &MSR_PR ) != (vcpu->arch.shared->msr &MSR_PR )) -kvmppc_mmu_priv_switch (vcpu, new_msr &MSR_PR ); - - vcpu->arch.shared->msr = new_msr; - -if (vcpu->arch.shared->msr &MSR_WE ) { -kvm_vcpu_block (vcpu); -kvmppc_set_exit_type (vcpu,EMULATED_MTMSRWE_EXITS ); - }; -} +void kvmppc_set_msr (struct kvm_vcpu *vcpu,u32 new_msr);int kvmppc_booke_emulate_op (struct kvm_run *run,struct kvm_vcpu *vcpu,unsigned int inst,int *advance);int kvmppc_booke_emulate_mfspr (struct kvm_vcpu *vcpu,int sprn,int rt);int kvmppc_booke_emulate_mtspr (struct kvm_vcpu *vcpu,int sprn,int rs); +/* low-level asm code to transfer guest state */ +void kvmppc_load_guest_spe (struct kvm_vcpu *vcpu); +void kvmppc_save_guest_spe (struct kvm_vcpu *vcpu); + +/* high-level function, manages flags, host state */ +void kvmppc_vcpu_disable_spe (struct kvm_vcpu *vcpu); +#endif /* __KVM_BOOKE_H__ */
arch/powerpc/kvm/booke_interrupts.S +38 -0
@@ -13,6 +13,7 @@ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Copyright IBM Corp. 2007 + * Copyright 2011 Freescale Semiconductor, Inc. * * Authors: Hollis Blanchard <[email protected]> */
@@ -239,6 +240,14 @@ _GLOBAL(kvmppc_resume_host) heavyweight_exit: /* Not returning to guest. */ +#ifdef CONFIG_SPE + /* save guest SPEFSCR and load host SPEFSCR */ + mfspr r9, SPRN_SPEFSCR + stw r9, VCPU_SPEFSCR(r4) + lwz r9, VCPU_HOST_SPEFSCR(r4) + mtspr SPRN_SPEFSCR, r9 +#endif + /* We already saved guest volatile register state; now save the * non-volatiles. */ stw r15, VCPU_GPR(r15)(r4)
@@ -340,6 +349,14 @@ _GLOBAL(__kvmppc_vcpu_run) lwz r30, VCPU_GPR(r30)(r4) lwz r31, VCPU_GPR(r31)(r4) +#ifdef CONFIG_SPE + /* save host SPEFSCR and load guest SPEFSCR */ + mfspr r3, SPRN_SPEFSCR + stw r3, VCPU_HOST_SPEFSCR(r4) + lwz r3, VCPU_SPEFSCR(r4) + mtspr SPRN_SPEFSCR, r3 +#endif + lightweight_exit: stw r2, HOST_R2(r1)
@@ -425,3 +442,24 @@ lightweight_exit: lwz r3, VCPU_GPR(r3)(r4) lwz r4, VCPU_GPR(r4)(r4) rfi + +#ifdef CONFIG_SPE +_GLOBAL(kvmppc_save_guest_spe) + cmpi 0,r3,0 + beqlr- + SAVE_32EVRS(0, r4, r3, VCPU_EVR) + evxor evr6, evr6, evr6 + evmwumiaa evr6, evr6, evr6 + li r4,VCPU_ACC + evstddx evr6, r4, r3 /* save acc */ + blr + +_GLOBAL(kvmppc_load_guest_spe) + cmpi 0,r3,0 + beqlr- + li r4,VCPU_ACC + evlddx evr6,r4,r3 + evmra evr6,evr6 /* load acc */ + REST_32EVRS(0, r4, r3, VCPU_EVR) + blr +#endif
arch/powerpc/kvm/e500.c +6 -1
@@ -1,5 +1,5 @@/* -* Copyright (C) 2008 Freescale Semiconductor, Inc. All rights reserved. +* Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All rights reserved. * * Author: Yu Liu, <[email protected]> *
@@ -41,6 +41,11 @@ void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)void kvmppc_core_vcpu_put (struct kvm_vcpu *vcpu) {kvmppc_e500_tlb_put (vcpu); + +#ifdef CONFIG_SPE +if (vcpu->arch.shadow_msr &MSR_SPE ) +kvmppc_vcpu_disable_spe (vcpu); +#endif }int kvmppc_core_check_processor_compat (void )
Signature · 1 line
1.7.4.1