]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg/BaseLib: Add support for the VMGEXIT instruction
authorTom Lendacky <thomas.lendacky@amd.com>
Wed, 12 Aug 2020 20:21:35 +0000 (15:21 -0500)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sun, 16 Aug 2020 16:45:42 +0000 (16:45 +0000)
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198

VMGEXIT is a new instruction used for Hypervisor/Guest communication when
running as an SEV-ES guest. A VMGEXIT will cause an automatic exit (AE)
to occur, resulting in a #VMEXIT with an exit code value of 0x403.

Since SEV-ES is only supported in X64, provide the necessary X64 support
to execute the VMGEXIT instruction, which is coded as "rep vmmcall". For
IA32, since "vmmcall" is not supported in NASM 32-bit mode and VMGEXIT
should never be called, provide a stub implementation that is identical
to CpuBreakpoint().

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Regression-tested-by: Laszlo Ersek <lersek@redhat.com>
MdePkg/Include/Library/BaseLib.h
MdePkg/Library/BaseLib/BaseLib.inf
MdePkg/Library/BaseLib/Ia32/VmgExit.nasm [new file with mode: 0644]
MdePkg/Library/BaseLib/X64/VmgExit.nasm [new file with mode: 0644]

index 7edf0051a0a0c2360964bcf7f5e7216c75656772..04fb329eaabb58906074d73a64b862c576aec0f8 100644 (file)
@@ -7848,6 +7848,20 @@ AsmXGetBv (
   );\r
 \r
 \r
+/**\r
+  Executes a VMGEXIT instruction (VMMCALL with a REP prefix)\r
+\r
+  Executes a VMGEXIT instruction. This function is only available on IA-32 and\r
+  x64.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+AsmVmgExit (\r
+  VOID\r
+  );\r
+\r
+\r
 /**\r
   Patch the immediate operand of an IA32 or X64 instruction such that the byte,\r
   word, dword or qword operand is encoded at the end of the instruction's\r
index 3b93b5db8d24f0e576284cb1978c41393a864da5..3b85c56c3c0398863de99ec4d22a09a3da0eb67d 100644 (file)
   Ia32/DisableCache.nasm| GCC\r
   Ia32/RdRand.nasm\r
   Ia32/XGetBv.nasm\r
+  Ia32/VmgExit.nasm\r
 \r
   Ia32/DivS64x64Remainder.c\r
   Ia32/InternalSwitchStack.c | MSFT\r
   X64/DisablePaging64.nasm\r
   X64/RdRand.nasm\r
   X64/XGetBv.nasm\r
+  X64/VmgExit.nasm\r
   ChkStkGcc.c  | GCC\r
 \r
 [Sources.EBC]\r
diff --git a/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm b/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm
new file mode 100644 (file)
index 0000000..69f7fbf
--- /dev/null
@@ -0,0 +1,38 @@
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>\r
+; SPDX-License-Identifier: BSD-2-Clause-Patent\r
+;\r
+; Module Name:\r
+;\r
+;   VmgExit.Asm\r
+;\r
+; Abstract:\r
+;\r
+;   AsmVmgExit function\r
+;\r
+; Notes:\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+    SECTION .text\r
+\r
+;------------------------------------------------------------------------------\r
+; VOID\r
+; EFIAPI\r
+; AsmVmgExit (\r
+;   VOID\r
+;   );\r
+;------------------------------------------------------------------------------\r
+global ASM_PFX(AsmVmgExit)\r
+ASM_PFX(AsmVmgExit):\r
+;\r
+; NASM doesn't support the vmmcall instruction in 32-bit mode and NASM versions\r
+; before 2.12 cannot translate the 64-bit "rep vmmcall" instruction into elf32\r
+; format. Given that VMGEXIT does not make sense on IA32, provide a stub\r
+; implementation that is identical to CpuBreakpoint(). In practice, AsmVmgExit()\r
+; should never be called on IA32.\r
+;\r
+    int  3\r
+    ret\r
+\r
diff --git a/MdePkg/Library/BaseLib/X64/VmgExit.nasm b/MdePkg/Library/BaseLib/X64/VmgExit.nasm
new file mode 100644 (file)
index 0000000..26f0345
--- /dev/null
@@ -0,0 +1,32 @@
+;------------------------------------------------------------------------------\r
+;\r
+; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>\r
+; SPDX-License-Identifier: BSD-2-Clause-Patent\r
+;\r
+; Module Name:\r
+;\r
+;   VmgExit.Asm\r
+;\r
+; Abstract:\r
+;\r
+;   AsmVmgExit function\r
+;\r
+; Notes:\r
+;\r
+;------------------------------------------------------------------------------\r
+\r
+    DEFAULT REL\r
+    SECTION .text\r
+\r
+;------------------------------------------------------------------------------\r
+; VOID\r
+; EFIAPI\r
+; AsmVmgExit (\r
+;   VOID\r
+;   );\r
+;------------------------------------------------------------------------------\r
+global ASM_PFX(AsmVmgExit)\r
+ASM_PFX(AsmVmgExit):\r
+    rep     vmmcall\r
+    ret\r
+\r