KVM: PPC: e500: Save/restore SPE state
Subsystems (2)
PATCH v5 4/4 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.
---
v5: disable preemption when restoring SPE state
Saving SPE state is only done from a preempt notifier or vcpu_put(), where preemption is already disabled.
The other patches in this series are the same as v4.
arch/powerpc/include/asm/kvm_host.h | 6 +++ arch/powerpc/include/asm/reg_booke.h | 1 + arch/powerpc/kernel/asm-offsets.c | 6 +++ arch/powerpc/kvm/booke.c | 72 +++++++++++++++++++++++++++++++++- arch/powerpc/kvm/booke.h | 18 ++------- arch/powerpc/kvm/booke_interrupts.S | 40 +++++++++++++++++++ arch/powerpc/kvm/e500.c | 19 ++++++++- 7 files changed, 145 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
@@ -312,6 +312,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 +6 -0
@@ -494,6 +494,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 +70 -2
98 lines not on this page · raw message
arch/powerpc/kvm/booke.h +4 -14
@@ -52,24 +52,14 @@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); +void kvmppc_load_guest_spe (struct kvm_vcpu *vcpu); +void kvmppc_save_guest_spe (struct kvm_vcpu *vcpu); +#endif /* __KVM_BOOKE_H__ */
arch/powerpc/kvm/booke_interrupts.S +40 -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)
@@ -426,3 +443,26 @@ 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- + addi r5,r3,VCPU_EVR + SAVE_32EVRS(0, r4, r5, 0) + 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 */ + addi r5,r3,VCPU_EVR + REST_32EVRS(0, r4, r5, 0) + blr +#endif
arch/powerpc/kvm/e500.c +18 -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]> *
@@ -25,6 +25,22 @@#include "booke.h" #include "e500_tlb.h" +#ifdef CONFIG_SPE +static void kvmppc_vcpu_spe_put (struct kvm_vcpu *vcpu) +{ +if (vcpu->arch.shadow_msr &MSR_SPE ) { +enable_kernel_spe (); +kvmppc_save_guest_spe (vcpu); + vcpu->arch.shadow_msr &= ~MSR_SPE ; + } +} + +#else +static void kvmppc_vcpu_spe_put (struct kvm_vcpu *vcpu) +{ +} +#endif +void kvmppc_core_load_host_debugstate (struct kvm_vcpu *vcpu) { }
@@ -41,6 +57,7 @@ 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); +kvmppc_vcpu_spe_put (vcpu); }int kvmppc_core_check_processor_compat (void )
Signature · 1 line
1.7.1
Quoted 10 lines · Scott Wood
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_SPEin 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]>
Looks good to me now, still waiting for ACKs on the first patches. Then I'll shove them into my tree.
Alex
Quoted 31 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Scott Wood
Sent: Thursday, March 31, 2011 7:35 AM
To: [email protected]
Cc: [email protected]
Subject: [PATCH v5 4/4] KVM: PPC: e500: Save/restore SPE stateThis 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 enablingMSR_SPEin 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]>---
v5: disable preemption when restoring SPE stateSaving SPE state is only done from a preempt notifier or
vcpu_put(), where preemption is already disabled.The other patches in this series are the same as v4.
Quoted 10 lines
arch/powerpc/include/asm/kvm_host.h | 6 +++ arch/powerpc/include/asm/reg_booke.h | 1 + arch/powerpc/kernel/asm-offsets.c | 6 +++ arch/powerpc/kvm/booke.c | 72 +++++++++++++++++++++++++++++++++- arch/powerpc/kvm/booke.h | 18 ++------- arch/powerpc/kvm/booke_interrupts.S | 40 +++++++++++++++++++ arch/powerpc/kvm/e500.c | 19 ++++++++- 7 files changed, 145 insertions(+), 17 deletions(-)
I think the patch miss the bit to handle the case that if guest clear the MSR_SPE.
Thanks,
Yu
Quoted 42 lines · On 31.03.2011, at 05:21, Liu Yu-B13201 wrote:
Quoted 31 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Scott Wood
Sent: Thursday, March 31, 2011 7:35 AM
To: [email protected]
Cc: [email protected]
Subject: [PATCH v5 4/4] KVM: PPC: e500: Save/restore SPE stateThis 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 enablingMSR_SPEin 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]>---
v5: disable preemption when restoring SPE stateSaving SPE state is only done from a preempt notifier or
vcpu_put(), where preemption is already disabled.The other patches in this series are the same as v4.
Quoted 10 lines
arch/powerpc/include/asm/kvm_host.h | 6 +++ arch/powerpc/include/asm/reg_booke.h | 1 + arch/powerpc/kernel/asm-offsets.c | 6 +++ arch/powerpc/kvm/booke.c | 72 +++++++++++++++++++++++++++++++++- arch/powerpc/kvm/booke.h | 18 ++------- arch/powerpc/kvm/booke_interrupts.S | 40 +++++++++++++++++++ arch/powerpc/kvm/e500.c | 19 ++++++++- 7 files changed, 145 insertions(+), 17 deletions(-)
Quoted 2 lines
I think the patch miss the bit to handle the case that if guest clear the
MSR_SPE.
Right. On set_msr the shadow_msr should get MSR_SPE removed. Thanks for the catch!
Alex
Quoted 57 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Alexander Graf
Sent: Thursday, March 31, 2011 3:51 PM
To: Liu Yu-B13201
Cc: Wood Scott-B07421; [email protected]
Subject: Re: [PATCH v5 4/4] KVM: PPC: e500: Save/restore SPE stateQuoted 11 lines · On 31.03.2011, at 05:21, Liu Yu-B13201 wrote:
Quoted 11 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Scott Wood
Sent: Thursday, March 31, 2011 7:35 AM
To: [email protected]
Cc: [email protected]
Subject: [PATCH v5 4/4] KVM: PPC: e500: Save/restore SPE stateThis is done lazily. The SPE save will be done only if
the guest has
Quoted 10 lines
Quoted 10 lines
used SPE since the last preemption or heavyweight exit. Restore will be
done only on demand, when enablingMSR_SPEin 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.Quoted 6 lines
Quoted 6 lines
Signed-off-by Liu Yu <[email protected]>Signed-off-by Scott Wood <[email protected]>---
v5: disable preemption when restoring SPE stateSaving SPE state is only done from a preempt notifier or
vcpu_put(),Quoted 15 lines
Quoted 14 lines
where preemption is already disabled.
The other patches in this series are the same as v4.
arch/powerpc/include/asm/kvm_host.h | 6 +++ arch/powerpc/include/asm/reg_booke.h | 1 + arch/powerpc/kernel/asm-offsets.c | 6 +++ arch/powerpc/kvm/booke.c | 72 +++++++++++++++++++++++++++++++++- arch/powerpc/kvm/booke.h | 18 ++------- arch/powerpc/kvm/booke_interrupts.S | 40 +++++++++++++++++++ arch/powerpc/kvm/e500.c | 19 ++++++++- 7 files changed, 145 insertions(+), 17 deletions(-)
Quoted 6 lines
Quoted 2 lines
I think the patch miss the bit to handle the case that if guest clear the
MSR_SPE.Right. On
set_msrtheshadow_msrshould getMSR_SPEremoved. Thanks for the catch!
BTW,
looks like guest trap on MSR[SPE] in para virt mode for now, is it? If we don't want to trap on that, then shadow_msr doesn't work here. That's the intend to use msr_block..
Thanks,
Yu
Quoted 60 lines · On 31.03.2011, at 10:06, Liu Yu-B13201 wrote:
Quoted 60 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Alexander Graf
Sent: Thursday, March 31, 2011 3:51 PM
To: Liu Yu-B13201
Cc: Wood Scott-B07421; [email protected]
Subject: Re: [PATCH v5 4/4] KVM: PPC: e500: Save/restore SPE stateQuoted 11 lines · On 31.03.2011, at 05:21, Liu Yu-B13201 wrote:
Quoted 11 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Scott Wood
Sent: Thursday, March 31, 2011 7:35 AM
To: [email protected]
Cc: [email protected]
Subject: [PATCH v5 4/4] KVM: PPC: e500: Save/restore SPE stateThis is done lazily. The SPE save will be done only if
the guest has
Quoted 10 lines
Quoted 10 lines
used SPE since the last preemption or heavyweight exit. Restore will be
done only on demand, when enablingMSR_SPEin 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.Quoted 6 lines
Quoted 6 lines
Signed-off-by Liu Yu <[email protected]>Signed-off-by Scott Wood <[email protected]>---
v5: disable preemption when restoring SPE stateSaving SPE state is only done from a preempt notifier or
vcpu_put(),Quoted 17 lines
Quoted 4 lines
where preemption is already disabled.
The other patches in this series are the same as v4.
Quoted 10 lines
arch/powerpc/include/asm/kvm_host.h | 6 +++ arch/powerpc/include/asm/reg_booke.h | 1 + arch/powerpc/kernel/asm-offsets.c | 6 +++ arch/powerpc/kvm/booke.c | 72 +++++++++++++++++++++++++++++++++- arch/powerpc/kvm/booke.h | 18 ++------- arch/powerpc/kvm/booke_interrupts.S | 40 +++++++++++++++++++ arch/powerpc/kvm/e500.c | 19 ++++++++- 7 files changed, 145 insertions(+), 17 deletions(-)I think the patch miss the bit to handle the case that if guest clear the
MSR_SPE.
Quoted 8 lines
Quoted 3 lines
Right. On
set_msrtheshadow_msrshould getMSR_SPEremoved. Thanks for the catch!BTW,
looks like guest trap on MSR[SPE] in para virt mode for now, is it? If we don't want to trap on that, thenshadow_msrdoesn't work here. That's the intend to usemsr_block..
I see. I still like it better when we explicitly set the MSR value that's used while running the guest. Makes it harder for things to slip through. Also, so far paravirt is disabled for BookE.
So what happens is that since MSR_SPE is disabled, we get a BOOKE_INTERRUPT_SPE_UNAVAIL. At that point, we need to check if it's enabled inside the guest already or if we merely need to activate the flag. That's what the patch does. We'd have to do the exact same when using msr_block, no? The only difference is that we'd set msr_block instead of shadow_msr when we are actually able to use the SPE inside the guest.
Alex
Quoted 81 lines
-----Original Message-----
From: Alexander Graf [mailto:[email protected]]
Sent: Thursday, March 31, 2011 4:15 PM
To: Liu Yu-B13201
Cc: Wood Scott-B07421; [email protected]
Subject: Re: [PATCH v5 4/4] KVM: PPC: e500: Save/restore SPE stateQuoted 60 lines · On 31.03.2011, at 10:06, Liu Yu-B13201 wrote:
Quoted 60 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Alexander Graf
Sent: Thursday, March 31, 2011 3:51 PM
To: Liu Yu-B13201
Cc: Wood Scott-B07421; [email protected]
Subject: Re: [PATCH v5 4/4] KVM: PPC: e500: Save/restore SPE stateQuoted 11 lines · On 31.03.2011, at 05:21, Liu Yu-B13201 wrote:
Quoted 11 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Scott Wood
Sent: Thursday, March 31, 2011 7:35 AM
To: [email protected]
Cc: [email protected]
Subject: [PATCH v5 4/4] KVM: PPC: e500: Save/restore SPE stateThis is done lazily. The SPE save will be done only if
the guest has
Quoted 10 lines
Quoted 10 lines
used SPE since the last preemption or heavyweight exit. Restore will be
done only on demand, when enablingMSR_SPEin 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.Quoted 6 lines
Quoted 6 lines
Signed-off-by Liu Yu <[email protected]>Signed-off-by Scott Wood <[email protected]>---
v5: disable preemption when restoring SPE stateSaving SPE state is only done from a preempt notifier or
vcpu_put(),Quoted 17 lines
Quoted 4 lines
where preemption is already disabled.
The other patches in this series are the same as v4.
Quoted 10 lines
arch/powerpc/include/asm/kvm_host.h | 6 +++ arch/powerpc/include/asm/reg_booke.h | 1 + arch/powerpc/kernel/asm-offsets.c | 6 +++ arch/powerpc/kvm/booke.c | 72 +++++++++++++++++++++++++++++++++- arch/powerpc/kvm/booke.h | 18 ++------- arch/powerpc/kvm/booke_interrupts.S | 40 +++++++++++++++++++ arch/powerpc/kvm/e500.c | 19 ++++++++- 7 files changed, 145 insertions(+), 17 deletions(-)I think the patch miss the bit to handle the case that if guest clear the
MSR_SPE.Quoted 8 lines
Quoted 3 lines
Right. On
set_msrtheshadow_msrshould getMSR_SPEremoved. Thanks for the catch!BTW,
looks like guest trap on MSR[SPE] in para virt mode for now, is it? If we don't want to trap on that, thenshadow_msrdoesn't work here. That's the intend to usemsr_block..
Quoted 4 lines
I see. I still like it better when we explicitly set the MSR value that's used while running the guest. Makes it harder for things to slip through. Also, so far paravirt is disabled for BookE.
We already use paravirt in internal tree.
Quoted 9 lines
So what happens is that since
MSR_SPEis disabled, we get aBOOKE_INTERRUPT_SPE_UNAVAIL. At that point, we need to check if it's enabled inside the guest already or if we merely need to activate the flag. That's what the patch does. We'd have to do the exact same when usingmsr_block, no? The only difference is that we'd setmsr_blockinstead ofshadow_msrwhen we are actually able to use the SPE inside the guest.
Hmm. I think you're right.
I thought that in paravirt mode, if we don't trap on MSR[SPE],
the shadow_msr cannot get notified timely (we don't have chance to call kvmppc_set_msr()). But looks like msr_block has the same issue.
So that MSR[SPE] should always be traped.
Thanks,
Yu
Quoted 98 lines · On 31.03.2011, at 10:40, Liu Yu-B13201 wrote:
Quoted 81 lines
-----Original Message-----
From: Alexander Graf [mailto:[email protected]]
Sent: Thursday, March 31, 2011 4:15 PM
To: Liu Yu-B13201
Cc: Wood Scott-B07421; [email protected]
Subject: Re: [PATCH v5 4/4] KVM: PPC: e500: Save/restore SPE stateQuoted 60 lines · On 31.03.2011, at 10:06, Liu Yu-B13201 wrote:
Quoted 60 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Alexander Graf
Sent: Thursday, March 31, 2011 3:51 PM
To: Liu Yu-B13201
Cc: Wood Scott-B07421; [email protected]
Subject: Re: [PATCH v5 4/4] KVM: PPC: e500: Save/restore SPE stateQuoted 11 lines · On 31.03.2011, at 05:21, Liu Yu-B13201 wrote:
Quoted 11 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Scott Wood
Sent: Thursday, March 31, 2011 7:35 AM
To: [email protected]
Cc: [email protected]
Subject: [PATCH v5 4/4] KVM: PPC: e500: Save/restore SPE stateThis is done lazily. The SPE save will be done only if
the guest has
Quoted 10 lines
Quoted 10 lines
used SPE since the last preemption or heavyweight exit. Restore will be
done only on demand, when enablingMSR_SPEin 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.Quoted 6 lines
Quoted 6 lines
Signed-off-by Liu Yu <[email protected]>Signed-off-by Scott Wood <[email protected]>---
v5: disable preemption when restoring SPE stateSaving SPE state is only done from a preempt notifier or
vcpu_put(),Quoted 17 lines
Quoted 4 lines
where preemption is already disabled.
The other patches in this series are the same as v4.
Quoted 10 lines
arch/powerpc/include/asm/kvm_host.h | 6 +++ arch/powerpc/include/asm/reg_booke.h | 1 + arch/powerpc/kernel/asm-offsets.c | 6 +++ arch/powerpc/kvm/booke.c | 72 +++++++++++++++++++++++++++++++++- arch/powerpc/kvm/booke.h | 18 ++------- arch/powerpc/kvm/booke_interrupts.S | 40 +++++++++++++++++++ arch/powerpc/kvm/e500.c | 19 ++++++++- 7 files changed, 145 insertions(+), 17 deletions(-)I think the patch miss the bit to handle the case that if guest clear the
MSR_SPE.Quoted 8 lines
Quoted 3 lines
Right. On
set_msrtheshadow_msrshould getMSR_SPEremoved. Thanks for the catch!BTW,
looks like guest trap on MSR[SPE] in para virt mode for now, is it? If we don't want to trap on that, thenshadow_msrdoesn't work here. That's the intend to usemsr_block..Quoted 4 lines
I see. I still like it better when we explicitly set the MSR value that's used while running the guest. Makes it harder for things to slip through. Also, so far paravirt is disabled for BookE.
We already use paravirt in internal tree.
Quoted 9 lines
So what happens is that since
MSR_SPEis disabled, we get aBOOKE_INTERRUPT_SPE_UNAVAIL. At that point, we need to check if it's enabled inside the guest already or if we merely need to activate the flag. That's what the patch does. We'd have to do the exact same when usingmsr_block, no? The only difference is that we'd setmsr_blockinstead ofshadow_msrwhen we are actually able to use the SPE inside the guest.
Quoted 5 lines
Hmm. I think you're right.
I thought that in paravirt mode, if we don't trap on MSR[SPE],
theshadow_msrcannot get notified timely (we don't have chance to callkvmppc_set_msr()). But looks likemsr_blockhas the same issue.
So that MSR[SPE] should always be traped.
It doesn't have to be trapped - we can enable it lazily on SPE_UNAVAIL :). Of course we should also explicitly enable it on set_msr.
Alex
Quoted 118 lines
-----Original Message-----
From: Alexander Graf [mailto:[email protected]]
Sent: Thursday, March 31, 2011 4:43 PM
To: Liu Yu-B13201
Cc: Wood Scott-B07421; [email protected]
Subject: Re: [PATCH v5 4/4] KVM: PPC: e500: Save/restore SPE stateQuoted 10 lines · On 31.03.2011, at 10:40, Liu Yu-B13201 wrote:
Quoted 10 lines
-----Original Message-----
From: Alexander Graf [mailto:[email protected]]
Sent: Thursday, March 31, 2011 4:15 PM
To: Liu Yu-B13201
Cc: Wood Scott-B07421; [email protected]
Subject: Re: [PATCH v5 4/4] KVM: PPC: e500: Save/restore SPE stateQuoted 7 lines
Quoted 7 lines · On 31.03.2011, at 10:06, Liu Yu-B13201 wrote:
Quoted 6 lines
Quoted 6 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf OfAlexander Graf
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Sent: Thursday, March 31, 2011 3:51 PM
To: Liu Yu-B13201
Cc: Wood Scott-B07421; [email protected]
Subject: Re: [PATCH v5 4/4] KVM: PPC: e500: Save/restoreSPE state
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines · On 31.03.2011, at 05:21, Liu Yu-B13201 wrote:
Quoted 11 lines
Quoted 11 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Scott Wood
Sent: Thursday, March 31, 2011 7:35 AM
To: [email protected]
Cc: [email protected]
Subject: [PATCH v5 4/4] KVM: PPC: e500: Save/restore SPE stateQuoted 1 line
Quoted 1 line
This is done lazily. The SPE save will be done only if
the guest has
Quoted 6 lines
Quoted 6 lines
used SPE since the last preemption or heavyweight exit. Restore will be
done only on demand, when enablingMSR_SPEin the shadow MSR, in response
to an SPE fault or mtmsr emulation.Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
For SPEFSCR, Linux already switches it on context switch (non-lazily), so
the only remaining bit is to save it between qemu andthe guest.
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 7 lines
Quoted 7 lines
Signed-off-by Liu Yu <[email protected]>Signed-off-by Scott Wood <[email protected]>---
v5: disable preemption when restoring SPE stateSaving SPE state is only done from a preempt notifier or
vcpu_put(),Quoted 17 lines
Quoted 4 lines
where preemption is already disabled.
The other patches in this series are the same as v4.
Quoted 10 lines
arch/powerpc/include/asm/kvm_host.h | 6 +++ arch/powerpc/include/asm/reg_booke.h | 1 + arch/powerpc/kernel/asm-offsets.c | 6 +++ arch/powerpc/kvm/booke.c | 72 +++++++++++++++++++++++++++++++++- arch/powerpc/kvm/booke.h | 18 ++------- arch/powerpc/kvm/booke_interrupts.S | 40 +++++++++++++++++++ arch/powerpc/kvm/e500.c | 19 ++++++++- 7 files changed, 145 insertions(+), 17 deletions(-)I think the patch miss the bit to handle the case that if guest clear the
MSR_SPE.Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Right. On
set_msrtheshadow_msrshould getMSR_SPEremoved. Thanks for the catch!BTW,
looks like guest trap on MSR[SPE] in para virt mode fornow, is it?
Quoted 1 line
Quoted 1 line
Quoted 1 line
If we don't want to trap on that, then
shadow_msrdoesn'twork here.
Quoted 19 lines
Quoted 6 lines
Quoted 1 line
That's the intend to use
msr_block..I see. I still like it better when we explicitly set the MSR value that's used while running the guest. Makes it harder for things to slip through. Also, so far paravirt is disabled for BookE.
We already use paravirt in internal tree.
Quoted 9 lines
So what happens is that since
MSR_SPEis disabled, we get aBOOKE_INTERRUPT_SPE_UNAVAIL. At that point, we need to check if it's enabled inside the guest already or if we merely need to activate the flag. That's what the patch does. We'd have to do the exact same when usingmsr_block, no? The only difference is that we'd setmsr_blockinstead ofshadow_msrwhen we are actually able to use the SPE inside the guest.Quoted 3 lines
Hmm. I think you're right.
I thought that in paravirt mode, if we don't trap on MSR[SPE], theshadow_msrcannot get notified timely (we don't have
Quoted 8 lines
chance to call
kvmppc_set_msr()).Quoted 2 lines
But looks like
msr_blockhas the same issue.
So that MSR[SPE] should always be traped.It doesn't have to be trapped - we can enable it lazily on
SPE_UNAVAIL:). Of course we should also explicitly enable it onset_msr.
It works on set MSR[SPE], but doesn't work on clear MSR[SPE]. Guest may also do lazy SPE, if guest clear MSR[SPE], but kvm don't know and still keep it.
Then guest app may get SPE state clobbered.
Thanks,
Yu
Quoted 127 lines · On 31.03.2011, at 11:01, Liu Yu-B13201 wrote:
Quoted 118 lines
-----Original Message-----
From: Alexander Graf [mailto:[email protected]]
Sent: Thursday, March 31, 2011 4:43 PM
To: Liu Yu-B13201
Cc: Wood Scott-B07421; [email protected]
Subject: Re: [PATCH v5 4/4] KVM: PPC: e500: Save/restore SPE stateQuoted 10 lines · On 31.03.2011, at 10:40, Liu Yu-B13201 wrote:
Quoted 10 lines
-----Original Message-----
From: Alexander Graf [mailto:[email protected]]
Sent: Thursday, March 31, 2011 4:15 PM
To: Liu Yu-B13201
Cc: Wood Scott-B07421; [email protected]
Subject: Re: [PATCH v5 4/4] KVM: PPC: e500: Save/restore SPE stateQuoted 7 lines
Quoted 7 lines · On 31.03.2011, at 10:06, Liu Yu-B13201 wrote:
Quoted 6 lines
Quoted 6 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf OfAlexander Graf
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Sent: Thursday, March 31, 2011 3:51 PM
To: Liu Yu-B13201
Cc: Wood Scott-B07421; [email protected]
Subject: Re: [PATCH v5 4/4] KVM: PPC: e500: Save/restoreSPE state
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines · On 31.03.2011, at 05:21, Liu Yu-B13201 wrote:
Quoted 11 lines
Quoted 11 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Scott Wood
Sent: Thursday, March 31, 2011 7:35 AM
To: [email protected]
Cc: [email protected]
Subject: [PATCH v5 4/4] KVM: PPC: e500: Save/restore SPE stateQuoted 1 line
Quoted 1 line
This is done lazily. The SPE save will be done only if
the guest has
Quoted 6 lines
Quoted 6 lines
used SPE since the last preemption or heavyweight exit. Restore will be
done only on demand, when enablingMSR_SPEin the shadow MSR, in response
to an SPE fault or mtmsr emulation.Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
For SPEFSCR, Linux already switches it on context switch (non-lazily), so
the only remaining bit is to save it between qemu andthe guest.
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 7 lines
Quoted 7 lines
Signed-off-by Liu Yu <[email protected]>Signed-off-by Scott Wood <[email protected]>---
v5: disable preemption when restoring SPE stateSaving SPE state is only done from a preempt notifier or
vcpu_put(),Quoted 17 lines
Quoted 4 lines
where preemption is already disabled.
The other patches in this series are the same as v4.
Quoted 10 lines
arch/powerpc/include/asm/kvm_host.h | 6 +++ arch/powerpc/include/asm/reg_booke.h | 1 + arch/powerpc/kernel/asm-offsets.c | 6 +++ arch/powerpc/kvm/booke.c | 72 +++++++++++++++++++++++++++++++++- arch/powerpc/kvm/booke.h | 18 ++------- arch/powerpc/kvm/booke_interrupts.S | 40 +++++++++++++++++++ arch/powerpc/kvm/e500.c | 19 ++++++++- 7 files changed, 145 insertions(+), 17 deletions(-)I think the patch miss the bit to handle the case that if guest clear the
MSR_SPE.Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Right. On
set_msrtheshadow_msrshould getMSR_SPEremoved. Thanks for the catch!BTW,
looks like guest trap on MSR[SPE] in para virt mode fornow, is it?
Quoted 1 line
Quoted 1 line
Quoted 1 line
If we don't want to trap on that, then
shadow_msrdoesn'twork here.
Quoted 19 lines
Quoted 6 lines
Quoted 1 line
That's the intend to use
msr_block..I see. I still like it better when we explicitly set the MSR value that's used while running the guest. Makes it harder for things to slip through. Also, so far paravirt is disabled for BookE.
We already use paravirt in internal tree.
Quoted 9 lines
So what happens is that since
MSR_SPEis disabled, we get aBOOKE_INTERRUPT_SPE_UNAVAIL. At that point, we need to check if it's enabled inside the guest already or if we merely need to activate the flag. That's what the patch does. We'd have to do the exact same when usingmsr_block, no? The only difference is that we'd setmsr_blockinstead ofshadow_msrwhen we are actually able to use the SPE inside the guest.Quoted 3 lines
Hmm. I think you're right.
I thought that in paravirt mode, if we don't trap on MSR[SPE], theshadow_msrcannot get notified timely (we don't haveQuoted 8 lines
chance to call
kvmppc_set_msr()).Quoted 2 lines
But looks like
msr_blockhas the same issue.
So that MSR[SPE] should always be traped.It doesn't have to be trapped - we can enable it lazily on
SPE_UNAVAIL:). Of course we should also explicitly enable it onset_msr.
Quoted 4 lines
It works on set MSR[SPE], but doesn't work on clear MSR[SPE]. Guest may also do lazy SPE, if guest clear MSR[SPE], but kvm don't know and still keep it.
Then guest app may get SPE state clobbered.
Ah, yes. On SPE clear we definitely have to trap :).
Alex
Quoted 130 lines · Alexander Graf
Quoted 127 lines · On 31.03.2011, at 11:01, Liu Yu-B13201 wrote:
Quoted 126 lines
-----Original Message-----
From: Alexander Graf [mailto:[email protected]]
Sent: Thursday, March 31, 2011 4:43 PM
To: Liu Yu-B13201
Cc: Wood Scott-B07421; [email protected]
Subject: Re: [PATCH v5 4/4] KVM: PPC: e500: Save/restore SPE stateQuoted 10 lines · On 31.03.2011, at 10:40, Liu Yu-B13201 wrote:
Quoted 10 lines
-----Original Message-----
From: Alexander Graf [mailto:[email protected]]
Sent: Thursday, March 31, 2011 4:15 PM
To: Liu Yu-B13201
Cc: Wood Scott-B07421; [email protected]
Subject: Re: [PATCH v5 4/4] KVM: PPC: e500: Save/restore SPE stateQuoted 7 lines
Quoted 7 lines · On 31.03.2011, at 10:06, Liu Yu-B13201 wrote:
Quoted 6 lines
Quoted 6 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf OfAlexander Graf
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Sent: Thursday, March 31, 2011 3:51 PM
To: Liu Yu-B13201
Cc: Wood Scott-B07421; [email protected]
Subject: Re: [PATCH v5 4/4] KVM: PPC: e500: Save/restoreSPE state
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines · On 31.03.2011, at 05:21, Liu Yu-B13201 wrote:
Quoted 11 lines
Quoted 11 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Scott Wood
Sent: Thursday, March 31, 2011 7:35 AM
To: [email protected]
Cc: [email protected]
Subject: [PATCH v5 4/4] KVM: PPC: e500: Save/restore SPE stateQuoted 1 line
Quoted 1 line
This is done lazily. The SPE save will be done only if
the guest has
Quoted 6 lines
Quoted 6 lines
used SPE since the last preemption or heavyweight exit. Restore will be
done only on demand, when enablingMSR_SPEin the shadow MSR, in response
to an SPE fault or mtmsr emulation.Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
For SPEFSCR, Linux already switches it on context switch (non-lazily), so
the only remaining bit is to save it between qemu andthe guest.
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 7 lines
Quoted 7 lines
Signed-off-by Liu Yu <[email protected]>Signed-off-by Scott Wood <[email protected]>---
v5: disable preemption when restoring SPE stateSaving SPE state is only done from a preempt notifier or
vcpu_put(),Quoted 17 lines
Quoted 4 lines
where preemption is already disabled.
The other patches in this series are the same as v4.
Quoted 10 lines
arch/powerpc/include/asm/kvm_host.h | 6 +++ arch/powerpc/include/asm/reg_booke.h | 1 + arch/powerpc/kernel/asm-offsets.c | 6 +++ arch/powerpc/kvm/booke.c | 72 +++++++++++++++++++++++++++++++++- arch/powerpc/kvm/booke.h | 18 ++------- arch/powerpc/kvm/booke_interrupts.S | 40 +++++++++++++++++++ arch/powerpc/kvm/e500.c | 19 ++++++++- 7 files changed, 145 insertions(+), 17 deletions(-)I think the patch miss the bit to handle the case that if guest clear the
MSR_SPE.Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Right. On
set_msrtheshadow_msrshould getMSR_SPEremoved. Thanks for the catch!BTW,
looks like guest trap on MSR[SPE] in para virt mode fornow, is it?
Quoted 1 line
Quoted 1 line
Quoted 1 line
If we don't want to trap on that, then
shadow_msrdoesn'twork here.
Quoted 19 lines
Quoted 6 lines
Quoted 1 line
That's the intend to use
msr_block..I see. I still like it better when we explicitly set the MSR value that's used while running the guest. Makes it harder for things to slip through. Also, so far paravirt is disabled for BookE.
We already use paravirt in internal tree.
Quoted 9 lines
So what happens is that since
MSR_SPEis disabled, we get aBOOKE_INTERRUPT_SPE_UNAVAIL. At that point, we need to check if it's enabled inside the guest already or if we merely need to activate the flag. That's what the patch does. We'd have to do the exact same when usingmsr_block, no? The only difference is that we'd setmsr_blockinstead ofshadow_msrwhen we are actually able to use the SPE inside the guest.Quoted 3 lines
Hmm. I think you're right.
I thought that in paravirt mode, if we don't trap on MSR[SPE], theshadow_msrcannot get notified timely (we don't havechance to call
kvmppc_set_msr()).Quoted 2 lines
But looks like
msr_blockhas the same issue.
So that MSR[SPE] should always be traped.It doesn't have to be trapped - we can enable it lazily on
SPE_UNAVAIL:). Of course we should also explicitly enable it onset_msr.
Quoted 6 lines
Quoted 4 lines
It works on set MSR[SPE], but doesn't work on clear MSR[SPE]. Guest may also do lazy SPE, if guest clear MSR[SPE], but kvm don't know and still keep it.
Then guest app may get SPE state clobbered.Ah, yes. On SPE clear we definitely have to trap :).
Scott, to verify that I don't completely screw up the lazy FPU work back when I did it, I wrote some small test program that would just initialize an fpu register with a value and then constantly loop to verify if it's still the same. I ran that program with different values on the host and guest sides. That exposed quite a lot of glitches.
It would be nice if you could provide something similar for the SPE patches, so we have some more faith in it :).
Alex
Quoted 5 lines · On Thu, 31 Mar 2011 12:11:48 +0200 Alexander Graf <[email protected]> wrote:
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines · On 31.03.2011, at 05:21, Liu Yu-B13201 wrote:
Quoted 4 lines
I think the patch miss the bit to handle the case that if guest clear the
MSR_SPE.
Doh.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 1 line
So that MSR[SPE] should always be traped.
It doesn't have to be trapped - we can enable it lazily on
SPE_UNAVAIL:). Of course we should also explicitly enable it onset_msr.
I don't see any benefit to doing this, if we're going to take a trap one way or another. Since we need to trap on clearing it anyway, might as well just keep things simple and have SPE always be a trapworthy MSR bit.
Quoted 3 lines
Scott, to verify that I don't completely screw up the lazy FPU work back when I did it, I wrote some small test program that would just initialize an fpu register with a value and then constantly loop to verify if it's still the same. I ran that program with different values on the host and guest sides. That exposed quite a lot of glitches.
It would be nice if you could provide something similar for the SPE patches, so we have some more faith in it :).
OK.
-Scott
Quoted 13 lines · Scott Wood
Quoted 5 lines · On Thu, 31 Mar 2011 12:11:48 +0200 Alexander Graf <[email protected]> wrote:
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines · On 31.03.2011, at 05:21, Liu Yu-B13201 wrote:
Quoted 4 lines
I think the patch miss the bit to handle the case that if guest clear the
MSR_SPE.Doh.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
So that MSR[SPE] should always be traped.
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
It doesn't have to be trapped - we can enable it lazily on
SPE_UNAVAIL:). Of course we should also explicitly enable it onset_msr.I don't see any benefit to doing this, if we're going to take a trap one way or another. Since we need to trap on clearing it anyway, might as well just keep things simple and have SPE always be a trapworthy MSR bit.
Agreed. Please make sure to enable it in advance on set_msr then though, as we'd otherwise get 2 exits to enable SPE.
Alex
PATCH v5 4/4 KVM: PPC: e500: Save/restore SPE state
In reply to Scott WoodThis 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.
---
v5: Clear shadow MSR[SPE] if guest clears MSR[SPE].
arch/powerpc/include/asm/kvm_host.h | 6 ++ arch/powerpc/include/asm/reg_booke.h | 1 + arch/powerpc/kernel/asm-offsets.c | 6 ++ arch/powerpc/kvm/booke.c | 84 +++++++++++++++++++++++++++++++++- arch/powerpc/kvm/booke.h | 22 +++------ arch/powerpc/kvm/booke_interrupts.S | 40 ++++++++++++++++ arch/powerpc/kvm/e500.c | 15 ++---- 7 files changed, 149 insertions(+), 25 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
@@ -312,6 +312,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 +6 -0
@@ -494,6 +494,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 +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 +40 -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)
@@ -426,3 +443,26 @@ 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- + addi r5,r3,VCPU_EVR + SAVE_32EVRS(0, r4, r5, 0) + 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 */ + addi r5,r3,VCPU_EVR + REST_32EVRS(0, r4, r5, 0) + blr +#endif
arch/powerpc/kvm/e500.c +6 -9
@@ -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]> *
@@ -25,14 +25,6 @@#include "booke.h" #include "e500_tlb.h" -void kvmppc_core_load_host_debugstate (struct kvm_vcpu *vcpu) -{ -} - -void kvmppc_core_load_guest_debugstate (struct kvm_vcpu *vcpu) -{ -} -void kvmppc_core_vcpu_load (struct kvm_vcpu *vcpu,int cpu) {kvmppc_e500_tlb_load (vcpu, cpu);
@@ -41,6 +33,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.1
Quoted 9 lines · Alexander Graf
Scott, to verify that I don't completely screw up the lazy FPU work back when I did it, I wrote some small test program that would just initialize an fpu register with a value and then constantly loop to verify if it's still the same. I ran that program with different values on the host and guest sides. That exposed quite a lot of glitches.
It would be nice if you could provide something similar for the SPE patches, so we have some more faith in it :).
Here it is. As expected, it fails with v4 of the SPE patch once you run two instances in parallel on the guest. It passes with v5, with multiple instances in both the host and the guest.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <stdint.h>
int main(void)
{
double reg, tmp;
uint64_t val;
srand(time(NULL) ^ (getpid() << 16));
val = rand();
val <<= 32;
val |= rand();
printf("pid %d: val is %#llx\n", getpid(), val);
asm volatile("evldd %0, %2;"
"1: evldd %1, %2;"
"evcmpeq 0, %0, %1;"
"bso 1b" :
"=r" (reg), "=r" (tmp) :
"m" (val));
printf("FAIL: pid %d: val %#llx reg %#llx tmp %#llx\n",
val, *(uint64_t *)®, *(uint64_t *)&tmp);
return 1;
}Quoted 56 lines · Scott Wood
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_SPEin 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]>---
v5: Clear shadow MSR[SPE] if guest clears MSR[SPE].arch/powerpc/include/asm/kvm_host.h | 6 ++ arch/powerpc/include/asm/reg_booke.h | 1 + arch/powerpc/kernel/asm-offsets.c | 6 ++ arch/powerpc/kvm/booke.c | 84 +++++++++++++++++++++++++++++++++- arch/powerpc/kvm/booke.h | 22 +++------ arch/powerpc/kvm/booke_interrupts.S | 40 ++++++++++++++++ arch/powerpc/kvm/e500.c | 15 ++---- 7 files changed, 149 insertions(+), 25 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@@ -312,6 +312,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 +0
-0
arch/powerpc/kernel/asm-offsets.c int main(void) · line 497
Quoted 4 lines
arch/powerpc/kernel/asm-offsets.c +1
-0@@ -494,6 +494,12 @@ int main(void)DEFINE (TLBCAM_MAS3 , offsetof(struct tlbcam , MAS3));DEFINE (TLBCAM_MAS7 , offsetof(struct tlbcam , MAS7));#endif +#ifdef CONFIG_SPE
if defined(CONFIG_KVM) && defined(CONFIG_SPE)
Quoted 40 lines
arch/powerpc/kernel/asm-offsets.c +5
-0+ 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 +17
-0@@ -13,6 +13,7 @@* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Copyright IBM Corp. 2007 +* Copyright 2010-2011 Freescale Semiconductor, Inc. * * Authors: Hollis Blanchard<[email protected]> * Christian Ehrhardt<[email protected]> @@ -78,6 +79,57 @@ void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu) } } +#ifdef CONFIG_SPE +void kvmppc_vcpu_disable_spe (struct kvm_vcpu *vcpu) +{ +preempt_disable (); +enable_kernel_spe (); +kvmppc_save_guest_spe (vcpu); + vcpu->arch.shadow_msr&= ~MSR_SPE ; +preempt_enable (); +} + +static void kvmppc_vcpu_enable_spe (struct kvm_vcpu *vcpu) +{ +preempt_disable (); +enable_kernel_spe (); +kvmppc_load_guest_spe (vcpu); + vcpu->arch.shadow_msr |=MSR_SPE ;
arch/powerpc/kvm/booke.c void kvmppc_dump_vcpu(struct kvm_vcpu *vcpu) · line 107
Quoted 10 lines
arch/powerpc/kvm/booke.c +10
-0+preempt_enable (); +} + +static void kvmppc_vcpu_sync_spe (struct kvm_vcpu *vcpu) +{ +if (vcpu->arch.shared->msr&MSR_SPE ) { +if (!(vcpu->arch.shadow_msr&MSR_SPE )) +kvmppc_vcpu_enable_spe (vcpu); + }else if (vcpu->arch.shadow_msr&MSR_SPE ) { +kvmppc_vcpu_disable_spe (vcpu);
So what if shared->msr & MSR_SPE && shadow_msr & MSR_SPE? Do you disable it then?
Quoted 160 lines
arch/powerpc/kvm/booke.c +55
-2+ } +} +#else +static void kvmppc_vcpu_sync_spe (struct kvm_vcpu *vcpu) +{ +} +#endif + +/* Helper function for "full" MSR writes. No need to call this if only EE is +* changing. */ +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 ); + }; + +kvmppc_vcpu_sync_spe (vcpu); +} +static void kvmppc_booke_queue_irqprio (struct kvm_vcpu *vcpu,unsigned int priority) {@@ -344,10 +396,16 @@ 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 : { +if (vcpu->arch.shared->msr&MSR_SPE ) +kvmppc_vcpu_enable_spe (vcpu); +else +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 +416,28 @@ 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 ; +#else +case BOOKE_INTERRUPT_SPE_UNAVAIL : +/* +* Guest wants SPE, but host kernel doesn't support it. Send +* an "unimplemented operation" program check to the guest. +*/ +kvmppc_core_queue_program (vcpu,ESR_PUO |ESR_SPV ); + r =RESUME_GUEST ; +break ; + +/* +* These really should never happen without CONFIG_SPE, +* as we should never enable the real MSR[SPE] in the guest. +*/ +case BOOKE_INTERRUPT_SPE_FP_DATA : +case BOOKE_INTERRUPT_SPE_FP_ROUND : +printk (KERN_CRIT "%s: unexpected SPE interrupt %u at %08lx\n" , + __func__, exit_nr, vcpu->arch.pc); + run->hw.hardware_exit_reason = exit_nr; + r =RESUME_HOST ; +break ; +#endif case BOOKE_INTERRUPT_DATA_STORAGE : kvmppc_core_queue_data_storage(vcpu, vcpu->arch.fault_dear,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 +18
-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)@@ -426,3 +443,26 @@ lightweight_exit: lwz r3, VCPU_GPR(r3)(r4) lwz r4, VCPU_GPR(r4)(r4) rfi +
arch/powerpc/kvm/booke_interrupts.S lightweight_exit: · line 456
Quoted 10 lines
arch/powerpc/kvm/booke_interrupts.S +10
-0+#ifdef CONFIG_SPE +_GLOBAL(kvmppc_save_guest_spe) + cmpi 0,r3,0 + beqlr- + addi r5,r3,VCPU_EVR + SAVE_32EVRS(0, r4, r5, 0) + evxor evr6, evr6, evr6 + evmwumiaa evr6, evr6, evr6 + li r4,VCPU_ACC + evstddx evr6, r4, r3 /* save acc */
I'm not sure I fully understand SPE instructions yet, but isn't evr6 just r6 plus its upper 32 bits? Then wouldn't it make sense to work in evr3/evr4 and only copy the upper 32 bits over to another register? Not that it should matter - I'm only being curious here :)
Alex
Quoted 12 lines · On Mon, 4 Apr 2011 17:01:31 +0200 Alexander Graf <[email protected]> wrote:
arch/powerpc/kernel/asm-offsets.c int main(void) · line 497
Quoted 9 lines · Scott Wood
arch/powerpc/kernel/asm-offsets.c +1
-0@@ -494,6 +494,12 @@ int main(void)DEFINE (TLBCAM_MAS3 , offsetof(struct tlbcam , MAS3));DEFINE (TLBCAM_MAS7 , offsetof(struct tlbcam , MAS7));#endif +#ifdef CONFIG_SPE if
defined(CONFIG_KVM)&&defined(CONFIG_SPE)
Right.
Quoted 10 lines
arch/powerpc/kernel/asm-offsets.c int main(void) · line 504
Quoted 7 lines
arch/powerpc/kernel/asm-offsets.c +7
-0+static void kvmppc_vcpu_sync_spe (struct kvm_vcpu *vcpu) +{ +if (vcpu->arch.shared->msr&MSR_SPE ) { +if (!(vcpu->arch.shadow_msr&MSR_SPE )) +kvmppc_vcpu_enable_spe (vcpu); + }else if (vcpu->arch.shadow_msr&MSR_SPE ) { +kvmppc_vcpu_disable_spe (vcpu);So what if
shared->msr&MSR_SPE&&shadow_msr&MSR_SPE? Do you disable it then?
No.
The only times it should get disabled are if the guest clears its MSR_SPE, or from kvmppc_core_vcpu_put().
If you're saying you think this code does so by accident, I don't see it -- the disable call is in an else branch that ensures !(shared->msr & MSR_SPE).
Quoted 6 lines
arch/powerpc/kernel/asm-offsets.c int main(void)
Quoted 6 lines
arch/powerpc/kernel/asm-offsets.c +6
-0+#ifdef CONFIG_SPE +_GLOBAL (kvmppc_save_guest_spe) + cmpi 0,r3,0 + beqlr- + addi r5,r3,VCPU_EVR +SAVE_32EVRS (0 , r4, r5,0 )
Hmm, I missed VCPU_EVR here, it can be directly passed to SAVE_32EVRS now.
Quoted 7 lines
arch/powerpc/kernel/asm-offsets.c
Quoted 4 lines
arch/powerpc/kernel/asm-offsets.c +4
-0+evxor evr6, evr6, evr6 + evmwumiaa evr6, evr6, evr6 + li r4,VCPU_ACC + evstddx evr6, r4, r3 /* save acc */I'm not sure I fully understand SPE instructions yet, but isn't evr6 just r6 plus its upper 32 bits?
Yes.
Quoted 3 lines
Then wouldn't it make sense to work in evr3/evr4 and only copy the upper 32 bits over to another register? Not that it should matter - I'm only being curious here :)
We need to save the whole thing -- evr6 holds the accumulator at that point (produced by the preceding evxor+evwmumiaa), not a regular EVR whose lower half has already been saved. evstddx is the easiest way to do that.
-Scott
Am 04.04.2011 um 18:07 schrieb Scott Wood <[email protected]>:
Quoted 29 lines
Quoted 12 lines · On Mon, 4 Apr 2011 17:01:31 +0200 Alexander Graf <[email protected]> wrote:
arch/powerpc/kernel/asm-offsets.c int main(void) · line 497
Quoted 9 lines · Scott Wood
arch/powerpc/kernel/asm-offsets.c +1
-0@@ -494,6 +494,12 @@ int main(void)DEFINE (TLBCAM_MAS3 , offsetof(struct tlbcam , MAS3));DEFINE (TLBCAM_MAS7 , offsetof(struct tlbcam , MAS7));#endif +#ifdef CONFIG_SPE if
defined(CONFIG_KVM)&&defined(CONFIG_SPE)Right.
Quoted 10 lines
arch/powerpc/kernel/asm-offsets.c int main(void) · line 504
Quoted 7 lines
arch/powerpc/kernel/asm-offsets.c +7
-0+static void kvmppc_vcpu_sync_spe (struct kvm_vcpu *vcpu) +{ +if (vcpu->arch.shared->msr&MSR_SPE ) { +if (!(vcpu->arch.shadow_msr&MSR_SPE )) +kvmppc_vcpu_enable_spe (vcpu); + }else if (vcpu->arch.shadow_msr&MSR_SPE ) { +kvmppc_vcpu_disable_spe (vcpu);So what if
shared->msr&MSR_SPE&&shadow_msr&MSR_SPE? Do you disable it then?
Quoted 7 lines
No.
The only times it should get disabled are if the guest clears its
MSR_SPE, or fromkvmppc_core_vcpu_put().If you're saying you think this code does so by accident, I don't see it -- the disable call is in an else branch that ensures !(shared->msr &
MSR_SPE).
Ah, I must have missen the branch levels :). You're right.
Quoted 9 lines
Quoted 7 lines
arch/powerpc/kernel/asm-offsets.c int main(void)
Quoted 7 lines
arch/powerpc/kernel/asm-offsets.c +6
-0+#ifdef CONFIG_SPE +_GLOBAL (kvmppc_save_guest_spe) + cmpi 0,r3,0 + beqlr- + addi r5,r3,VCPU_EVR +SAVE_32EVRS (0 , r4, r5,0 )Hmm, I missed
VCPU_EVRhere, it can be directly passed toSAVE_32EVRSnow.
Yup :)
Quoted 11 lines
Quoted 8 lines
arch/powerpc/kernel/asm-offsets.c
Quoted 5 lines
arch/powerpc/kernel/asm-offsets.c +4
-0+evxor evr6, evr6, evr6 + evmwumiaa evr6, evr6, evr6 + li r4,VCPU_ACC + evstddx evr6, r4, r3 /* save acc */I'm not sure I fully understand SPE instructions yet, but isn't evr6 just r6 plus its upper 32 bits?
Yes.
Quoted 8 lines
Quoted 3 lines
Then wouldn't it make sense to work in evr3/evr4 and only copy the upper 32 bits over to another register? Not that it should matter - I'm only being curious here :)
We need to save the whole thing -- evr6 holds the accumulator at that point (produced by the preceding evxor+evwmumiaa), not a regular EVR whose lower half has already been saved. evstddx is the easiest way to do that.
Okies :)
Alex