Skip to contentSkip to conversation

KVM: SEV: Update SEV-ES shutdown intercepts with more metadata

PATCH Applied Peter Gonda 3 participants 3 messages Sep 7, 2023 – Sep 29, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 KVM: SEV: Update SEV-ES shutdown intercepts with more metadata

Currently if an SEV-ES VM shuts down userspace sees KVM_RUN struct with only the INVALID_ARGUMENT. This is a very limited amount of information to debug the situation. Instead KVM can return a KVM_EXIT_SHUTDOWN to alert userspace the VM is shutting down and is not usable any further.

---
 arch/x86/kvm/svm/svm.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
arch/x86/kvm/svm/svm.c +7 -8
index 956726d867aa..114afc897465 100644
@@ -2127,12 +2127,6 @@ static int shutdown_interception(struct kvm_vcpu *vcpu)
 	struct kvm_run *kvm_run = vcpu->run;
 	struct vcpu_svm *svm = to_svm(vcpu);
 
-	/*
-	 * The VM save area has already been encrypted so it
-	 * cannot be reinitialized - just terminate.
-	 */
-	if (sev_es_guest(vcpu->kvm))
-		return -EINVAL;
 
 	/*
 	 * VMCB is undefined after a SHUTDOWN intercept.  INIT the vCPU to put
@@ -2141,9 +2135,14 @@ static int shutdown_interception(struct kvm_vcpu *vcpu)
 	 * userspace.  At a platform view, INIT is acceptable behavior as
 	 * there exist bare metal platforms that automatically INIT the CPU
 	 * in response to shutdown.
+	 *
+	 * The VM save area for SEV-ES guests has already been encrypted so it
+	 * cannot be reinitialized, i.e. synthesizing INIT is futile.
 	 */
-	clear_page(svm->vmcb);
-	kvm_vcpu_reset(vcpu, true);
+	if (!sev_es_guest(vcpu->kvm)) {
+		clear_page(svm->vmcb);
+		kvm_vcpu_reset(vcpu, true);
+	}
 
 	kvm_run->exit_reason = KVM_EXIT_SHUTDOWN;
 	return 0;
Signature · 1 line
2.42.0.283.g2d96d420d3-goog
Reviewed-by on v3 1/1
#1 lore raw
Quoted 6 lines · Peter Gonda

Currently if an SEV-ES VM shuts down userspace sees KVM_RUN struct with only the INVALID_ARGUMENT. This is a very limited amount of information to debug the situation. Instead KVM can return a KVM_EXIT_SHUTDOWN to alert userspace the VM is shutting down and is not usable any further.

Quoted 11 lines
Quoted 38 lines
---
  arch/x86/kvm/svm/svm.c | 15 +++++++--------
  1 file changed, 7 insertions(+), 8 deletions(-)
arch/x86/kvm/svm/svm.c +7 -8
index 956726d867aa..114afc897465 100644
@@ -2127,12 +2127,6 @@ static int shutdown_interception(struct kvm_vcpu *vcpu)
  	struct kvm_run *kvm_run = vcpu->run;
  	struct vcpu_svm *svm = to_svm(vcpu);
 
-	/*
-	 * The VM save area has already been encrypted so it
-	 * cannot be reinitialized - just terminate.
-	 */
-	if (sev_es_guest(vcpu->kvm))
-		return -EINVAL;
 
  	/*
  	 * VMCB is undefined after a SHUTDOWN intercept.  INIT the vCPU to put
@@ -2141,9 +2135,14 @@ static int shutdown_interception(struct kvm_vcpu *vcpu)
  	 * userspace.  At a platform view, INIT is acceptable behavior as
  	 * there exist bare metal platforms that automatically INIT the CPU
  	 * in response to shutdown.
+	 *
+	 * The VM save area for SEV-ES guests has already been encrypted so it
+	 * cannot be reinitialized, i.e. synthesizing INIT is futile.
  	 */
-	clear_page(svm->vmcb);
-	kvm_vcpu_reset(vcpu, true);
+	if (!sev_es_guest(vcpu->kvm)) {
+		clear_page(svm->vmcb);
+		kvm_vcpu_reset(vcpu, true);
+	}
 
  	kvm_run->exit_reason = KVM_EXIT_SHUTDOWN;
  	return 0;
maintainer Applied
#2 lore raw
In reply to Peter Gonda
Quoted 8 lines · Peter Gonda

Currently if an SEV-ES VM shuts down userspace sees KVM_RUN struct with only the INVALID_ARGUMENT. This is a very limited amount of information to debug the situation. Instead KVM can return a KVM_EXIT_SHUTDOWN to alert userspace the VM is shutting down and is not usable any further.

[...]

Applied to kvm-x86 svm, thanks!

[1/1] KVM: SEV: Update SEV-ES shutdown intercepts with more metadata

      https://github.com/kvm-x86/linux/commit/bc3d7c5570a0

--
https://github.com/kvm-x86/linux/tree/next