[edk2-devel] [PATCH v9 07/46] MdePkg/BaseLib: Add support for the VMGEXIT instruction

Lendacky, Thomas thomas.lendacky at amd.com
Fri Jun 5 13:26:58 UTC 2020


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.

Provide the necessary support to execute the VMGEXIT instruction, which
is "rep; vmmcall".

Cc: Michael D Kinney <michael.d.kinney at intel.com>
Cc: Liming Gao <liming.gao at intel.com>
Signed-off-by: Tom Lendacky <thomas.lendacky at amd.com>
---
 MdePkg/Library/BaseLib/BaseLib.inf       |  2 ++
 MdePkg/Include/Library/BaseLib.h         | 14 ++++++++
 MdePkg/Library/BaseLib/Ia32/GccInline.c  | 17 +++++++++
 MdePkg/Library/BaseLib/X64/GccInline.c   | 17 +++++++++
 MdePkg/Library/BaseLib/Ia32/VmgExit.nasm | 37 ++++++++++++++++++++
 MdePkg/Library/BaseLib/X64/VmgExit.nasm  | 32 +++++++++++++++++
 6 files changed, 119 insertions(+)

diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/BaseLib.inf
index da6bc22a3e2b..7cf6467fa77b 100644
--- a/MdePkg/Library/BaseLib/BaseLib.inf
+++ b/MdePkg/Library/BaseLib/BaseLib.inf
@@ -154,6 +154,7 @@ [Sources.Ia32]
   Ia32/EnableCache.c | MSFT

   Ia32/DisableCache.c | MSFT

   Ia32/XGetBv.nasm | MSFT

+  Ia32/VmgExit.nasm | MSFT

 

 

   Ia32/GccInline.c | GCC

@@ -289,6 +290,7 @@ [Sources.X64]
   X64/ReadCr0.nasm| MSFT

   X64/ReadEflags.nasm| MSFT

   X64/XGetBv.nasm | MSFT

+  X64/VmgExit.nasm | MSFT

 

 

   X64/Non-existing.c

diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h
index 7edf0051a0a0..04fb329eaabb 100644
--- a/MdePkg/Include/Library/BaseLib.h
+++ b/MdePkg/Include/Library/BaseLib.h
@@ -7848,6 +7848,20 @@ AsmXGetBv (
   );

 

 

+/**

+  Executes a VMGEXIT instruction (VMMCALL with a REP prefix)

+

+  Executes a VMGEXIT instruction. This function is only available on IA-32 and

+  x64.

+

+**/

+VOID

+EFIAPI

+AsmVmgExit (

+  VOID

+  );

+

+

 /**

   Patch the immediate operand of an IA32 or X64 instruction such that the byte,

   word, dword or qword operand is encoded at the end of the instruction's

diff --git a/MdePkg/Library/BaseLib/Ia32/GccInline.c b/MdePkg/Library/BaseLib/Ia32/GccInline.c
index c962bcfa4617..d6a7581b36f6 100644
--- a/MdePkg/Library/BaseLib/Ia32/GccInline.c
+++ b/MdePkg/Library/BaseLib/Ia32/GccInline.c
@@ -1791,3 +1791,20 @@ AsmXGetBv (
 }

 

 

+/**

+  Executes a VMGEXIT instruction.

+

+  Executes a VMGEXIT instruction. This function is only available on IA-32 and

+  X64.

+

+**/

+VOID

+EFIAPI

+AsmVmgExit (

+  VOID

+  )

+{

+  __asm__ __volatile__ ("rep; vmmcall":::"memory");

+}

+

+

diff --git a/MdePkg/Library/BaseLib/X64/GccInline.c b/MdePkg/Library/BaseLib/X64/GccInline.c
index 915555198f9f..0685337bbb56 100644
--- a/MdePkg/Library/BaseLib/X64/GccInline.c
+++ b/MdePkg/Library/BaseLib/X64/GccInline.c
@@ -1828,3 +1828,20 @@ AsmXGetBv (
 }

 

 

+/**

+  Executes a VMGEXIT instruction.

+

+  Executes a VMGEXIT instruction. This function is only available on IA-32 and

+  X64.

+

+**/

+VOID

+EFIAPI

+AsmVmgExit (

+  VOID

+  )

+{

+  __asm__ __volatile__ ("rep; vmmcall":::"memory");

+}

+

+

diff --git a/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm b/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm
new file mode 100644
index 000000000000..a4b37385cc7a
--- /dev/null
+++ b/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm
@@ -0,0 +1,37 @@
+;------------------------------------------------------------------------------

+;

+; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>

+; SPDX-License-Identifier: BSD-2-Clause-Patent

+;

+; Module Name:

+;

+;   VmgExit.Asm

+;

+; Abstract:

+;

+;   AsmVmgExit function

+;

+; Notes:

+;

+;------------------------------------------------------------------------------

+

+    SECTION .text

+

+;------------------------------------------------------------------------------

+; VOID

+; EFIAPI

+; AsmVmgExit (

+;   VOID

+;   );

+;------------------------------------------------------------------------------

+global ASM_PFX(AsmVmgExit)

+ASM_PFX(AsmVmgExit):

+;

+; NASM doesn't support the vmmcall instruction in 32-bit mode, so work around

+; this by temporarily switching to 64-bit mode.

+;

+BITS    64

+    rep     vmmcall

+BITS    32

+    ret

+

diff --git a/MdePkg/Library/BaseLib/X64/VmgExit.nasm b/MdePkg/Library/BaseLib/X64/VmgExit.nasm
new file mode 100644
index 000000000000..26f034593c67
--- /dev/null
+++ b/MdePkg/Library/BaseLib/X64/VmgExit.nasm
@@ -0,0 +1,32 @@
+;------------------------------------------------------------------------------

+;

+; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.<BR>

+; SPDX-License-Identifier: BSD-2-Clause-Patent

+;

+; Module Name:

+;

+;   VmgExit.Asm

+;

+; Abstract:

+;

+;   AsmVmgExit function

+;

+; Notes:

+;

+;------------------------------------------------------------------------------

+

+    DEFAULT REL

+    SECTION .text

+

+;------------------------------------------------------------------------------

+; VOID

+; EFIAPI

+; AsmVmgExit (

+;   VOID

+;   );

+;------------------------------------------------------------------------------

+global ASM_PFX(AsmVmgExit)

+ASM_PFX(AsmVmgExit):

+    rep     vmmcall

+    ret

+

-- 
2.27.0


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.

View/Reply Online (#60777): https://edk2.groups.io/g/devel/message/60777
Mute This Topic: https://groups.io/mt/74692412/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub  [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-





More information about the edk2-devel-archive mailing list