On Thu, Feb 06, 2025 at 02:10:58PM +0000, Mark Rutland wrote: > When KVM is in VHE mode, the host kernel tries to save and restore the > configuration of CPACR_EL1.SMEN (i.e. CPTR_EL2.SMEN 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 > has historically been broken, and is currently redundant. > > This logic was originally introduced in commit: > > 861262ab86270206 ("KVM: arm64: Handle SME host state when running guests") > > At the time, the VHE hyp code would reset CPTR_EL2.SMEN to 0b00 when > returning to the host, trapping host access to SME state. Unfortunately, > this was unsafe as the host could take a softirq before calling > kvm_arch_vcpu_put_fp(), and if a softirq handler were to use kernel mode > NEON the resulting attempt to save the live FPSIMD/SVE/SME state would > result in a fatal trap. > > That issue was limited to VHE mode. For nVHE/hVHE modes, KVM always > saved/restored the host kernel's CPACR_EL1 value, and configured > CPTR_EL2.TSM to 0b0, ensuring that host usage of SME would not be > trapped. > > The issue above was incidentally fixed by commit: > > 375110ab51dec5dc ("KVM: arm64: Fix resetting SME trap values on reset for (h)VHE") > > That commit changed the VHE hyp code to configure CPTR_EL2.SMEN to 0b01 > when returning to the host, permitting host kernel usage of SME, > avoiding the issue described above. At the time, this was not identified > as a fix for commit 861262ab86270206. > > 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 SME 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 <mark.rutland@xxxxxxx> > Reviewed-by: Mark Brown <broonie@xxxxxxxxxx> > Cc: Catalin Marinas <catalin.marinas@xxxxxxx> > Cc: Fuad Tabba <tabba@xxxxxxxxxx> > Cc: Marc Zyngier <maz@xxxxxxxxxx> > Cc: Mark Brown <broonie@xxxxxxxxxx> > Cc: Oliver Upton <oliver.upton@xxxxxxxxx> > Cc: Will Deacon <will@xxxxxxxxxx> > --- > arch/arm64/include/asm/kvm_host.h | 1 - > arch/arm64/kvm/fpsimd.c | 21 --------------------- > 2 files changed, 22 deletions(-) Acked-by: Will Deacon <will@xxxxxxxxxx> Will