Skip to content

Commit 459f059

Browse files
mrutland-armMarc Zyngier
authored andcommitted
KVM: arm64: Remove VHE host restore of CPACR_EL1.ZEN
When KVM is in VHE mode, the host kernel tries to save and restore the configuration of CPACR_EL1.ZEN (i.e. CPTR_EL2.ZEN when HCR_EL2.E2H=1) across kvm_arch_vcpu_load_fp() and kvm_arch_vcpu_put_fp(), since the configuration may be clobbered by hyp when running a vCPU. This logic is currently redundant. The VHE hyp code unconditionally configures CPTR_EL2.ZEN to 0b01 when returning to the host, permitting host kernel usage of SVE. Now that the host eagerly saves and unbinds its own FPSIMD/SVE/SME state, there's no need to save/restore the state of the EL0 SVE trap. The kernel can safely save/restore state without trapping, as described above, and will restore userspace state (including trap controls) before returning to userspace. Remove the redundant logic. Signed-off-by: Mark Rutland <[email protected]> Reviewed-by: Mark Brown <[email protected]> Tested-by: Mark Brown <[email protected]> Acked-by: Will Deacon <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Fuad Tabba <[email protected]> Cc: Marc Zyngier <[email protected]> Cc: Oliver Upton <[email protected]> Reviewed-by: Oliver Upton <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Zyngier <[email protected]>
1 parent 8eca7f6 commit 459f059

File tree

2 files changed

+0
-17
lines changed

2 files changed

+0
-17
lines changed

arch/arm64/include/asm/kvm_host.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,6 @@ struct cpu_sve_state {
615615
struct kvm_host_data {
616616
#define KVM_HOST_DATA_FLAG_HAS_SPE 0
617617
#define KVM_HOST_DATA_FLAG_HAS_TRBE 1
618-
#define KVM_HOST_DATA_FLAG_HOST_SVE_ENABLED 2
619618
#define KVM_HOST_DATA_FLAG_HOST_SME_ENABLED 3
620619
#define KVM_HOST_DATA_FLAG_TRBE_ENABLED 4
621620
#define KVM_HOST_DATA_FLAG_EL1_TRACING_CONFIGURED 5

arch/arm64/kvm/fpsimd.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ void kvm_arch_vcpu_load_fp(struct kvm_vcpu *vcpu)
6565
fpsimd_save_and_flush_cpu_state();
6666
*host_data_ptr(fp_owner) = FP_STATE_FREE;
6767

68-
host_data_clear_flag(HOST_SVE_ENABLED);
69-
if (read_sysreg(cpacr_el1) & CPACR_EL1_ZEN_EL0EN)
70-
host_data_set_flag(HOST_SVE_ENABLED);
71-
7268
if (system_supports_sme()) {
7369
host_data_clear_flag(HOST_SME_ENABLED);
7470
if (read_sysreg(cpacr_el1) & CPACR_EL1_SMEN_EL0EN)
@@ -202,18 +198,6 @@ void kvm_arch_vcpu_put_fp(struct kvm_vcpu *vcpu)
202198
* when needed.
203199
*/
204200
fpsimd_save_and_flush_cpu_state();
205-
} else if (has_vhe() && system_supports_sve()) {
206-
/*
207-
* The FPSIMD/SVE state in the CPU has not been touched, and we
208-
* have SVE (and VHE): CPACR_EL1 (alias CPTR_EL2) has been
209-
* reset by kvm_reset_cptr_el2() in the Hyp code, disabling SVE
210-
* for EL0. To avoid spurious traps, restore the trap state
211-
* seen by kvm_arch_vcpu_load_fp():
212-
*/
213-
if (host_data_test_flag(HOST_SVE_ENABLED))
214-
sysreg_clear_set(CPACR_EL1, 0, CPACR_EL1_ZEN_EL0EN);
215-
else
216-
sysreg_clear_set(CPACR_EL1, CPACR_EL1_ZEN_EL0EN, 0);
217201
}
218202

219203
local_irq_restore(flags);

0 commit comments

Comments
 (0)