]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/PlatformPei: Reserve GHCB-related areas if S3 is supported
authorTom Lendacky <thomas.lendacky@amd.com>
Wed, 12 Aug 2020 20:21:40 +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

Protect the memory used by an SEV-ES guest when S3 is supported. This
includes the page table used to break down the 2MB page that contains
the GHCB so that it can be marked un-encrypted, as well as the GHCB
area.

Regarding the lifecycle of the GHCB-related memory areas:
  PcdOvmfSecGhcbPageTableBase
  PcdOvmfSecGhcbBase

(a) when and how it is initialized after first boot of the VM

  If SEV-ES is enabled, the GHCB-related areas are initialized during
  the SEC phase [OvmfPkg/ResetVector/Ia32/PageTables64.asm].

(b) how it is protected from memory allocations during DXE

  If S3 and SEV-ES are enabled, then InitializeRamRegions()
  [OvmfPkg/PlatformPei/MemDetect.c] protects the ranges with an AcpiNVS
  memory allocation HOB, in PEI.

  If S3 is disabled, then these ranges are not protected. DXE's own page
  tables are first built while still in PEI (see HandOffToDxeCore()
  [MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c]). Those tables are
  located in permanent PEI memory. After CR3 is switched over to them
  (which occurs before jumping to the DXE core entry point), we don't have
  to preserve PcdOvmfSecGhcbPageTableBase. PEI switches to GHCB pages in
  permanent PEI memory and DXE will use these PEI GHCB pages, so we don't
  have to preserve PcdOvmfSecGhcbBase.

(c) how it is protected from the OS

  If S3 is enabled, then (b) reserves it from the OS too.

  If S3 is disabled, then the range needs no protection.

(d) how it is accessed on the S3 resume path

  It is rewritten same as in (a), which is fine because (b) reserved it.

(e) how it is accessed on the warm reset path

  It is rewritten same as in (a).

Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Anthony Perard <anthony.perard@citrix.com>
Cc: Julien Grall <julien@xen.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Regression-tested-by: Laszlo Ersek <lersek@redhat.com>
OvmfPkg/PlatformPei/MemDetect.c
OvmfPkg/PlatformPei/PlatformPei.inf

index 3b46ea431ade589d5827e229b7ed471c3982d3da..6b5fee166b5d0ab5bb51190687b40e733bbeaf97 100644 (file)
@@ -27,6 +27,7 @@ Module Name:
 #include <Library/DebugLib.h>\r
 #include <Library/HobLib.h>\r
 #include <Library/IoLib.h>\r
+#include <Library/MemEncryptSevLib.h>\r
 #include <Library/PcdLib.h>\r
 #include <Library/PciLib.h>\r
 #include <Library/PeimEntryPoint.h>\r
@@ -866,6 +867,28 @@ InitializeRamRegions (
       (UINT64)(UINTN) PcdGet32 (PcdOvmfSecPageTablesSize),\r
       EfiACPIMemoryNVS\r
       );\r
+\r
+    if (MemEncryptSevEsIsEnabled ()) {\r
+      //\r
+      // If SEV-ES is enabled, reserve the GHCB-related memory area. This\r
+      // includes the extra page table used to break down the 2MB page\r
+      // mapping into 4KB page entries where the GHCB resides and the\r
+      // GHCB area itself.\r
+      //\r
+      // Since this memory range will be used by the Reset Vector on S3\r
+      // resume, it must be reserved as ACPI NVS.\r
+      //\r
+      BuildMemoryAllocationHob (\r
+        (EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfSecGhcbPageTableBase),\r
+        (UINT64)(UINTN) PcdGet32 (PcdOvmfSecGhcbPageTableSize),\r
+        EfiACPIMemoryNVS\r
+        );\r
+      BuildMemoryAllocationHob (\r
+        (EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfSecGhcbBase),\r
+        (UINT64)(UINTN) PcdGet32 (PcdOvmfSecGhcbSize),\r
+        EfiACPIMemoryNVS\r
+        );\r
+    }\r
 #endif\r
   }\r
 \r
index 00feb96c93085781b15d57555597a2395e1d2b2e..a54d10ba90d5321a82c6db505d5d3268c3333df4 100644 (file)
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize\r
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase\r
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize\r
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableBase\r
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableSize\r
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase\r
+  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize\r
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageBase\r
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageSize\r
   gUefiOvmfPkgTokenSpaceGuid.PcdGuidedExtractHandlerTableSize\r