2022-12-20 03:22:34

by Dong Bo

[permalink] [raw]
Subject: [PATCH] KVM: arm64: Synchronize SMEN on vcpu schedule out

From: Nianyao Tang <[email protected]>

If we have VHE and need to reenable SME for host in
kvm_arch_vcpu_put_fp, CPACR.SMEN is modified from 0 to 1. Trap
control for reading SVCR is modified from enable to disable.
Synchronization is needed before reading SVCR later in
fpsimd_save, or it may cause sync exception which can not be
handled by host.

Cc: Marc Zyngier <[email protected]>
Cc: James Morse <[email protected]>
Cc: Alexandru Elisei <[email protected]>
Cc: Suzuki K Poulose <[email protected]>
Cc: Oliver Upton <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Will Deacon <[email protected]>
Signed-off-by: Nianyao Tang <[email protected]>
---
arch/arm64/kvm/fpsimd.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/arch/arm64/kvm/fpsimd.c b/arch/arm64/kvm/fpsimd.c
index 02dd7e9ebd39..f5799f571317 100644
--- a/arch/arm64/kvm/fpsimd.c
+++ b/arch/arm64/kvm/fpsimd.c
@@ -184,6 +184,7 @@ void kvm_arch_vcpu_put_fp(struct kvm_vcpu *vcpu)
sysreg_clear_set(CPACR_EL1,
CPACR_EL1_SMEN_EL0EN,
CPACR_EL1_SMEN_EL1EN);
+ isb();
}

if (vcpu->arch.fp_state == FP_STATE_GUEST_OWNED) {
--
1.8.3.1


2022-12-20 11:13:27

by Marc Zyngier

[permalink] [raw]
Subject: Re: [PATCH] KVM: arm64: Synchronize SMEN on vcpu schedule out

+ Mark

On Tue, 20 Dec 2022 10:50:24 +0000,
Dong Bo <[email protected]> wrote:
>
> From: Nianyao Tang <[email protected]>
>
> If we have VHE and need to reenable SME for host in
> kvm_arch_vcpu_put_fp, CPACR.SMEN is modified from 0 to 1. Trap
> control for reading SVCR is modified from enable to disable.
> Synchronization is needed before reading SVCR later in
> fpsimd_save, or it may cause sync exception which can not be
> handled by host.
>
> Cc: Marc Zyngier <[email protected]>
> Cc: James Morse <[email protected]>
> Cc: Alexandru Elisei <[email protected]>
> Cc: Suzuki K Poulose <[email protected]>
> Cc: Oliver Upton <[email protected]>
> Cc: Catalin Marinas <[email protected]>
> Cc: Will Deacon <[email protected]>
> Signed-off-by: Nianyao Tang <[email protected]>
> ---
> arch/arm64/kvm/fpsimd.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/arch/arm64/kvm/fpsimd.c b/arch/arm64/kvm/fpsimd.c
> index 02dd7e9ebd39..f5799f571317 100644
> --- a/arch/arm64/kvm/fpsimd.c
> +++ b/arch/arm64/kvm/fpsimd.c
> @@ -184,6 +184,7 @@ void kvm_arch_vcpu_put_fp(struct kvm_vcpu *vcpu)
> sysreg_clear_set(CPACR_EL1,
> CPACR_EL1_SMEN_EL0EN,
> CPACR_EL1_SMEN_EL1EN);
> + isb();
> }
>
> if (vcpu->arch.fp_state == FP_STATE_GUEST_OWNED) {
> --
> 1.8.3.1
>
>

--
Without deviation from the norm, progress is not possible.

2022-12-21 14:24:41

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH] KVM: arm64: Synchronize SMEN on vcpu schedule out

On Tue, Dec 20, 2022 at 10:15:18AM +0000, Marc Zyngier wrote:
> Dong Bo <[email protected]> wrote:

> > If we have VHE and need to reenable SME for host in
> > kvm_arch_vcpu_put_fp, CPACR.SMEN is modified from 0 to 1. Trap
> > control for reading SVCR is modified from enable to disable.
> > Synchronization is needed before reading SVCR later in
> > fpsimd_save, or it may cause sync exception which can not be
> > handled by host.

Reviewed-by: Mark Brown <[email protected]>


Attachments:
(No filename) (491.00 B)
signature.asc (499.00 B)
Download all attachments

2023-01-23 20:26:41

by Oliver Upton

[permalink] [raw]
Subject: Re: [PATCH] KVM: arm64: Synchronize SMEN on vcpu schedule out

On Tue, 20 Dec 2022 18:50:24 +0800, Dong Bo wrote:
> From: Nianyao Tang <[email protected]>
>
> If we have VHE and need to reenable SME for host in
> kvm_arch_vcpu_put_fp, CPACR.SMEN is modified from 0 to 1. Trap
> control for reading SVCR is modified from enable to disable.
> Synchronization is needed before reading SVCR later in
> fpsimd_save, or it may cause sync exception which can not be
> handled by host.
>
> [...]

Applied to kvmarm/next, thanks!

[1/1] KVM: arm64: Synchronize SMEN on vcpu schedule out
https://git.kernel.org/kvmarm/kvmarm/c/59d78a2ec0e9

--
Best,
Oliver