]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/QemuFlashFvbServicesRuntimeDxe: Clear C-bit when SEV is active
authorBrijesh Singh <brijesh.singh@amd.com>
Fri, 9 Mar 2018 16:06:03 +0000 (10:06 -0600)
committerLaszlo Ersek <lersek@redhat.com>
Fri, 9 Mar 2018 20:44:53 +0000 (21:44 +0100)
Commit:24e4ad7 (OvmfPkg: Add AmdSevDxe driver) added a driver which runs
early in DXE phase and clears the C-bit from NonExistent entry -- which
is later split and accommodate the flash MMIO. When SMM is enabled, we
build two sets of page tables; first page table is used when executing
code in non SMM mode (SMM-less-pgtable) and second page table is used
when we are executing code in SMM mode (SMM-pgtable).

During boot time, AmdSevDxe driver clears the C-bit from the
SMM-less-pgtable. But when SMM is enabled, Qemu Flash services are used
from SMM mode.

In this patch we explicitly clear the C-bit from Qemu flash MMIO range
before we probe the flash. When OVMF is built with SMM_REQUIRE then
call to initialize the flash services happen after the SMM-pgtable is
created and processor has served the first SMI. At this time we will
have access to the SMM-pgtable.

Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
[lersek@redhat.com: trivial coding style improvements]
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesSmm.inf
OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c
OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h
OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c
OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashSmm.c [new file with mode: 0644]

index ba2d3679a46daf5aea28b166f41a8e2e2744d68c..b5c79762c23f04b986517e1a6eff90f202b767b6 100644 (file)
@@ -40,6 +40,7 @@
   FwBlockService.c\r
   FwBlockServiceSmm.c\r
   QemuFlash.c\r
+  QemuFlashSmm.c\r
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
@@ -53,6 +54,7 @@
   DevicePathLib\r
   DxeServicesTableLib\r
   MemoryAllocationLib\r
+  MemEncryptSevLib\r
   PcdLib\r
   SmmServicesTableLib\r
   UefiBootServicesTableLib\r
index 5677b5ee119ca11f1e8322962e8d3408652ff814..462d9c0322f4d5d242e2f5f5d342e3d64812a2c1 100644 (file)
@@ -244,6 +244,15 @@ QemuFlashInitialize (
   ASSERT(PcdGet32 (PcdOvmfFirmwareFdSize) % mFdBlockSize == 0);\r
   mFdBlockCount = PcdGet32 (PcdOvmfFirmwareFdSize) / mFdBlockSize;\r
 \r
+  //\r
+  // execute module specific hooks before probing the flash\r
+  //\r
+  QemuFlashBeforeProbe (\r
+    (EFI_PHYSICAL_ADDRESS)(UINTN) mFlashBase,\r
+    mFdBlockSize,\r
+    mFdBlockCount\r
+    );\r
+\r
   if (!QemuFlashDetected ()) {\r
     ASSERT (!FeaturePcdGet (PcdSmmSmramRequire));\r
     return EFI_WRITE_PROTECTED;\r
index 8d83dca7a52c36dfd1749955da518304b601b48d..d34a8a19a039a1612c25b57ca874f25a5b9bc707 100644 (file)
@@ -88,5 +88,12 @@ QemuFlashConvertPointers (
   VOID\r
   );\r
 \r
+VOID\r
+QemuFlashBeforeProbe (\r
+  IN  EFI_PHYSICAL_ADDRESS    BaseAddress,\r
+  IN  UINTN                   FdBlockSize,\r
+  IN  UINTN                   FdBlockCount\r
+  );\r
+\r
 #endif\r
 \r
index 08ece2beaeca6f9328fb63e72029e876dc1799ec..332ceafd3f788ff88967cb39182ba625bb01e345 100644 (file)
@@ -26,3 +26,15 @@ QemuFlashConvertPointers (
 {\r
   EfiConvertPointer (0x0, (VOID **) &mFlashBase);\r
 }\r
+\r
+VOID\r
+QemuFlashBeforeProbe (\r
+  IN  EFI_PHYSICAL_ADDRESS    BaseAddress,\r
+  IN  UINTN                   FdBlockSize,\r
+  IN  UINTN                   FdBlockCount\r
+  )\r
+{\r
+  //\r
+  // Do nothing\r
+  //\r
+}\r
diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashSmm.c b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashSmm.c
new file mode 100644 (file)
index 0000000..8999ad8
--- /dev/null
@@ -0,0 +1,54 @@
+/** @file\r
+  Define the module hooks used while probing the QEMU flash device.\r
+\r
+  Copyright (C) 2018, Advanced Micro Devices. All rights reserved.\r
+\r
+  This program and the accompanying materials are licensed and made available\r
+  under the terms and conditions of the BSD License which accompanies this\r
+  distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/MemEncryptSevLib.h>\r
+\r
+#include "QemuFlash.h"\r
+\r
+VOID\r
+QemuFlashBeforeProbe (\r
+  IN  EFI_PHYSICAL_ADDRESS    BaseAddress,\r
+  IN  UINTN                   FdBlockSize,\r
+  IN  UINTN                   FdBlockCount\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  ASSERT (FeaturePcdGet (PcdSmmSmramRequire));\r
+\r
+  if (!MemEncryptSevIsEnabled ()) {\r
+    return;\r
+  }\r
+\r
+  //\r
+  // When SEV is enabled, AmdSevDxe runs early in DXE phase and clears the\r
+  // C-bit from the NonExistent entry -- which is later split and accommodate\r
+  // the flash MMIO but the driver runs in non SMM context hence it cleared the\r
+  // flash ranges from non SMM page table. When SMM is enabled, the flash\r
+  // services are accessed from the SMM mode hence we explicitly clear the\r
+  // C-bit on flash ranges from SMM page table.\r
+  //\r
+\r
+  Status = MemEncryptSevClearPageEncMask (\r
+             0,\r
+             BaseAddress,\r
+             EFI_SIZE_TO_PAGES (FdBlockSize * FdBlockCount),\r
+             FALSE\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+}\r