public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: SVM: Assume a 64-bit hypercall for guests with protected state
@ 2021-05-22 16:43 Tom Lendacky
  2021-05-22 18:17 ` Tom Lendacky
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Tom Lendacky @ 2021-05-22 16:43 UTC (permalink / raw)
  To: kvm, linux-kernel, x86
  Cc: Paolo Bonzini, Jim Mattson, Joerg Roedel, Sean Christopherson,
	Vitaly Kuznetsov, Wanpeng Li, Borislav Petkov, Ingo Molnar,
	Thomas Gleixner, Brijesh Singh, Ashish Kalra

When processing a hypercall for a guest with protected state, currently
SEV-ES guests, the guest CS segment register can't be checked to
determine if the guest is in 64-bit mode. For an SEV-ES guest, it is
expected that communication between the guest and the hypervisor is
performed to shared memory using the GHCB. In order to use the GHCB, the
guest must have been in long mode, otherwise writes by the guest to the
GHCB would be encrypted and not be able to be comprehended by the
hypervisor. Given that, assume that the guest is in 64-bit mode when
processing a hypercall from a guest with protected state.

Fixes: f1c6366e3043 ("KVM: SVM: Add required changes to support intercepts under SEV-ES")
Reported-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
---
 arch/x86/kvm/x86.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 9b6bca616929..e715c69bb882 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -8403,7 +8403,12 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
 
 	trace_kvm_hypercall(nr, a0, a1, a2, a3);
 
-	op_64_bit = is_64_bit_mode(vcpu);
+	/*
+	 * If running with protected guest state, the CS register is not
+	 * accessible. The hypercall register values will have had to been
+	 * provided in 64-bit mode, so assume the guest is in 64-bit.
+	 */
+	op_64_bit = is_64_bit_mode(vcpu) || vcpu->arch.guest_state_protected;
 	if (!op_64_bit) {
 		nr &= 0xFFFFFFFF;
 		a0 &= 0xFFFFFFFF;
-- 
2.31.0


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

end of thread, other threads:[~2021-05-24 17:40 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-22 16:43 [PATCH] KVM: SVM: Assume a 64-bit hypercall for guests with protected state Tom Lendacky
2021-05-22 18:17 ` Tom Lendacky
2021-05-24 11:53 ` Vitaly Kuznetsov
2021-05-24 13:28   ` Tom Lendacky
2021-05-24 13:49     ` Vitaly Kuznetsov
2021-05-24 13:58       ` Tom Lendacky
2021-05-24 14:20         ` Paolo Bonzini
2021-05-24 16:05           ` Tom Lendacky
2021-05-24 17:03           ` Sean Christopherson
2021-05-24 17:06             ` Paolo Bonzini
2021-05-24 17:40               ` Tom Lendacky
2021-05-24 12:29 ` Paolo Bonzini

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