]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/SEV: don't manage the lifecycle of the SMRAM at the default SMBASE
authorLaszlo Ersek <lersek@redhat.com>
Fri, 20 Sep 2019 15:07:43 +0000 (17:07 +0200)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 5 Feb 2020 12:59:32 +0000 (12:59 +0000)
When OVMF runs in a SEV guest, the initial SMM Save State Map is

(1) allocated as EfiBootServicesData type memory in OvmfPkg/PlatformPei,
    function AmdSevInitialize(), for preventing unintended information
    sharing with the hypervisor;

(2) decrypted in AmdSevDxe;

(3) re-encrypted in OvmfPkg/Library/SmmCpuFeaturesLib, function
    SmmCpuFeaturesSmmRelocationComplete(), which is called by
    PiSmmCpuDxeSmm right after initial SMBASE relocation;

(4) released to DXE at the same location.

The SMRAM at the default SMBASE is a superset of the initial Save State
Map. The reserved memory allocation in InitializeRamRegions(), from the
previous patch, must override the allocating and freeing in (1) and (4),
respectively. (Note: the decrypting and re-encrypting in (2) and (3) are
unaffected.)

In AmdSevInitialize(), only assert the containment of the initial Save
State Map, in the larger area already allocated by InitializeRamRegions().

In SmmCpuFeaturesSmmRelocationComplete(), preserve the allocation of the
initial Save State Map into OS runtime, as part of the allocation done by
InitializeRamRegions(). Only assert containment.

These changes only affect the normal boot path (the UEFI memory map is
untouched during S3 resume).

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1512
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Message-Id: <20200129214412.2361-9-lersek@redhat.com>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c
OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf
OvmfPkg/PlatformPei/AmdSev.c

index 0bfdeda78d3357d72036318af89358eb78015706..7ef7ed98342e9382585c0ac43d86f26abae29858 100644 (file)
@@ -6,14 +6,17 @@
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 **/\r
 \r
+#include <IndustryStandard/Q35MchIch9.h>\r
 #include <Library/BaseLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/MemEncryptSevLib.h>\r
+#include <Library/PcdLib.h>\r
 #include <Library/SmmCpuFeaturesLib.h>\r
 #include <Library/SmmServicesTableLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <PiSmm.h>\r
+#include <Register/Intel/SmramSaveStateMap.h>\r
 #include <Register/QemuSmramSaveStateMap.h>\r
 \r
 //\r
@@ -215,8 +218,22 @@ SmmCpuFeaturesSmmRelocationComplete (
 \r
   ZeroMem ((VOID *)MapPagesBase, EFI_PAGES_TO_SIZE (MapPagesCount));\r
 \r
-  Status = gBS->FreePages (MapPagesBase, MapPagesCount);\r
-  ASSERT_EFI_ERROR (Status);\r
+  if (PcdGetBool (PcdQ35SmramAtDefaultSmbase)) {\r
+    //\r
+    // The initial SMRAM Save State Map has been covered as part of a larger\r
+    // reserved memory allocation in PlatformPei's InitializeRamRegions(). That\r
+    // allocation is supposed to survive into OS runtime; we must not release\r
+    // any part of it. Only re-assert the containment here.\r
+    //\r
+    ASSERT (SMM_DEFAULT_SMBASE <= MapPagesBase);\r
+    ASSERT (\r
+      (MapPagesBase + EFI_PAGES_TO_SIZE (MapPagesCount) <=\r
+       SMM_DEFAULT_SMBASE + MCH_DEFAULT_SMBASE_SIZE)\r
+      );\r
+  } else {\r
+    Status = gBS->FreePages (MapPagesBase, MapPagesCount);\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
 }\r
 \r
 /**\r
index dd316f2b1bd8c673dbfa96ba91999e92aeac8c96..97a10afb6e274fbc86d52e87a588c5f07743d42c 100644 (file)
@@ -30,5 +30,9 @@
   BaseMemoryLib\r
   DebugLib\r
   MemEncryptSevLib\r
+  PcdLib\r
   SmmServicesTableLib\r
   UefiBootServicesTableLib\r
+\r
+[Pcd]\r
+  gUefiOvmfPkgTokenSpaceGuid.PcdQ35SmramAtDefaultSmbase\r
index 2ae8126ccf8a77e215945249277799ce47e336ee..e484f4b311feaf7cc473f2aea44d0e9b30f67b46 100644 (file)
@@ -9,6 +9,7 @@
 //\r
 // The package level header files this module uses\r
 //\r
+#include <IndustryStandard/Q35MchIch9.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/HobLib.h>\r
 #include <Library/MemEncryptSevLib.h>\r
@@ -16,6 +17,7 @@
 #include <PiPei.h>\r
 #include <Register/Amd/Cpuid.h>\r
 #include <Register/Cpuid.h>\r
+#include <Register/Intel/SmramSaveStateMap.h>\r
 \r
 #include "Platform.h"\r
 \r
@@ -83,10 +85,22 @@ AmdSevInitialize (
                         );\r
     ASSERT_RETURN_ERROR (LocateMapStatus);\r
 \r
-    BuildMemoryAllocationHob (\r
-      MapPagesBase,                      // BaseAddress\r
-      EFI_PAGES_TO_SIZE (MapPagesCount), // Length\r
-      EfiBootServicesData                // MemoryType\r
-      );\r
+    if (mQ35SmramAtDefaultSmbase) {\r
+      //\r
+      // The initial SMRAM Save State Map has been covered as part of a larger\r
+      // reserved memory allocation in InitializeRamRegions().\r
+      //\r
+      ASSERT (SMM_DEFAULT_SMBASE <= MapPagesBase);\r
+      ASSERT (\r
+        (MapPagesBase + EFI_PAGES_TO_SIZE (MapPagesCount) <=\r
+         SMM_DEFAULT_SMBASE + MCH_DEFAULT_SMBASE_SIZE)\r
+        );\r
+    } else {\r
+      BuildMemoryAllocationHob (\r
+        MapPagesBase,                      // BaseAddress\r
+        EFI_PAGES_TO_SIZE (MapPagesCount), // Length\r
+        EfiBootServicesData                // MemoryType\r
+        );\r
+    }\r
   }\r
 }\r