Skip to content

Commit 99419b2

Browse files
tlendackysuryasaimadhu
authored andcommitted
x86/kvm: Add KVM-specific VMMCALL handling under SEV-ES
Implement the callbacks to copy the processor state required by KVM to the GHCB. Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com> [ jroedel@suse.de: - Split out of a larger patch - Adapt to different callback functions ] Co-developed-by: Joerg Roedel <jroedel@suse.de> Signed-off-by: Joerg Roedel <jroedel@suse.de> Signed-off-by: Borislav Petkov <bp@suse.de> Link: https://lkml.kernel.org/r/20200907131613.12703-64-joro@8bytes.org
1 parent f6a9f8a commit 99419b2

1 file changed

Lines changed: 29 additions & 6 deletions

File tree

arch/x86/kernel/kvm.c

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include <asm/hypervisor.h>
3737
#include <asm/tlb.h>
3838
#include <asm/cpuidle_haltpoll.h>
39+
#include <asm/ptrace.h>
40+
#include <asm/svm.h>
3941

4042
DEFINE_STATIC_KEY_FALSE(kvm_async_pf_enabled);
4143

@@ -746,13 +748,34 @@ static void __init kvm_init_platform(void)
746748
x86_platform.apic_post_init = kvm_apic_init;
747749
}
748750

751+
#if defined(CONFIG_AMD_MEM_ENCRYPT)
752+
static void kvm_sev_es_hcall_prepare(struct ghcb *ghcb, struct pt_regs *regs)
753+
{
754+
/* RAX and CPL are already in the GHCB */
755+
ghcb_set_rbx(ghcb, regs->bx);
756+
ghcb_set_rcx(ghcb, regs->cx);
757+
ghcb_set_rdx(ghcb, regs->dx);
758+
ghcb_set_rsi(ghcb, regs->si);
759+
}
760+
761+
static bool kvm_sev_es_hcall_finish(struct ghcb *ghcb, struct pt_regs *regs)
762+
{
763+
/* No checking of the return state needed */
764+
return true;
765+
}
766+
#endif
767+
749768
const __initconst struct hypervisor_x86 x86_hyper_kvm = {
750-
.name = "KVM",
751-
.detect = kvm_detect,
752-
.type = X86_HYPER_KVM,
753-
.init.guest_late_init = kvm_guest_init,
754-
.init.x2apic_available = kvm_para_available,
755-
.init.init_platform = kvm_init_platform,
769+
.name = "KVM",
770+
.detect = kvm_detect,
771+
.type = X86_HYPER_KVM,
772+
.init.guest_late_init = kvm_guest_init,
773+
.init.x2apic_available = kvm_para_available,
774+
.init.init_platform = kvm_init_platform,
775+
#if defined(CONFIG_AMD_MEM_ENCRYPT)
776+
.runtime.sev_es_hcall_prepare = kvm_sev_es_hcall_prepare,
777+
.runtime.sev_es_hcall_finish = kvm_sev_es_hcall_finish,
778+
#endif
756779
};
757780

758781
static __init int activate_jump_labels(void)

0 commit comments

Comments
 (0)