Re: [PATCH v2 1/4] KVM: x86: invert KVM_HYPERCALL to default to VMMCALL
From: Sean Christopherson
Date: Fri Apr 23 2021 - 13:44:40 EST
On Fri, Apr 23, 2021, Jim Mattson wrote:
> On Fri, Apr 23, 2021 at 9:00 AM Ashish Kalra <Ashish.Kalra@xxxxxxx> wrote:
> >
> > From: Ashish Kalra <ashish.kalra@xxxxxxx>
> >
> > KVM hypercall framework relies on alternative framework to patch the
> > VMCALL -> VMMCALL on AMD platform. If a hypercall is made before
> > apply_alternative() is called then it defaults to VMCALL. The approach
> > works fine on non SEV guest. A VMCALL would causes #UD, and hypervisor
> > will be able to decode the instruction and do the right things. But
> > when SEV is active, guest memory is encrypted with guest key and
> > hypervisor will not be able to decode the instruction bytes.
> >
> > So invert KVM_HYPERCALL and X86_FEATURE_VMMCALL to default to VMMCALL
> > and opt into VMCALL.
> >
> > Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> > Cc: Ingo Molnar <mingo@xxxxxxxxxx>
> > Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
> > Cc: Paolo Bonzini <pbonzini@xxxxxxxxxx>
> > Cc: Joerg Roedel <joro@xxxxxxxxxx>
> > Cc: Borislav Petkov <bp@xxxxxxx>
> > Cc: Tom Lendacky <thomas.lendacky@xxxxxxx>
> > Cc: x86@xxxxxxxxxx
> > Cc: kvm@xxxxxxxxxxxxxxx
> > Cc: linux-kernel@xxxxxxxxxxxxxxx
> > Signed-off-by: Brijesh Singh <brijesh.singh@xxxxxxx>
> > Signed-off-by: Ashish Kalra <ashish.kalra@xxxxxxx>
> > ---
> > arch/x86/include/asm/kvm_para.h | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/arch/x86/include/asm/kvm_para.h b/arch/x86/include/asm/kvm_para.h
> > index 338119852512..fda2fe0d1b10 100644
> > --- a/arch/x86/include/asm/kvm_para.h
> > +++ b/arch/x86/include/asm/kvm_para.h
> > @@ -19,7 +19,7 @@ static inline bool kvm_check_and_clear_guest_paused(void)
> > #endif /* CONFIG_KVM_GUEST */
> >
> > #define KVM_HYPERCALL \
> > - ALTERNATIVE("vmcall", "vmmcall", X86_FEATURE_VMMCALL)
> > + ALTERNATIVE("vmmcall", "vmcall", X86_FEATURE_VMCALL)
> >
> > /* For KVM hypercalls, a three-byte sequence of either the vmcall or the vmmcall
> > * instruction. The hypervisor may replace it with something else but only the
> > --
> > 2.17.1
> >
>
> Won't this result in the same problem when Intel implements full VM encryption?
TDX uses yet another opcode, TDCALL, along with a different ABI. The existing
KVM hypercalls are then tunneled through that ABI. TDX-specific hypercalls,
which will handle the private vs. shared conversions, will not go through the
KVM defined hypercalls because Intel has defined an ABI for guest/host
communication to handle hypercalls that will be needed by all guest+VMM combos.
E.g. to allow Linux/Windows guests to run on KVM/HyperV/VMware without having to
have additional enlightment for the "basic" functionality.
TL;DR: TDX won't use kvm_hypercall() before apply_alternative().