[PATCH 4/4] KVM: PPC: e500: SPE switch between guest and host

Alexander Graf agraf at suse.de
Tue Mar 29 20:47:51 EST 2011


On 28.03.2011, at 21:25, Scott Wood wrote:

> From: yu liu <yu.liu at freescale.com>
> 
> 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.
> 
> Signed-off-by: Liu Yu <yu.liu at freescale.com>
> Signed-off-by: Scott Wood <scottwood at freescale.com>
> ---
> 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(-)
> 
> diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h
> index c376f6b..171cd85 100644
> --- a/arch/powerpc/include/asm/kvm_host.h
> +++ b/arch/powerpc/include/asm/kvm_host.h
> @@ -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;
> diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c
> index 75b72c7..554f4d6 100644
> --- a/arch/powerpc/kernel/asm-offsets.c
> +++ b/arch/powerpc/kernel/asm-offsets.c
> @@ -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,
> diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
> index ef76acb..4e9c1a9 100644
> --- a/arch/powerpc/kvm/booke.c
> +++ b/arch/powerpc/kvm/booke.c
> @@ -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 <hollisb at us.ibm.com>
>  *          Christian Ehrhardt <ehrhardt at linux.vnet.ibm.com>
> @@ -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: {

This means that on non-SPE enabled host kernels you'll get a KVM fatal error when the guest triggers SPE_UNAVAIL, as the exit simply isn't handled and triggers:

        default:
                printk(KERN_EMERG "exit_nr %d\n", exit_nr);
                BUG();


Alex



More information about the Linuxppc-dev mailing list