From nobody Thu Nov 14 17:04:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+70375+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+70375+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=oracle.com ARC-Seal: i=1; a=rsa-sha256; t=1610696749; cv=none; d=zohomail.com; s=zohoarc; b=Mt8Im8hXZzT0A6z/XE6rV7D007Wk3hdwFK8MUBBxyNTbdSuS2gMv2Gu7XE3nk4m1qzTDyHaBk+gonchdvtV48f5fD8n80y+Hll5D1wETrPba4tnOOeQn6xGzlLT4mZWBmTAt/eWkm7gfQInyMMEFBsQ8riSDuKmM8nf+C7ftT30= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610696749; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=aOHOfJPrE6LDcdKpycZrQEUfinz6xRE7esZq7RvlWbY=; b=cye4zKPbqDqUv2F7+CcJ0YQ9K+XTXcnbo41YSMwCOunZW7Wu40e27CdWiatXl2EeRDnPj9KC2vFF7aJ6P0e5HRA0oBQkTh4+krkGZzoRtpuqHFYtud7FACTuYw5/6LwAJARryiFFJOmbHLN6iI1WHN/RzYR76vMlQTh+hGms8dQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+70375+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1610696749907250.70388328027946; Thu, 14 Jan 2021 23:45:49 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id AS8cYY1788612xwE65ZXOEvl; Thu, 14 Jan 2021 23:45:49 -0800 X-Received: from userp2130.oracle.com (userp2130.oracle.com [156.151.31.86]) by mx.groups.io with SMTP id smtpd.web11.1035.1610696748969758267 for ; Thu, 14 Jan 2021 23:45:49 -0800 X-Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10F7jLrY124578; Fri, 15 Jan 2021 07:45:46 GMT X-Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 360kvkbnhk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Jan 2021 07:45:45 +0000 X-Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 10F7efCx005641; Fri, 15 Jan 2021 07:45:45 GMT X-Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 360kfapwkv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 15 Jan 2021 07:45:45 +0000 X-Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 10F7jiuH020813; Fri, 15 Jan 2021 07:45:44 GMT X-Received: from localhost.localdomain (/70.36.60.91) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 14 Jan 2021 23:45:44 -0800 From: "Ankur Arora" To: devel@edk2.groups.io Cc: imammedo@redhat.com, lersek@redhat.com, Ankur Arora , Jordan Justen , Ard Biesheuvel , Boris Ostrovsky , Aaron Young Subject: [edk2-devel] [PATCH v3 05/10] OvmfPkg/SmmCpuFeaturesLib: init CPU ejection state Date: Thu, 14 Jan 2021 23:45:28 -0800 Message-Id: <20210115074533.277448-6-ankur.a.arora@oracle.com> In-Reply-To: <20210115074533.277448-1-ankur.a.arora@oracle.com> References: <20210115074533.277448-1-ankur.a.arora@oracle.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ankur.a.arora@oracle.com X-Gm-Message-State: Vg6w7xXVj7wiHLM8uD8Re6W2x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1610696749; bh=PhVsmJZkz1JLh071a2ZWaiXk3aOrzxRof+u9O6/Um8I=; h=Cc:Date:From:Reply-To:Subject:To; b=J53cyrfoQGCifUTbY/qUA361xORgioVTnEsMyI+kEOoI93k/ckqGYcfcGzAWIqtTVxD bI9smVcIwXCocKHnCIY7D4G7mhWZXh50/ogqGpMs2CHnDXCKQOq+cxp4JUxN8xllXggwi lK3kvWlV3iXv9lz9Wxw90PWrNpVMiYHIAxc= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Init CPU_HOT_EJECT_DATA, exposed via PcdCpuHotEjectDataAddress. This is owned by PiSmmCpuDxeSmm, managed in OvmfPkg/SmmCpuFeaturesLib, and is consumed in OvmfPkg/CpuHotPlugSmm which sets up CPU_HOT_EJECT_DATA->Handler which handles the mechanics of CPU ejection. Cc: Laszlo Ersek Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Igor Mammedov Cc: Boris Ostrovsky Cc: Aaron Young Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3132 Signed-off-by: Ankur Arora --- .../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 68 ++++++++++++++++++= ++++ .../SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf | 3 + 2 files changed, 71 insertions(+) diff --git a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c b/OvmfPk= g/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c index 7ef7ed98342e..5e7f2de25911 100644 --- a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c +++ b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c @@ -14,6 +14,7 @@ #include #include #include +#include // AllocatePool() #include #include #include @@ -171,6 +172,61 @@ SmmCpuFeaturesHookReturnFromSmm ( return OriginalInstructionPointer; } =20 +// +// The PCD corresponding to CPU_HOT_EJECT_DATA is owned by UefiCpuPkg +// but we allocate and set it up here because it is needed from +// SmmCpuFeaturesRendezvousExit() on all CPUs exiting SMI and +// simultaneous PcdGet64() on multiple CPUs is not supported. +// + +GLOBAL_REMOVE_IF_UNREFERENCED +CPU_HOT_EJECT_DATA *mCpuHotEjectData; + +STATIC +VOID +EFIAPI +SmmCpuFeaturesSmmInitHotEject( + VOID + ) +{ + UINT32 mMaxNumberOfCpus; + EFI_STATUS Status; + + if (!FeaturePcdGet (PcdCpuHotPlugSupport)) { + return; + } + + // PcdCpuHotPlugSupport =3D> PcdCpuMaxLogicalProcessorNumber + mMaxNumberOfCpus =3D PcdGet32 (PcdCpuMaxLogicalProcessorNumber); + + // No spare CPUs to eject + if (mMaxNumberOfCpus =3D=3D 1) { + return; + } + + mCpuHotEjectData =3D + (CPU_HOT_EJECT_DATA *)AllocatePool (sizeof (*mCpuHotEjectData)); + ASSERT (mCpuHotEjectData !=3D NULL); + + // + // Allocate buffer for pointers to array in CPU_HOT_EJECT_DATA. + // + mCpuHotEjectData->Revision =3D CPU_HOT_EJECT_DATA_REVISION_1; // Revis= ion + mCpuHotEjectData->ArrayLength =3D mMaxNumberOfCpus; // Array= Length of APIC ID + mCpuHotEjectData->ApicIdMap =3D // CpuIn= dex -> APIC ID map + (UINT64 *)AllocatePool (sizeof (UINT64) * mCpuHotEjectData->ArrayLengt= h); + mCpuHotEjectData->Handler =3D NULL; // Hot E= ject handler + mCpuHotEjectData->Handler =3D 0; // Reser= ved + + ASSERT (mCpuHotEjectData->ApicIdMap !=3D NULL); + + // + // Expose address of CPU Hot eject Data structure + // + Status =3D PcdSet64S (PcdCpuHotEjectDataAddress, (UINT64)(VOID *)mCpuHot= EjectData); + ASSERT_EFI_ERROR (Status); +} + /** Hook point in normal execution mode that allows the one CPU that was ele= cted as monarch during System Management Mode initialization to perform addit= ional @@ -188,6 +244,9 @@ SmmCpuFeaturesSmmRelocationComplete ( UINTN MapPagesBase; UINTN MapPagesCount; =20 + + SmmCpuFeaturesSmmInitHotEject(); + if (!MemEncryptSevIsEnabled ()) { return; } @@ -375,6 +434,15 @@ SmmCpuFeaturesRendezvousExit ( IN UINTN CpuIndex ) { + // + // CPU Hot eject not enabled. + // + if (mCpuHotEjectData =3D=3D NULL || + mCpuHotEjectData->Handler =3D=3D NULL) { + return; + } + + mCpuHotEjectData->Handler(CpuIndex); } =20 /** diff --git a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf b/Ovmf= Pkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf index 97a10afb6e27..3043f02b2216 100644 --- a/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf +++ b/OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf @@ -36,3 +36,6 @@ =20 [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdQ35SmramAtDefaultSmbase + gUefiCpuPkgTokenSpaceGuid.PcdCpuHotPlugSupport + gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber + gUefiCpuPkgTokenSpaceGuid.PcdCpuHotEjectDataAddress --=20 2.9.3 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#70375): https://edk2.groups.io/g/devel/message/70375 Mute This Topic: https://groups.io/mt/79697146/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-