]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/VmgExitLib: Implement new VmgExitLib interfaces
authorTom Lendacky <thomas.lendacky@amd.com>
Fri, 6 Nov 2020 17:53:05 +0000 (11:53 -0600)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Tue, 10 Nov 2020 19:07:55 +0000 (19:07 +0000)
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3008

The VmgExitLib library added two new interfaces, VmgSetOffsetValid() and
VmgIsOffsetValid(), that must now be implemented in the OvmfPkg version
of the library.

Implement VmgSetOffsetValid() and VmgIsOffsetValid() and update existing
code, that is directly accessing ValidBitmap, to use the new interfaces.

Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Message-Id: <939e9dc375e6085bc67942fe9a00ecd4c6b77ecf.1604685192.git.thomas.lendacky@amd.com>

OvmfPkg/Library/VmgExitLib/VmgExitLib.c
OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c

index 53040cc6f6495c5122ac459cb6a5ff5469e17c1e..21f68b19c94e2ce645b79ed7035d62e4b7056fad 100644 (file)
@@ -157,3 +157,57 @@ VmgDone (
 {\r
 }\r
 \r
+/**\r
+  Marks a field at the specified offset as valid in the GHCB.\r
+\r
+  The ValidBitmap area represents the areas of the GHCB that have been marked\r
+  valid. Set the bit in ValidBitmap for the input offset.\r
+\r
+  @param[in, out] Ghcb    Pointer to the Guest-Hypervisor Communication Block\r
+  @param[in]      Offset  Qword offset in the GHCB to mark valid\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+VmgSetOffsetValid (\r
+  IN OUT GHCB                *Ghcb,\r
+  IN     GHCB_REGISTER       Offset\r
+  )\r
+{\r
+  UINT32  OffsetIndex;\r
+  UINT32  OffsetBit;\r
+\r
+  OffsetIndex = Offset / 8;\r
+  OffsetBit   = Offset % 8;\r
+\r
+  Ghcb->SaveArea.ValidBitmap[OffsetIndex] |= (1 << OffsetBit);\r
+}\r
+\r
+/**\r
+  Checks if a specified offset is valid in the GHCB.\r
+\r
+  The ValidBitmap area represents the areas of the GHCB that have been marked\r
+  valid. Return whether the bit in the ValidBitmap is set for the input offset.\r
+\r
+  @param[in]  Ghcb            A pointer to the GHCB\r
+  @param[in]  Offset          Qword offset in the GHCB to mark valid\r
+\r
+  @retval TRUE                Offset is marked valid in the GHCB\r
+  @retval FALSE               Offset is not marked valid in the GHCB\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+VmgIsOffsetValid (\r
+  IN GHCB                    *Ghcb,\r
+  IN GHCB_REGISTER           Offset\r
+  )\r
+{\r
+  UINT32  OffsetIndex;\r
+  UINT32  OffsetBit;\r
+\r
+  OffsetIndex = Offset / 8;\r
+  OffsetBit   = Offset % 8;\r
+\r
+  return ((Ghcb->SaveArea.ValidBitmap[OffsetIndex] & (1 << OffsetBit)) != 0);\r
+}\r
index 8e42b305e83cb154311f9a0fefb0ae748378aa81..7d14341d592b87c344b5964aa3452e5f53a50a8a 100644 (file)
@@ -135,62 +135,6 @@ typedef struct {
 } SEV_ES_PER_CPU_DATA;\r
 \r
 \r
-/**\r
-  Checks the GHCB to determine if the specified register has been marked valid.\r
-\r
-  The ValidBitmap area represents the areas of the GHCB that have been marked\r
-  valid. Return an indication of whether the area of the GHCB that holds the\r
-  specified register has been marked valid.\r
-\r
-  @param[in] Ghcb    Pointer to the Guest-Hypervisor Communication Block\r
-  @param[in] Reg     Offset in the GHCB of the register to check\r
-\r
-  @retval TRUE       Register has been marked vald in the GHCB\r
-  @retval FALSE      Register has not been marked valid in the GHCB\r
-\r
-**/\r
-STATIC\r
-BOOLEAN\r
-GhcbIsRegValid (\r
-  IN GHCB                *Ghcb,\r
-  IN GHCB_REGISTER       Reg\r
-  )\r
-{\r
-  UINT32  RegIndex;\r
-  UINT32  RegBit;\r
-\r
-  RegIndex = Reg / 8;\r
-  RegBit   = Reg & 0x07;\r
-\r
-  return ((Ghcb->SaveArea.ValidBitmap[RegIndex] & (1 << RegBit)) != 0);\r
-}\r
-\r
-/**\r
-  Marks a register as valid in the GHCB.\r
-\r
-  The ValidBitmap area represents the areas of the GHCB that have been marked\r
-  valid. Set the area of the GHCB that holds the specified register as valid.\r
-\r
-  @param[in, out] Ghcb    Pointer to the Guest-Hypervisor Communication Block\r
-  @param[in] Reg          Offset in the GHCB of the register to mark valid\r
-\r
-**/\r
-STATIC\r
-VOID\r
-GhcbSetRegValid (\r
-  IN OUT GHCB                *Ghcb,\r
-  IN     GHCB_REGISTER       Reg\r
-  )\r
-{\r
-  UINT32  RegIndex;\r
-  UINT32  RegBit;\r
-\r
-  RegIndex = Reg / 8;\r
-  RegBit   = Reg & 0x07;\r
-\r
-  Ghcb->SaveArea.ValidBitmap[RegIndex] |= (1 << RegBit);\r
-}\r
-\r
 /**\r
   Return a pointer to the contents of the specified register.\r
 \r
@@ -891,9 +835,9 @@ MwaitExit (
   DecodeModRm (Regs, InstructionData);\r
 \r
   Ghcb->SaveArea.Rax = Regs->Rax;\r
-  GhcbSetRegValid (Ghcb, GhcbRax);\r
+  VmgSetOffsetValid (Ghcb, GhcbRax);\r
   Ghcb->SaveArea.Rcx = Regs->Rcx;\r
-  GhcbSetRegValid (Ghcb, GhcbRcx);\r
+  VmgSetOffsetValid (Ghcb, GhcbRcx);\r
 \r
   return VmgExit (Ghcb, SVM_EXIT_MWAIT, 0, 0);\r
 }\r
@@ -923,11 +867,11 @@ MonitorExit (
   DecodeModRm (Regs, InstructionData);\r
 \r
   Ghcb->SaveArea.Rax = Regs->Rax;  // Identity mapped, so VA = PA\r
-  GhcbSetRegValid (Ghcb, GhcbRax);\r
+  VmgSetOffsetValid (Ghcb, GhcbRax);\r
   Ghcb->SaveArea.Rcx = Regs->Rcx;\r
-  GhcbSetRegValid (Ghcb, GhcbRcx);\r
+  VmgSetOffsetValid (Ghcb, GhcbRcx);\r
   Ghcb->SaveArea.Rdx = Regs->Rdx;\r
-  GhcbSetRegValid (Ghcb, GhcbRdx);\r
+  VmgSetOffsetValid (Ghcb, GhcbRdx);\r
 \r
   return VmgExit (Ghcb, SVM_EXIT_MONITOR, 0, 0);\r
 }\r
@@ -988,9 +932,9 @@ RdtscpExit (
     return Status;\r
   }\r
 \r
-  if (!GhcbIsRegValid (Ghcb, GhcbRax) ||\r
-      !GhcbIsRegValid (Ghcb, GhcbRcx) ||\r
-      !GhcbIsRegValid (Ghcb, GhcbRdx)) {\r
+  if (!VmgIsOffsetValid (Ghcb, GhcbRax) ||\r
+      !VmgIsOffsetValid (Ghcb, GhcbRcx) ||\r
+      !VmgIsOffsetValid (Ghcb, GhcbRdx)) {\r
     return UnsupportedExit (Ghcb, Regs, InstructionData);\r
   }\r
   Regs->Rax = Ghcb->SaveArea.Rax;\r
@@ -1027,16 +971,16 @@ VmmCallExit (
   DecodeModRm (Regs, InstructionData);\r
 \r
   Ghcb->SaveArea.Rax = Regs->Rax;\r
-  GhcbSetRegValid (Ghcb, GhcbRax);\r
+  VmgSetOffsetValid (Ghcb, GhcbRax);\r
   Ghcb->SaveArea.Cpl = (UINT8) (Regs->Cs & 0x3);\r
-  GhcbSetRegValid (Ghcb, GhcbCpl);\r
+  VmgSetOffsetValid (Ghcb, GhcbCpl);\r
 \r
   Status = VmgExit (Ghcb, SVM_EXIT_VMMCALL, 0, 0);\r
   if (Status != 0) {\r
     return Status;\r
   }\r
 \r
-  if (!GhcbIsRegValid (Ghcb, GhcbRax)) {\r
+  if (!VmgIsOffsetValid (Ghcb, GhcbRax)) {\r
     return UnsupportedExit (Ghcb, Regs, InstructionData);\r
   }\r
   Regs->Rax = Ghcb->SaveArea.Rax;\r
@@ -1074,15 +1018,15 @@ MsrExit (
   case 0x30: // WRMSR\r
     ExitInfo1 = 1;\r
     Ghcb->SaveArea.Rax = Regs->Rax;\r
-    GhcbSetRegValid (Ghcb, GhcbRax);\r
+    VmgSetOffsetValid (Ghcb, GhcbRax);\r
     Ghcb->SaveArea.Rdx = Regs->Rdx;\r
-    GhcbSetRegValid (Ghcb, GhcbRdx);\r
+    VmgSetOffsetValid (Ghcb, GhcbRdx);\r
     //\r
     // fall through\r
     //\r
   case 0x32: // RDMSR\r
     Ghcb->SaveArea.Rcx = Regs->Rcx;\r
-    GhcbSetRegValid (Ghcb, GhcbRcx);\r
+    VmgSetOffsetValid (Ghcb, GhcbRcx);\r
     break;\r
   default:\r
     return UnsupportedExit (Ghcb, Regs, InstructionData);\r
@@ -1094,8 +1038,8 @@ MsrExit (
   }\r
 \r
   if (ExitInfo1 == 0) {\r
-    if (!GhcbIsRegValid (Ghcb, GhcbRax) ||\r
-        !GhcbIsRegValid (Ghcb, GhcbRdx)) {\r
+    if (!VmgIsOffsetValid (Ghcb, GhcbRax) ||\r
+        !VmgIsOffsetValid (Ghcb, GhcbRdx)) {\r
       return UnsupportedExit (Ghcb, Regs, InstructionData);\r
     }\r
     Regs->Rax = Ghcb->SaveArea.Rax;\r
@@ -1311,7 +1255,7 @@ IoioExit (
     } else {\r
       CopyMem (&Ghcb->SaveArea.Rax, &Regs->Rax, IOIO_DATA_BYTES (ExitInfo1));\r
     }\r
-    GhcbSetRegValid (Ghcb, GhcbRax);\r
+    VmgSetOffsetValid (Ghcb, GhcbRax);\r
 \r
     Status = VmgExit (Ghcb, SVM_EXIT_IOIO_PROT, ExitInfo1, 0);\r
     if (Status != 0) {\r
@@ -1319,7 +1263,7 @@ IoioExit (
     }\r
 \r
     if ((ExitInfo1 & IOIO_TYPE_IN) != 0) {\r
-      if (!GhcbIsRegValid (Ghcb, GhcbRax)) {\r
+      if (!VmgIsOffsetValid (Ghcb, GhcbRax)) {\r
         return UnsupportedExit (Ghcb, Regs, InstructionData);\r
       }\r
       CopyMem (&Regs->Rax, &Ghcb->SaveArea.Rax, IOIO_DATA_BYTES (ExitInfo1));\r
@@ -1379,15 +1323,15 @@ CpuidExit (
   UINT64  Status;\r
 \r
   Ghcb->SaveArea.Rax = Regs->Rax;\r
-  GhcbSetRegValid (Ghcb, GhcbRax);\r
+  VmgSetOffsetValid (Ghcb, GhcbRax);\r
   Ghcb->SaveArea.Rcx = Regs->Rcx;\r
-  GhcbSetRegValid (Ghcb, GhcbRcx);\r
+  VmgSetOffsetValid (Ghcb, GhcbRcx);\r
   if (Regs->Rax == CPUID_EXTENDED_STATE) {\r
     IA32_CR4  Cr4;\r
 \r
     Cr4.UintN = AsmReadCr4 ();\r
     Ghcb->SaveArea.XCr0 = (Cr4.Bits.OSXSAVE == 1) ? AsmXGetBv (0) : 1;\r
-    GhcbSetRegValid (Ghcb, GhcbXCr0);\r
+    VmgSetOffsetValid (Ghcb, GhcbXCr0);\r
   }\r
 \r
   Status = VmgExit (Ghcb, SVM_EXIT_CPUID, 0, 0);\r
@@ -1395,10 +1339,10 @@ CpuidExit (
     return Status;\r
   }\r
 \r
-  if (!GhcbIsRegValid (Ghcb, GhcbRax) ||\r
-      !GhcbIsRegValid (Ghcb, GhcbRbx) ||\r
-      !GhcbIsRegValid (Ghcb, GhcbRcx) ||\r
-      !GhcbIsRegValid (Ghcb, GhcbRdx)) {\r
+  if (!VmgIsOffsetValid (Ghcb, GhcbRax) ||\r
+      !VmgIsOffsetValid (Ghcb, GhcbRbx) ||\r
+      !VmgIsOffsetValid (Ghcb, GhcbRcx) ||\r
+      !VmgIsOffsetValid (Ghcb, GhcbRdx)) {\r
     return UnsupportedExit (Ghcb, Regs, InstructionData);\r
   }\r
   Regs->Rax = Ghcb->SaveArea.Rax;\r
@@ -1434,15 +1378,15 @@ RdpmcExit (
   UINT64  Status;\r
 \r
   Ghcb->SaveArea.Rcx = Regs->Rcx;\r
-  GhcbSetRegValid (Ghcb, GhcbRcx);\r
+  VmgSetOffsetValid (Ghcb, GhcbRcx);\r
 \r
   Status = VmgExit (Ghcb, SVM_EXIT_RDPMC, 0, 0);\r
   if (Status != 0) {\r
     return Status;\r
   }\r
 \r
-  if (!GhcbIsRegValid (Ghcb, GhcbRax) ||\r
-      !GhcbIsRegValid (Ghcb, GhcbRdx)) {\r
+  if (!VmgIsOffsetValid (Ghcb, GhcbRax) ||\r
+      !VmgIsOffsetValid (Ghcb, GhcbRdx)) {\r
     return UnsupportedExit (Ghcb, Regs, InstructionData);\r
   }\r
   Regs->Rax = Ghcb->SaveArea.Rax;\r
@@ -1480,8 +1424,8 @@ RdtscExit (
     return Status;\r
   }\r
 \r
-  if (!GhcbIsRegValid (Ghcb, GhcbRax) ||\r
-      !GhcbIsRegValid (Ghcb, GhcbRdx)) {\r
+  if (!VmgIsOffsetValid (Ghcb, GhcbRax) ||\r
+      !VmgIsOffsetValid (Ghcb, GhcbRdx)) {\r
     return UnsupportedExit (Ghcb, Regs, InstructionData);\r
   }\r
   Regs->Rax = Ghcb->SaveArea.Rax;\r
@@ -1531,7 +1475,7 @@ Dr7WriteExit (
   // Using a value of 0 for ExitInfo1 means RAX holds the value\r
   //\r
   Ghcb->SaveArea.Rax = *Register;\r
-  GhcbSetRegValid (Ghcb, GhcbRax);\r
+  VmgSetOffsetValid (Ghcb, GhcbRax);\r
 \r
   Status = VmgExit (Ghcb, SVM_EXIT_DR7_WRITE, 0, 0);\r
   if (Status != 0) {\r