From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by mx.groups.io with SMTP id smtpd.web09.14240.1583156757497357802 for ; Mon, 02 Mar 2020 05:45:57 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=mnBnm6sF; spf=pass (domain: linaro.org, ip: 209.85.221.68, mailfrom: ard.biesheuvel@linaro.org) Received: by mail-wr1-f68.google.com with SMTP id v2so12569623wrp.12 for ; Mon, 02 Mar 2020 05:45:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=5r+2L9d0URzij5JIwwoMPujw6k7rW6cH9KES7J652m0=; b=mnBnm6sFFFMat3m3MvyQSLlyJT+i4npgyGvg1LvQ0RBgh09NmDlh3hnnulJuwylMb/ LYmV+lH4QQX5b9GxSlqkCtpMoinFkw8oGy1TCk6X7iwLSyQA+eR4eLEOWTSIy5NAlbal Hnk++veVUvdS7lVsLWEMWmNvTAp3gSxoC78p7DBLyFfZCbZwihAUpaoSytwbANYD1via 6aLL+iAQyV/th82TwjuoiZKQ8lwHBj2gGgIbURzDWYMja01U+FUWLr+qaanXVAyKFRW6 kzemQBjdaKTRc2w//z5qkwxV5EkfV6fjFFDaWq3bNQ+wSiCkCdVcBZNyTgkbTU6+BfpK M+ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=5r+2L9d0URzij5JIwwoMPujw6k7rW6cH9KES7J652m0=; b=L9d0qWZc8RmxOrTGil4ay4jyn03aRDkv2lanmpNfI0Ri1b1EPFl8gyRGWdwHku8vvK Re2854TuSIVdmRfn2OHkbgH2YBx3BhDkSzu2IKa4hoTZXdxRl4/J9AsDl/5ubORHvHkd e23tdq2gKk6qpyqEkGpT2/NnCX1hKypdAwQqHVdrPhvqK6tboXfEGrTjcGr263E/OoOX PYHTVXdSWoRA9e2asYPno0Dfp3ufKXvxtqjX7N/YUQRIZ9YK5KAqRHOfI1Dau8GcNLvG rULzTcWRNwOCkOjNbENI+8No2L3h6IPcUfz8BhIwl5G8bVUXe7ueT8wxOFVEvu29Crbs 8y1A== X-Gm-Message-State: APjAAAUE+0thEPIxOsJxjTylgU+nO48crZb+XiXd6LaRRxTFmyY4FLz9 qwDRAN5QozzHX+zxfe3WYHwuiUQwrYaYSMCz9UFMUQ== X-Google-Smtp-Source: APXvYqwslaZ8ZMH0k0mPhEdLGAPu8UGQ+C9hGCVS8w2xtxmbUbEVmU64wxdsBoMrBVwHuKzv6agHTRBknxvenhDLNhE= X-Received: by 2002:a05:6000:110b:: with SMTP id z11mr23018822wrw.252.1583156755998; Mon, 02 Mar 2020 05:45:55 -0800 (PST) MIME-Version: 1.0 References: <20200226221156.29589-1-lersek@redhat.com> <20200226221156.29589-9-lersek@redhat.com> In-Reply-To: <20200226221156.29589-9-lersek@redhat.com> From: "Ard Biesheuvel" Date: Mon, 2 Mar 2020 14:45:45 +0100 Message-ID: Subject: Re: [PATCH v2 08/16] OvmfPkg/CpuHotplugSmm: define the QEMU_CPUHP_CMD_GET_ARCH_ID macro To: Laszlo Ersek Cc: edk2-devel-groups-io , Igor Mammedov , Jiewen Yao , Jordan Justen , Michael Kinney , =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, 26 Feb 2020 at 23:12, Laszlo Ersek 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: th= e > 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 > Cc: Igor Mammedov > Cc: Jiewen Yao > Cc: Jordan Justen > Cc: Michael Kinney > Cc: Philippe Mathieu-Daud=C3=A9 > Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1512 > Signed-off-by: Laszlo Ersek > Acked-by: Ard Biesheuvel Reviewed-by: Ard Biesheuvel > --- > > 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 > > // > // Each register offset is: > // - relative to the board-dependent IO base address of the register blo= ck, > // - 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/C= puHotplug.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 // ICH9_APM_CNT > +#include // QEMU_CPUHP_CMD_GET_PENDI= NG > #include // CpuDeadLoop() > #include // ASSERT() > #include // gMmst > #include // PcdGetBool() > #include // EFI_MM_CPU_IO_PROTOCOL > #include // EFI_STATUS > > +#include "QemuCpuhp.h" // QemuCpuhpWriteCpuSelecto= r() > + > // > // 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 hand= ler 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 handle= r, > Context is ASSERT()ed to be NULL. > @@ -149,43 +152,75 @@ CpuHotplugEntry ( > // > // This driver depends on the dynamically detected "SMRAM at default S= MBASE" > // 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 a= re > // listed in our module DEPEX. > // > Status =3D gMmst->MmLocateProtocol (&gEfiMmCpuIoProtocolGuid, > NULL /* Registration */, (VOID **)&mMmCpuIo); > if (EFI_ERROR (Status)) { > DEBUG ((DEBUG_ERROR, "%a: locate MmCpuIo: %r\n", __FUNCTION__, Statu= s)); > goto Fatal; > } > > + // > + // Sanity-check the CPU hotplug interface. > + // > + // Both of the following features are part of QEMU 5.0, introduced pri= marily > + // in commit range 3e08b2b9cb64..3a61c8db9d25: > + // > + // (a) the QEMU_CPUHP_CMD_GET_ARCH_ID command of the modern CPU hotplu= g > + // 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 str= icter > + // 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 v= erify > + // (sanity-check) that the modern interface is active, at least. > + // > + // Consult the "Typical usecases | Detecting and enabling modern CPU h= otplug > + // 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) !=3D 0) { > + Status =3D 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 =3D 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 > >