]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/VmgExitLib: Add support for RDTSC NAE events
authorTom Lendacky <thomas.lendacky@amd.com>
Wed, 12 Aug 2020 20:21:38 +0000 (15:21 -0500)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 17 Aug 2020 02:46:39 +0000 (02:46 +0000)
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198

Under SEV-ES, a RDTSC intercept generates a #VC exception. VMGEXIT must be
used to allow the hypervisor to handle this intercept.

Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Regression-tested-by: Laszlo Ersek <lersek@redhat.com>
OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c

index 2070c943de9393082fc1ab070c11f437a1c35151..aa1e78f35735d42656ea9db81e9b8787ec1738c8 100644 (file)
@@ -1223,6 +1223,45 @@ CpuidExit (
   return 0;\r
 }\r
 \r
+/**\r
+  Handle a RDTSC event.\r
+\r
+  Use the VMGEXIT instruction to handle a RDTSC event.\r
+\r
+  @param[in, out] Ghcb             Pointer to the Guest-Hypervisor Communication\r
+                                   Block\r
+  @param[in, out] Regs             x64 processor context\r
+  @param[in]      InstructionData  Instruction parsing context\r
+\r
+  @retval 0                        Event handled successfully\r
+  @return                          New exception value to propagate\r
+\r
+**/\r
+STATIC\r
+UINT64\r
+RdtscExit (\r
+  IN OUT GHCB                     *Ghcb,\r
+  IN OUT EFI_SYSTEM_CONTEXT_X64   *Regs,\r
+  IN     SEV_ES_INSTRUCTION_DATA  *InstructionData\r
+  )\r
+{\r
+  UINT64  Status;\r
+\r
+  Status = VmgExit (Ghcb, SVM_EXIT_RDTSC, 0, 0);\r
+  if (Status != 0) {\r
+    return Status;\r
+  }\r
+\r
+  if (!GhcbIsRegValid (Ghcb, GhcbRax) ||\r
+      !GhcbIsRegValid (Ghcb, GhcbRdx)) {\r
+    return UnsupportedExit (Ghcb, Regs, InstructionData);\r
+  }\r
+  Regs->Rax = Ghcb->SaveArea.Rax;\r
+  Regs->Rdx = Ghcb->SaveArea.Rdx;\r
+\r
+  return 0;\r
+}\r
+\r
 /**\r
   Handle a #VC exception.\r
 \r
@@ -1267,6 +1306,10 @@ VmgExitHandleVc (
 \r
   ExitCode = Regs->ExceptionData;\r
   switch (ExitCode) {\r
+  case SVM_EXIT_RDTSC:\r
+    NaeExit = RdtscExit;\r
+    break;\r
+\r
   case SVM_EXIT_CPUID:\r
     NaeExit = CpuidExit;\r
     break;\r