[PATCH 4/4] RFC: KVM: SVM: WARN if VMSAVE/VMLOAD are not intercepted or virtualized

Yosry Ahmed posted 4 patches 4 weeks, 1 day ago
[PATCH 4/4] RFC: KVM: SVM: WARN if VMSAVE/VMLOAD are not intercepted or virtualized
Posted by Yosry Ahmed 4 weeks, 1 day ago
Signed-off-by: Yosry Ahmed <yosry.ahmed@linux.dev>
---
 arch/x86/kvm/svm/svm.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index f1b032114406..983ae98133e9 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -1387,6 +1387,14 @@ static void svm_prepare_switch_to_guest(struct kvm_vcpu *vcpu)
 	if (svm->guest_state_loaded)
 		return;
 
+	/*
+	 * Without virtual VMSAVE/VMLOAD, the instruction would directly access
+	 * host physical addresses, so make sure they are intercepted.
+	 */
+	if (!(svm->vmcb->control.virt_ext & VIRTUAL_VMLOAD_VMSAVE_ENABLE_MASK))
+		WARN_ON_ONCE(!svm_is_intercept(svm, INTERCEPT_VMSAVE) ||
+			     !svm_is_intercept(svm, INTERCEPT_VMLOAD));
+
 	/*
 	 * Save additional host state that will be restored on VMEXIT (sev-es)
 	 * or subsequent vmload of host save area.
-- 
2.52.0.457.g6b5491de43-goog