From nobody Fri May 17 12:14:31 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+87133+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+87133+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=fail(p=none dis=none) header.from=intel.com Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1646122217384870.7215244428943; Tue, 1 Mar 2022 00:10:17 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 0O0tYY1788612xSj1mnnJ2VK; Tue, 01 Mar 2022 00:10:17 -0800 X-Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web09.6007.1646122216088077517 for ; Tue, 01 Mar 2022 00:10:16 -0800 X-IronPort-AV: E=McAfee;i="6200,9189,10272"; a="236592450" X-IronPort-AV: E=Sophos;i="5.90,145,1643702400"; d="scan'208";a="236592450" X-Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Mar 2022 00:10:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,145,1643702400"; d="scan'208";a="629934819" X-Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by FMSMGA003.fm.intel.com with ESMTP; 01 Mar 2022 00:10:15 -0800 X-Received: from orsmsx609.amr.corp.intel.com (10.22.229.22) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Tue, 1 Mar 2022 00:10:14 -0800 X-Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx609.amr.corp.intel.com (10.22.229.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21 via Frontend Transport; Tue, 1 Mar 2022 00:10:14 -0800 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.104) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.20; Tue, 1 Mar 2022 00:10:14 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Pb1yv9+FbMAfl9lDFnB9xIuE921VzDtGvqUBpIkIM13a25alnKorDeVkaqz+Ba98Ca4gW2i2dtI8C+rPPVhDXeMP9LQYPmOZdtiTqsgS9SxP9ZDgKm3RsoiA9WCBom201sb3majMg4cbo+hoYuWOl8LgGdRDjDPhiG403S4KoByms+mFmcJS3EEKOhEhQmzsI/9iktyf5A0JbVK59at16YRISt6hKhVIasvMt+jW08NAjEG5vslPeZKbIKx/nqoSI4MpvQsRbpia3hR6M6N7veX4ZgPdY2VhonDkH73r5XWDs78xTIKV7VXVWKSiHI5GCz9fwqtt078YLULlglZSTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ETFU+3WB6DWGPIgXCLdBycQG5ceCkn45dh44wnWhuxc=; b=hiUFLHNWTI0CXw8XAzmSibs2yrJrXIbz7WUYDhW3JjL3C/v0E+j34aY1ocRvwYh3kfaKDodr10Zdx9xSORlATRUEkEOIse9tYwMJZTyVMcbXVLFGIsa84r8BYKA2WUmVjNQg0GZE6fDuih7IHCHopReWxBmGghE9e/zAaV2XjXEf3404719K64mJzX4v2jnWXN0Q00Bk6aDKkSt8E4jDSxxRicNMDGeFh0y5cJ0yyb50mAvr0ZgAMz2OaR1H+/i7ExIbt661YqH72mb6NKc8Q+1OYFpZOLTjdSw0hV9XWKE0mDQWCf2Em2iAdZMsPnzIxUZ01ZYrsZUeICiqhZVi3A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none X-Received: from DM6PR11MB4738.namprd11.prod.outlook.com (2603:10b6:5:2a3::18) by CH0PR11MB5377.namprd11.prod.outlook.com (2603:10b6:610:b8::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22; Tue, 1 Mar 2022 08:10:12 +0000 X-Received: from DM6PR11MB4738.namprd11.prod.outlook.com ([fe80::1527:223f:8a2d:4f5e]) by DM6PR11MB4738.namprd11.prod.outlook.com ([fe80::1527:223f:8a2d:4f5e%8]) with mapi id 15.20.5038.014; Tue, 1 Mar 2022 08:10:12 +0000 From: "Li, Zhihao" To: "Ni, Ray" , "devel@edk2.groups.io" CC: "Dong, Eric" , "Kumar, Rahul1" , "Fu, Siyuan" Subject: FW: [edk2-devel] [PATCH v4 1/1] UefiCpuPkg: Extend SMM CPU Service with rendezvous support. Thread-Topic: [edk2-devel] [PATCH v4 1/1] UefiCpuPkg: Extend SMM CPU Service with rendezvous support. Thread-Index: AQHYKLUsfGMY6C7FI0iK1O06T35XlKyqL3CAgAAAHrA= Date: Tue, 1 Mar 2022 08:10:12 +0000 Message-ID: References: <20220223125902.3649-1-zhihao.li@intel.com> In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 86e9de04-5e14-4c97-5fce-08d9fb5ae8f2 x-ms-traffictypediagnostic: CH0PR11MB5377:EE_ x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: DA3LestNm1k/RX3jtOfctxLUkE4ECrXySjuvT0qzFUrhTJDrynXWsBUsIJCw7Tf2HbNe297JMSrsRXYoeh8KC2ZxC5Zu6AxYuW09UOoEtFLVGf+PMsQfB/46F30gYmQQYWiMTT4Qhg0zyp48ejq4WpIBuoC+MGzWwPSAgKlTeugNpm2HVtNkNl8hvJ2ou/tidejYRtF3JcWq9j7K1FshCGaKMZgnCvp5NNI2XVSJusA3hkKfgt+gWYwZSpqO36OOxLlV3nEihT6GPKgulhzikR/Yh9q911xPNGbvz5iM74TnuDjMlzclQ+r5X9tay7oaqJyCi9HzE7M9GMGioWO09Zof+s1+3Naag35BvHCjfbh+saGSjCtwRiEU3hnUnGIQ3yj3gv/RDgD/4zH/owyGOBGarESALjWqNfKqGT/yTYLCsV5rVfWS67+xCEL7XKt0dxw8ciPYhTt3mZmRh/K5h5qWiIofxhb0HuL5ZS944ntNm1BwvI88kdoMiKb09/VSIqGr+Prs5oJmsmactu/pnxr5XnX1O6kXZ2I7lnAByh8O37pZZntT9Otfx4x8Fbf6G4VNT3saxiOrjgre55EKh30W1PJt1VNJYWCKbTy5PuZnQmZJK7PkZRjfQctYW3N0YMitdXctBhVMUCWKaOJsBWw8MTm2/SeKh39KGfiZFYbVLQZPfRbuk5zVDmtb02cbtRZVGbh7Z9iYQh+hKvF99WvyvkQiREuSaDB2wl1h74MBIvRrpsCvnxQ1jh/wgrWh0Ztlo45jL9BfgFMD7/rKSE6kDRIbUdFrr3neLzTtU4nOhe00GorcjLXfF2AEcRdhzAG9IyZPB2Kp0O1a6/fOHQ== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?B?aEQwcU9wSzluZlgzTWpSV3BiVEpVOU9Eb1NnYXhaQ1dYY3dkcWdSckhWVUkr?= =?utf-8?B?NytsR2tLUVFrL2k4cUtJdGpHMHVxcXhvMk13aTdvMzFTWG9jeD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MjljUDdTd0dUR2p3dGMrWEtpM3k5dWZWaUdObDVO?= =?utf-8?B?MC9pWFdoWUUwL3YxYXp2TnNFcUxlV2t3SWorSDk5Y2tmeUpTOVBFc1IrVFJ6?= =?utf-8?B?MGVLcklrTm8vcDVPR3YrNk5CRkFEVlpCU1ZrV2dyUzJqM1VOMExLTENaRVBY?= =?utf-8?B?UEhwZEc5c0lNTklXbWMyWDFaTkNESk5aTWZ1NG5EV09KbVdtQlJNZXpEZmEw?= =?utf-8?B?MTdLZmswQ2ZYenZUbTJ4Zi9tT3FEenhLMXV4V1pKbzBVMjNFNitBbkMxNWxP?= =?utf-8?B?Qmc9PQ==?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR11MB4738.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 86e9de04-5e14-4c97-5fce-08d9fb5ae8f2 X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Mar 2022 08:10:12.1899 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: NESbpD53T+4zXtDF7ZOSoOurqCq8ZywojeXGQbsf/NloAeAuIyHCAD3eof71V8hg7BAz3svKFLm0Mu+f4uC0MA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR11MB5377 X-OriginatorOrg: intel.com Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: 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,zhihao.li@intel.com X-Gm-Message-State: t1IRS87NGs3Ym0BNxI8OOuD9x1787277AA= Content-Language: en-US Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1646122217; bh=54BZHFho5gOuhXPY1kdqaYcGL8yo2Go/soUh0lbAtoU=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=N8P2QGOA+M7mkpfBkm0FiyZamRWXx2fT2QE4FuR9woxWCHnjDJGCz98lpSG/P2hbLmX m+cwhiu+6KUk2ubg+ciDACg2SF1+FliuKGlHL0EF2iMm2jramOdM1OhDRu9rTDZ0GqvZq hxsM/gq4FId51bBqYYubSR3Yt/9R8siKaT4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1646122218520100001 1. InitializeSmmCpuServices(): please keep the ASSERT_EFI_ERROR (Status) fo= r CpuService protocol installation. Will add assert. 2. SmmWaitForApArrival (): Can you remove the BlockingMode parameter becaus= e I cannot find any invocation using FALSE as parameter. Have removed in patchv4. 3. mSmmMpSyncData->AllApArrivedWithException: where is this variable assign= ed to TRUE? Have added in patchv4. 4. SmmCpuRendezvousProtocolNotify(): Function header is incorrect (I saw "R= eport Status Code"). Can you add comments to explain why protocol notificat= ion is needed instead of using library constructor to locate the protocol? Feature need to support MM_STANDALONE and DXE_SMM_DRIVER driver. They have = different entry function parameter. Will add comment in function header. 5. Lib: SmmWaitForAllProcessor(): Can you add comments to explain why (mSmm= CpuRendezvous =3D=3D NULL) is a success? And this API is the same as the in= ternal function name in PiSmmCpuDxe driver. It may cause confusing. Can you= change that internal function to use a different name? 1) If SmmCpuRendezvous service do not locate, it means the platform have no= t setup and influence cpu rendezvous. Will add comment in function header. 2) For this, I plan to modified name of SmmWaitForAllProcessor in SmmCpuRen= dezvousLib to be SmmCpuRendezvous() and keep PiSmmCpuDxe driver the same. -----Original Message----- From: Fu, Siyuan =20 Sent: Tuesday, March 1, 2022 3:46 PM To: Li, Zhihao Subject: FW: [edk2-devel] [PATCH v4 1/1] UefiCpuPkg: Extend SMM CPU Service= with rendezvous support. Best Regards Siyuan=20 -----Original Message----- From: devel@edk2.groups.io On Behalf Of Li, Zhihao Sent: 2022=E5=B9=B42=E6=9C=8823=E6=97=A5 20:59 To: devel@edk2.groups.io Cc: Dong, Eric ; Ni, Ray ; Kumar, Ra= hul1 ; Fu, Siyuan Subject: [edk2-devel] [PATCH v4 1/1] UefiCpuPkg: Extend SMM CPU Service wit= h rendezvous support. REF=EF=BC=9A https://bugzilla.tianocore.org/show_bug.cgi?id=3D3815 This patch define a new Protocol with the new services SmmWaitForAllProcess= or(), which can be used by SMI handler to optionally wait for other APs to = complete SMM rendezvous in relaxed AP mode. A new library SmmCpuRendezvousLib is provided to abstract the service into = library API to simple SMI handler code. Patch_v3 modified to pass CI test. (1)Add SmmCpuRendezvousLib.inf into Uefi= CpuPkg.dsc / (2)Add SmmCpuRendezvousLib.h in Uef= iCpuPkg.dec [Libraryclasses.IA32, Libraryclasses.x64] (3) Some UncrustifyCh= eck modifications. Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Siyuan Fu Signed-off-by: Zhihao Li --- UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c | 98 ++++++= ++++++++++++++ UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c | 68 ++++++= +++++++- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 20 +++- UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h | 27 ++++++ UefiCpuPkg/Include/Protocol/SmmCpuService.h | 36 ++++++- UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf | 35 +++++++ UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 29 +++++- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 5 +- UefiCpuPkg/UefiCpuPkg.dec | 8 +- UefiCpuPkg/UefiCpuPkg.dsc | 2 + 10 files changed, 316 insertions(+), 12 deletions(-) diff --git a/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c b= /UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c new file mode 100644 index 000000000000..22f694b77d51 --- /dev/null +++ b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c @@ -0,0 +1,98 @@ +/** @file + SMM CPU Rendezvous sevice implement. + + Copyright (c) 2022, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include + +STATIC EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL *mSmmCpuRendezvous =3D NULL; +STATIC VOID *mRegistration =3D NULL; + +/** + Register status code callback function only when Report Status Code=20 + protocol + is installed. + + @param[in] Protocol Points to the protocol's unique identifier. + @param[in] Interface Points to the interface instance. + @param[in] Handle The handle on which the interface was installed. + + @retval EFI_SUCCESS Notification runs successfully. + +**/ +EFI_STATUS +EFIAPI +SmmCpuRendezvousProtocolNotify ( + IN CONST EFI_GUID *Protocol, + IN VOID *Interface, + IN EFI_HANDLE Handle + ) +{ + EFI_STATUS Status; + + Status =3D gMmst->MmLocateProtocol ( + &gEdkiiSmmCpuRendezvousProtocolGuid, + NULL, + (VOID **)&mSmmCpuRendezvous + ); + ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; +} + +/** + This routine wait for all AP processors to arrive in SMM. + + @param[in] BlockingMode Blocking mode or non-blocking mode. + + @retval EFI_SUCCESS All avaiable APs arrived. + @retval EFI_TIMEOUT Wait for all APs until timeout. + @retval OTHER Fail to register SMM CPU Rendezvous service Protoco= l. +**/ +EFI_STATUS +EFIAPI +SmmWaitForAllProcessor ( + IN BOOLEAN BlockingMode + ) +{ + EFI_STATUS Status; + + if ((mRegistration =3D=3D NULL) && (mSmmCpuRendezvous =3D=3D NULL)) { + // + // Locate SMM cpu rendezvous protocol for the first time execute the f= unction. + // + Status =3D gMmst->MmLocateProtocol ( + &gEdkiiSmmCpuRendezvousProtocolGuid, + NULL, + (VOID **)&mSmmCpuRendezvous + ); + if (EFI_ERROR (Status)) { + Status =3D gMmst->MmRegisterProtocolNotify ( + &gEdkiiSmmCpuRendezvousProtocolGuid, + SmmCpuRendezvousProtocolNotify, + &mRegistration + ); + if (EFI_ERROR (Status)) { + return Status; + } + } + } + + if (mSmmCpuRendezvous =3D=3D NULL) { + return EFI_SUCCESS; + } + + Status =3D mSmmCpuRendezvous->WaitForAllProcessor ( + mSmmCpuRendezvous, + BlockingMode + ); + return Status; +} diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c b/UefiCpuPkg/PiSmmCpuDx= eSmm/CpuService.c index 5d624f8e9ed6..e096970ac62e 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c @@ -1,7 +1,7 @@ /** @file Implementation of SMM CPU Services Protocol. =20 -Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2011 - 2022, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -20,6 +20,13 @@ EFI_SMM_CPU_SERVICE_PROTOCOL mSmmCpuService =3D { SmmRegisterExceptionHandler }; =20 +// +// EDKII SMM CPU Rendezvous Service Protocol instance +// +EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL mSmmCpuRendezvousService =3D { + SmmWaitForAllProcessor +}; + /** Gets processor information on the requested processor at the instant thi= s call is made. =20 @@ -350,6 +357,7 @@ SmmRegisterExceptionHandler ( @param ImageHandle The firmware allocated handle for the EFI image. =20 @retval EFI_SUCCESS EFI SMM CPU Services Protocol was installed succe= ssfully. + @retval OTHER Fail to install Protocol. **/ EFI_STATUS InitializeSmmCpuServices ( @@ -364,6 +372,64 @@ InitializeSmmCpuServices ( EFI_NATIVE_INTERFACE, &mSmmCpuService ); + if (EFI_ERROR (Status)) { + return Status; + } + + Status =3D gSmst->SmmInstallProtocolInterface ( + &Handle, + &gEdkiiSmmCpuRendezvousProtocolGuid, + EFI_NATIVE_INTERFACE, + &mSmmCpuRendezvousService + ); ASSERT_EFI_ERROR (Status); return Status; } + +/** + Wait for all processors enterring SMM until all CPUs are already synchro= nized or not. + + If BlockingMode is False, timeout value is zero. + + @param This A pointer to the EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL = instance. + @param BlockingMode Blocking mode or non-blocking mode. + + @retval EFI_SUCCESS All avaiable APs arrived. + @retval EFI_TIMEOUT Wait for all APs until timeout. + +**/ +EFI_STATUS +EFIAPI +SmmWaitForAllProcessor ( + IN EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL *This, + IN BOOLEAN BlockingMode + ) +{ + EFI_STATUS Status; + + // + // Return success immediately if all CPUs are already synchronized. + // + if (mSmmMpSyncData->AllApArrivedWithException) { + Status =3D EFI_SUCCESS; + goto ON_EXIT; + } + + if (!BlockingMode) { + Status =3D EFI_TIMEOUT; + goto ON_EXIT; + } + + // + // There are some APs outside SMM, Wait for all avaiable APs to arrive. + // + SmmWaitForApArrival (); + Status =3D mSmmMpSyncData->AllApArrivedWithException ? EFI_SUCCESS :=20 + EFI_TIMEOUT; + +ON_EXIT: + if (!mSmmMpSyncData->AllApArrivedWithException) { + DEBUG ((DEBUG_INFO, "EdkiiSmmWaitForAllApArrival: Timeout to wait=20 + all APs arrival\n")); + } + + return Status; +} diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxe= Smm/MpService.c index 882dee4fe246..13c2cb8da4c3 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -1,7 +1,7 @@ /** @file SMM MP service implementation =20 -Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.
+Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.
Copyright (c) 2017, AMD Incorporated. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent @@ -293,10 +293,14 @@ SmmWaitForApArrival ( // Sync with APs 1st timeout // for (Timer =3D StartSyncTimer (); - !IsSyncTimerTimeout (Timer) && !(LmceEn && LmceSignal) && - !AllCpusInSmmWithExceptions (ARRIVAL_EXCEPTION_BLOCKED | ARRIVAL_EX= CEPTION_SMI_DISABLED); + !IsSyncTimerTimeout (Timer) && !(LmceEn && LmceSignal); ) { + mSmmMpSyncData->AllApArrivedWithException =3D=20 + AllCpusInSmmWithExceptions (ARRIVAL_EXCEPTION_BLOCKED |=20 + ARRIVAL_EXCEPTION_SMI_DISABLED); + if (mSmmMpSyncData->AllApArrivedWithException) { + break; + } + CpuPause (); } =20 @@ -330,10 +334,14 @@ SmmWaitForApArrival ( // Sync with APs 2nd timeout. // for (Timer =3D StartSyncTimer (); - !IsSyncTimerTimeout (Timer) && - !AllCpusInSmmWithExceptions (ARRIVAL_EXCEPTION_BLOCKED | ARRIVAL_= EXCEPTION_SMI_DISABLED); + !IsSyncTimerTimeout (Timer); ) { + mSmmMpSyncData->AllApArrivedWithException =3D=20 + AllCpusInSmmWithExceptions (ARRIVAL_EXCEPTION_BLOCKED |=20 + ARRIVAL_EXCEPTION_SMI_DISABLED); + if (mSmmMpSyncData->AllApArrivedWithException) { + break; + } + CpuPause (); } } @@ -1887,6 +1895,8 @@ InitializeMpSyncData ( *mSmmMpSyncData->InsideSmm =3D FALSE; *mSmmMpSyncData->AllCpusInSync =3D FALSE; =20 + mSmmMpSyncData->AllApArrivedWithException =3D FALSE; + for (CpuIndex =3D 0; CpuIndex < gSmmCpuPrivate->SmmCoreEntryContext.Nu= mberOfCpus; CpuIndex++) { mSmmMpSyncData->CpuData[CpuIndex].Busy =3D (SPIN_LOCK *)((UINTN)mSmmCpuSemaphores.SemaphoreCpu.Busy + mSemaph= oreSize * CpuIndex); diff --git a/UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h b/UefiCpuPkg/= Include/Library/SmmCpuRendezvousLib.h new file mode 100644 index 000000000000..82e459e9106e --- /dev/null +++ b/UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h @@ -0,0 +1,27 @@ +/** @file + SMM CPU Rendezvous library header file. + + Copyright (c) 2022, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef SMM_CPU_RENDEZVOUS_H_ +#define SMM_CPU_RENDEZVOUS_H_ + +/** + This routine wait for all AP processors to arrive in SMM. + + @param[in] BlockingMode Blocking mode or non-blocking mode. + + @retval EFI_SUCCESS All processors checked in to SMM. + @retval EFI_TIMEOUT Wait for all APs until timeout. + +**/ +EFI_STATUS +EFIAPI +SmmWaitForAllProcessor ( + IN BOOLEAN BlockingMode + ); + +#endif diff --git a/UefiCpuPkg/Include/Protocol/SmmCpuService.h b/UefiCpuPkg/Inclu= de/Protocol/SmmCpuService.h index 952767afce75..3d93d243409c 100644 --- a/UefiCpuPkg/Include/Protocol/SmmCpuService.h +++ b/UefiCpuPkg/Include/Protocol/SmmCpuService.h @@ -1,7 +1,7 @@ /** @file SMM CPU Service protocol definition. =20 -Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2013 - 2022, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -200,4 +200,38 @@ struct _EFI_SMM_CPU_SERVICE_PROTOCOL { =20 extern EFI_GUID gEfiSmmCpuServiceProtocolGuid; =20 +// +// EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL provide SMM CPU +// rendezvous service support. +// +#define EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL_GUID \ + { \ + 0xaa00d50b, 0x4911, 0x428f, { 0xb9, 0x1a, 0xa5, 0x9d, 0xdb, 0x13,=20 + 0xe2, 0x4c } \ + } + +typedef struct _EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL=20 +EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL; + +/** + Wait for all APs to arrive SMM mode in given timeout constraint. + + @param[in] This A pointer to the EDKII_SMM_CPU_RENDEZV= OUS_PROTOCOL instance. + @param[in] BlockingMode Block or non-block mode. + + @retval EFI_SUCCESS All APs have arrived SMM mode except S= MI disabled APs. + @retval EFI_TIMEOUT There are APs not in SMM mode in given= timeout constraint. + +**/ +typedef +EFI_STATUS +(EFIAPI *EDKII_WAIT_FOR_ALL_PROCESSOR)( + IN EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL *This, + IN BOOLEAN BlockingMode + ); + +struct _EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL { + EDKII_WAIT_FOR_ALL_PROCESSOR WaitForAllProcessor; +}; + +extern EFI_GUID gEdkiiSmmCpuRendezvousProtocolGuid; + #endif diff --git a/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf= b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf new file mode 100644 index 000000000000..52374bf6e9b4 --- /dev/null +++ b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf @@ -0,0 +1,35 @@ +## @file +# SMM CPU Rendezvous service lib. +# +# This is SMM CPU rendezvous service lib that wait for all +# APs to enter SMM mode. +# +# Copyright (c) 2022, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D SmmCpuRendezvousLib + FILE_GUID =3D 1509Bb36-9Ba4-438B-B195-Ac5914Db14E2 + MODULE_TYPE =3D DXE_SMM_DRIVER + LIBRARY_CLASS =3D SmmCpuRendezvousLib|MM_STANDALONE DXE= _SMM_DRIVER + +[Sources] + SmmCpuRendezvousLib.c + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + MmServicesTableLib + +[Pcd] + gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmApSyncTimeout ## CONS= UMES + +[Protocols] + gEdkiiSmmCpuRendezvousProtocolGuid diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmC= puDxeSmm/PiSmmCpuDxeSmm.h index 26d07c5b5ea0..c7f47a1d2fe5 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h @@ -1,7 +1,7 @@ /** @file Agent Module to load other modules to deploy SMM Entry Vector for X86 CPU. =20 -Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.
+Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.
Copyright (c) 2017, AMD Incorporated. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent @@ -428,6 +428,7 @@ typedef struct { volatile SMM_CPU_SYNC_MODE EffectiveSyncMode; volatile BOOLEAN SwitchBsp; volatile BOOLEAN *CandidateBsp; + volatile BOOLEAN AllApArrivedWithException; EFI_AP_PROCEDURE StartupProcedure; VOID *StartupProcArgs; } SMM_DISPATCHER_MP_SYNC_DATA; @@ -1488,4 +1489,30 @@ IsRestrictedMemoryAccess ( VOID ); =20 +/** + Choose blocking or non-blocking mode to Wait for all APs. + + @param[in] This A pointer to the EDKII_SMM_CPU_RENDEZV= OUS_PROTOCOL instance. + @param[in] BlockingMode Blocking or non-blocking mode. + + @retval EFI_SUCCESS All APs have arrived SMM mode except S= MI disabled APs. + @retval EFI_TIMEOUT There are APs not in SMM mode in given= timeout constraint. + +**/ +EFI_STATUS +EFIAPI +SmmWaitForAllProcessor ( + IN EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL *This, + IN BOOLEAN BlockingMode + ); + +/** + Insure when this function returns, no AP will execute normal mode code b= efore entering SMM, except SMI disabled APs. + +**/ +VOID +SmmWaitForApArrival ( + VOID + ); + #endif diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf b/UefiCpuPkg/PiSm= mCpuDxeSmm/PiSmmCpuDxeSmm.inf index 0e88071c7079..deef00f9c6e9 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf @@ -4,7 +4,7 @@ # This SMM driver performs SMM initialization, deploy SMM Entry Vector, # provides CPU specific services in SMM. # -# Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.
+# Copyright (c) 2009 - 2022, Intel Corporation. All rights=20 +reserved.
# Copyright (c) 2017, AMD Incorporated. All rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent @@ -107,7 +107,8 @@ gEfiSmmReadyToLockProtocolGuid ## NOTIFY gEfiSmmCpuServiceProtocolGuid ## PRODUCES gEdkiiSmmMemoryAttributeProtocolGuid ## PRODUCES - gEfiMmMpProtocolGuid ## PRODUCES + gEfiMmMpProtocolGuid ## PRODUCES + gEdkiiSmmCpuRendezvousProtocolGuid ## PRODUCES =20 [Guids] gEfiAcpiVariableGuid ## SOMETIMES_CONSUMES ## HOB # = it is used for S3 boot. diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 7d= e66fde674c..525cde463435 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -1,7 +1,7 @@ ## @file UefiCpuPkg.dec # This Package provides UEFI compatible CPU modules and libraries. # -# Copyright (c) 2007 - 2021, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2022, Intel Corporation. All rights=20 +reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -62,6 +62,9 @@ ## @libraryclass Provides function for loading microcode. MicrocodeLib|Include/Library/MicrocodeLib.h =20 + ## @libraryclass Provides function for SMM CPU Rendezvous Library. + SmmCpuRendezvousLib|Include/Library/SmmCpuRendezvousLib.h + [Guids] gUefiCpuPkgTokenSpaceGuid =3D { 0xac05bf33, 0x995a, 0x4ed4, { 0xaa,= 0xb8, 0xef, 0x7a, 0xe8, 0xf, 0x5c, 0xb0 }} gMsegSmramGuid =3D { 0x5802bce4, 0xeeee, 0x4e33, { 0xa1,= 0x30, 0xeb, 0xad, 0x27, 0xf0, 0xe4, 0x39 }} @@ -77,7 +80,8 @@ =20 [Protocols] ## Include/Protocol/SmmCpuService.h - gEfiSmmCpuServiceProtocolGuid =3D { 0x1d202cab, 0xc8ab, 0x4d5c, { 0x94,= 0xf7, 0x3c, 0xfc, 0xc0, 0xd3, 0xd3, 0x35 }} + gEfiSmmCpuServiceProtocolGuid =3D { 0x1d202cab, 0xc8ab, 0x4d5c, { 0x94= , 0xf7, 0x3c, 0xfc, 0xc0, 0xd3, 0xd3, 0x35 }} + gEdkiiSmmCpuRendezvousProtocolGuid =3D { 0xaa00d50b, 0x4911, 0x428f, {=20 + 0xb9, 0x1a, 0xa5, 0x9d, 0xdb, 0x13, 0xe2, 0x4c }} =20 ## Include/Protocol/SmMonitorInit.h gEfiSmMonitorInitProtocolGuid =3D { 0x228f344d, 0xb3de, 0x43bb, { 0xa4,= 0xd7, 0xea, 0x20, 0xb, 0x1b, 0x14, 0x82 }} diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index d1= d61dd6a03b..a0bbde9985d3 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -61,6 +61,7 @@ TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurem= entLibNull.inf VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf MicrocodeLib|UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.inf + =20 + SmmCpuRendezvousLib|UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRende + zvousLib.inf =20 [LibraryClasses.common.SEC] PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.= inf @@ -173,6 +174,7 @@ } UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf UefiCpuPkg/ResetVector/Vtf0/Bin/ResetVector.inf + UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf =20 [BuildOptions] *_*_*_CC_FLAGS =3D -D DISABLE_NEW_DEPRECATED_INTERFACES -- 2.26.2.windows.1 -=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 (#87133): https://edk2.groups.io/g/devel/message/87133 Mute This Topic: https://groups.io/mt/89471600/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-