powerpc/e500v2: Save SPEFCSR in
Subsystems (2)
PATCH v2 1/4 powerpc/e500v2: Save SPEFCSR in
From: yu liu <[email protected]>
giveup_spe() saves the SPE state which is protected by MSR[SPE]. However, modifying SPEFSCR does not trap when MSR[SPE]=0. And since SPEFSCR is already saved/restored in _switch(), not all the callers want to save SPEFSCR again.
Thus, saving SPEFSCR should not belong to giveup_spe().
This patch moves SPEFSCR saving to flush_spe_to_thread(), and cleans up the caller that needs to save SPEFSCR accordingly.
---
v2: added kvm-ppc (sorry for the resend)
Kumar, could you ack this to go via the KVM tree, since the KVM SPE save/restore patches depend on it?
arch/powerpc/kernel/head_fsl_booke.S | 2 -- arch/powerpc/kernel/process.c | 1 + arch/powerpc/kernel/traps.c | 5 +---- 3 files changed, 2 insertions(+), 6 deletions(-)
arch/powerpc/kernel/head_fsl_booke.S +0 -2
@@ -792,8 +792,6 @@ _GLOBAL(giveup_spe) evmwumiaa evr6, evr6, evr6 /* evr6 <- ACC = 0 * 0 + ACC */ li r4,THREAD_ACC evstddx evr6, r4, r3 /* save off accumulator */ - mfspr r6,SPRN_SPEFSCR - stw r6,THREAD_SPEFSCR(r3) /* save spefscr register value */ beq 1f lwz r4,_MSR-STACK_FRAME_OVERHEAD(r5) lis r3,MSR_SPE@h
arch/powerpc/kernel/process.c +1 -0
@@ -213,6 +213,7 @@ void flush_spe_to_thread(struct task_struct *tsk)#ifdef CONFIG_SMP BUG_ON (tsk != current);#endif + tsk->thread.spefscr =mfspr (SPRN_SPEFSCR );giveup_spe (tsk); }preempt_enable ();
arch/powerpc/kernel/traps.c +1 -4
@@ -1356,10 +1356,7 @@ void SPEFloatingPointException(struct pt_regs *regs)int code =0 ;int err; -preempt_disable (); -if (regs->msr &MSR_SPE ) -giveup_spe (current); -preempt_enable (); +flush_spe_to_thread (current); spefscr = current->thread.spefscr; fpexc_mode = current->thread.fpexc_mode;
Signature · 1 line
1.7.1
PATCH v2 2/4 KVM: PPC: booke: Wrap __kvmppc_vcpu_run()
From: yu liu <[email protected]>
We need to save/restore SPE environment on e500 core. Wrap __kvmppc_vcpu_run() so that we can put the SPE code in e500.c.
---
v2: added kvm-ppc (sorry for the resend)
arch/powerpc/include/asm/kvm_ppc.h | 1 + arch/powerpc/kvm/44x.c | 5 +++++ arch/powerpc/kvm/book3s.c | 1 - arch/powerpc/kvm/booke_interrupts.S | 2 +- arch/powerpc/kvm/e500.c | 5 +++++ 5 files changed, 12 insertions(+), 2 deletions(-)
arch/powerpc/include/asm/kvm_ppc.h +1 -0
@@ -42,6 +42,7 @@ enum emulation_result { EMULATE_AGAIN, /* something went wrong. go again */ }; +extern int __kvmppc_vcpu_entry (struct kvm_run *kvm_run,struct kvm_vcpu *vcpu);extern int __kvmppc_vcpu_run (struct kvm_run *kvm_run,struct kvm_vcpu *vcpu);extern char kvmppc_handlers_start[];extern unsigned long kvmppc_handler_len;
arch/powerpc/kvm/44x.c +5 -0
@@ -147,6 +147,11 @@ void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)kmem_cache_free (kvm_vcpu_cache, vcpu_44x); } +int __kvmppc_vcpu_run (struct kvm_run *kvm_run,struct kvm_vcpu *vcpu) +{ +return __kvmppc_vcpu_entry (kvm_run, vcpu); +} +static int __init kvmppc_44x_init (void ) {int r;
arch/powerpc/kvm/book3s.c +0 -1
@@ -1379,7 +1379,6 @@ void kvmppc_core_vcpu_free(struct kvm_vcpu *vcpu)vfree (vcpu_book3s); } -extern int __kvmppc_vcpu_entry (struct kvm_run *kvm_run,struct kvm_vcpu *vcpu);int __kvmppc_vcpu_run (struct kvm_run *kvm_run,struct kvm_vcpu *vcpu) {int ret;
arch/powerpc/kvm/booke_interrupts.S +1 -1
@@ -293,7 +293,7 @@ heavyweight_exit: * r3: kvm_run pointer * r4: vcpu pointer */ -_GLOBAL(__kvmppc_vcpu_run) +_GLOBAL(__kvmppc_vcpu_entry) stwu r1, -HOST_STACK_SIZE(r1) stw r1, VCPU_HOST_STACK(r4) /* Save stack pointer to vcpu. */
arch/powerpc/kvm/e500.c +5 -0
@@ -70,6 +70,11 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)return 0 ; } +int __kvmppc_vcpu_run (struct kvm_run *kvm_run,struct kvm_vcpu *vcpu) +{ +return __kvmppc_vcpu_entry (kvm_run, vcpu); +} +/* 'linear_address' is actually an encoding of AS|PID|EADDR . */ int kvmppc_core_vcpu_translate (struct kvm_vcpu *vcpu,struct kvm_translation *tr)
Signature · 1 line
1.7.1
PATCH v2 3/4 KVM: PPC: e500: Introduce msr_block for e500v2
In reply to Scott WoodFrom: yu liu <[email protected]>
In order to use lazy SPE register save/restore, we need to know when the guest is using MSR[SPE]. In order to do that, we need to control the actual MSR[SPE] separately from the guest's notion of MSR[SPE].
Only bits set in msr_block can be changed by the guest in the real MSR.
---
v2: added kvm-ppc (sorry for the resend)
arch/powerpc/include/asm/kvm_host.h | 3 +++ arch/powerpc/kernel/asm-offsets.c | 3 +++ arch/powerpc/kvm/booke.h | 17 +++++++++++++++++ arch/powerpc/kvm/booke_interrupts.S | 6 +++++- arch/powerpc/kvm/e500.c | 3 +++ 5 files changed, 31 insertions(+), 1 deletions(-)
arch/powerpc/include/asm/kvm_host.h +3 -0
@@ -217,6 +217,9 @@ struct kvm_vcpu_arch {ulong xer;u32 cr;#endif +#ifdef CONFIG_FSL_BOOKE +ulong msr_block; +#endif #ifdef CONFIG_PPC_BOOK3S ulong shadow_msr;
arch/powerpc/kernel/asm-offsets.c +3 -0
@@ -403,6 +403,9 @@ int main(void) DEFINE(VCPU_SHARED, offsetof(struct kvm_vcpu, arch.shared));DEFINE (VCPU_SHARED_MSR , offsetof(struct kvm_vcpu_arch_shared , msr)); +#ifdef CONFIG_FSL_BOOKE + DEFINE(VCPU_MSR_BLOCK, offsetof(struct kvm_vcpu, arch.msr_block)); +#endif /* book3s */ #ifdef CONFIG_PPC_BOOK3S DEFINE(VCPU_HOST_RETIP, offsetof(struct kvm_vcpu, arch.host_retip));
arch/powerpc/kvm/booke.h +17 -0
@@ -52,6 +52,23 @@extern unsigned long kvmppc_booke_handlers; +#ifdef CONFIG_FSL_BOOKE +static inline bool kvmppc_msr_block_has (struct kvm_vcpu *vcpu,u32 block_bit) +{ +return !(vcpu->arch.msr_block & block_bit); +} + +static inline void kvmppc_set_msr_block (struct kvm_vcpu *vcpu,u32 block_bit) +{ + vcpu->arch.msr_block &= ~block_bit; +} + +static inline void kvmppc_clr_msr_block (struct kvm_vcpu *vcpu,u32 block_bit) +{ + vcpu->arch.msr_block |= block_bit; +} +#endif +/* 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)
arch/powerpc/kvm/booke_interrupts.S +5 -1
@@ -409,7 +409,6 @@ lightweight_exit: mtctr r3 lwz r3, VCPU_CR(r4) mtcr r3 - lwz r5, VCPU_GPR(r5)(r4) lwz r6, VCPU_GPR(r6)(r4) lwz r7, VCPU_GPR(r7)(r4) lwz r8, VCPU_GPR(r8)(r4)
@@ -419,6 +418,11 @@ lightweight_exit: lwz r3, (VCPU_SHARED_MSR + 4)(r3) oris r3, r3, KVMPPC_MSR_MASK@h ori r3, r3, KVMPPC_MSR_MASK@l +#ifdef CONFIG_FSL_BOOKE + lwz r5, VCPU_MSR_BLOCK(r4) + and r3, r3, r5 +#endif + lwz r5, VCPU_GPR(r5)(r4) mtsrr1 r3 /* Clear any debug events which occurred since we disabled MSR[DE].
arch/powerpc/kvm/e500.c +3 -0
@@ -67,6 +67,9 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)/* Since booke kvm only support one core, update all vcpus' PIR to 0 */ vcpu->vcpu_id =0 ; +/* Unblock all msr bits */ +kvmppc_clr_msr_block (vcpu, ~0UL ); +return 0 ; }
Signature · 1 line
1.7.1
PATCH v2 4/4 KVM: PPC: e500: SPE switch between guest and host
In reply to Scott WoodFrom: yu liu <[email protected]>
This patch provide a lazy way to do SPE switch. The SPE save/restore will be done only if it's needed.
Linux already switches SPEFSCR on context switch (non-lazily), so the only remaining bit is to save it between qemu and the guest.
---
v2: added kvm-ppc (sorry for the resend)
arch/powerpc/include/asm/kvm_host.h | 6 +++ arch/powerpc/kernel/asm-offsets.c | 6 +++ arch/powerpc/kvm/booke.c | 15 +++++++- arch/powerpc/kvm/booke_interrupts.S | 62 +++++++++++++++++++++++++++++++++++ arch/powerpc/kvm/e500.c | 45 ++++++++++++++++++++++++- 5 files changed, 130 insertions(+), 4 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/kernel/asm-offsets.c +6 -0
@@ -497,6 +497,12 @@ int main(void)DEFINE (TLBCAM_MAS3 , offsetof(struct tlbcam , MAS3));DEFINE (TLBCAM_MAS7 , offsetof(struct tlbcam , MAS7));#endif +#ifdef 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 /* CONFIG_SPE */ #ifdef CONFIG_KVM_EXIT_TIMING DEFINE(VCPU_TIMING_EXIT_TBU, offsetof(struct kvm_vcpu,
arch/powerpc/kvm/booke.c +13 -2
@@ -13,6 +13,7 @@* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Copyright IBM Corp. 2007 +* Copyright (C) 2010 Freescale Semiconductor, Inc. * * Authors: Hollis Blanchard <[email protected]> * Christian Ehrhardt <[email protected]>
@@ -344,10 +345,19 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu, r =RESUME_GUEST ;break ; -case BOOKE_INTERRUPT_SPE_UNAVAIL : -kvmppc_booke_queue_irqprio (vcpu,BOOKE_IRQPRIO_SPE_UNAVAIL ); +#ifdef CONFIG_SPE +case BOOKE_INTERRUPT_SPE_UNAVAIL : { +extern void kvmppc_vcpu_spe_load (struct kvm_vcpu *vcpu); + +/* reload the SPE env if guest first use SPE since last save */ +if (kvmppc_msr_block_has (vcpu,MSR_SPE )) +kvmppc_vcpu_spe_load (vcpu); + +if (!(vcpu->arch.shared->msr &MSR_SPE )) +kvmppc_booke_queue_irqprio (vcpu,BOOKE_IRQPRIO_SPE_UNAVAIL ); r =RESUME_GUEST ;break ; + }case BOOKE_INTERRUPT_SPE_FP_DATA :kvmppc_booke_queue_irqprio (vcpu,BOOKE_IRQPRIO_SPE_FP_DATA );
@@ -358,6 +368,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,kvmppc_booke_queue_irqprio (vcpu,BOOKE_IRQPRIO_SPE_FP_ROUND ); r =RESUME_GUEST ;break ; +#endif case BOOKE_INTERRUPT_DATA_STORAGE : kvmppc_core_queue_data_storage(vcpu, vcpu->arch.fault_dear,
arch/powerpc/kvm/booke_interrupts.S +62 -0
77 lines not on this page · raw message
arch/powerpc/kvm/e500.c +43 -2
67 lines not on this page · raw message
Signature · 1 line
1.7.1