[edk2-devel] [PATCH v5 4/9] OvmfPkg/CpuHotplugSmm: introduce UnplugCpus()

Ankur Arora posted 9 patches 3 years, 9 months ago
There is a newer version of this series
[edk2-devel] [PATCH v5 4/9] OvmfPkg/CpuHotplugSmm: introduce UnplugCpus()
Posted by Ankur Arora 3 years, 9 months ago
Introduce UnplugCpus() which maps each APIC ID being unplugged
onto the hardware ID of the processor and informs PiSmmCpuDxeSmm
of removal by calling EFI_SMM_CPU_SERVICE_PROTOCOL.RemoveProcessor().

With this change we handle the first phase of unplug where we collect
the CPUs that need to be unplugged and mark them for removal in SMM
data structures.

Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Aaron Young <aaron.young@oracle.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3132
Signed-off-by: Ankur Arora <ankur.a.arora@oracle.com>
---
 OvmfPkg/CpuHotplugSmm/CpuHotplug.c | 77 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 77 insertions(+)

diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c
index a5052a501e5a..d165d6ccea0d 100644
--- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c
+++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c
@@ -182,6 +182,81 @@ Fatal:
 }

 

 /**

+  CPU Hot-unplug MMI handler function.

+

+  @param[in] UnplugApicIds       List of APIC IDs to be unplugged.

+

+  @param[in] ToUnplugCount       Count of APIC IDs to be unplugged.

+

+  @retval EFI_SUCCESS            Some of the requested APIC IDs will be hot-unplugged.

+

+  @retval EFI_INTERRUPT_PENDING  Fatal error while hot-plugging.

+

+**/

+STATIC

+EFI_STATUS

+EFIAPI

+UnplugCpus(

+  IN APIC_ID                      *UnplugApicIds,

+  IN UINT32                       ToUnplugCount

+  )

+{

+  EFI_STATUS Status;

+  UINT32     ToUnplugIdx;

+  UINTN      ProcessorNum;

+

+  ToUnplugIdx = 0;

+  while (ToUnplugIdx < ToUnplugCount) {

+    APIC_ID    RemoveApicId;

+

+    RemoveApicId = UnplugApicIds[ToUnplugIdx];

+

+    //

+    // mCpuHotPlugData->ApicId maps ProcessorNum -> ApicId. Use it to find

+    // the ProcessorNum for the APIC ID to be removed.

+    //

+    for (ProcessorNum = 0;

+         ProcessorNum < mCpuHotPlugData->ArrayLength;

+         ProcessorNum++) {

+      if (mCpuHotPlugData->ApicId[ProcessorNum] == RemoveApicId) {

+        break;

+      }

+    }

+

+    //

+    // Ignore the unplug if APIC ID not found

+    //

+    if (ProcessorNum == mCpuHotPlugData->ArrayLength) {

+      DEBUG ((DEBUG_INFO, "%a: did not find APIC ID " FMT_APIC_ID " to unplug\n",

+        __FUNCTION__, RemoveApicId));

+      ToUnplugIdx++;

+      continue;

+    }

+

+    //

+    // Mark ProcessorNum for removal from SMM data structures

+    //

+    Status = mMmCpuService->RemoveProcessor (mMmCpuService, ProcessorNum);

+

+    if (EFI_ERROR(Status)) {

+      DEBUG ((DEBUG_ERROR, "%a: RemoveProcessor(" FMT_APIC_ID "): %r\n",

+        __FUNCTION__, RemoveApicId, Status));

+      goto Fatal;

+    }

+

+    ToUnplugIdx++;

+  }

+

+  //

+  // We've handled this unplug.

+  //

+  return EFI_SUCCESS;

+

+Fatal:

+  return EFI_INTERRUPT_PENDING;

+}

+

+/**

   CPU Hotplug MMI handler function.

 

   This is a root MMI handler.

@@ -297,6 +372,8 @@ CpuHotplugMmi (
 

   if (PluggedCount > 0) {

     Status = PlugCpus(mPluggedApicIds, PluggedCount);

+  } else if (ToUnplugCount > 0) {

+    Status = UnplugCpus(mToUnplugApicIds, ToUnplugCount);

   }

 

   if (EFI_ERROR(Status)) {

-- 
2.9.3



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#70763): https://edk2.groups.io/g/devel/message/70763
Mute This Topic: https://groups.io/mt/80125311/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-