]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/MemEncryptSevLib: find pages of initial SMRAM save state map
authorLaszlo Ersek <lersek@redhat.com>
Thu, 1 Mar 2018 16:31:44 +0000 (17:31 +0100)
committerLaszlo Ersek <lersek@redhat.com>
Tue, 6 Mar 2018 12:30:30 +0000 (13:30 +0100)
In the next three patches, we're going to modify three modules under
OvmfPkg. When OVMF is built with -D SMM_REQUIRE and runs in an SEV guest,
each affected module will have to know the page range that covers the
initial (pre-SMBASE relocation) SMRAM save state map. Add a helper
function to MemEncryptSevLib that calculates the "base address" and
"number of pages" constants for this page range.

(In a RELEASE build -- i.e., with assertions disabled and optimization
enabled --, the helper function can be compiled to store two constants
determined at compile time.)

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Tested-by: Brijesh Singh <brijesh.singh@amd.com>
Reviewed-by: Brijesh Singh <brijesh.singh@amd.com>
OvmfPkg/Include/Library/MemEncryptSevLib.h
OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevLib.inf
OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c

index e5ebb4401818a5d1b824f783065c18be427a30c1..1e2ec8641d465851775dbff33883339b30ed57c2 100644 (file)
@@ -86,4 +86,27 @@ MemEncryptSevSetPageEncMask (
   IN UINTN                    NumPages,\r
   IN BOOLEAN                  Flush\r
   );\r
+\r
+\r
+/**\r
+  Locate the page range that covers the initial (pre-SMBASE-relocation) SMRAM\r
+  Save State Map.\r
+\r
+  @param[out] BaseAddress     The base address of the lowest-address page that\r
+                              covers the initial SMRAM Save State Map.\r
+\r
+  @param[out] NumberOfPages   The number of pages in the page range that covers\r
+                              the initial SMRAM Save State Map.\r
+\r
+  @retval RETURN_SUCCESS      BaseAddress and NumberOfPages have been set on\r
+                              output.\r
+\r
+  @retval RETURN_UNSUPPORTED  SMM is unavailable.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+MemEncryptSevLocateInitialSmramSaveStateMapPages (\r
+  OUT UINTN *BaseAddress,\r
+  OUT UINTN *NumberOfPages\r
+  );\r
 #endif // _MEM_ENCRYPT_SEV_LIB_H_\r
index 2f0a2392a7adb60476134dcf6bc5d3b96d5eedb0..464fe1f33e6642e01e23e7aa88de46e33748e98f 100644 (file)
@@ -51,3 +51,7 @@
   CpuLib\r
   DebugLib\r
   MemoryAllocationLib\r
+  PcdLib\r
+\r
+[FeaturePcd]\r
+  gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire\r
index 7078ab0d3f4607a4b4160e7a760b6d1e24d8ca34..b92ba50c616c4d1caa310d373c0d34578f5d1633 100644 (file)
 #include <Library/BaseLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/MemEncryptSevLib.h>\r
+#include <Library/PcdLib.h>\r
 #include <Register/Amd/Cpuid.h>\r
 #include <Register/Amd/Msr.h>\r
 #include <Register/Cpuid.h>\r
+#include <Register/QemuSmramSaveStateMap.h>\r
+#include <Register/SmramSaveStateMap.h>\r
+#include <Uefi/UefiBaseType.h>\r
 \r
 STATIC BOOLEAN mSevStatus = FALSE;\r
 STATIC BOOLEAN mSevStatusChecked = FALSE;\r
@@ -87,3 +91,50 @@ MemEncryptSevIsEnabled (
 \r
   return mSevStatus;\r
 }\r
+\r
+\r
+/**\r
+  Locate the page range that covers the initial (pre-SMBASE-relocation) SMRAM\r
+  Save State Map.\r
+\r
+  @param[out] BaseAddress     The base address of the lowest-address page that\r
+                              covers the initial SMRAM Save State Map.\r
+\r
+  @param[out] NumberOfPages   The number of pages in the page range that covers\r
+                              the initial SMRAM Save State Map.\r
+\r
+  @retval RETURN_SUCCESS      BaseAddress and NumberOfPages have been set on\r
+                              output.\r
+\r
+  @retval RETURN_UNSUPPORTED  SMM is unavailable.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+MemEncryptSevLocateInitialSmramSaveStateMapPages (\r
+  OUT UINTN *BaseAddress,\r
+  OUT UINTN *NumberOfPages\r
+  )\r
+{\r
+  UINTN MapStart;\r
+  UINTN MapEnd;\r
+  UINTN MapPagesStart; // MapStart rounded down to page boundary\r
+  UINTN MapPagesEnd;   // MapEnd rounded up to page boundary\r
+  UINTN MapPagesSize;  // difference between MapPagesStart and MapPagesEnd\r
+\r
+  if (!FeaturePcdGet (PcdSmmSmramRequire)) {\r
+    return RETURN_UNSUPPORTED;\r
+  }\r
+\r
+  MapStart      = SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET;\r
+  MapEnd        = MapStart + sizeof (QEMU_SMRAM_SAVE_STATE_MAP);\r
+  MapPagesStart = MapStart & ~(UINTN)EFI_PAGE_MASK;\r
+  MapPagesEnd   = ALIGN_VALUE (MapEnd, EFI_PAGE_SIZE);\r
+  MapPagesSize  = MapPagesEnd - MapPagesStart;\r
+\r
+  ASSERT ((MapPagesSize & EFI_PAGE_MASK) == 0);\r
+\r
+  *BaseAddress   = MapPagesStart;\r
+  *NumberOfPages = MapPagesSize >> EFI_PAGE_SHIFT;\r
+\r
+  return RETURN_SUCCESS;\r
+}\r