public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ard Biesheuvel" <ard.biesheuvel@linaro.org>
To: Laszlo Ersek <lersek@redhat.com>
Cc: edk2-devel-groups-io <devel@edk2.groups.io>,
	"Igor Mammedov" <imammedo@redhat.com>,
	"Jiewen Yao" <jiewen.yao@intel.com>,
	"Jordan Justen" <jordan.l.justen@intel.com>,
	"Michael Kinney" <michael.d.kinney@intel.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: Re: [PATCH v2 08/16] OvmfPkg/CpuHotplugSmm: define the QEMU_CPUHP_CMD_GET_ARCH_ID macro
Date: Mon, 2 Mar 2020 14:45:45 +0100	[thread overview]
Message-ID: <CAKv+Gu_KLr86F=vo8AAP0wtYwtyR+tnvjtvo53K+yZ6FRsyzWg@mail.gmail.com> (raw)
In-Reply-To: <20200226221156.29589-9-lersek@redhat.com>

On Wed, 26 Feb 2020 at 23:12, Laszlo Ersek <lersek@redhat.com> wrote:
>
> QEMU commit 3a61c8db9d25 ("acpi: cpuhp: add CPHP_GET_CPU_ID_CMD command",
> 2020-01-22) introduced a new command in the modern CPU hotplug register
> block that lets the firmware query the arch-specific IDs (on IA32/X64: the
> APIC IDs) of CPUs. Add a macro for this command value, because we'll need
> it later.
>
> At the same time, add a sanity check for the modern hotplug interface to
> CpuHotplugSmm.
>
> 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>
> Acked-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

