public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ankur Arora" <ankur.a.arora@oracle.com>
To: devel@edk2.groups.io
Cc: imammedo@redhat.com, lersek@redhat.com,
	boris.ostrovsky@oracle.com,
	Ankur Arora <ankur.a.arora@oracle.com>
Subject: [RFC PATCH 4/5] OvmfPkg/CpuHotplugSmm: handle CPU hot-unplug
Date: Mon,  7 Dec 2020 21:34:31 -0800	[thread overview]
Message-ID: <20201208053432.2690694-5-ankur.a.arora@oracle.com> (raw)
In-Reply-To: <20201208053432.2690694-1-ankur.a.arora@oracle.com>

Introduce a new function UnplugCpus() which, for each
unplugged CPU:

  - find the slot for APIC ID in CPU_HOT_PLUG_DATA.

  - inform PiSmmCPuDxeSmm by calling
    EFI_SMM_CPU_SERVICE_PROTOCOL.RemoveProcessor().

  - update the QEMU_CPUHP_STAT_EJECTED bit in the
    QEMU_CPUHP_R_CPU_STAT regiser.

Signed-off-by: Ankur Arora <ankur.a.arora@oracle.com>
---
 OvmfPkg/CpuHotplugSmm/CpuHotplug.c | 80 ++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)

diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c
index 0f8f210d0ecf..0a839ae52215 100644
--- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c
+++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c
@@ -181,6 +181,84 @@ Fatal:
   return EFI_INTERRUPT_PENDING;
 }
 
+/**
+  CPU Hot-unplug handler function.
+
+  @param[in] mUnplugApicIds      List of APIC IDs to be plugged.
+
+  @param[in] ToUnplugCount       Count of APIC IDs to be plugged.
+
+  @retval EFI_SUCCESS	         Some of the requested APIC IDs were hot-unplugged.
+
+  @retval EFI_INTERRUPT_PENDING  Fatal error while hot-plugging.
+
+**/
+STATIC
+EFI_STATUS
+EFIAPI
+UnplugCpus(
+  IN APIC_ID                      *mUnplugApicIds,
+  IN UINT32                       ToUnplugCount
+  )
+{
+  EFI_STATUS Status = EFI_SUCCESS;
+  UINT32     ToUnplugIdx;
+
+    //
+    // Remove the CPU with EFI_SMM_CPU_SERVICE_PROTOCOL.
+    //
+
+  ToUnplugIdx = 0;
+  while (ToUnplugIdx < ToUnplugCount) {
+    APIC_ID    RemoveApicId;
+    UINT32     ProcessorNum;
+
+    RemoveApicId = mUnplugApicIds[ToUnplugIdx];
+
+    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_VERBOSE, "%a: did not find APIC ID " FMT_APIC_ID " to unplug\n",
+        __FUNCTION__, RemoveApicId));
+      ToUnplugIdx++;
+      continue;
+    }
+
+    Status = mMmCpuService->RemoveProcessor (mMmCpuService, ProcessorNum);
+
+    if (EFI_ERROR(Status)) {
+      DEBUG ((DEBUG_ERROR, "%a: RemoveProcessor(" FMT_APIC_ID "): %r\n",
+        __FUNCTION__, RemoveApicId, Status));
+      goto Fatal;
+    }
+
+      //
+      // Tell the host that the firmware is done.
+      //
+    QemuCpuhpWriteCpuSelector (mMmCpuIo, RemoveApicId);
+    QemuCpuhpWriteCpuStatus (mMmCpuIo, QEMU_CPUHP_STAT_EJECTED);
+
+    ToUnplugIdx++;
+  }
+
+  //
+  // We've handled this unplug.
+  //
+  return EFI_SUCCESS;
+
+Fatal:
+  return EFI_INTERRUPT_PENDING;
+}
+
 /**
   CPU Hotplug MMI handler function.
 
@@ -297,6 +375,8 @@ CpuHotplugMmi (
 
   if (PluggedCount > 0) {
     Status = PlugCpus(mPluggedApicIds, PluggedCount);
+  } else if (ToUnplugCount > 0) {
+    Status = UnplugCpus(mToUnplugApicIds, ToUnplugCount);
   }
 
   if (EFI_ERROR(Status)) {
-- 
2.25.4


  parent reply	other threads:[~2020-12-08  5:35 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-08  5:34 [RFC PATCH 0/5] support CPU hot-unplug ankur.a.arora
2020-12-08  5:34 ` [RFC PATCH 1/5] OvmfPkg/CpuHotplugSmm: move CPU Hotplug into PlugCpus() Ankur Arora
2020-12-08  5:34 ` [RFC PATCH 2/5] OvmfPkg/CpuHotplugSmm: handle fw_remove Ankur Arora
2020-12-08  5:34 ` [RFC PATCH 3/5] OvmfPkg/CpuHotplugSmm: add CpuStatus helper function Ankur Arora
2020-12-08  5:34 ` Ankur Arora [this message]
2020-12-08  5:34 ` [RFC PATCH 5/5] OvmfPkg/SmmControl2Dxe: negotiate ICH9_LPC_SMI_F_CPU_HOT_UNPLUG Ankur Arora
2020-12-10  9:21 ` [RFC PATCH 0/5] support CPU hot-unplug Laszlo Ersek
2020-12-10 20:08   ` Ankur Arora
2020-12-11 16:21     ` [edk2-devel] " Igor Mammedov
2020-12-21 14:44 ` Laszlo Ersek
2020-12-21 15:03   ` Laszlo Ersek
2020-12-21 15:46   ` Igor Mammedov
2020-12-21 19:57     ` Laszlo Ersek
2020-12-21 19:09   ` Ankur Arora
2020-12-21 19:58     ` Laszlo Ersek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201208053432.2690694-5-ankur.a.arora@oracle.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox