From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.61]) by mx.groups.io with SMTP id smtpd.web11.13863.1583155349485582049 for ; Mon, 02 Mar 2020 05:22:29 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XjYfqZNV; spf=pass (domain: redhat.com, ip: 205.139.110.61, mailfrom: philmd@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583155348; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+Fnge45USeR7sWcYpbdPuVrip3BEN5r2fbN9rqfSbdA=; b=XjYfqZNV7eX4y5A8pO6WuKmmGdHNI0CqDim91a2+CRgA0scJVLN9OjfbMqjEGJQVsQKxqs wm3rG4RSd95i/O3Ha9tXpuuNXkozlp0L7/qJXWCOOQW6zmNZQMy8+97xSqHkuKm/m6O7cY BPpVxvaO7OaEpIIC20JWcteDnZ2pBHE= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-336-2e-VNrS7OI2jfvh7zGTU_g-1; Mon, 02 Mar 2020 08:22:25 -0500 X-MC-Unique: 2e-VNrS7OI2jfvh7zGTU_g-1 Received: by mail-wr1-f72.google.com with SMTP id m18so4547826wro.22 for ; Mon, 02 Mar 2020 05:22:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Rix+93eBC4ajWAlzbzj9xVlzPH1qm9q6QmDK4PAnhr8=; b=MqoqXryAGESR1UKUGCYtIsS12Y2/+Yk9U/Fx21X07vXkmzbDtFx2BKOIIWrn9kMvKK DogKZ4XoIyQtidthXGYK/IB/JDzTXiC+BVgdTDzaFAM1+63aDWboWjO/pwOG7JDpQHnV sEIb16o+trjQv3s3IV08Nt5+DjC/OBQy96/XnJPIQ5Fg0maR2setenbLyNCH0jdaFRt6 aZBV0TKhS58BlteD4B5zGWO7ZAKxCwnc/2MZ70BV5k7/m4VDs/uccbMkXZJlv2VwUsha OTRWM340APenXTASUxwsGaHUxjfHySvSpMXR47PGqk4N3U8Ye6WZDv/qlOFBsJQAI9Fz x/aQ== X-Gm-Message-State: APjAAAUQPA4gKfkOfSMHUCpbToQnh+GCcFAYsq4BAmivk9VNz+m9gZlX A8JUtDpqRUDMQzQzGUcZ5TSY5KYTLFyPxyBA9ORB06w6JMBJMvMQUPjO5GnUtvkUdqioA52/Q/2 6h/Bq8TN+FOWZaA== X-Received: by 2002:adf:aa0e:: with SMTP id p14mr22997222wrd.399.1583155342833; Mon, 02 Mar 2020 05:22:22 -0800 (PST) X-Google-Smtp-Source: APXvYqw9KXVRAycAGCzHogwtaJ6+yM+80AQy+MoBuUqebEjTdEJRbJs7/JsnEsgEn+vR5QxcYKi9EA== X-Received: by 2002:adf:aa0e:: with SMTP id p14mr22997198wrd.399.1583155342499; Mon, 02 Mar 2020 05:22:22 -0800 (PST) Return-Path: Received: from ?IPv6:2a01:e35:2fb0:49e0:3f7b:4b69:b9c:cdc0? ([2a01:e35:2fb0:49e0:3f7b:4b69:b9c:cdc0]) by smtp.gmail.com with ESMTPSA id q16sm11931903wrj.73.2020.03.02.05.22.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 02 Mar 2020 05:22:22 -0800 (PST) Subject: Re: [PATCH v2 08/16] OvmfPkg/CpuHotplugSmm: define the QEMU_CPUHP_CMD_GET_ARCH_ID macro To: Laszlo Ersek , edk2-devel-groups-io Cc: Ard Biesheuvel , Igor Mammedov , Jiewen Yao , Jordan Justen , Michael Kinney References: <20200226221156.29589-1-lersek@redhat.com> <20200226221156.29589-9-lersek@redhat.com> From: =?UTF-8?B?UGhpbGlwcGUgTWF0aGlldS1EYXVkw6k=?= Message-ID: Date: Mon, 2 Mar 2020 14:22:21 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <20200226221156.29589-9-lersek@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable On 2/26/20 11:11 PM, 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. >=20 > At the same time, add a sanity check for the modern hotplug interface to > CpuHotplugSmm. >=20 > 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 > --- >=20 > Notes: > v2: > =20 > - Pick up Ard's Acked-by, which is conditional on approval from Inte= l > reviewers on Cc. (I'd like to save Ard the churn of re-acking > unmodified patches.) >=20 > OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h | 1 + > OvmfPkg/CpuHotplugSmm/CpuHotplug.c | 35 ++++++++++++++++= ++++ > 2 files changed, 36 insertions(+) >=20 > 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_ > =20 > #include > =20 > // > // Each register offset is: > // - relative to the board-dependent IO base address of the register bl= ock, > // - named QEMU_CPUHP_(R|W|RW)_*, according to the possible access mode= s of the > // register, > // - followed by distinguished bitmasks or values in the register. > // > #define QEMU_CPUHP_R_CMD_DATA2 0x0 > =20 > #define QEMU_CPUHP_R_CPU_STAT 0x4 > #define QEMU_CPUHP_STAT_ENABLED BIT0 > =20 > #define QEMU_CPUHP_RW_CMD_DATA 0x8 > =20 > #define QEMU_CPUHP_W_CPU_SEL 0x0 > =20 > #define QEMU_CPUHP_W_CMD 0x5 > #define QEMU_CPUHP_CMD_GET_PENDING 0x0 > +#define QEMU_CPUHP_CMD_GET_ARCH_ID 0x3 > =20 > #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. > =20 > Copyright (c) 2020, Red Hat, Inc. > =20 > SPDX-License-Identifier: BSD-2-Clause-Patent > **/ > =20 > #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 > =20 > +#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; > =20 > =20 > /** > CPU Hotplug MMI handler function. > =20 > This is a root MMI handler. > =20 > @param[in] DispatchHandle The unique handle assigned to this han= dler by > EFI_MM_SYSTEM_TABLE.MmiHandlerRegister= (). > =20 > @param[in] Context Context passed in by > EFI_MM_SYSTEM_TABLE.MmiManage(). Due t= o > CpuHotplugMmi() being a root MMI handl= er, > 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; > } > =20 > // > // 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 =3D gMmst->MmLocateProtocol (&gEfiMmCpuIoProtocolGuid, > NULL /* Registration */, (VOID **)&mMmCpuIo); > if (EFI_ERROR (Status)) { > DEBUG ((DEBUG_ERROR, "%a: locate MmCpuIo: %r\n", __FUNCTION__, Stat= us)); > goto Fatal; > } > =20 > + // > + // 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); Reviewed-by: Philippe Mathieu-Daude > + 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; > } > =20 > return EFI_SUCCESS; > =20 > Fatal: > ASSERT (FALSE); > CpuDeadLoop (); > return Status; > } >=20