From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=fbfl0FH8; spf=pass (domain: oracle.com, ip: 156.151.31.86, mailfrom: ankur.a.arora@oracle.com) 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=k6AQMfI99yEUd9pdOUW1kDCDkXXc6QimaIw6fPDnORI=; b=fbfl0FH8clsHnbLNaFOg9XUFn9Ojosdp6/FdDNpG3NLHfkb9upb1Wpp66L4CghZkYypr /pAeIxlDqUPL87tJLikqLIXfqTnCtvBzbcId5ENsfWMoROCQO4wuHukft7vQQFr0L05k 929DSDblr29AZjU2cMq7bE9lChqMfvhVqOdh9h+U+O3l2kx18ZbLi2BUFVw5hJ0Q/XJh hZD3hhPTfBab3fXAihdYQguZzd3xFyqqfhqAe5ZRRBaFczL/yUk0NvQtuQxYyh7S7GgE OZgc0ud2Ck+joVZ8Fn/zRYDs2K8SCNwdaT8iLzwNly01WxtOdqm/qahYQG6ix4yIVg6x 4w== 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 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 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 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 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: [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> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20210115074533.277448-1-ankur.a.arora@oracle.com> References: <20210115074533.277448-1-ankur.a.arora@oracle.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9864 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101150044 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9864 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 phishscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 malwarescore=0 clxscore=1015 impostorscore=0 spamscore=0 mlxscore=0 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101150044 Content-Transfer-Encoding: quoted-printable 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 =0D #include =0D #include =0D +#include // AllocatePool() #include =0D #include =0D #include =0D @@ -171,6 +172,61 @@ SmmCpuFeaturesHookReturnFromSmm ( return OriginalInstructionPointer;=0D }=0D =0D +// +// 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); +} + /**=0D Hook point in normal execution mode that allows the one CPU that was ele= cted=0D as monarch during System Management Mode initialization to perform addit= ional=0D @@ -188,6 +244,9 @@ SmmCpuFeaturesSmmRelocationComplete ( UINTN MapPagesBase;=0D UINTN MapPagesCount;=0D =0D + + SmmCpuFeaturesSmmInitHotEject(); + if (!MemEncryptSevIsEnabled ()) {=0D return;=0D }=0D @@ -375,6 +434,15 @@ SmmCpuFeaturesRendezvousExit ( IN UINTN CpuIndex=0D )=0D {=0D + // + // CPU Hot eject not enabled. + // + if (mCpuHotEjectData =3D=3D NULL || + mCpuHotEjectData->Handler =3D=3D NULL) { + return; + } + + mCpuHotEjectData->Handler(CpuIndex); }=0D =0D /**=0D 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 @@ =0D [Pcd]=0D gUefiOvmfPkgTokenSpaceGuid.PcdQ35SmramAtDefaultSmbase=0D + gUefiCpuPkgTokenSpaceGuid.PcdCpuHotPlugSupport + gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber + gUefiCpuPkgTokenSpaceGuid.PcdCpuHotEjectDataAddress --=20 2.9.3