public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Laszlo Ersek" <lersek@redhat.com>
To: devel@edk2.groups.io, ankur.a.arora@oracle.com
Cc: imammedo@redhat.com, boris.ostrovsky@oracle.com,
	Jordan Justen <jordan.l.justen@intel.com>,
	Ard Biesheuvel <ard.biesheuvel@arm.com>,
	Aaron Young <aaron.young@oracle.com>
Subject: Re: [edk2-devel] [PATCH v9 09/10] OvmfPkg/CpuHotplugSmm: do actual CPU hot-eject
Date: Tue, 16 Mar 2021 13:52:58 +0100	[thread overview]
Message-ID: <0554816f-7a59-0fde-281b-6b2dadf30a4b@redhat.com> (raw)
In-Reply-To: <20210312062656.2477515-10-ankur.a.arora@oracle.com>

On 03/12/21 07:26, Ankur Arora wrote:

> @@ -214,6 +243,83 @@ EjectCpu (
>  {
>    UINT64 QemuSelector;
>  
> +  if (CheckIfBsp ()) {
> +    UINT32 Idx;
> +
> +    for (Idx = 0; Idx < mCpuHotEjectData->ArrayLength; Idx++) {
> +      UINT64 QemuSelector;

Visual Studio warns that the inner QemuSelector declaration shadows the
outer one. I'm going to remove the inner declaration, due to:

> +
> +      QemuSelector = mCpuHotEjectData->QemuSelectorMap[Idx];
> +
> +      if (QemuSelector != CPU_EJECT_QEMU_SELECTOR_INVALID) {
> +        //
> +        // This to-be-ejected-CPU has already received the BSP's SMI exit
> +        // signal and will execute SmmCpuFeaturesRendezvousExit()
> +        // followed by this callback or is already penned in the
> +        // CpuSleep() loop below.
> +        //
> +        // Tell QEMU to context-switch it out.
> +        //
> +        QemuCpuhpWriteCpuSelector (mMmCpuIo, (UINT32) QemuSelector);
> +        QemuCpuhpWriteCpuStatus (mMmCpuIo, QEMU_CPUHP_STAT_EJECT);
> +
> +        //
> +        // Now that we've ejected the CPU corresponding to QemuSelectorMap[Idx],
> +        // clear its eject status to ensure that an invalid future SMI does
> +        // not end up trying a spurious eject or a newly hotplugged CPU does
> +        // not get penned in the CpuSleep() loop.
> +        //
> +        // Note that the QemuCpuhpWriteCpuStatus() command above is a write to
> +        // a different address space and uses the EFI_MM_CPU_IO_PROTOCOL.
> +        //
> +        // This means that we are guaranteed that the following assignment
> +        // will not be reordered before the eject. And, so we can safely
> +        // do this write here.
> +        //
> +        mCpuHotEjectData->QemuSelectorMap[Idx] =
> +          CPU_EJECT_QEMU_SELECTOR_INVALID;
> +
> +        DEBUG ((DEBUG_INFO, "%a: Unplugged ProcessorNum %u, "
> +          "QemuSelector %Lu\n", __FUNCTION__, Idx, QemuSelector));
> +      }
> +    }
> +
> +    //
> +    // We are done until the next hot-unplug; clear the handler.
> +    //
> +    // mCpuHotEjectData->Handler is a NOP for any CPU not under ejection.
> +    // So, once we are done with all the ejections, we can safely reset it
> +    // here since any CPU dereferencing it would only see either the old
> +    // or the new value (since it is aligned at a natural boundary.)
> +    //
> +    mCpuHotEjectData->Handler = NULL;
> +    return;
> +  }
> +
> +  //
> +  // Reached only on APs
> +  //
> +
> +  //
> +  // mCpuHotEjectData->QemuSelectorMap[ProcessorNum] is updated
> +  // on the BSP in the ongoing SMI at two places:
> +  //
> +  // - UnplugCpus() where the BSP determines if a CPU is under ejection
> +  //   or not. As a comment in UnplugCpus() at set-up, and in
> +  //   SmmCpuFeaturesRendezvousExit() where it is dereferenced describe,
> +  //   any such updates are guaranteed to be ordered-before the
> +  //   dereference below.
> +  //
> +  // - EjectCpu() on the BSP (above) updates QemuSelectorMap[ProcessorNum]
> +  //   for a CPU once it's ejected.
> +  //
> +  //   The CPU under ejection: might be executing anywhere between the
> +  //   AllCpusInSync loop in SmiRendezvous(), to about to dereference
> +  //   QemuSelectorMap[ProcessorNum].
> +  //   As described in the comment above where we do the reset, this
> +  //   is not a problem since the ejected CPU never sees the after value.
> +  //   CPUs not-under ejection: never see any changes so they are fine.
> +  //
>    QemuSelector = mCpuHotEjectData->QemuSelectorMap[ProcessorNum];

this reference being to the outer one.

Thanks
Laszlo

>    if (QemuSelector == CPU_EJECT_QEMU_SELECTOR_INVALID) {
>      return;
> @@ -495,11 +601,6 @@ CpuHotplugMmi (
>    if (EFI_ERROR (Status)) {
>      goto Fatal;
>    }
> -  if (ToUnplugCount > 0) {
> -    DEBUG ((DEBUG_ERROR, "%a: hot-unplug is not supported yet\n",
> -      __FUNCTION__));
> -    goto Fatal;
> -  }
>  
>    if (PluggedCount > 0) {
>      Status = ProcessHotAddedCpus (mPluggedApicIds, PluggedCount);
> 


  parent reply	other threads:[~2021-03-16 12:53 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-12  6:26 [PATCH v9 00/10] support CPU hot-unplug Ankur Arora
2021-03-12  6:26 ` [PATCH v9 01/10] OvmfPkg/CpuHotplugSmm: refactor hotplug logic Ankur Arora
2021-03-12  6:26 ` [PATCH v9 02/10] OvmfPkg/CpuHotplugSmm: collect hot-unplug events Ankur Arora
2021-03-16  9:56   ` [edk2-devel] " Laszlo Ersek
2021-03-12  6:26 ` [PATCH v9 03/10] OvmfPkg/CpuHotplugSmm: add Qemu Cpu Status helper Ankur Arora
2021-03-12  6:26 ` [PATCH v9 04/10] OvmfPkg/CpuHotplugSmm: introduce UnplugCpus() Ankur Arora
2021-03-12  6:26 ` [PATCH v9 05/10] OvmfPkg: define CPU_HOT_EJECT_DATA Ankur Arora
2021-03-16 10:03   ` [edk2-devel] " Laszlo Ersek
2021-03-12  6:26 ` [PATCH v9 06/10] OvmfPkg/SmmCpuFeaturesLib: init CPU ejection state Ankur Arora
2021-03-16 10:12   ` [edk2-devel] " Laszlo Ersek
2021-03-12  6:26 ` [PATCH v9 07/10] OvmfPkg/SmmCpuFeaturesLib: call CPU hot-eject handler Ankur Arora
2021-03-16 10:20   ` [edk2-devel] " Laszlo Ersek
2021-03-12  6:26 ` [PATCH v9 08/10] OvmfPkg/CpuHotplugSmm: add EjectCpu() Ankur Arora
2021-03-16 10:35   ` [edk2-devel] " Laszlo Ersek
2021-03-12  6:26 ` [PATCH v9 09/10] OvmfPkg/CpuHotplugSmm: do actual CPU hot-eject Ankur Arora
2021-03-16 11:27   ` [edk2-devel] " Laszlo Ersek
2021-03-16 12:52   ` Laszlo Ersek [this message]
2021-03-12  6:26 ` [PATCH v9 10/10] OvmfPkg/SmmControl2Dxe: negotiate CPU hot-unplug Ankur Arora
2021-03-16 11:40   ` [edk2-devel] " Laszlo Ersek
2021-03-16 14:07 ` [PATCH v9 00/10] support " Laszlo Ersek
2021-03-16 17:56   ` Ankur Arora

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=0554816f-7a59-0fde-281b-6b2dadf30a4b@redhat.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