From b7d8bdc3bf1abb7ff15c19e933463ccb45acc431 Mon Sep 17 00:00:00 2001 From: Quentin Perret Date: Tue, 24 Jan 2023 17:09:47 +0000 Subject: [PATCH] ANDROID: KVM: arm64: Restore host FP state before SMCs Nothing currently prevents a CPU suspend/resume cycle (for example) while a vCPU is loaded under pKVM. The resume path will disable FP/SVE traps, which may corrupt the guest FP state if it was in use when suspend was issued. To fix this issue and all related problems, proactively restore the host FP state prior to handling SMCs form the host. Bug: 266405428 Bug: 265901597 Change-Id: I75f7d18f81f17dfa323d3128d2c66769ef19c591 Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c index d67b02fe7ca5..8a9681874dd6 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -1311,8 +1311,13 @@ inval: static void handle_host_smc(struct kvm_cpu_context *host_ctxt) { + struct pkvm_hyp_vcpu *hyp_vcpu; bool handled; + hyp_vcpu = pkvm_get_loaded_hyp_vcpu(); + if (hyp_vcpu && hyp_vcpu->vcpu.arch.fp_state == FP_STATE_GUEST_OWNED) + fpsimd_host_restore(); + handled = kvm_host_psci_handler(host_ctxt); if (!handled) handled = kvm_host_ffa_handler(host_ctxt);