mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH V3] KVM: SEV: Update SEV-ES shutdown intercepts with more metadata
@ 2023-09-07 16:24 Peter Gonda
  2023-09-07 21:56 ` Tom Lendacky
  2023-09-29  2:21 ` Sean Christopherson
  0 siblings, 2 replies; 3+ messages in thread
From: Peter Gonda @ 2023-09-07 16:24 UTC (permalink / raw)
  To: kvm
  Cc: Peter Gonda, Sean Christopherson, Tom Lendacky, Paolo Bonzini,
	Joerg Roedel, Borislav Petkov, x86, linux-kernel

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.

Signed-off-by: Peter Gonda <pgonda@google.com>
Suggested-by: Sean Christopherson <seanjc@google.com>
Suggested-by: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: x86@kernel.org
Cc: kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 arch/x86/kvm/svm/svm.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 956726d867aa..114afc897465 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -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;
-- 
2.42.0.283.g2d96d420d3-goog


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH V3] KVM: SEV: Update SEV-ES shutdown intercepts with more metadata
  2023-09-07 16:24 [PATCH V3] KVM: SEV: Update SEV-ES shutdown intercepts with more metadata Peter Gonda
@ 2023-09-07 21:56 ` Tom Lendacky
  2023-09-29  2:21 ` Sean Christopherson
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Lendacky @ 2023-09-07 21:56 UTC (permalink / raw)
  To: Peter Gonda, kvm
  Cc: Sean Christopherson, Paolo Bonzini, Joerg Roedel,
	Borislav Petkov, x86, linux-kernel

On 9/7/23 11:24, Peter Gonda wrote:
> 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.
> 
> Signed-off-by: Peter Gonda <pgonda@google.com>
> Suggested-by: Sean Christopherson <seanjc@google.com>
> Suggested-by: Tom Lendacky <thomas.lendacky@amd.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Sean Christopherson <seanjc@google.com>
> Cc: Tom Lendacky <thomas.lendacky@amd.com>
> Cc: Joerg Roedel <joro@8bytes.org>
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: x86@kernel.org
> Cc: kvm@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org

Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>

> ---
>   arch/x86/kvm/svm/svm.c | 15 +++++++--------
>   1 file changed, 7 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index 956726d867aa..114afc897465 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -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;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH V3] KVM: SEV: Update SEV-ES shutdown intercepts with more metadata
  2023-09-07 16:24 [PATCH V3] KVM: SEV: Update SEV-ES shutdown intercepts with more metadata Peter Gonda
  2023-09-07 21:56 ` Tom Lendacky
@ 2023-09-29  2:21 ` Sean Christopherson
  1 sibling, 0 replies; 3+ messages in thread
From: Sean Christopherson @ 2023-09-29  2:21 UTC (permalink / raw)
  To: Sean Christopherson, kvm, Peter Gonda
  Cc: Tom Lendacky, Paolo Bonzini, Joerg Roedel, Borislav Petkov, x86,
	linux-kernel

On Thu, 07 Sep 2023 09:24:49 -0700, Peter Gonda wrote:
> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-09-29  2:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-07 16:24 [PATCH V3] KVM: SEV: Update SEV-ES shutdown intercepts with more metadata Peter Gonda
2023-09-07 21:56 ` Tom Lendacky
2023-09-29  2:21 ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®