]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/CpuHotplugSmm: complete root MMI handler for CPU hotplug
authorLaszlo Ersek <lersek@redhat.com>
Wed, 26 Feb 2020 22:11:53 +0000 (23:11 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 4 Mar 2020 12:22:07 +0000 (12:22 +0000)
With the help of the Post-SMM Pen and the SMBASE relocation functions
added in the previous patches, we can now complete the root MMI handler
for CPU hotplug.

In the driver's entry point function:

- allocate the pen (in a reserved page in normal RAM),

- install the default ("first") SMI handler for hot-added CPUs (which
  includes priming the exchange area between the MM Monarch and the
  hot-added CPUs, i.e., shutting the APIC ID gate).

In the root MMI handler, for each hot-added CPU:

- record the APIC ID of the new CPU in CPU_HOT_PLUG_DATA,

- relocate the SMBASE of the new CPU,

- inform PiSmmCpuDxeSmm by calling
  EFI_SMM_CPU_SERVICE_PROTOCOL.AddProcessor().

Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Michael Kinney <michael.d.kinney@intel.com>
Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1512
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20200226221156.29589-14-lersek@redhat.com>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Tested-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
OvmfPkg/CpuHotplugSmm/CpuHotplug.c

index 42e023cb85c0bff46009978b550fb428b5c2b7ac..20e6bec04f41981fc8af311eececc28559fb8a77 100644 (file)
@@ -20,6 +20,7 @@
 \r
 #include "ApicId.h"                          // APIC_ID\r
 #include "QemuCpuhp.h"                       // QemuCpuhpWriteCpuSelector()\r
+#include "Smbase.h"                          // SmbaseAllocatePostSmmPen()\r
 \r
 //\r
 // We use this protocol for accessing IO Ports.\r
@@ -52,6 +53,11 @@ STATIC CPU_HOT_PLUG_DATA *mCpuHotPlugData;
 STATIC APIC_ID *mPluggedApicIds;\r
 STATIC APIC_ID *mToUnplugApicIds;\r
 //\r
+// Address of the non-SMRAM reserved memory page that contains the Post-SMM Pen\r
+// for hot-added CPUs.\r
+//\r
+STATIC UINT32 mPostSmmPenAddress;\r
+//\r
 // Represents the registration of the CPU Hotplug MMI handler.\r
 //\r
 STATIC EFI_HANDLE mDispatchHandle;\r
@@ -116,6 +122,8 @@ CpuHotplugMmi (
   UINT8      ApmControl;\r
   UINT32     PluggedCount;\r
   UINT32     ToUnplugCount;\r
+  UINT32     PluggedIdx;\r
+  UINT32     NewSlot;\r
 \r
   //\r
   // Assert that we are entering this function due to our root MMI handler\r
@@ -171,11 +179,78 @@ CpuHotplugMmi (
     goto Fatal;\r
   }\r
 \r
+  //\r
+  // Process hot-added CPUs.\r
+  //\r
+  // The Post-SMM Pen need not be reinstalled multiple times within a single\r
+  // root MMI handling. Even reinstalling once per root MMI is only prudence;\r
+  // in theory installing the pen in the driver's entry point function should\r
+  // suffice.\r
+  //\r
+  SmbaseReinstallPostSmmPen (mPostSmmPenAddress);\r
+\r
+  PluggedIdx = 0;\r
+  NewSlot = 0;\r
+  while (PluggedIdx < PluggedCount) {\r
+    APIC_ID NewApicId;\r
+    UINTN   NewProcessorNumberByProtocol;\r
+\r
+    NewApicId = mPluggedApicIds[PluggedIdx];\r
+    //\r
+    // Find the first empty slot in CPU_HOT_PLUG_DATA.\r
+    //\r
+    while (NewSlot < mCpuHotPlugData->ArrayLength &&\r
+           mCpuHotPlugData->ApicId[NewSlot] != MAX_UINT64) {\r
+      NewSlot++;\r
+    }\r
+    if (NewSlot == mCpuHotPlugData->ArrayLength) {\r
+      DEBUG ((DEBUG_ERROR, "%a: no room for APIC ID " FMT_APIC_ID "\n",\r
+        __FUNCTION__, NewApicId));\r
+      goto Fatal;\r
+    }\r
+\r
+    //\r
+    // Store the APIC ID of the new processor to the slot.\r
+    //\r
+    mCpuHotPlugData->ApicId[NewSlot] = NewApicId;\r
+\r
+    //\r
+    // Relocate the SMBASE of the new CPU.\r
+    //\r
+    Status = SmbaseRelocate (NewApicId, mCpuHotPlugData->SmBase[NewSlot],\r
+               mPostSmmPenAddress);\r
+    if (EFI_ERROR (Status)) {\r
+      goto RevokeNewSlot;\r
+    }\r
+\r
+    //\r
+    // Add the new CPU with EFI_SMM_CPU_SERVICE_PROTOCOL.\r
+    //\r
+    Status = mMmCpuService->AddProcessor (mMmCpuService, NewApicId,\r
+                              &NewProcessorNumberByProtocol);\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((DEBUG_ERROR, "%a: AddProcessor(" FMT_APIC_ID "): %r\n",\r
+        __FUNCTION__, NewApicId, Status));\r
+      goto RevokeNewSlot;\r
+    }\r
+\r
+    DEBUG ((DEBUG_INFO, "%a: hot-added APIC ID " FMT_APIC_ID ", SMBASE 0x%Lx, "\r
+      "EFI_SMM_CPU_SERVICE_PROTOCOL assigned number %Lu\n", __FUNCTION__,\r
+      NewApicId, (UINT64)mCpuHotPlugData->SmBase[NewSlot],\r
+      (UINT64)NewProcessorNumberByProtocol));\r
+\r
+    NewSlot++;\r
+    PluggedIdx++;\r
+  }\r
+\r
   //\r
   // We've handled this MMI.\r
   //\r
   return EFI_SUCCESS;\r
 \r
+RevokeNewSlot:\r
+  mCpuHotPlugData->ApicId[NewSlot] = MAX_UINT64;\r
+\r
 Fatal:\r
   ASSERT (FALSE);\r
   CpuDeadLoop ();\r
@@ -270,6 +345,15 @@ CpuHotplugEntry (
     goto ReleasePluggedApicIds;\r
   }\r
 \r
+  //\r
+  // Allocate the Post-SMM Pen for hot-added CPUs.\r
+  //\r
+  Status = SmbaseAllocatePostSmmPen (&mPostSmmPenAddress,\r
+             SystemTable->BootServices);\r
+  if (EFI_ERROR (Status)) {\r
+    goto ReleaseToUnplugApicIds;\r
+  }\r
+\r
   //\r
   // Sanity-check the CPU hotplug interface.\r
   //\r
@@ -299,7 +383,7 @@ CpuHotplugEntry (
     Status = EFI_NOT_FOUND;\r
     DEBUG ((DEBUG_ERROR, "%a: modern CPU hotplug interface: %r\n",\r
       __FUNCTION__, Status));\r
-    goto ReleaseToUnplugApicIds;\r
+    goto ReleasePostSmmPen;\r
   }\r
 \r
   //\r
@@ -313,11 +397,20 @@ CpuHotplugEntry (
   if (EFI_ERROR (Status)) {\r
     DEBUG ((DEBUG_ERROR, "%a: MmiHandlerRegister(): %r\n", __FUNCTION__,\r
       Status));\r
-    goto ReleaseToUnplugApicIds;\r
+    goto ReleasePostSmmPen;\r
   }\r
 \r
+  //\r
+  // Install the handler for the hot-added CPUs' first SMI.\r
+  //\r
+  SmbaseInstallFirstSmiHandler ();\r
+\r
   return EFI_SUCCESS;\r
 \r
+ReleasePostSmmPen:\r
+  SmbaseReleasePostSmmPen (mPostSmmPenAddress, SystemTable->BootServices);\r
+  mPostSmmPenAddress = 0;\r
+\r
 ReleaseToUnplugApicIds:\r
   gMmst->MmFreePool (mToUnplugApicIds);\r
   mToUnplugApicIds = NULL;\r