Skip to content

Commit 7d14919

Browse files
Marc Zyngierchristofferdall-arm
authored andcommitted
arm64: KVM: Only force FPEXC32_EL2.EN if trapping FPSIMD
If trapping FPSIMD in the context of an AArch32 guest, it is critical to set FPEXC32_EL2.EN to 1 so that the trapping is taken to EL2 and not EL1. Conversely, it is just as critical *not* to set FPEXC32_EL2.EN to 1 if we're not going to trap FPSIMD, as we then corrupt the existing VFP state. Moving the call to __activate_traps_fpsimd32 to the point where we know for sure that we are going to trap ensures that we don't set that bit spuriously. Fixes: e6b673b ("KVM: arm64: Optimise FPSIMD handling to reduce guest/host thrashing") Cc: stable@vger.kernel.org # v4.18 Cc: Dave Martin <dave.martin@arm.com> Reported-by: Alexander Graf <agraf@suse.de> Tested-by: Alexander Graf <agraf@suse.de> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Christoffer Dall <christoffer.dall@arm.com>
1 parent 694556d commit 7d14919

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

arch/arm64/kvm/hyp/switch.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ static void activate_traps_vhe(struct kvm_vcpu *vcpu)
9898
val = read_sysreg(cpacr_el1);
9999
val |= CPACR_EL1_TTA;
100100
val &= ~CPACR_EL1_ZEN;
101-
if (!update_fp_enabled(vcpu))
101+
if (!update_fp_enabled(vcpu)) {
102102
val &= ~CPACR_EL1_FPEN;
103+
__activate_traps_fpsimd32(vcpu);
104+
}
103105

104106
write_sysreg(val, cpacr_el1);
105107

@@ -114,8 +116,10 @@ static void __hyp_text __activate_traps_nvhe(struct kvm_vcpu *vcpu)
114116

115117
val = CPTR_EL2_DEFAULT;
116118
val |= CPTR_EL2_TTA | CPTR_EL2_TZ;
117-
if (!update_fp_enabled(vcpu))
119+
if (!update_fp_enabled(vcpu)) {
118120
val |= CPTR_EL2_TFP;
121+
__activate_traps_fpsimd32(vcpu);
122+
}
119123

120124
write_sysreg(val, cptr_el2);
121125
}
@@ -129,7 +133,6 @@ static void __hyp_text __activate_traps(struct kvm_vcpu *vcpu)
129133
if (cpus_have_const_cap(ARM64_HAS_RAS_EXTN) && (hcr & HCR_VSE))
130134
write_sysreg_s(vcpu->arch.vsesr_el2, SYS_VSESR_EL2);
131135

132-
__activate_traps_fpsimd32(vcpu);
133136
if (has_vhe())
134137
activate_traps_vhe(vcpu);
135138
else

0 commit comments

Comments
 (0)