Skip to content

Commit 1a222de

Browse files
dcovellisuryasaimadhu
authored andcommitted
x86/vmware: Add VMware-specific handling for VMMCALL under SEV-ES
Add VMware-specific handling for #VC faults caused by VMMCALL instructions. Signed-off-by: Doug Covelli <dcovelli@vmware.com> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com> [ jroedel@suse.de: - Adapt to different paravirt interface ] 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-65-joro@8bytes.org
1 parent 99419b2 commit 1a222de

1 file changed

Lines changed: 45 additions & 5 deletions

File tree

arch/x86/kernel/cpu/vmware.c

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <asm/timer.h>
3434
#include <asm/apic.h>
3535
#include <asm/vmware.h>
36+
#include <asm/svm.h>
3637

3738
#undef pr_fmt
3839
#define pr_fmt(fmt) "vmware: " fmt
@@ -476,10 +477,49 @@ static bool __init vmware_legacy_x2apic_available(void)
476477
(eax & (1 << VMWARE_CMD_LEGACY_X2APIC)) != 0;
477478
}
478479

480+
#ifdef CONFIG_AMD_MEM_ENCRYPT
481+
static void vmware_sev_es_hcall_prepare(struct ghcb *ghcb,
482+
struct pt_regs *regs)
483+
{
484+
/* Copy VMWARE specific Hypercall parameters to the GHCB */
485+
ghcb_set_rip(ghcb, regs->ip);
486+
ghcb_set_rbx(ghcb, regs->bx);
487+
ghcb_set_rcx(ghcb, regs->cx);
488+
ghcb_set_rdx(ghcb, regs->dx);
489+
ghcb_set_rsi(ghcb, regs->si);
490+
ghcb_set_rdi(ghcb, regs->di);
491+
ghcb_set_rbp(ghcb, regs->bp);
492+
}
493+
494+
static bool vmware_sev_es_hcall_finish(struct ghcb *ghcb, struct pt_regs *regs)
495+
{
496+
if (!(ghcb_rbx_is_valid(ghcb) &&
497+
ghcb_rcx_is_valid(ghcb) &&
498+
ghcb_rdx_is_valid(ghcb) &&
499+
ghcb_rsi_is_valid(ghcb) &&
500+
ghcb_rdi_is_valid(ghcb) &&
501+
ghcb_rbp_is_valid(ghcb)))
502+
return false;
503+
504+
regs->bx = ghcb->save.rbx;
505+
regs->cx = ghcb->save.rcx;
506+
regs->dx = ghcb->save.rdx;
507+
regs->si = ghcb->save.rsi;
508+
regs->di = ghcb->save.rdi;
509+
regs->bp = ghcb->save.rbp;
510+
511+
return true;
512+
}
513+
#endif
514+
479515
const __initconst struct hypervisor_x86 x86_hyper_vmware = {
480-
.name = "VMware",
481-
.detect = vmware_platform,
482-
.type = X86_HYPER_VMWARE,
483-
.init.init_platform = vmware_platform_setup,
484-
.init.x2apic_available = vmware_legacy_x2apic_available,
516+
.name = "VMware",
517+
.detect = vmware_platform,
518+
.type = X86_HYPER_VMWARE,
519+
.init.init_platform = vmware_platform_setup,
520+
.init.x2apic_available = vmware_legacy_x2apic_available,
521+
#ifdef CONFIG_AMD_MEM_ENCRYPT
522+
.runtime.sev_es_hcall_prepare = vmware_sev_es_hcall_prepare,
523+
.runtime.sev_es_hcall_finish = vmware_sev_es_hcall_finish,
524+
#endif
485525
};

0 commit comments

Comments
 (0)