]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/PlatformPei: Reserve SEV-ES work area if S3 is supported
authorTom Lendacky <thomas.lendacky@amd.com>
Wed, 12 Aug 2020 20:21:41 +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 SEV-ES work area memory used by an SEV-ES guest.

Regarding the lifecycle of the SEV-ES memory area:
  PcdSevEsWorkArea

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

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

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

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

(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 6b5fee166b5d0ab5bb51190687b40e733bbeaf97..ffbbef891a1178cc000d77a232f0fa9ddda36f7f 100644 (file)
@@ -940,5 +940,25 @@ InitializeRamRegions (
           );\r
       }\r
     }\r
+\r
+#ifdef MDE_CPU_X64\r
+    if (MemEncryptSevEsIsEnabled ()) {\r
+      //\r
+      // If SEV-ES is enabled, reserve the SEV-ES work area.\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
+      // If S3 is unsupported, then various drivers might still write to the\r
+      // work area. We ought to prevent DXE from serving allocation requests\r
+      // such that they would overlap the work area.\r
+      //\r
+      BuildMemoryAllocationHob (\r
+        (EFI_PHYSICAL_ADDRESS)(UINTN) FixedPcdGet32 (PcdSevEsWorkAreaBase),\r
+        (UINT64)(UINTN) FixedPcdGet32 (PcdSevEsWorkAreaSize),\r
+        mS3Supported ? EfiACPIMemoryNVS : EfiBootServicesData\r
+        );\r
+    }\r
+#endif\r
   }\r
 }\r
index 4742e1bdf42b7076351c1320a8d8e63aacb134ae..c53be2f4925c56ba828f73953ff08b716d7feba3 100644 (file)
   gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType\r
   gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode\r
   gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData\r
+  gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase\r
+  gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaSize\r
 \r
 [FeaturePcd]\r
   gUefiOvmfPkgTokenSpaceGuid.PcdCsmEnable\r