> ---
>
> Notes:
>     v2:
>
>     - Pick up Ard's Acked-by, which is conditional on approval from Intel
>       reviewers on Cc. (I'd like to save Ard the churn of re-acking
>       unmodified patches.)
>
>  OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h |  1 +
>  OvmfPkg/CpuHotplugSmm/CpuHotplug.c                | 35 ++++++++++++++++++++
>  2 files changed, 36 insertions(+)
>
> diff --git a/OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h b/OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h
> index cf0745610f2c..3d013633501b 100644
> --- a/OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h
> +++ b/OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h
> @@ -20,24 +20,25 @@
>  #define QEMU_CPU_HOTPLUG_H_
>
>  #include <Base.h>
>
>  //
>  // Each register offset is:
>  // - relative to the board-dependent IO base address of the register block,
>  // - named QEMU_CPUHP_(R|W|RW)_*, according to the possible access modes of the
>  //   register,
>  // - followed by distinguished bitmasks or values in the register.
>  //
>  #define QEMU_CPUHP_R_CMD_DATA2               0x0
>
>  #define QEMU_CPUHP_R_CPU_STAT                0x4
>  #define QEMU_CPUHP_STAT_ENABLED                BIT0
>
>  #define QEMU_CPUHP_RW_CMD_DATA               0x8
>
>  #define QEMU_CPUHP_W_CPU_SEL                 0x0
>
>  #define QEMU_CPUHP_W_CMD                     0x5
>  #define QEMU_CPUHP_CMD_GET_PENDING             0x0
> +#define QEMU_CPUHP_CMD_GET_ARCH_ID             0x3
>
>  #endif // QEMU_CPU_HOTPLUG_H_
> diff --git a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c
> index fd09403eabf3..5df8c689c63a 100644
> --- a/OvmfPkg/CpuHotplugSmm/CpuHotplug.c
> +++ b/OvmfPkg/CpuHotplugSmm/CpuHotplug.c
> @@ -1,38 +1,41 @@
>  /** @file
>    Root SMI handler for VCPU hotplug SMIs.
>
>    Copyright (c) 2020, Red Hat, Inc.
>
>    SPDX-License-Identifier: BSD-2-Clause-Patent
>  **/
>
>  #include <IndustryStandard/Q35MchIch9.h>     // ICH9_APM_CNT
> +#include <IndustryStandard/QemuCpuHotplug.h> // QEMU_CPUHP_CMD_GET_PENDING
>  #include <Library/BaseLib.h>                 // CpuDeadLoop()
>  #include <Library/DebugLib.h>                // ASSERT()
>  #include <Library/MmServicesTableLib.h>      // gMmst
>  #include <Library/PcdLib.h>                  // PcdGetBool()
>  #include <Protocol/MmCpuIo.h>                // EFI_MM_CPU_IO_PROTOCOL
>  #include <Uefi/UefiBaseType.h>               // EFI_STATUS
>
> +#include "QemuCpuhp.h"                       // QemuCpuhpWriteCpuSelector()
> +
>  //
>  // We use this protocol for accessing IO Ports.
>  //
>  STATIC EFI_MM_CPU_IO_PROTOCOL *mMmCpuIo;
>  //
>  // Represents the registration of the CPU Hotplug MMI handler.
>  //
>  STATIC EFI_HANDLE mDispatchHandle;
>
>
>  /**
>    CPU Hotplug MMI handler function.
>
>    This is a root MMI handler.
>
>    @param[in] DispatchHandle      The unique handle assigned to this handler by
>                                   EFI_MM_SYSTEM_TABLE.MmiHandlerRegister().
>
>    @param[in] Context             Context passed in by
>                                   EFI_MM_SYSTEM_TABLE.MmiManage(). Due to
>                                   CpuHotplugMmi() being a root MMI handler,
>                                   Context is ASSERT()ed to be NULL.
> @@ -149,43 +152,75 @@ CpuHotplugEntry (
>    //
>    // This driver depends on the dynamically detected "SMRAM at default SMBASE"
>    // feature.
>    //
>    if (!PcdGetBool (PcdQ35SmramAtDefaultSmbase)) {
>      return EFI_UNSUPPORTED;
>    }
>
>    //
>    // Errors from here on are fatal; we cannot allow the boot to proceed if we
>    // can't set up this driver to handle CPU hotplug.
>    //
>    // First, collect the protocols needed later. All of these protocols are
>    // listed in our module DEPEX.
>    //
>    Status = gMmst->MmLocateProtocol (&gEfiMmCpuIoProtocolGuid,
>                      NULL /* Registration */, (VOID **)&mMmCpuIo);
>    if (EFI_ERROR (Status)) {
>      DEBUG ((DEBUG_ERROR, "%a: locate MmCpuIo: %r\n", __FUNCTION__, Status));
>      goto Fatal;
>    }
>
> +  //
> +  // Sanity-check the CPU hotplug interface.
> +  //
> +  // Both of the following features are part of QEMU 5.0, introduced primarily
> +  // in commit range 3e08b2b9cb64..3a61c8db9d25:
> +  //
> +  // (a) the QEMU_CPUHP_CMD_GET_ARCH_ID command of the modern CPU hotplug
> +  //     interface,
> +  //
> +  // (b) the "SMRAM at default SMBASE" feature.
> +  //
> +  // From these, (b) is restricted to 5.0+ machine type versions, while (a)
> +  // does not depend on machine type version. Because we ensured the stricter
> +  // condition (b) through PcdQ35SmramAtDefaultSmbase above, the (a)
> +  // QEMU_CPUHP_CMD_GET_ARCH_ID command must now be available too. While we
> +  // can't verify the presence of precisely that command, we can still verify
> +  // (sanity-check) that the modern interface is active, at least.
> +  //
> +  // Consult the "Typical usecases | Detecting and enabling modern CPU hotplug
> +  // interface" section in QEMU's "docs/specs/acpi_cpu_hotplug.txt", on the
> +  // following.
> +  //
> +  QemuCpuhpWriteCpuSelector (mMmCpuIo, 0);
> +  QemuCpuhpWriteCpuSelector (mMmCpuIo, 0);
> +  QemuCpuhpWriteCommand (mMmCpuIo, QEMU_CPUHP_CMD_GET_PENDING);
> +  if (QemuCpuhpReadCommandData2 (mMmCpuIo) != 0) {
> +    Status = EFI_NOT_FOUND;
> +    DEBUG ((DEBUG_ERROR, "%a: modern CPU hotplug interface: %r\n",
> +      __FUNCTION__, Status));
> +    goto Fatal;
> +  }
> +
>    //
>    // Register the handler for the CPU Hotplug MMI.
>    //
>    Status = gMmst->MmiHandlerRegister (
>                      CpuHotplugMmi,
>                      NULL,            // HandlerType: root MMI handler
>                      &mDispatchHandle
>                      );
>    if (EFI_ERROR (Status)) {
>      DEBUG ((DEBUG_ERROR, "%a: MmiHandlerRegister(): %r\n", __FUNCTION__,
>        Status));
>      goto Fatal;
>    }
>
>    return EFI_SUCCESS;
>
>  Fatal:
>    ASSERT (FALSE);
>    CpuDeadLoop ();
>    return Status;
>  }
> --
> 2.19.1.3.g30247aa5d201
>
>

  parent reply	other threads:[~2020-03-02 13:45 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-26 22:11 [PATCH v2 00/16] OvmfPkg: support VCPU hotplug with -D SMM_REQUIRE Laszlo Ersek
2020-02-26 22:11 ` [PATCH v2 01/16] MdeModulePkg/PiSmmCore: log SMM image start failure Laszlo Ersek
2020-03-02 12:47   ` [edk2-devel] " Laszlo Ersek
2020-03-02 12:55     ` Liming Gao
2020-03-02 13:46   ` Philippe Mathieu-Daudé
2020-03-03  0:46   ` Dong, Eric
2020-02-26 22:11 ` [PATCH v2 02/16] UefiCpuPkg/PiSmmCpuDxeSmm: fix S3 Resume for CPU hotplug Laszlo Ersek
2020-02-28  3:05   ` [edk2-devel] " Dong, Eric
2020-02-28 10:50     ` Laszlo Ersek
2020-03-04 12:23     ` Laszlo Ersek
2020-03-04 14:36       ` Dong, Eric
2020-02-26 22:11 ` [PATCH v2 03/16] OvmfPkg: clone SmmCpuPlatformHookLib from UefiCpuPkg Laszlo Ersek
2020-03-02 13:27   ` Ard Biesheuvel
2020-03-02 13:49   ` Philippe Mathieu-Daudé
2020-02-26 22:11 ` [PATCH v2 04/16] OvmfPkg: enable SMM Monarch Election in PiSmmCpuDxeSmm Laszlo Ersek
2020-03-02 13:32   ` Ard Biesheuvel
2020-02-26 22:11 ` [PATCH v2 05/16] OvmfPkg: enable CPU hotplug support " Laszlo Ersek
2020-03-02 13:33   ` Ard Biesheuvel
2020-02-26 22:11 ` [PATCH v2 06/16] OvmfPkg/CpuHotplugSmm: introduce skeleton for CPU Hotplug SMM driver Laszlo Ersek
2020-03-02 13:44   ` Ard Biesheuvel
2020-02-26 22:11 ` [PATCH v2 07/16] OvmfPkg/CpuHotplugSmm: add hotplug register block helper functions Laszlo Ersek
2020-03-02 13:24   ` Philippe Mathieu-Daudé
2020-03-02 13:45   ` [edk2-devel] " Ard Biesheuvel
2020-02-26 22:11 ` [PATCH v2 08/16] OvmfPkg/CpuHotplugSmm: define the QEMU_CPUHP_CMD_GET_ARCH_ID macro Laszlo Ersek
2020-03-02 13:22   ` Philippe Mathieu-Daudé
2020-03-02 13:45   ` Ard Biesheuvel [this message]
2020-02-26 22:11 ` [PATCH v2 09/16] OvmfPkg/CpuHotplugSmm: add function for collecting CPUs with events Laszlo Ersek
2020-03-02 13:49   ` Ard Biesheuvel
2020-03-02 20:34   ` Philippe Mathieu-Daudé
2020-03-03 10:31     ` Laszlo Ersek
2020-02-26 22:11 ` [PATCH v2 10/16] OvmfPkg/CpuHotplugSmm: collect " Laszlo Ersek
2020-03-02 13:58   ` Ard Biesheuvel
2020-02-26 22:11 ` [PATCH v2 11/16] OvmfPkg/CpuHotplugSmm: introduce Post-SMM Pen for hot-added CPUs Laszlo Ersek
2020-03-02 14:02   ` [edk2-devel] " Ard Biesheuvel
2020-02-26 22:11 ` [PATCH v2 12/16] OvmfPkg/CpuHotplugSmm: introduce First SMI Handler " Laszlo Ersek
2020-03-02 14:03   ` Ard Biesheuvel
2020-02-26 22:11 ` [PATCH v2 13/16] OvmfPkg/CpuHotplugSmm: complete root MMI handler for CPU hotplug Laszlo Ersek
2020-03-02 14:05   ` Ard Biesheuvel
2020-02-26 22:11 ` [PATCH v2 14/16] OvmfPkg: clone CpuS3DataDxe from UefiCpuPkg Laszlo Ersek
2020-03-02 13:44   ` Philippe Mathieu-Daudé
2020-03-02 14:06   ` Ard Biesheuvel
2020-02-26 22:11 ` [PATCH v2 15/16] OvmfPkg/CpuS3DataDxe: superficial cleanups Laszlo Ersek
2020-03-02 13:25   ` Philippe Mathieu-Daudé
2020-03-02 14:06   ` Ard Biesheuvel
2020-02-26 22:11 ` [PATCH v2 16/16] OvmfPkg/CpuS3DataDxe: enable S3 resume after CPU hotplug Laszlo Ersek
2020-03-02 14:16   ` Ard Biesheuvel
2020-03-02 15:46 ` [edk2-devel] [PATCH v2 00/16] OvmfPkg: support VCPU hotplug with -D SMM_REQUIRE Boris Ostrovsky
2020-03-02 19:22   ` Laszlo Ersek
2020-03-02 19:59 ` Laszlo Ersek
2020-03-04 13:29   ` Philippe Mathieu-Daudé
2020-03-04 18:09     ` Laszlo Ersek
2020-03-04 12:29 ` Laszlo Ersek
2020-03-05  8:32   ` 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='CAKv+Gu_KLr86F=vo8AAP0wtYwtyR+tnvjtvo53K+yZ6FRsyzWg@mail.gmail.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