[PATCH v2 09/11] KVM: arm64: Trap host SVE accesses when the FPSIMD state is dirty

Will Deacon will at kernel.org
Thu Mar 18 14:11:44 GMT 2021


On Thu, Mar 18, 2021 at 12:25:30PM +0000, Marc Zyngier wrote:
> ZCR_EL2 controls the upper bound for ZCR_EL1, and is set to
> a potentially lower limit when the guest uses SVE. In order
> to restore the SVE state on the EL1 host, we must first
> reset ZCR_EL2 to its original value.
> 
> To make it as lazy as possible on the EL1 host side, set
> the SVE trapping in place when returning exiting from

"returning exiting"?

> diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c
> index f3d0e9eca56c..60adc7ff4caa 100644
> --- a/arch/arm64/kvm/hyp/nvhe/switch.c
> +++ b/arch/arm64/kvm/hyp/nvhe/switch.c
> @@ -68,7 +68,7 @@ static void __activate_traps(struct kvm_vcpu *vcpu)
>  static void __deactivate_traps(struct kvm_vcpu *vcpu)
>  {
>  	extern char __kvm_hyp_host_vector[];
> -	u64 mdcr_el2;
> +	u64 mdcr_el2, cptr;
>  
>  	___deactivate_traps(vcpu);
>  
> @@ -101,7 +101,12 @@ static void __deactivate_traps(struct kvm_vcpu *vcpu)
>  		write_sysreg(HCR_HOST_NVHE_PROTECTED_FLAGS, hcr_el2);
>  	else
>  		write_sysreg(HCR_HOST_NVHE_FLAGS, hcr_el2);
> -	write_sysreg(CPTR_EL2_DEFAULT, cptr_el2);
> +
> +	cptr = CPTR_EL2_DEFAULT;
> +	if (vcpu_has_sve(vcpu) && (vcpu->arch.flags & KVM_ARM64_FP_ENABLED))
> +		cptr |= CPTR_EL2_TZ;

Acked-by: Will Deacon <will at kernel.org>

Will



More information about the linux-arm-kernel mailing list