]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
UefiCpuPkg/MpInitLib: Allocate a separate SEV-ES AP reset stack area
[mirror_edk2.git] / UefiCpuPkg / Library / MpInitLib / DxeMpLib.c
index 2c00d72ddefe1487b72189dd9d16d6a20cd4bd2b..93fc63bf93e3070d5e3ddffae14158d72aacc74c 100644 (file)
@@ -29,6 +29,11 @@ VOID             *mReservedApLoopFunc = NULL;
 UINTN            mReservedTopOfApStack;\r
 volatile UINT32  mNumberToFinish = 0;\r
 \r
+//\r
+// Begin wakeup buffer allocation below 0x88000\r
+//\r
+STATIC EFI_PHYSICAL_ADDRESS mSevEsDxeWakeupBuffer = 0x88000;\r
+\r
 /**\r
   Enable Debug Agent to support source debugging on AP function.\r
 \r
@@ -102,7 +107,14 @@ GetWakeupBuffer (
   // LagacyBios driver depends on CPU Arch protocol which guarantees below\r
   // allocation runs earlier than LegacyBios driver.\r
   //\r
-  StartAddress = 0x88000;\r
+  if (PcdGetBool (PcdSevEsIsEnabled)) {\r
+    //\r
+    // SEV-ES Wakeup buffer should be under 0x88000 and under any previous one\r
+    //\r
+    StartAddress = mSevEsDxeWakeupBuffer;\r
+  } else {\r
+    StartAddress = 0x88000;\r
+  }\r
   Status = gBS->AllocatePages (\r
                   AllocateMaxAddress,\r
                   MemoryType,\r
@@ -112,6 +124,11 @@ GetWakeupBuffer (
   ASSERT_EFI_ERROR (Status);\r
   if (EFI_ERROR (Status)) {\r
     StartAddress = (EFI_PHYSICAL_ADDRESS) -1;\r
+  } else if (PcdGetBool (PcdSevEsIsEnabled)) {\r
+    //\r
+    // Next SEV-ES wakeup buffer allocation must be below this allocation\r
+    //\r
+    mSevEsDxeWakeupBuffer = StartAddress;\r
   }\r
 \r
   DEBUG ((DEBUG_INFO, "WakeupBufferStart = %x, WakeupBufferSize = %x\n",\r
@@ -171,6 +188,7 @@ GetSevEsAPMemory (
   EFI_PHYSICAL_ADDRESS      StartAddress;\r
   MSR_SEV_ES_GHCB_REGISTER  Msr;\r
   GHCB                      *Ghcb;\r
+  BOOLEAN                   InterruptState;\r
 \r
   //\r
   // Allocate 1 page for AP jump table page\r
@@ -192,9 +210,9 @@ GetSevEsAPMemory (
   Msr.GhcbPhysicalAddress = AsmReadMsr64 (MSR_SEV_ES_GHCB);\r
   Ghcb = Msr.Ghcb;\r
 \r
-  VmgInit (Ghcb);\r
+  VmgInit (Ghcb, &InterruptState);\r
   VmgExit (Ghcb, SVM_EXIT_AP_JUMP_TABLE, 0, (UINT64) (UINTN) StartAddress);\r
-  VmgDone (Ghcb);\r
+  VmgDone (Ghcb, InterruptState);\r
 \r
   return (UINTN) StartAddress;\r
 }\r