From nobody Thu May 9 20:19:57 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+111893+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+111893+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701325909; cv=none; d=zohomail.com; s=zohoarc; b=MYJbcUMeYvUhLMuKrR985sVQSrm+ftyNQtKFUC6Xx+HVhevz1a/TsM7c7LeLXaz7z2VlSzf49LU1SrWDV+FA9PPGC6+h7AwQgUc+YCuRlqE/7gsQkF7ygN7RfS4opQabDG+qf+vuXF0UC5gTjyf44KeCZpBXJpzbyuWEq4vJ2C0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701325909; h=Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=nyZBeqLHLBzQ6aOyfw3aV8OHTgTjdqKVqzktgcL0yjM=; b=C7ZgGE+FTaLO5L3gNDLbjNF5Ck+RJEEjoViaW0wt/LjsabEwqtqh7DJZrXxSFuvfqOcokxGkriCgsyWrusQdX2y1Xn1uo9HZvhk2ROpKXkYET3L5G43ah4fkDt+1xa8uR91PdUIkW9RBq945+3RQeUhyT8RNa9k8VmmD7tPoux4= 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+111893+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1701325909213485.89122533012403; Wed, 29 Nov 2023 22:31:49 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=eVnFnds4KiUWaZ9bD9+c2QPIJDvrPu0KGllXwVJKw6E=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe; s=20140610; t=1701325908; v=1; b=wUlLBffm/fkywwh8xmfie4l7b/Iy5cSP0pzC0UJyqmucXQXSi/ZK78HUq4hsx99mPVgQeGgK gJR+fVBxYRZeDy/nPYdNd7hKvetEc0z4h6QF4C+DfEwlTEhzSHtocP+1XPaLo2yWzCSbpHNejeH WUSfJ86hdIxAlj5Ds/lyi0/A= X-Received: by 127.0.0.2 with SMTP id 8t24YY1788612xq5WOGFgEkS; Wed, 29 Nov 2023 22:31:48 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by mx.groups.io with SMTP id smtpd.web10.66761.1701325906495811111 for ; Wed, 29 Nov 2023 22:31:48 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="6496117" X-IronPort-AV: E=Sophos;i="6.04,237,1695711600"; d="scan'208";a="6496117" X-Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Nov 2023 22:31:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="913091950" X-IronPort-AV: E=Sophos;i="6.04,237,1695711600"; d="scan'208";a="913091950" X-Received: from sh1gapp1009.ccr.corp.intel.com ([10.239.189.219]) by fmsmga001.fm.intel.com with ESMTP; 29 Nov 2023 22:31:46 -0800 From: "Wu, Jiaxin" To: devel@edk2.groups.io Cc: Laszlo Ersek , Eric Dong , Ray Ni , Zeng Star , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH v2 1/6] UefiCpuPkg/PiSmmCpuDxeSmm: Optimize Semaphore Sync between BSP and AP Date: Thu, 30 Nov 2023 14:31:34 +0800 Message-Id: <20231130063139.7472-2-jiaxin.wu@intel.com> In-Reply-To: <20231130063139.7472-1-jiaxin.wu@intel.com> References: <20231130063139.7472-1-jiaxin.wu@intel.com> Precedence: Bulk 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,jiaxin.wu@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: aI9G4CjO3WohHlqOqIXb5Rbxx1787277AA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1701325910839000005 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch is to define 3 new functions (WaitForBsp & ReleaseBsp & ReleaseOneAp) used for the semaphore sync between BSP & AP. With the change, BSP and AP Sync flow will be easy understand as below: BSP: ReleaseAllAPs or ReleaseOneAp --> AP: WaitForBsp BSP: WaitForAllAPs <-- AP: ReleaseBsp Cc: Laszlo Ersek Cc: Eric Dong Cc: Ray Ni Cc: Zeng Star Cc: Rahul Kumar Cc: Gerd Hoffmann Signed-off-by: Jiaxin Wu --- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 72 ++++++++++++++++++++++++++++---= ---- 1 file changed, 58 insertions(+), 14 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxe= Smm/MpService.c index b279f5dfcc..54542262a2 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -120,10 +120,11 @@ LockdownSemaphore ( =20 return Value; } =20 /** + Used for BSP to wait all APs. Wait all APs to performs an atomic compare exchange operation to release= semaphore. =20 @param NumberOfAPs AP number =20 **/ @@ -139,10 +140,11 @@ WaitForAllAPs ( WaitForSemaphore (mSmmMpSyncData->CpuData[BspIndex].Run); } } =20 /** + Used for BSP to release all APs. Performs an atomic compare exchange operation to release semaphore for each AP. =20 **/ VOID @@ -157,10 +159,52 @@ ReleaseAllAPs ( ReleaseSemaphore (mSmmMpSyncData->CpuData[Index].Run); } } } =20 +/** + Used for BSP to release one AP. + + @param ApSem IN: 32-bit unsigned integer + OUT: original integer + 1 +**/ +VOID +ReleaseOneAp ( + IN OUT volatile UINT32 *ApSem + ) +{ + ReleaseSemaphore (ApSem); +} + +/** + Used for AP to wait BSP. + + @param ApSem IN: 32-bit unsigned integer + OUT: original integer - 1 +**/ +VOID +WaitForBsp ( + IN OUT volatile UINT32 *ApSem + ) +{ + WaitForSemaphore (ApSem); +} + +/** + Used for AP to release BSP. + + @param BspSem IN: 32-bit unsigned integer + OUT: original integer + 1 +**/ +VOID +ReleaseBsp ( + IN OUT volatile UINT32 *BspSem + ) +{ + ReleaseSemaphore (BspSem); +} + /** Check whether the index of CPU perform the package level register programming during System Management Mode initialization. =20 The index of Processor specified by mPackageFirstThreadIndex[PackageInde= x] @@ -632,11 +676,11 @@ BSPHandler ( // Signal all APs it's time for backup MTRRs // ReleaseAllAPs (); =20 // - // WaitForSemaphore() may wait for ever if an AP happens to enter SM= M at + // WaitForAllAPs() may wait for ever if an AP happens to enter SMM at // exactly this point. Please make sure PcdCpuSmmMaxSyncLoops has be= en set // to a large enough value to avoid this situation. // Note: For HT capable CPUs, threads within a core share the same s= et of MTRRs. // We do the backup first and then set MTRR to avoid race condition = for threads // in the same core. @@ -652,11 +696,11 @@ BSPHandler ( // Let all processors program SMM MTRRs together // ReleaseAllAPs (); =20 // - // WaitForSemaphore() may wait for ever if an AP happens to enter SM= M at + // WaitForAllAPs() may wait for ever if an AP happens to enter SMM at // exactly this point. Please make sure PcdCpuSmmMaxSyncLoops has be= en set // to a large enough value to avoid this situation. // ReplaceOSMtrrs (CpuIndex); =20 @@ -898,50 +942,50 @@ APHandler ( =20 if ((SyncMode =3D=3D SmmCpuSyncModeTradition) || SmmCpuFeaturesNeedConfi= gureMtrrs ()) { // // Notify BSP of arrival at this point // - ReleaseSemaphore (mSmmMpSyncData->CpuData[BspIndex].Run); + ReleaseBsp (mSmmMpSyncData->CpuData[BspIndex].Run); } =20 if (SmmCpuFeaturesNeedConfigureMtrrs ()) { // // Wait for the signal from BSP to backup MTRRs // - WaitForSemaphore (mSmmMpSyncData->CpuData[CpuIndex].Run); + WaitForBsp (mSmmMpSyncData->CpuData[CpuIndex].Run); =20 // // Backup OS MTRRs // MtrrGetAllMtrrs (&Mtrrs); =20 // // Signal BSP the completion of this AP // - ReleaseSemaphore (mSmmMpSyncData->CpuData[BspIndex].Run); + ReleaseBsp (mSmmMpSyncData->CpuData[BspIndex].Run); =20 // // Wait for BSP's signal to program MTRRs // - WaitForSemaphore (mSmmMpSyncData->CpuData[CpuIndex].Run); + WaitForBsp (mSmmMpSyncData->CpuData[CpuIndex].Run); =20 // // Replace OS MTRRs with SMI MTRRs // ReplaceOSMtrrs (CpuIndex); =20 // // Signal BSP the completion of this AP // - ReleaseSemaphore (mSmmMpSyncData->CpuData[BspIndex].Run); + ReleaseBsp (mSmmMpSyncData->CpuData[BspIndex].Run); } =20 while (TRUE) { // // Wait for something to happen // - WaitForSemaphore (mSmmMpSyncData->CpuData[CpuIndex].Run); + WaitForBsp (mSmmMpSyncData->CpuData[CpuIndex].Run); =20 // // Check if BSP wants to exit SMM // if (!(*mSmmMpSyncData->InsideSmm)) { @@ -977,16 +1021,16 @@ APHandler ( =20 if (SmmCpuFeaturesNeedConfigureMtrrs ()) { // // Notify BSP the readiness of this AP to program MTRRs // - ReleaseSemaphore (mSmmMpSyncData->CpuData[BspIndex].Run); + ReleaseBsp (mSmmMpSyncData->CpuData[BspIndex].Run); =20 // // Wait for the signal from BSP to program MTRRs // - WaitForSemaphore (mSmmMpSyncData->CpuData[CpuIndex].Run); + WaitForBsp (mSmmMpSyncData->CpuData[CpuIndex].Run); =20 // // Restore OS MTRRs // SmmCpuFeaturesReenableSmrr (); @@ -994,26 +1038,26 @@ APHandler ( } =20 // // Notify BSP the readiness of this AP to Reset states/semaphore for thi= s processor // - ReleaseSemaphore (mSmmMpSyncData->CpuData[BspIndex].Run); + ReleaseBsp (mSmmMpSyncData->CpuData[BspIndex].Run); =20 // // Wait for the signal from BSP to Reset states/semaphore for this proce= ssor // - WaitForSemaphore (mSmmMpSyncData->CpuData[CpuIndex].Run); + WaitForBsp (mSmmMpSyncData->CpuData[CpuIndex].Run); =20 // // Reset states/semaphore for this processor // *(mSmmMpSyncData->CpuData[CpuIndex].Present) =3D FALSE; =20 // // Notify BSP the readiness of this AP to exit SMM // - ReleaseSemaphore (mSmmMpSyncData->CpuData[BspIndex].Run); + ReleaseBsp (mSmmMpSyncData->CpuData[BspIndex].Run); } =20 /** Checks whether the input token is the current used token. =20 @@ -1277,11 +1321,11 @@ InternalSmmStartupThisAp ( mSmmMpSyncData->CpuData[CpuIndex].Status =3D CpuStatus; if (mSmmMpSyncData->CpuData[CpuIndex].Status !=3D NULL) { *mSmmMpSyncData->CpuData[CpuIndex].Status =3D EFI_NOT_READY; } =20 - ReleaseSemaphore (mSmmMpSyncData->CpuData[CpuIndex].Run); + ReleaseOneAp (mSmmMpSyncData->CpuData[CpuIndex].Run); =20 if (Token =3D=3D NULL) { AcquireSpinLock (mSmmMpSyncData->CpuData[CpuIndex].Busy); ReleaseSpinLock (mSmmMpSyncData->CpuData[CpuIndex].Busy); } --=20 2.16.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 (#111893): https://edk2.groups.io/g/devel/message/111893 Mute This Topic: https://groups.io/mt/102889291/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- From nobody Thu May 9 20:19:57 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+111894+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+111894+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701325912; cv=none; d=zohomail.com; s=zohoarc; b=R9WAkMdDgfEZukJzmTtvAR8bZwZwPJAj1L7nEI1mPjLLnH6cqDxQQRIAukX7Zsa6xqBYDGi5sqNWstWT18pno5hj3Nla2MwzBhJGIFKr8fWpXjNrMpxr5nLrzJPliXtlHYcDVu6YY9ZY3sBiLohcN7MZFMgOQwM1d9gt83J3sUo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701325912; h=Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=UX6rTUT56oHuRW9UgRPI3JMJSBTYNS/wLj3Y0k88fVQ=; b=kvqSzhtJNN3o2czY+Z6fYemRIuih21ftkF1BHPk66DzLTgZtiEYSi+SKE5g98FVyqfrh34avJaVQzpX2FggYdt9wJFD5LLW+SDy1A2vrz/T66RAT06AeRRR4Qu9XfmKTCHYc5Az5T1xJE/Iyl0UKWkw2A7d9FeMGkJxn11z5xaw= 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+111894+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1701325912310666.8722416841025; Wed, 29 Nov 2023 22:31:52 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=9NQ95pcjSFwv4Q0+di+fprqyCC4MoXQ75RENCWV4aKU=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe; s=20140610; t=1701325910; v=1; b=IDRX7tVMv8Xs/SSJmBKajAsXF53SNbjcYhZCThsPOSbsWZA0G8kVtYgDKD/XhapvJyR1UbNV aC3pz6K99ssBpUz6pQgi6koQ3Hamzq4Kh3ef+cn2eCh2nEFZNygSD8ypyC5VBFgzAirVxXFqvLk C6sgIsovz6ybr9qLntQUrUm4= X-Received: by 127.0.0.2 with SMTP id T7LmYY1788612xVGmy8GtoBl; Wed, 29 Nov 2023 22:31:50 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by mx.groups.io with SMTP id smtpd.web10.66761.1701325906495811111 for ; Wed, 29 Nov 2023 22:31:50 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="6496130" X-IronPort-AV: E=Sophos;i="6.04,237,1695711600"; d="scan'208";a="6496130" X-Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Nov 2023 22:31:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="913091969" X-IronPort-AV: E=Sophos;i="6.04,237,1695711600"; d="scan'208";a="913091969" X-Received: from sh1gapp1009.ccr.corp.intel.com ([10.239.189.219]) by fmsmga001.fm.intel.com with ESMTP; 29 Nov 2023 22:31:48 -0800 From: "Wu, Jiaxin" To: devel@edk2.groups.io Cc: Laszlo Ersek , Eric Dong , Ray Ni , Zeng Star , Gerd Hoffmann , Rahul Kumar Subject: [edk2-devel] [PATCH v2 2/6] UefiCpuPkg: Adds SmmCpuSyncLib library class Date: Thu, 30 Nov 2023 14:31:35 +0800 Message-Id: <20231130063139.7472-3-jiaxin.wu@intel.com> In-Reply-To: <20231130063139.7472-1-jiaxin.wu@intel.com> References: <20231130063139.7472-1-jiaxin.wu@intel.com> Precedence: Bulk 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,jiaxin.wu@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: xvkGl0L4nAH2JGZ6Wuy5iQYex1787277AA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1701325912860000009 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Intel is planning to provide different SMM CPU Sync implementation along with some specific registers to improve the SMI performance, hence need SmmCpuSyncLib Library for Intel. This patch is to: 1.Adds SmmCpuSyncLib Library class in UefiCpuPkg.dec. 2.Adds SmmCpuSyncLib.h function declaration header file. For the new SmmCpuSyncLib, it provides 3 sets of APIs: 1. ContextInit/ContextDeinit/ContextReset: ContextInit() is called in driver's entrypoint to allocate and initialize the SMM CPU Sync context. ContextDeinit() is called in driver's unload function to deinitialize SMM CPU Sync context. ContextReset() is called before CPU exist SMI, which allows CPU to check into the next SMI from this point. 2. GetArrivedCpuCount/CheckInCpu/CheckOutCpu/LockDoor: When SMI happens, all processors including BSP enter to SMM mode by calling CheckInCpu(). The elected BSP calls LockDoor() so that CheckInCpu() will return the error code after that. CheckOutCpu() can be called in error handling flow for the CPU who calls CheckInCpu() earlier. GetArrivedCpuCount() returns the number of checked-in CPUs. 3. WaitForAPs/ReleaseOneAp/WaitForBsp/ReleaseBsp WaitForAPs() & ReleaseOneAp() are called from BSP to wait the number of APs and release one specific AP. WaitForBsp() & ReleaseBsp() are called from APs to wait and release BSP. The 4 APIs are used to synchronize the running flow among BSP and APs. BSP and AP Sync flow can be easy understand as below: BSP: ReleaseOneAp --> AP: WaitForBsp BSP: WaitForAPs <-- AP: ReleaseBsp Cc: Laszlo Ersek Cc: Eric Dong Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- UefiCpuPkg/Include/Library/SmmCpuSyncLib.h | 278 +++++++++++++++++++++++++= ++++ UefiCpuPkg/UefiCpuPkg.dec | 3 + 2 files changed, 281 insertions(+) create mode 100644 UefiCpuPkg/Include/Library/SmmCpuSyncLib.h diff --git a/UefiCpuPkg/Include/Library/SmmCpuSyncLib.h b/UefiCpuPkg/Includ= e/Library/SmmCpuSyncLib.h new file mode 100644 index 0000000000..22935cc006 --- /dev/null +++ b/UefiCpuPkg/Include/Library/SmmCpuSyncLib.h @@ -0,0 +1,278 @@ +/** @file +Library that provides SMM CPU Sync related operations. +The lib provides 3 sets of APIs: +1. ContextInit/ContextDeinit/ContextReset: +ContextInit() is called in driver's entrypoint to allocate and initialize = the SMM CPU Sync context. +ContextDeinit() is called in driver's unload function to deinitialize the = SMM CPU Sync context. +ContextReset() is called before CPU exist SMI, which allows CPU to check i= nto the next SMI from this point. + +2. GetArrivedCpuCount/CheckInCpu/CheckOutCpu/LockDoor: +When SMI happens, all processors including BSP enter to SMM mode by callin= g CheckInCpu(). +The elected BSP calls LockDoor() so that CheckInCpu() will return the erro= r code after that. +CheckOutCpu() can be called in error handling flow for the CPU who calls C= heckInCpu() earlier. +GetArrivedCpuCount() returns the number of checked-in CPUs. + +3. WaitForAPs/ReleaseOneAp/WaitForBsp/ReleaseBsp +WaitForAPs() & ReleaseOneAp() are called from BSP to wait the number of AP= s and release one specific AP. +WaitForBsp() & ReleaseBsp() are called from APs to wait and release BSP. +The 4 APIs are used to synchronize the running flow among BSP and APs. BSP= and AP Sync flow can be +easy understand as below: +BSP: ReleaseOneAp --> AP: WaitForBsp +BSP: WaitForAPs <-- AP: ReleaseBsp + +Copyright (c) 2023, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef SMM_CPU_SYNC_LIB_H_ +#define SMM_CPU_SYNC_LIB_H_ + +#include + +// +// Opaque structure for SMM CPU Sync context. +// +typedef struct SMM_CPU_SYNC_CTX SMM_CPU_SYNC_CTX; + +/** + Create and initialize the SMM CPU Sync context. + + SmmCpuSyncContextInit() function is to allocate and initialize the SMM C= PU Sync context. + + @param[in] NumberOfCpus The number of Logical Processors in th= e system. + @param[out] SmmCpuSyncCtx Pointer to the new created and initial= ized SMM CPU Sync context object. + NULL will be returned if any error hap= pen during init. + + @retval RETURN_SUCCESS The SMM CPU Sync context was successfu= l created and initialized. + @retval RETURN_INVALID_PARAMETER SmmCpuSyncCtx is NULL. + @retval RETURN_BUFFER_TOO_SMALL Overflow happen + @retval RETURN_OUT_OF_RESOURCES There are not enough resources availab= le to create and initialize SMM CPU Sync context. + +**/ +RETURN_STATUS +EFIAPI +SmmCpuSyncContextInit ( + IN UINTN NumberOfCpus, + OUT SMM_CPU_SYNC_CTX **SmmCpuSyncCtx + ); + +/** + Deinit an allocated SMM CPU Sync context. + + SmmCpuSyncContextDeinit() function is to deinitialize SMM CPU Sync conte= xt, the resources allocated in + SmmCpuSyncContextInit() will be freed. + + Note: This function only can be called after SmmCpuSyncContextInit() ret= urn success. + + @param[in,out] SmmCpuSyncCtx Pointer to the SMM CPU Sync context ob= ject to be deinitialized. + + @retval RETURN_SUCCESS The SMM CPU Sync context was successfu= l deinitialized. + @retval RETURN_INVALID_PARAMETER SmmCpuSyncCtx is NULL. + +**/ +RETURN_STATUS +EFIAPI +SmmCpuSyncContextDeinit ( + IN OUT SMM_CPU_SYNC_CTX *SmmCpuSyncCtx + ); + +/** + Reset SMM CPU Sync context. + + SmmCpuSyncContextReset() function is to reset SMM CPU Sync context to th= e initialized state. + + @param[in,out] SmmCpuSyncCtx Pointer to the SMM CPU Sync context ob= ject to be reset. + + @retval RETURN_SUCCESS The SMM CPU Sync context was successfu= l reset. + @retval RETURN_INVALID_PARAMETER SmmCpuSyncCtx is NULL. + +**/ +RETURN_STATUS +EFIAPI +SmmCpuSyncContextReset ( + IN OUT SMM_CPU_SYNC_CTX *SmmCpuSyncCtx + ); + +/** + Get current number of arrived CPU in SMI. + + For traditional CPU synchronization method, BSP might need to know the c= urrent number of arrived CPU in + SMI to make sure all APs in SMI. This API can be for that purpose. + + @param[in] SmmCpuSyncCtx Pointer to the SMM CPU Sync context ob= ject. + @param[in,out] CpuCount Current count of arrived CPU in SMI. + + @retval RETURN_SUCCESS Get current number of arrived CPU in S= MI successfully. + @retval RETURN_INVALID_PARAMETER SmmCpuSyncCtx or CpuCount is NULL. + @retval RETURN_ABORTED Function Aborted due to the door has b= een locked by SmmCpuSyncLockDoor() function. + +**/ +RETURN_STATUS +EFIAPI +SmmCpuSyncGetArrivedCpuCount ( + IN SMM_CPU_SYNC_CTX *SmmCpuSyncCtx, + IN OUT UINTN *CpuCount + ); + +/** + Performs an atomic operation to check in CPU. + + When SMI happens, all processors including BSP enter to SMM mode by call= ing SmmCpuSyncCheckInCpu(). + + @param[in,out] SmmCpuSyncCtx Pointer to the SMM CPU Sync context ob= ject. + @param[in] CpuIndex Check in CPU index. + + @retval RETURN_SUCCESS Check in CPU (CpuIndex) successfully. + @retval RETURN_INVALID_PARAMETER SmmCpuSyncCtx is NULL. + @retval RETURN_ABORTED Check in CPU failed due to SmmCpuSyncL= ockDoor() has been called by one elected CPU. + +**/ +RETURN_STATUS +EFIAPI +SmmCpuSyncCheckInCpu ( + IN OUT SMM_CPU_SYNC_CTX *SmmCpuSyncCtx, + IN UINTN CpuIndex + ); + +/** + Performs an atomic operation to check out CPU. + + CheckOutCpu() can be called in error handling flow for the CPU who calls= CheckInCpu() earlier. + + @param[in,out] SmmCpuSyncCtx Pointer to the SMM CPU Sync context ob= ject. + @param[in] CpuIndex Check out CPU index. + + @retval RETURN_SUCCESS Check out CPU (CpuIndex) successfully. + @retval RETURN_INVALID_PARAMETER SmmCpuSyncCtx is NULL. + @retval RETURN_NOT_READY The CPU is not checked-in. + @retval RETURN_ABORTED Check out CPU failed due to SmmCpuSync= LockDoor() has been called by one elected CPU. + +**/ +RETURN_STATUS +EFIAPI +SmmCpuSyncCheckOutCpu ( + IN OUT SMM_CPU_SYNC_CTX *SmmCpuSyncCtx, + IN UINTN CpuIndex + ); + +/** + Performs an atomic operation lock door for CPU checkin or checkout. + + After this function: + CPU can not check in via SmmCpuSyncCheckInCpu(). + CPU can not check out via SmmCpuSyncCheckOutCpu(). + CPU can not get number of arrived CPU in SMI via SmmCpuSyncGetArrivedCpu= Count(). The number of + arrived CPU in SMI will be returned in CpuCount. + + The CPU specified by CpuIndex is elected to lock door. + + @param[in,out] SmmCpuSyncCtx Pointer to the SMM CPU Sync context ob= ject. + @param[in] CpuIndex Indicate which CPU to lock door. + @param[in,out] CpuCount Number of arrived CPU in SMI after loo= k door. + + @retval RETURN_SUCCESS Lock door for CPU successfully. + @retval RETURN_INVALID_PARAMETER SmmCpuSyncCtx or CpuCount is NULL. + +**/ +RETURN_STATUS +EFIAPI +SmmCpuSyncLockDoor ( + IN OUT SMM_CPU_SYNC_CTX *SmmCpuSyncCtx, + IN UINTN CpuIndex, + IN OUT UINTN *CpuCount + ); + +/** + Used by the BSP to wait for APs. + + The number of APs need to be waited is specified by NumberOfAPs. The BSP= is specified by BspIndex. + + Note: This function is blocking mode, and it will return only after the = number of APs released by + calling SmmCpuSyncReleaseBsp(): + BSP: WaitForAPs <-- AP: ReleaseBsp + + @param[in,out] SmmCpuSyncCtx Pointer to the SMM CPU Sync context ob= ject. + @param[in] NumberOfAPs Number of APs need to be waited by BSP. + @param[in] BspIndex The BSP Index to wait for APs. + + @retval RETURN_SUCCESS BSP to wait for APs successfully. + @retval RETURN_INVALID_PARAMETER SmmCpuSyncCtx is NULL or NumberOfAPs >= total number of processors in system. + +**/ +RETURN_STATUS +EFIAPI +SmmCpuSyncWaitForAPs ( + IN OUT SMM_CPU_SYNC_CTX *SmmCpuSyncCtx, + IN UINTN NumberOfAPs, + IN UINTN BspIndex + ); + +/** + Used by the BSP to release one AP. + + The AP is specified by CpuIndex. The BSP is specified by BspIndex. + + @param[in,out] SmmCpuSyncCtx Pointer to the SMM CPU Sync context ob= ject. + @param[in] CpuIndex Indicate which AP need to be released. + @param[in] BspIndex The BSP Index to release AP. + + @retval RETURN_SUCCESS BSP to release one AP successfully. + @retval RETURN_INVALID_PARAMETER SmmCpuSyncCtx is NULL or CpuIndex is s= ame as BspIndex. + +**/ +RETURN_STATUS +EFIAPI +SmmCpuSyncReleaseOneAp ( + IN OUT SMM_CPU_SYNC_CTX *SmmCpuSyncCtx, + IN UINTN CpuIndex, + IN UINTN BspIndex + ); + +/** + Used by the AP to wait BSP. + + The AP is specified by CpuIndex. The BSP is specified by BspIndex. + + Note: This function is blocking mode, and it will return only after the = AP released by + calling SmmCpuSyncReleaseOneAp(): + BSP: ReleaseOneAp --> AP: WaitForBsp + + @param[in,out] SmmCpuSyncCtx Pointer to the SMM CPU Sync context obj= ect. + @param[in] CpuIndex Indicate which AP wait BSP. + @param[in] BspIndex The BSP Index to be waited. + + @retval RETURN_SUCCESS AP to wait BSP successfully. + @retval RETURN_INVALID_PARAMETER SmmCpuSyncCtx is NULL or CpuIndex is s= ame as BspIndex. + +**/ +RETURN_STATUS +EFIAPI +SmmCpuSyncWaitForBsp ( + IN OUT SMM_CPU_SYNC_CTX *SmmCpuSyncCtx, + IN UINTN CpuIndex, + IN UINTN BspIndex + ); + +/** + Used by the AP to release BSP. + + The AP is specified by CpuIndex. The BSP is specified by BspIndex. + + @param[in,out] SmmCpuSyncCtx Pointer to the SMM CPU Sync context ob= ject. + @param[in] CpuIndex Indicate which AP release BSP. + @param[in] BspIndex The BSP Index to be released. + + @retval RETURN_SUCCESS AP to release BSP successfully. + @retval RETURN_INVALID_PARAMETER SmmCpuSyncCtx is NULL or CpuIndex is s= ame as BspIndex. + +**/ +RETURN_STATUS +EFIAPI +SmmCpuSyncReleaseBsp ( + IN OUT SMM_CPU_SYNC_CTX *SmmCpuSyncCtx, + IN UINTN CpuIndex, + IN UINTN BspIndex + ); + +#endif diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 0b5431dbf7..20ab079219 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -62,10 +62,13 @@ CpuPageTableLib|Include/Library/CpuPageTableLib.h =20 ## @libraryclass Provides functions for manipulating smram savestate r= egisters. MmSaveStateLib|Include/Library/MmSaveStateLib.h =20 + ## @libraryclass Provides functions for SMM CPU Sync Operation. + SmmCpuSyncLib|Include/Library/SmmCpuSyncLib.h + [LibraryClasses.RISCV64] ## @libraryclass Provides functions to manage MMU features on RISCV64 = CPUs. ## RiscVMmuLib|Include/Library/BaseRiscVMmuLib.h =20 --=20 2.16.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 (#111894): https://edk2.groups.io/g/devel/message/111894 Mute This Topic: https://groups.io/mt/102889292/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- From nobody Thu May 9 20:19:57 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+111895+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+111895+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701325913; cv=none; d=zohomail.com; s=zohoarc; b=XdDrh+bnPJxH42dnhpWjVXGGMiHCXpzLpT/BhNFiTF3/H8lqxQYculj+mht1f/dCWHO/5S2bgrj7kPt1tEdtQmSJ5wLnuPxM3ZjShF6Fu3+Z0lgP4FnVi4kIy9BpCRjPs4oWRqH82D4aZSM6j5+lxAwuK40yuFB3eamrSfwq/Ww= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701325913; h=Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=bI6CT1PALDFSPuR3e//aJgk7nmtx9UTxl2GjHE1Lt1s=; b=MQM4BnUZOCLJBhAuLYw0APaWxV2SqCprbHvC8d+Y390bt+kUX5LDij1KH4oUA2BTc0OJ8F7HeOF4jBgWo5UwiPbkP2PASTp5Up7aBAQZCwrRBjbsazcqHGuxhkN7aDnsoKMz3GnPPqb5hULSODYsULRlkdGqFJ/vYbH1l1tMmjs= 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+111895+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1701325913481431.44316919950506; Wed, 29 Nov 2023 22:31:53 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=2MgDMPTYnqMAO0BCWdSjInn58A/7XGXhQMKHW021sS8=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe; s=20140610; t=1701325912; v=1; b=j/NBtB8RdJusvxbbQiwA4DNDAeBe9fUcqNVboENamjBfPs7nQHSKibFPNsNJTjygFgxjI2fG krtyohvnMjJFq+co3/7kItH/wBzMsPR8w5ewkopDfVOARL/4LdpAR36CcEBi2cjKLyEcsuXfc7d 2ADUzMtCNKE7KMd5i/LEOgfA= X-Received: by 127.0.0.2 with SMTP id 2WNrYY1788612xoC7ZIfq1Uo; Wed, 29 Nov 2023 22:31:52 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by mx.groups.io with SMTP id smtpd.web10.66761.1701325906495811111 for ; Wed, 29 Nov 2023 22:31:52 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="6496143" X-IronPort-AV: E=Sophos;i="6.04,237,1695711600"; d="scan'208";a="6496143" X-Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Nov 2023 22:31:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="913091989" X-IronPort-AV: E=Sophos;i="6.04,237,1695711600"; d="scan'208";a="913091989" X-Received: from sh1gapp1009.ccr.corp.intel.com ([10.239.189.219]) by fmsmga001.fm.intel.com with ESMTP; 29 Nov 2023 22:31:50 -0800 From: "Wu, Jiaxin" To: devel@edk2.groups.io Cc: Laszlo Ersek , Eric Dong , Ray Ni , Zeng Star , Gerd Hoffmann , Rahul Kumar Subject: [edk2-devel] [PATCH v2 3/6] UefiCpuPkg: Implements SmmCpuSyncLib library instance Date: Thu, 30 Nov 2023 14:31:36 +0800 Message-Id: <20231130063139.7472-4-jiaxin.wu@intel.com> In-Reply-To: <20231130063139.7472-1-jiaxin.wu@intel.com> References: <20231130063139.7472-1-jiaxin.wu@intel.com> Precedence: Bulk 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,jiaxin.wu@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 1fr654xcjTJRHJD1YqWRuR7Ix1787277AA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1701325914868000013 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Implements SmmCpuSyncLib Library instance. The instance refers the existing SMM CPU driver (PiSmmCpuDxeSmm) sync implementation and behavior: 1.Abstract Counter and Run semaphores into SmmCpuSyncCtx. 2.Abstract CPU arrival count operation to SmmCpuSyncGetArrivedCpuCount(), SmmCpuSyncCheckInCpu(), SmmCpuSyncCheckOutCpu(), SmmCpuSyncLockDoor(). Implementation is aligned with existing SMM CPU driver. 3. Abstract SMM CPU Sync flow to: BSP: SmmCpuSyncReleaseOneAp --> AP: SmmCpuSyncWaitForBsp BSP: SmmCpuSyncWaitForAPs <-- AP: SmmCpuSyncReleaseBsp Semaphores release & wait during sync flow is same as existing SMM CPU driver. 4.Same operation to Counter and Run semaphores by leverage the atomic compare exchange. Cc: Laszlo Ersek Cc: Eric Dong Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.c | 690 +++++++++++++++++= ++++ UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf | 39 ++ UefiCpuPkg/UefiCpuPkg.dsc | 3 + 3 files changed, 732 insertions(+) create mode 100644 UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.c create mode 100644 UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf diff --git a/UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.c b/UefiCpuPkg/= Library/SmmCpuSyncLib/SmmCpuSyncLib.c new file mode 100644 index 0000000000..307a6b3d78 --- /dev/null +++ b/UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.c @@ -0,0 +1,690 @@ +/** @file + SMM CPU Sync lib implementation. + The lib provides 3 sets of APIs: + 1. ContextInit/ContextDeinit/ContextReset: + ContextInit() is called in driver's entrypoint to allocate and initializ= e the SMM CPU Sync context. + ContextDeinit() is called in driver's unload function to deinitialize th= e SMM CPU Sync context. + ContextReset() is called before CPU exist SMI, which allows CPU to check= into the next SMI from this point. + + 2. GetArrivedCpuCount/CheckInCpu/CheckOutCpu/LockDoor: + When SMI happens, all processors including BSP enter to SMM mode by call= ing CheckInCpu(). + The elected BSP calls LockDoor() so that CheckInCpu() will return the er= ror code after that. + CheckOutCpu() can be called in error handling flow for the CPU who calls= CheckInCpu() earlier. + GetArrivedCpuCount() returns the number of checked-in CPUs. + + 3. WaitForAPs/ReleaseOneAp/WaitForBsp/ReleaseBsp + WaitForAPs() & ReleaseOneAp() are called from BSP to wait the number of = APs and release one specific AP. + WaitForBsp() & ReleaseBsp() are called from APs to wait and release BSP. + The 4 APIs are used to synchronize the running flow among BSP and APs. B= SP and AP Sync flow can be + easy understand as below: + BSP: ReleaseOneAp --> AP: WaitForBsp + BSP: WaitForAPs <-- AP: ReleaseBsp + + Copyright (c) 2023, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +typedef struct { + /// + /// Indicate how many CPU entered SMM. + /// + volatile UINT32 *Counter; +} SMM_CPU_SYNC_SEMAPHORE_GLOBAL; + +typedef struct { + /// + /// Used for control each CPU continue run or wait for signal + /// + volatile UINT32 *Run; +} SMM_CPU_SYNC_SEMAPHORE_CPU; + +struct SMM_CPU_SYNC_CTX { + /// + /// All global semaphores' pointer in SMM CPU Sync + /// + SMM_CPU_SYNC_SEMAPHORE_GLOBAL *GlobalSem; + /// + /// All semaphores for each processor in SMM CPU Sync + /// + SMM_CPU_SYNC_SEMAPHORE_CPU *CpuSem; + /// + /// The number of processors in the system. + /// This does not indicate the number of processors that entered SMM. + /// + UINTN NumberOfCpus; + /// + /// Address of global and each CPU semaphores + /// + UINTN *SemBlock; + /// + /// Size of global and each CPU semaphores + /// + UINTN SemBlockPages; +}; + +/** + Performs an atomic compare exchange operation to get semaphore. + The compare exchange operation must be performed using MP safe + mechanisms. + + @param[in,out] Sem IN: 32-bit unsigned integer + OUT: original integer - 1 + + @retval Original integer - 1 + +**/ +UINT32 +InternalWaitForSemaphore ( + IN OUT volatile UINT32 *Sem + ) +{ + UINT32 Value; + + for ( ; ;) { + Value =3D *Sem; + if ((Value !=3D 0) && + (InterlockedCompareExchange32 ( + (UINT32 *)Sem, + Value, + Value - 1 + ) =3D=3D Value)) + { + break; + } + + CpuPause (); + } + + return Value - 1; +} + +/** + Performs an atomic compare exchange operation to release semaphore. + The compare exchange operation must be performed using MP safe + mechanisms. + + @param[in,out] Sem IN: 32-bit unsigned integer + OUT: original integer + 1 + + @retval Original integer + 1 + +**/ +UINT32 +InternalReleaseSemaphore ( + IN OUT volatile UINT32 *Sem + ) +{ + UINT32 Value; + + do { + Value =3D *Sem; + } while (Value + 1 !=3D 0 && + InterlockedCompareExchange32 ( + (UINT32 *)Sem, + Value, + Value + 1 + ) !=3D Value); + + return Value + 1; +} + +/** + Performs an atomic compare exchange operation to lock semaphore. + The compare exchange operation must be performed using MP safe + mechanisms. + + @param[in,out] Sem IN: 32-bit unsigned integer + OUT: -1 + + @retval Original integer + +**/ +UINT32 +InternalLockdownSemaphore ( + IN OUT volatile UINT32 *Sem + ) +{ + UINT32 Value; + + do { + Value =3D *Sem; + } while (InterlockedCompareExchange32 ( + (UINT32 *)Sem, + Value, + (UINT32)-1 + ) !=3D Value); + + return Value; +} + +/** + Create and initialize the SMM CPU Sync context. + + SmmCpuSyncContextInit() function is to allocate and initialize the SMM C= PU Sync context. + + @param[in] NumberOfCpus The number of Logical Processors in th= e system. + @param[out] SmmCpuSyncCtx Pointer to the new created and initial= ized SMM CPU Sync context object. + NULL will be returned if any error hap= pen during init. + + @retval RETURN_SUCCESS The SMM CPU Sync context was successfu= l created and initialized. + @retval RETURN_INVALID_PARAMETER SmmCpuSyncCtx is NULL. + @retval RETURN_BUFFER_TOO_SMALL Overflow happen + @retval RETURN_OUT_OF_RESOURCES There are not enough resources availab= le to create and initialize SMM CPU Sync context. + +**/ +RETURN_STATUS +EFIAPI +SmmCpuSyncContextInit ( + IN UINTN NumberOfCpus, + OUT SMM_CPU_SYNC_CTX **SmmCpuSyncCtx + ) +{ + RETURN_STATUS Status; + + UINTN CpuSemInCtxSize; + UINTN CtxSize; + + UINTN OneSemSize; + UINTN GlobalSemSize; + UINTN OneCpuSemSize; + UINTN CpuSemSize; + UINTN TotalSemSize; + + UINTN SemAddr; + UINTN CpuIndex; + + if (SmmCpuSyncCtx =3D=3D NULL) { + return RETURN_INVALID_PARAMETER; + } + + // + // Count the CtxSize + // + Status =3D SafeUintnMult (NumberOfCpus, sizeof (SMM_CPU_SYNC_SEMAPHORE_C= PU), &CpuSemInCtxSize); + if (EFI_ERROR (Status)) { + return Status; + } + + Status =3D SafeUintnAdd (sizeof (SMM_CPU_SYNC_CTX), CpuSemInCtxSize, &Ct= xSize); + if (EFI_ERROR (Status)) { + return Status; + } + + Status =3D SafeUintnAdd (CtxSize, sizeof (SMM_CPU_SYNC_SEMAPHORE_GLOBAL)= , &CtxSize); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Allocate CtxSize buffer for the *SmmCpuSyncCtx + // + *SmmCpuSyncCtx =3D NULL; + *SmmCpuSyncCtx =3D (SMM_CPU_SYNC_CTX *)AllocatePages (EFI_SIZE_TO_PAGES = (CtxSize)); + ASSERT (*SmmCpuSyncCtx !=3D NULL); + if (*SmmCpuSyncCtx =3D=3D NULL) { + return RETURN_OUT_OF_RESOURCES; + } + + (*SmmCpuSyncCtx)->GlobalSem =3D (SMM_CPU_SYNC_SEMAPHORE_GLOBAL *)((UI= NT8 *)(*SmmCpuSyncCtx) + sizeof (SMM_CPU_SYNC_CTX)); + (*SmmCpuSyncCtx)->CpuSem =3D (SMM_CPU_SYNC_SEMAPHORE_CPU *)((UINT8= *)(*SmmCpuSyncCtx) + sizeof (SMM_CPU_SYNC_CTX) + sizeof (SMM_CPU_SYNC_SEMA= PHORE_GLOBAL)); + (*SmmCpuSyncCtx)->NumberOfCpus =3D NumberOfCpus; + + // + // Count the TotalSemSize + // + OneSemSize =3D GetSpinLockProperties (); + + Status =3D SafeUintnMult (OneSemSize, sizeof (SMM_CPU_SYNC_SEMAPHORE_GLO= BAL) / sizeof (VOID *), &GlobalSemSize); + if (EFI_ERROR (Status)) { + goto ON_ERROR; + } + + Status =3D SafeUintnMult (OneSemSize, sizeof (SMM_CPU_SYNC_SEMAPHORE_CPU= ) / sizeof (VOID *), &OneCpuSemSize); + if (EFI_ERROR (Status)) { + goto ON_ERROR; + } + + Status =3D SafeUintnMult (NumberOfCpus, OneCpuSemSize, &CpuSemSize); + if (EFI_ERROR (Status)) { + goto ON_ERROR; + } + + Status =3D SafeUintnAdd (GlobalSemSize, CpuSemSize, &TotalSemSize); + if (EFI_ERROR (Status)) { + goto ON_ERROR; + } + + DEBUG ((DEBUG_INFO, "[%a] - One Semaphore Size =3D 0x%x\n", __func__,= OneSemSize)); + DEBUG ((DEBUG_INFO, "[%a] - Total Semaphores Size =3D 0x%x\n", __func__,= TotalSemSize)); + + // + // Allocate for Semaphores in the *SmmCpuSyncCtx + // + (*SmmCpuSyncCtx)->SemBlockPages =3D EFI_SIZE_TO_PAGES (TotalSemSize); + (*SmmCpuSyncCtx)->SemBlock =3D AllocatePages ((*SmmCpuSyncCtx)->Sem= BlockPages); + ASSERT ((*SmmCpuSyncCtx)->SemBlock !=3D NULL); + if ((*SmmCpuSyncCtx)->SemBlock =3D=3D NULL) { + Status =3D RETURN_OUT_OF_RESOURCES; + goto ON_ERROR; + } + + ZeroMem ((*SmmCpuSyncCtx)->SemBlock, TotalSemSize); + + // + // Assign Global Semaphore pointer + // + SemAddr =3D (UINTN)(*SmmCpuSyncCtx)->SemBl= ock; + (*SmmCpuSyncCtx)->GlobalSem->Counter =3D (UINT32 *)SemAddr; + *(*SmmCpuSyncCtx)->GlobalSem->Counter =3D 0; + DEBUG ((DEBUG_INFO, "[%a] - (*SmmCpuSyncCtx)->GlobalSem->Counter Address= : 0x%08x\n", __func__, (UINTN)(*SmmCpuSyncCtx)->GlobalSem->Counter)); + + SemAddr +=3D GlobalSemSize; + + // + // Assign CPU Semaphore pointer + // + for (CpuIndex =3D 0; CpuIndex < NumberOfCpus; CpuIndex++) { + (*SmmCpuSyncCtx)->CpuSem[CpuIndex].Run =3D (UINT32 *)(SemAddr + (CpuS= emSize / NumberOfCpus) * CpuIndex); + *(*SmmCpuSyncCtx)->CpuSem[CpuIndex].Run =3D 0; + DEBUG ((DEBUG_INFO, "[%a] - (*SmmCpuSyncCtx)->CpuSem[%d].Run Address: = 0x%08x\n", __func__, CpuIndex, (UINTN)(*SmmCpuSyncCtx)->CpuSem[CpuIndex].Ru= n)); + } + + return RETURN_SUCCESS; + +ON_ERROR: + FreePages (*SmmCpuSyncCtx, EFI_SIZE_TO_PAGES (CtxSize)); + return Status; +} + +/** + Deinit an allocated SMM CPU Sync context. + + SmmCpuSyncContextDeinit() function is to deinitialize SMM CPU Sync conte= xt, the resources allocated in + SmmCpuSyncContextInit() will be freed. + + Note: This function only can be called after SmmCpuSyncContextInit() ret= urn success. + + @param[in,out] SmmCpuSyncCtx Pointer to the SMM CPU Sync context ob= ject to be deinitialized. + + @retval RETURN_SUCCESS The SMM CPU Sync context was successfu= l deinitialized. + @retval RETURN_INVALID_PARAMETER SmmCpuSyncCtx is NULL. + +**/ +RETURN_STATUS +EFIAPI +SmmCpuSyncContextDeinit ( + IN OUT SMM_CPU_SYNC_CTX *SmmCpuSyncCtx + ) +{ + SMM_CPU_SYNC_CTX *Ctx; + UINTN CtxSize; + + if (SmmCpuSyncCtx =3D=3D NULL) { + return RETURN_INVALID_PARAMETER; + } + + Ctx =3D (SMM_CPU_SYNC_CTX *)SmmCpuSyncCtx; + + // + // Don't need Safe multiplication & Addition here since it has already c= hecked in + // SmmCpuSyncContextInit(), and this function only can be called after S= mmCpuSyncContextInit() + // return success. + // + CtxSize =3D sizeof (SMM_CPU_SYNC_CTX) + sizeof (SMM_CPU_SYNC_SEMAPHORE_G= LOBAL) + sizeof (SMM_CPU_SYNC_SEMAPHORE_CPU) * (Ctx->NumberOfCpus); + + FreePages (Ctx->SemBlock, Ctx->SemBlockPages); + + FreePages (Ctx, EFI_SIZE_TO_PAGES (CtxSize)); + + return RETURN_SUCCESS; +} + +/** + Reset SMM CPU Sync context. + + SmmCpuSyncContextReset() function is to reset SMM CPU Sync context to th= e initialized state. + + @param[in,out] SmmCpuSyncCtx Pointer to the SMM CPU Sync context ob= ject to be reset. + + @retval RETURN_SUCCESS The SMM CPU Sync context was successfu= l reset. + @retval RETURN_INVALID_PARAMETER SmmCpuSyncCtx is NULL. + +**/ +RETURN_STATUS +EFIAPI +SmmCpuSyncContextReset ( + IN OUT SMM_CPU_SYNC_CTX *SmmCpuSyncCtx + ) +{ + SMM_CPU_SYNC_CTX *Ctx; + + if (SmmCpuSyncCtx =3D=3D NULL) { + return RETURN_INVALID_PARAMETER; + } + + Ctx =3D (SMM_CPU_SYNC_CTX *)SmmCpuSyncCtx; + + *Ctx->GlobalSem->Counter =3D 0; + + return RETURN_SUCCESS; +} + +/** + Get current number of arrived CPU in SMI. + + For traditional CPU synchronization method, BSP might need to know the c= urrent number of arrived CPU in + SMI to make sure all APs in SMI. This API can be for that purpose. + + @param[in] SmmCpuSyncCtx Pointer to the SMM CPU Sync context ob= ject. + @param[in,out] CpuCount Current count of arrived CPU in SMI. + + @retval RETURN_SUCCESS Get current number of arrived CPU in S= MI successfully. + @retval RETURN_INVALID_PARAMETER SmmCpuSyncCtx or CpuCount is NULL. + @retval RETURN_ABORTED Function Aborted due to the door has b= een locked by SmmCpuSyncLockDoor() function. + +**/ +RETURN_STATUS +EFIAPI +SmmCpuSyncGetArrivedCpuCount ( + IN SMM_CPU_SYNC_CTX *SmmCpuSyncCtx, + IN OUT UINTN *CpuCount + ) +{ + SMM_CPU_SYNC_CTX *Ctx; + + if ((SmmCpuSyncCtx =3D=3D NULL) || (CpuCount =3D=3D NULL)) { + return RETURN_INVALID_PARAMETER; + } + + Ctx =3D (SMM_CPU_SYNC_CTX *)SmmCpuSyncCtx; + + if (*Ctx->GlobalSem->Counter < 0) { + return RETURN_ABORTED; + } + + *CpuCount =3D *Ctx->GlobalSem->Counter; + + return RETURN_SUCCESS; +} + +/** + Performs an atomic operation to check in CPU. + + When SMI happens, all processors including BSP enter to SMM mode by call= ing SmmCpuSyncCheckInCpu(). + + @param[in,out] SmmCpuSyncCtx Pointer to the SMM CPU Sync context ob= ject. + @param[in] CpuIndex Check in CPU index. + + @retval RETURN_SUCCESS Check in CPU (CpuIndex) successfully. + @retval RETURN_INVALID_PARAMETER SmmCpuSyncCtx is NULL. + @retval RETURN_ABORTED Check in CPU failed due to SmmCpuSyncL= ockDoor() has been called by one elected CPU. + +**/ +RETURN_STATUS +EFIAPI +SmmCpuSyncCheckInCpu ( + IN OUT SMM_CPU_SYNC_CTX *SmmCpuSyncCtx, + IN UINTN CpuIndex + ) +{ + SMM_CPU_SYNC_CTX *Ctx; + + if (SmmCpuSyncCtx =3D=3D NULL) { + return RETURN_INVALID_PARAMETER; + } + + Ctx =3D (SMM_CPU_SYNC_CTX *)SmmCpuSyncCtx; + + // + // Check to return if Counter has already been locked. + // + if ((INT32)InternalReleaseSemaphore (Ctx->GlobalSem->Counter) <=3D 0) { + return RETURN_ABORTED; + } + + return RETURN_SUCCESS; +} + +/** + Performs an atomic operation to check out CPU. + + CheckOutCpu() can be called in error handling flow for the CPU who calls= CheckInCpu() earlier. + + @param[in,out] SmmCpuSyncCtx Pointer to the SMM CPU Sync context ob= ject. + @param[in] CpuIndex Check out CPU index. + + @retval RETURN_SUCCESS Check out CPU (CpuIndex) successfully. + @retval RETURN_INVALID_PARAMETER SmmCpuSyncCtx is NULL. + @retval RETURN_NOT_READY The CPU is not checked-in. + @retval RETURN_ABORTED Check out CPU failed due to SmmCpuSync= LockDoor() has been called by one elected CPU. + +**/ +RETURN_STATUS +EFIAPI +SmmCpuSyncCheckOutCpu ( + IN OUT SMM_CPU_SYNC_CTX *SmmCpuSyncCtx, + IN UINTN CpuIndex + ) +{ + SMM_CPU_SYNC_CTX *Ctx; + + if (SmmCpuSyncCtx =3D=3D NULL) { + return RETURN_INVALID_PARAMETER; + } + + Ctx =3D (SMM_CPU_SYNC_CTX *)SmmCpuSyncCtx; + + if (*Ctx->GlobalSem->Counter =3D=3D 0) { + return RETURN_NOT_READY; + } + + if ((INT32)InternalWaitForSemaphore (Ctx->GlobalSem->Counter) < 0) { + return RETURN_ABORTED; + } + + return RETURN_SUCCESS; +} + +/** + Performs an atomic operation lock door for CPU checkin or checkout. + + After this function: + CPU can not check in via SmmCpuSyncCheckInCpu(). + CPU can not check out via SmmCpuSyncCheckOutCpu(). + CPU can not get number of arrived CPU in SMI via SmmCpuSyncGetArrivedCpu= Count(). The number of + arrived CPU in SMI will be returned in CpuCount. + + The CPU specified by CpuIndex is elected to lock door. + + @param[in,out] SmmCpuSyncCtx Pointer to the SMM CPU Sync context ob= ject. + @param[in] CpuIndex Indicate which CPU to lock door. + @param[in,out] CpuCount Number of arrived CPU in SMI after loo= k door. + + @retval RETURN_SUCCESS Lock door for CPU successfully. + @retval RETURN_INVALID_PARAMETER SmmCpuSyncCtx or CpuCount is NULL. + +**/ +RETURN_STATUS +EFIAPI +SmmCpuSyncLockDoor ( + IN OUT SMM_CPU_SYNC_CTX *SmmCpuSyncCtx, + IN UINTN CpuIndex, + IN OUT UINTN *CpuCount + ) +{ + SMM_CPU_SYNC_CTX *Ctx; + + if ((SmmCpuSyncCtx =3D=3D NULL) || (CpuCount =3D=3D NULL)) { + return RETURN_INVALID_PARAMETER; + } + + Ctx =3D (SMM_CPU_SYNC_CTX *)SmmCpuSyncCtx; + + *CpuCount =3D InternalLockdownSemaphore (Ctx->GlobalSem->Counter); + + return RETURN_SUCCESS; +} + +/** + Used by the BSP to wait for APs. + + The number of APs need to be waited is specified by NumberOfAPs. The BSP= is specified by BspIndex. + + Note: This function is blocking mode, and it will return only after the = number of APs released by + calling SmmCpuSyncReleaseBsp(): + BSP: WaitForAPs <-- AP: ReleaseBsp + + @param[in,out] SmmCpuSyncCtx Pointer to the SMM CPU Sync context ob= ject. + @param[in] NumberOfAPs Number of APs need to be waited by BSP. + @param[in] BspIndex The BSP Index to wait for APs. + + @retval RETURN_SUCCESS BSP to wait for APs successfully. + @retval RETURN_INVALID_PARAMETER SmmCpuSyncCtx is NULL or NumberOfAPs >= total number of processors in system. + +**/ +RETURN_STATUS +EFIAPI +SmmCpuSyncWaitForAPs ( + IN OUT SMM_CPU_SYNC_CTX *SmmCpuSyncCtx, + IN UINTN NumberOfAPs, + IN UINTN BspIndex + ) +{ + SMM_CPU_SYNC_CTX *Ctx; + + if (SmmCpuSyncCtx =3D=3D NULL) { + return RETURN_INVALID_PARAMETER; + } + + Ctx =3D (SMM_CPU_SYNC_CTX *)SmmCpuSyncCtx; + + if (NumberOfAPs > Ctx->NumberOfCpus) { + return RETURN_INVALID_PARAMETER; + } + + while (NumberOfAPs-- > 0) { + InternalWaitForSemaphore (Ctx->CpuSem[BspIndex].Run); + } + + return RETURN_SUCCESS; +} + +/** + Used by the BSP to release one AP. + + The AP is specified by CpuIndex. The BSP is specified by BspIndex. + + @param[in,out] SmmCpuSyncCtx Pointer to the SMM CPU Sync context ob= ject. + @param[in] CpuIndex Indicate which AP need to be released. + @param[in] BspIndex The BSP Index to release AP. + + @retval RETURN_SUCCESS BSP to release one AP successfully. + @retval RETURN_INVALID_PARAMETER SmmCpuSyncCtx is NULL or CpuIndex is s= ame as BspIndex. + +**/ +RETURN_STATUS +EFIAPI +SmmCpuSyncReleaseOneAp ( + IN OUT SMM_CPU_SYNC_CTX *SmmCpuSyncCtx, + IN UINTN CpuIndex, + IN UINTN BspIndex + ) +{ + SMM_CPU_SYNC_CTX *Ctx; + + if ((SmmCpuSyncCtx =3D=3D NULL) || (BspIndex =3D=3D CpuIndex)) { + return RETURN_INVALID_PARAMETER; + } + + Ctx =3D (SMM_CPU_SYNC_CTX *)SmmCpuSyncCtx; + + InternalReleaseSemaphore (Ctx->CpuSem[CpuIndex].Run); + + return RETURN_SUCCESS; +} + +/** + Used by the AP to wait BSP. + + The AP is specified by CpuIndex. The BSP is specified by BspIndex. + + Note: This function is blocking mode, and it will return only after the = AP released by + calling SmmCpuSyncReleaseOneAp(): + BSP: ReleaseOneAp --> AP: WaitForBsp + + @param[in,out] SmmCpuSyncCtx Pointer to the SMM CPU Sync context obj= ect. + @param[in] CpuIndex Indicate which AP wait BSP. + @param[in] BspIndex The BSP Index to be waited. + + @retval RETURN_SUCCESS AP to wait BSP successfully. + @retval RETURN_INVALID_PARAMETER SmmCpuSyncCtx is NULL or CpuIndex is s= ame as BspIndex. + +**/ +RETURN_STATUS +EFIAPI +SmmCpuSyncWaitForBsp ( + IN OUT SMM_CPU_SYNC_CTX *SmmCpuSyncCtx, + IN UINTN CpuIndex, + IN UINTN BspIndex + ) +{ + SMM_CPU_SYNC_CTX *Ctx; + + if ((SmmCpuSyncCtx =3D=3D NULL) || (BspIndex =3D=3D CpuIndex)) { + return RETURN_INVALID_PARAMETER; + } + + Ctx =3D (SMM_CPU_SYNC_CTX *)SmmCpuSyncCtx; + + InternalWaitForSemaphore (Ctx->CpuSem[CpuIndex].Run); + + return RETURN_SUCCESS; +} + +/** + Used by the AP to release BSP. + + The AP is specified by CpuIndex. The BSP is specified by BspIndex. + + @param[in,out] SmmCpuSyncCtx Pointer to the SMM CPU Sync context ob= ject. + @param[in] CpuIndex Indicate which AP release BSP. + @param[in] BspIndex The BSP Index to be released. + + @retval RETURN_SUCCESS AP to release BSP successfully. + @retval RETURN_INVALID_PARAMETER SmmCpuSyncCtx is NULL or CpuIndex is s= ame as BspIndex. + +**/ +RETURN_STATUS +EFIAPI +SmmCpuSyncReleaseBsp ( + IN OUT SMM_CPU_SYNC_CTX *SmmCpuSyncCtx, + IN UINTN CpuIndex, + IN UINTN BspIndex + ) +{ + SMM_CPU_SYNC_CTX *Ctx; + + if ((SmmCpuSyncCtx =3D=3D NULL) || (BspIndex =3D=3D CpuIndex)) { + return RETURN_INVALID_PARAMETER; + } + + Ctx =3D (SMM_CPU_SYNC_CTX *)SmmCpuSyncCtx; + + InternalReleaseSemaphore (Ctx->CpuSem[BspIndex].Run); + + return RETURN_SUCCESS; +} diff --git a/UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf b/UefiCpuPk= g/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf new file mode 100644 index 0000000000..6bb1895577 --- /dev/null +++ b/UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf @@ -0,0 +1,39 @@ +## @file +# SMM CPU Synchronization lib. +# +# This is SMM CPU Synchronization lib used for SMM CPU sync operations. +# +# Copyright (c) 2023, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D SmmCpuSyncLib + FILE_GUID =3D 1ca1bc1a-16a4-46ef-956a-ca500fd3381f + MODULE_TYPE =3D DXE_SMM_DRIVER + LIBRARY_CLASS =3D SmmCpuSyncLib|DXE_SMM_DRIVER + +[Sources] + SmmCpuSyncLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + UefiLib + BaseLib + DebugLib + PrintLib + SafeIntLib + SynchronizationLib + BaseMemoryLib + SmmServicesTableLib + MemoryAllocationLib + +[Pcd] + +[Protocols] diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index 074fd77461..f264031c77 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -23,10 +23,11 @@ # =20 !include MdePkg/MdeLibs.dsc.inc =20 [LibraryClasses] + SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf BaseLib|MdePkg/Library/BaseLib/BaseLib.inf BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf SerialPortLib|MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull= .inf @@ -54,10 +55,11 @@ CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMain= tenanceLib.inf PciLib|MdePkg/Library/BasePciLibPciExpress/BasePciLibPciExpress.inf PciExpressLib|MdePkg/Library/BasePciExpressLib/BasePciExpressLib.inf SmmCpuPlatformHookLib|UefiCpuPkg/Library/SmmCpuPlatformHookLibNull/SmmCp= uPlatformHookLibNull.inf SmmCpuFeaturesLib|UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib= .inf + SmmCpuSyncLib|UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeC= offGetEntryPointLib.inf PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeC= offExtraActionLibNull.inf TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurem= entLibNull.inf CcExitLib|UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf MicrocodeLib|UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.inf @@ -154,10 +156,11 @@ UefiCpuPkg/Library/RegisterCpuFeaturesLib/DxeRegisterCpuFeaturesLib.inf UefiCpuPkg/Library/SmmCpuPlatformHookLibNull/SmmCpuPlatformHookLibNull.i= nf UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf UefiCpuPkg/Library/SmmCpuFeaturesLib/StandaloneMmCpuFeaturesLib.inf + UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf UefiCpuPkg/Library/CcExitLibNull/CcExitLibNull.inf UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.inf UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationSmm.inf UefiCpuPkg/SecCore/SecCore.inf UefiCpuPkg/SecCore/SecCoreNative.inf --=20 2.16.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 (#111895): https://edk2.groups.io/g/devel/message/111895 Mute This Topic: https://groups.io/mt/102889293/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- From nobody Thu May 9 20:19:57 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+111896+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+111896+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701325916; cv=none; d=zohomail.com; s=zohoarc; b=lAZeS8ZrKZQAJJBPczWb/s/yTu9k3UVU7btVZXh5eyQEk6J6R573V1u8cyXuhDjuwZzjiN7MsdGLZiHY8Vkg1VhNaSVMaBvZBdg5Kmnw7po7/Zv7D+ZC4fyIN4UZ04OciTRvHvVCY8BqDqRqcNYohMp7oO4RKNQbvKFDfPpSV74= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701325916; h=Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=tmgtbA3aF8k5N0NoTKyZm8MpBtLmzEDSRUB7gl7eE1M=; b=Q3fG0b2Vi/AvGI9XdCw71dDO4GqbB7KaQ0a/26bIK9IWYX2LO0EtSEBy9ZGgcsbsck/D5KnPb39Kgs/4rCz/2SJLz5MuGivUX5Au/Vxpy3lJoGLST8Pg89IuQeIPDwq74ioSM8Rn6oFOjRqGNNVi0vtcPHxjvp8QPdRY+Pg1deg= 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+111896+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1701325916158517.7328650251137; Wed, 29 Nov 2023 22:31:56 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=9gIrSCuYwNh/FS959PwDquEqTT0ljaH4G7+5KeKu2UI=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe; s=20140610; t=1701325915; v=1; b=wxUaN7LsAbX/mxHF8Co71mby36c2DO8NrWVL8+hiMDK2au9QUrqEf9LaRf8/ymOgxl8Me3Os 2A38zT4dC8cPouyXME3VsPuqek2vhZnm+RLpIoHm6sJDeVn7S+NjX2n51hC/8cdb3Pn3Kpalqwd RbJZd+GmguYf7/HguVs1AdAg= X-Received: by 127.0.0.2 with SMTP id d8uAYY1788612xIBToEoYmD1; Wed, 29 Nov 2023 22:31:55 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by mx.groups.io with SMTP id smtpd.web10.66761.1701325906495811111 for ; Wed, 29 Nov 2023 22:31:55 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="6496162" X-IronPort-AV: E=Sophos;i="6.04,237,1695711600"; d="scan'208";a="6496162" X-Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Nov 2023 22:31:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="913092010" X-IronPort-AV: E=Sophos;i="6.04,237,1695711600"; d="scan'208";a="913092010" X-Received: from sh1gapp1009.ccr.corp.intel.com ([10.239.189.219]) by fmsmga001.fm.intel.com with ESMTP; 29 Nov 2023 22:31:52 -0800 From: "Wu, Jiaxin" To: devel@edk2.groups.io Cc: Laszlo Ersek , Ard Biesheuvel , Jiewen Yao , Jordan Justen , Eric Dong , Ray Ni , Zeng Star , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH v2 4/6] OvmfPkg: Specifies SmmCpuSyncLib instance Date: Thu, 30 Nov 2023 14:31:37 +0800 Message-Id: <20231130063139.7472-5-jiaxin.wu@intel.com> In-Reply-To: <20231130063139.7472-1-jiaxin.wu@intel.com> References: <20231130063139.7472-1-jiaxin.wu@intel.com> Precedence: Bulk 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,jiaxin.wu@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: AT0HcFEGJvsTrZYyOV0N7UVIx1787277AA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1701325916832000017 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch is to specify SmmCpuSyncLib instance for OvmfPkg. Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Eric Dong Cc: Ray Ni Cc: Zeng Star Cc: Rahul Kumar Cc: Gerd Hoffmann Signed-off-by: Jiaxin Wu --- OvmfPkg/CloudHv/CloudHvX64.dsc | 2 ++ OvmfPkg/OvmfPkgIa32.dsc | 2 ++ OvmfPkg/OvmfPkgIa32X64.dsc | 2 ++ OvmfPkg/OvmfPkgX64.dsc | 1 + 4 files changed, 7 insertions(+) diff --git a/OvmfPkg/CloudHv/CloudHvX64.dsc b/OvmfPkg/CloudHv/CloudHvX64.dsc index 821ad1b9fa..f735b69a37 100644 --- a/OvmfPkg/CloudHv/CloudHvX64.dsc +++ b/OvmfPkg/CloudHv/CloudHvX64.dsc @@ -183,10 +183,12 @@ PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf DxeHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/DxeHardwareInfoLib.inf ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/I= magePropertiesRecordLib.inf !if $(SMM_REQUIRE) =3D=3D FALSE LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf +!else + SmmCpuSyncLib|UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf !endif CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/Customize= dDisplayLib.inf FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltL= ib.inf MemEncryptTdxLib|OvmfPkg/Library/BaseMemEncryptTdxLib/BaseMemEncryptTdxL= ib.inf =20 diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index bce2aedcd7..b05b13b18c 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -188,10 +188,12 @@ PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf DxeHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/DxeHardwareInfoLib.inf ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/I= magePropertiesRecordLib.inf !if $(SMM_REQUIRE) =3D=3D FALSE LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf +!else + SmmCpuSyncLib|UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf !endif CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/Customize= dDisplayLib.inf FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltL= ib.inf =20 !if $(SOURCE_DEBUG_ENABLE) =3D=3D TRUE diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 631e909a54..5a16eb7abe 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -193,10 +193,12 @@ PeiHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/PeiHardwareInfoLib.inf DxeHardwareInfoLib|OvmfPkg/Library/HardwareInfoLib/DxeHardwareInfoLib.inf ImagePropertiesRecordLib|MdeModulePkg/Library/ImagePropertiesRecordLib/I= magePropertiesRecordLib.inf !if $(SMM_REQUIRE) =3D=3D FALSE LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf +!else + SmmCpuSyncLib|UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf !endif CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/Customize= dDisplayLib.inf FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltL= ib.inf =20 !if $(SOURCE_DEBUG_ENABLE) =3D=3D TRUE diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 4ea3008cc6..6bb4c777b9 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -209,10 +209,11 @@ !if $(SMM_REQUIRE) =3D=3D FALSE LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf CcProbeLib|OvmfPkg/Library/CcProbeLib/DxeCcProbeLib.inf !else CcProbeLib|MdePkg/Library/CcProbeLibNull/CcProbeLibNull.inf + SmmCpuSyncLib|UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf !endif CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/Customize= dDisplayLib.inf FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltL= ib.inf =20 !if $(SOURCE_DEBUG_ENABLE) =3D=3D TRUE --=20 2.16.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 (#111896): https://edk2.groups.io/g/devel/message/111896 Mute This Topic: https://groups.io/mt/102889294/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- From nobody Thu May 9 20:19:57 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+111897+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+111897+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701325918; cv=none; d=zohomail.com; s=zohoarc; b=RWJ0tfyDigPmLmm7gPMNl5ImjFgifmYq9t2uOAuHDNyb3T+mbrZGH8RPDYjCgUO+pIrqkw62lHG+SW/32rxpoVl15zWjbNJtD+juwSJrUAa5k1M+XWsrGyjDJsiTzsoOTAu0iJKManS2QAQB082E7FxPgCdkjKuVKEz6//nGY7k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701325918; h=Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=PTuwGakGgrzbXWmeKRhJBPPCPjGIbjcds4xEF3ZeGVg=; b=NnxkSDKH0XHth51UxJbFcJvD2zoUlqnOCF7gp6ef+sQPBFfoYci5P8RSFugRsgj4VjdCbx98oAW/QtInE72Fy9UPp5bUt/DD5eDLfKg9FBoiOv/7CgkA63ANd2fb1iH1Eyc5Rp2zojE8ztWcrub1aEsx8CfIYbcO/xqPVxMhTOk= 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+111897+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1701325918466421.230553114392; Wed, 29 Nov 2023 22:31:58 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=0PXt8MZ7QZeqiR9HC8NNyavSXtKyWG4OuB6k6wZPScQ=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe; s=20140610; t=1701325917; v=1; b=IQRMaOxM2zG0ngiFspESnIAb8Pjp7Iemf0yq88WcOOMUoP10r8MHhyHrTkO6mNEFtjmJisy1 XNO8k14N8ih52ZmTuucIQp7Hc28PpFVa9xVjsdpf0tLCNoqAReHD4N9RFbVTALNGX5yvYeh15D4 ClhIEa/4B2uhx0U+ZKvvBELQ= X-Received: by 127.0.0.2 with SMTP id J4ToYY1788612xCzQp9faGav; Wed, 29 Nov 2023 22:31:57 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by mx.groups.io with SMTP id smtpd.web10.66761.1701325906495811111 for ; Wed, 29 Nov 2023 22:31:57 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="6496173" X-IronPort-AV: E=Sophos;i="6.04,237,1695711600"; d="scan'208";a="6496173" X-Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Nov 2023 22:31:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="913092032" X-IronPort-AV: E=Sophos;i="6.04,237,1695711600"; d="scan'208";a="913092032" X-Received: from sh1gapp1009.ccr.corp.intel.com ([10.239.189.219]) by fmsmga001.fm.intel.com with ESMTP; 29 Nov 2023 22:31:55 -0800 From: "Wu, Jiaxin" To: devel@edk2.groups.io Cc: Laszlo Ersek , Guo Dong , Sean Rhodes , James Lu , Gua Guo , Ray Ni , Zeng Star Subject: [edk2-devel] [PATCH v2 5/6] UefiPayloadPkg: Specifies SmmCpuSyncLib instance Date: Thu, 30 Nov 2023 14:31:38 +0800 Message-Id: <20231130063139.7472-6-jiaxin.wu@intel.com> In-Reply-To: <20231130063139.7472-1-jiaxin.wu@intel.com> References: <20231130063139.7472-1-jiaxin.wu@intel.com> Precedence: Bulk 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,jiaxin.wu@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: GK2ljmEReeQQbXNelyiyTZmax1787277AA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1701325918825000021 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch is to specify SmmCpuSyncLib instance for UefiPayloadPkg. Cc: Laszlo Ersek Cc: Guo Dong Cc: Sean Rhodes Cc: James Lu Cc: Gua Guo Cc: Ray Ni Cc: Zeng Star Signed-off-by: Jiaxin Wu Reviewed-by: Gua Guo --- UefiPayloadPkg/UefiPayloadPkg.dsc | 1 + 1 file changed, 1 insertion(+) diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayload= Pkg.dsc index a65f9d5b83..b8b13ad201 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -253,10 +253,11 @@ # MtrrLib|UefiCpuPkg/Library/MtrrLib/MtrrLib.inf LocalApicLib|UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.inf MicrocodeLib|UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.inf CpuPageTableLib|UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableLib.inf + SmmCpuSyncLib|UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf =20 # # Platform # !if $(CPU_TIMER_LIB_ENABLE) =3D=3D TRUE && $(UNIVERSAL_PAYLOAD) =3D=3D TRUE --=20 2.16.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 (#111897): https://edk2.groups.io/g/devel/message/111897 Mute This Topic: https://groups.io/mt/102889295/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- From nobody Thu May 9 20:19:57 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+111898+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+111898+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701325920; cv=none; d=zohomail.com; s=zohoarc; b=kNURj/XM0vBBo8DzH5It1ucvZg9+oU2Ay9JAXlkNkto0ZDV2AUUceXX+XfwmmqZ2RQo1ZlpeticQZQ/E3OyY2vN7lN5hux5/U1IPpiJQuMh8ATre7x9TX6N9G7c2p4iGkM6XDl6rdhwE3KRohB6n1AMUJtctLN3n2NX3pzZ/ndE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701325920; h=Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=gVr1hiMVmzkSLOfGRCRrrIiGIbPZ1NlaaRVPmUD+2UA=; b=NawMaT3xq5/J2etOuC7fjmj3FFRN7/3PADtV1BNEEagt2qo1PVM+uSTqjdRqe9REXN3Un5+VFxohM+xcSfxf5bXWDYrRBzB9c87Dl/1uwY3Q33zFgXE5c8VqqkZi5e3NQirp6zu4X0QUHN1zph09X943x+9SG4Va9foENjhABvY= 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+111898+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1701325920723399.4510418574416; Wed, 29 Nov 2023 22:32:00 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=sfIAzRgQ1fMHQhj3CcH26b3k72FW/HYw+rrsZpcy4TA=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe; s=20140610; t=1701325920; v=1; b=JgJK8SinIGGoOi6XISgv5vugHLZQylIO5kbMp17o42g3mK7YgNl6Y40WSk5kHYd+qF8MWRsc VNjZfJJF1XouHUglqymzqZxfvkEtGD7d/fmVNWxbt5ai0cDqtS9Bh3ekXmzdOZvrs0/JnzVVB9h ISBkrAmZLM50S/Kl8mY16gYY= X-Received: by 127.0.0.2 with SMTP id DGkVYY1788612xG8OGQWIqRN; Wed, 29 Nov 2023 22:32:00 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by mx.groups.io with SMTP id smtpd.web10.66761.1701325906495811111 for ; Wed, 29 Nov 2023 22:31:59 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="6496181" X-IronPort-AV: E=Sophos;i="6.04,237,1695711600"; d="scan'208";a="6496181" X-Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Nov 2023 22:31:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10909"; a="913092043" X-IronPort-AV: E=Sophos;i="6.04,237,1695711600"; d="scan'208";a="913092043" X-Received: from sh1gapp1009.ccr.corp.intel.com ([10.239.189.219]) by fmsmga001.fm.intel.com with ESMTP; 29 Nov 2023 22:31:57 -0800 From: "Wu, Jiaxin" To: devel@edk2.groups.io Cc: Laszlo Ersek , Eric Dong , Ray Ni , Zeng Star , Gerd Hoffmann , Rahul Kumar Subject: [edk2-devel] [PATCH v2 6/6] UefiCpuPkg/PiSmmCpuDxeSmm: Consume SmmCpuSyncLib Date: Thu, 30 Nov 2023 14:31:39 +0800 Message-Id: <20231130063139.7472-7-jiaxin.wu@intel.com> In-Reply-To: <20231130063139.7472-1-jiaxin.wu@intel.com> References: <20231130063139.7472-1-jiaxin.wu@intel.com> Precedence: Bulk 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,jiaxin.wu@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: eefVRGhTwbf6X1kLtyXS1Jyjx1787277AA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1701325920898000025 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" There is the SmmCpuSyncLib Library class define the SMM CPU sync flow, which is aligned with existing SMM CPU driver sync behavior. This patch is to consume SmmCpuSyncLib instance directly. With this change, SMM CPU Sync flow/logic can be customized with different implementation no matter for any purpose, e.g. performance tuning, handle specific register, etc. Cc: Laszlo Ersek Cc: Eric Dong Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 317 +++++++++--------------= ---- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 6 +- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 1 + 3 files changed, 110 insertions(+), 214 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxe= Smm/MpService.c index 54542262a2..e37c03d0e5 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -27,122 +27,10 @@ MM_COMPLETION mSmmStartupThisApToken; // // Processor specified by mPackageFirstThreadIndex[PackageIndex] will do t= he package-scope register check. // UINT32 *mPackageFirstThreadIndex =3D NULL; =20 -/** - Performs an atomic compare exchange operation to get semaphore. - The compare exchange operation must be performed using - MP safe mechanisms. - - @param Sem IN: 32-bit unsigned integer - OUT: original integer - 1 - @return Original integer - 1 - -**/ -UINT32 -WaitForSemaphore ( - IN OUT volatile UINT32 *Sem - ) -{ - UINT32 Value; - - for ( ; ;) { - Value =3D *Sem; - if ((Value !=3D 0) && - (InterlockedCompareExchange32 ( - (UINT32 *)Sem, - Value, - Value - 1 - ) =3D=3D Value)) - { - break; - } - - CpuPause (); - } - - return Value - 1; -} - -/** - Performs an atomic compare exchange operation to release semaphore. - The compare exchange operation must be performed using - MP safe mechanisms. - - @param Sem IN: 32-bit unsigned integer - OUT: original integer + 1 - @return Original integer + 1 - -**/ -UINT32 -ReleaseSemaphore ( - IN OUT volatile UINT32 *Sem - ) -{ - UINT32 Value; - - do { - Value =3D *Sem; - } while (Value + 1 !=3D 0 && - InterlockedCompareExchange32 ( - (UINT32 *)Sem, - Value, - Value + 1 - ) !=3D Value); - - return Value + 1; -} - -/** - Performs an atomic compare exchange operation to lock semaphore. - The compare exchange operation must be performed using - MP safe mechanisms. - - @param Sem IN: 32-bit unsigned integer - OUT: -1 - @return Original integer - -**/ -UINT32 -LockdownSemaphore ( - IN OUT volatile UINT32 *Sem - ) -{ - UINT32 Value; - - do { - Value =3D *Sem; - } while (InterlockedCompareExchange32 ( - (UINT32 *)Sem, - Value, - (UINT32)-1 - ) !=3D Value); - - return Value; -} - -/** - Used for BSP to wait all APs. - Wait all APs to performs an atomic compare exchange operation to release= semaphore. - - @param NumberOfAPs AP number - -**/ -VOID -WaitForAllAPs ( - IN UINTN NumberOfAPs - ) -{ - UINTN BspIndex; - - BspIndex =3D mSmmMpSyncData->BspIndex; - while (NumberOfAPs-- > 0) { - WaitForSemaphore (mSmmMpSyncData->CpuData[BspIndex].Run); - } -} - /** Used for BSP to release all APs. Performs an atomic compare exchange operation to release semaphore for each AP. =20 @@ -154,57 +42,15 @@ ReleaseAllAPs ( { UINTN Index; =20 for (Index =3D 0; Index < mMaxNumberOfCpus; Index++) { if (IsPresentAp (Index)) { - ReleaseSemaphore (mSmmMpSyncData->CpuData[Index].Run); + SmmCpuSyncReleaseOneAp (mSmmMpSyncData->SmmCpuSyncCtx, Index, gSmmCp= uPrivate->SmmCoreEntryContext.CurrentlyExecutingCpu); } } } =20 -/** - Used for BSP to release one AP. - - @param ApSem IN: 32-bit unsigned integer - OUT: original integer + 1 -**/ -VOID -ReleaseOneAp ( - IN OUT volatile UINT32 *ApSem - ) -{ - ReleaseSemaphore (ApSem); -} - -/** - Used for AP to wait BSP. - - @param ApSem IN: 32-bit unsigned integer - OUT: original integer - 1 -**/ -VOID -WaitForBsp ( - IN OUT volatile UINT32 *ApSem - ) -{ - WaitForSemaphore (ApSem); -} - -/** - Used for AP to release BSP. - - @param BspSem IN: 32-bit unsigned integer - OUT: original integer + 1 -**/ -VOID -ReleaseBsp ( - IN OUT volatile UINT32 *BspSem - ) -{ - ReleaseSemaphore (BspSem); -} - /** Check whether the index of CPU perform the package level register programming during System Management Mode initialization. =20 The index of Processor specified by mPackageFirstThreadIndex[PackageInde= x] @@ -285,42 +131,53 @@ GetSmmDelayedBlockedDisabledCount ( BOOLEAN AllCpusInSmmExceptBlockedDisabled ( VOID ) { + RETURN_STATUS Status; + + UINTN CpuCount; UINT32 BlockedCount; UINT32 DisabledCount; =20 + CpuCount =3D 0; BlockedCount =3D 0; DisabledCount =3D 0; =20 + Status =3D SmmCpuSyncGetArrivedCpuCount (mSmmMpSyncData->SmmCpuSyncCtx, = &CpuCount); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "AllCpusInSmmExceptBlockedDisabled: SmmCpuSyncGet= ArrivedCpuCount return error %r!\n", Status)); + CpuDeadLoop (); + return FALSE; + } + // - // Check to make sure mSmmMpSyncData->Counter is valid and not locked. + // Check to make sure the CPU arrival count is valid and not locked. // - ASSERT (*mSmmMpSyncData->Counter <=3D mNumberOfCpus); + ASSERT (CpuCount <=3D mNumberOfCpus); =20 // // Check whether all CPUs in SMM. // - if (*mSmmMpSyncData->Counter =3D=3D mNumberOfCpus) { + if (CpuCount =3D=3D mNumberOfCpus) { return TRUE; } =20 // // Check for the Blocked & Disabled Exceptions Case. // GetSmmDelayedBlockedDisabledCount (NULL, &BlockedCount, &DisabledCount); =20 // - // *mSmmMpSyncData->Counter might be updated by all APs concurrently. Th= e value + // The CPU arrival count might be updated by all APs concurrently. The v= alue // can be dynamic changed. If some Aps enter the SMI after the BlockedCo= unt & - // DisabledCount check, then the *mSmmMpSyncData->Counter will be increa= sed, thus - // leading the *mSmmMpSyncData->Counter + BlockedCount + DisabledCount >= mNumberOfCpus. + // DisabledCount check, then the CPU arrival count will be increased, th= us + // leading the retrieved CPU arrival count + BlockedCount + DisabledCoun= t > mNumberOfCpus. // since the BlockedCount & DisabledCount are local variable, it's ok he= re only for // the checking of all CPUs In Smm. // - if (*mSmmMpSyncData->Counter + BlockedCount + DisabledCount >=3D mNumber= OfCpus) { + if (CpuCount + BlockedCount + DisabledCount >=3D mNumberOfCpus) { return TRUE; } =20 return FALSE; } @@ -384,23 +241,35 @@ IsLmceSignaled ( VOID SmmWaitForApArrival ( VOID ) { + RETURN_STATUS Status; + + UINTN CpuCount; UINT64 Timer; UINTN Index; BOOLEAN LmceEn; BOOLEAN LmceSignal; UINT32 DelayedCount; UINT32 BlockedCount; =20 PERF_FUNCTION_BEGIN (); =20 + CpuCount =3D 0; DelayedCount =3D 0; BlockedCount =3D 0; =20 - ASSERT (*mSmmMpSyncData->Counter <=3D mNumberOfCpus); + Status =3D SmmCpuSyncGetArrivedCpuCount (mSmmMpSyncData->SmmCpuSyncCtx, = &CpuCount); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "SmmWaitForApArrival: SmmCpuSyncGetArrivedCpuCoun= t return error %r!\n", Status)); + CpuDeadLoop (); + PERF_FUNCTION_END (); + return; + } + + ASSERT (CpuCount <=3D mNumberOfCpus); =20 LmceEn =3D FALSE; LmceSignal =3D FALSE; if (mMachineCheckSupported) { LmceEn =3D IsLmceOsEnabled (); @@ -431,10 +300,21 @@ SmmWaitForApArrival ( } =20 CpuPause (); } =20 + // + // Check the CpuCount after Sync with APs 1st. + // + Status =3D SmmCpuSyncGetArrivedCpuCount (mSmmMpSyncData->SmmCpuSyncCtx, = &CpuCount); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "SmmWaitForApArrival: SmmCpuSyncGetArrivedCpuCoun= t return error %r!\n", Status)); + CpuDeadLoop (); + PERF_FUNCTION_END (); + return; + } + // // Not all APs have arrived, so we need 2nd round of timeout. IPIs shoul= d be sent to ALL none present APs, // because: // a) Delayed AP may have just come out of the delayed state. Blocked AP= may have just been brought out of blocked state by some AP running // normal mode code. These APs need to be guaranteed to have an SMI p= ending to insure that once they are out of delayed / blocked state, they @@ -447,11 +327,11 @@ SmmWaitForApArrival ( // d) We don't add code to check SMI disabling status to skip sending IP= I to SMI disabled APs, because: // - In traditional flow, SMI disabling is discouraged. // - In relaxed flow, CheckApArrival() will check SMI disabling statu= s before calling this function. // In both cases, adding SMI-disabling checking code increases overhe= ad. // - if (*mSmmMpSyncData->Counter < mNumberOfCpus) { + if (CpuCount < mNumberOfCpus) { // // Send SMI IPIs to bring outside processors in // for (Index =3D 0; Index < mMaxNumberOfCpus; Index++) { if (!(*(mSmmMpSyncData->CpuData[Index].Present)) && (gSmmCpuPrivate-= >ProcessorInfo[Index].ProcessorId !=3D INVALID_APIC_ID)) { @@ -610,18 +490,22 @@ VOID BSPHandler ( IN UINTN CpuIndex, IN SMM_CPU_SYNC_MODE SyncMode ) { + RETURN_STATUS Status; + + UINTN CpuCount; UINTN Index; MTRR_SETTINGS Mtrrs; UINTN ApCount; BOOLEAN ClearTopLevelSmiResult; UINTN PresentCount; =20 ASSERT (CpuIndex =3D=3D mSmmMpSyncData->BspIndex); - ApCount =3D 0; + CpuCount =3D 0; + ApCount =3D 0; =20 PERF_FUNCTION_BEGIN (); =20 // // Flag BSP's presence @@ -659,28 +543,35 @@ BSPHandler ( // Wait for APs to arrive // SmmWaitForApArrival (); =20 // - // Lock the counter down and retrieve the number of APs + // Lock door for late comming CPU checkin and retrieve the Arrived num= ber of APs // *mSmmMpSyncData->AllCpusInSync =3D TRUE; - ApCount =3D LockdownSemaphore (mSmmMpSyncData->= Counter) - 1; + + Status =3D SmmCpuSyncLockDoor (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex= , &CpuCount); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "BSPHandler: SmmCpuSyncLockDoor return error %r= !\n", Status)); + CpuDeadLoop (); + } + + ApCount =3D CpuCount - 1; =20 // // Wait for all APs to get ready for programming MTRRs // - WaitForAllAPs (ApCount); + SmmCpuSyncWaitForAPs (mSmmMpSyncData->SmmCpuSyncCtx, ApCount, CpuIndex= ); =20 if (SmmCpuFeaturesNeedConfigureMtrrs ()) { // // Signal all APs it's time for backup MTRRs // ReleaseAllAPs (); =20 // - // WaitForAllAPs() may wait for ever if an AP happens to enter SMM at + // SmmCpuSyncWaitForAPs() may wait for ever if an AP happens to ente= r SMM at // exactly this point. Please make sure PcdCpuSmmMaxSyncLoops has be= en set // to a large enough value to avoid this situation. // Note: For HT capable CPUs, threads within a core share the same s= et of MTRRs. // We do the backup first and then set MTRR to avoid race condition = for threads // in the same core. @@ -688,28 +579,28 @@ BSPHandler ( MtrrGetAllMtrrs (&Mtrrs); =20 // // Wait for all APs to complete their MTRR saving // - WaitForAllAPs (ApCount); + SmmCpuSyncWaitForAPs (mSmmMpSyncData->SmmCpuSyncCtx, ApCount, CpuInd= ex); =20 // // Let all processors program SMM MTRRs together // ReleaseAllAPs (); =20 // - // WaitForAllAPs() may wait for ever if an AP happens to enter SMM at + // SmmCpuSyncWaitForAPs() may wait for ever if an AP happens to ente= r SMM at // exactly this point. Please make sure PcdCpuSmmMaxSyncLoops has be= en set // to a large enough value to avoid this situation. // ReplaceOSMtrrs (CpuIndex); =20 // // Wait for all APs to complete their MTRR programming // - WaitForAllAPs (ApCount); + SmmCpuSyncWaitForAPs (mSmmMpSyncData->SmmCpuSyncCtx, ApCount, CpuInd= ex); } } =20 // // The BUSY lock is initialized to Acquired state @@ -741,14 +632,21 @@ BSPHandler ( // make those APs to exit SMI synchronously. APs which arrive later will= be excluded and // will run through freely. // if ((SyncMode !=3D SmmCpuSyncModeTradition) && !SmmCpuFeaturesNeedConfig= ureMtrrs ()) { // - // Lock the counter down and retrieve the number of APs + // Lock door for late comming CPU checkin and retrieve the Arrived num= ber of APs // *mSmmMpSyncData->AllCpusInSync =3D TRUE; - ApCount =3D LockdownSemaphore (mSmmMpSyncData->= Counter) - 1; + Status =3D SmmCpuSyncLockDoor (mSmmMpSyncData-= >SmmCpuSyncCtx, CpuIndex, &CpuCount); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "BSPHandler: SmmCpuSyncLockDoor return error %r= !\n", Status)); + CpuDeadLoop (); + } + + ApCount =3D CpuCount - 1; + // // Make sure all APs have their Present flag set // while (TRUE) { PresentCount =3D 0; @@ -771,11 +669,11 @@ BSPHandler ( ReleaseAllAPs (); =20 // // Wait for all APs to complete their pending tasks // - WaitForAllAPs (ApCount); + SmmCpuSyncWaitForAPs (mSmmMpSyncData->SmmCpuSyncCtx, ApCount, CpuIndex); =20 if (SmmCpuFeaturesNeedConfigureMtrrs ()) { // // Signal APs to restore MTRRs // @@ -788,11 +686,11 @@ BSPHandler ( MtrrSetAllMtrrs (&Mtrrs); =20 // // Wait for all APs to complete MTRR programming // - WaitForAllAPs (ApCount); + SmmCpuSyncWaitForAPs (mSmmMpSyncData->SmmCpuSyncCtx, ApCount, CpuIndex= ); } =20 // // Stop source level debug in BSP handler, the code below will not be // debugged. @@ -816,11 +714,11 @@ BSPHandler ( =20 // // Gather APs to exit SMM synchronously. Note the Present flag is cleare= d by now but // WaitForAllAps does not depend on the Present flag. // - WaitForAllAPs (ApCount); + SmmCpuSyncWaitForAPs (mSmmMpSyncData->SmmCpuSyncCtx, ApCount, CpuIndex); =20 // // At this point, all APs should have exited from APHandler(). // Migrate the SMM MP performance logging to standard SMM performance lo= gging. // Any SMM MP performance logging after this point will be migrated in n= ext SMI. @@ -842,11 +740,11 @@ BSPHandler ( } =20 // // Allow APs to check in from this point on // - *mSmmMpSyncData->Counter =3D 0; + SmmCpuSyncContextReset (mSmmMpSyncData->SmmCpuSyncCtx); *mSmmMpSyncData->AllCpusInSync =3D FALSE; mSmmMpSyncData->AllApArrivedWithException =3D FALSE; =20 PERF_FUNCTION_END (); } @@ -912,21 +810,21 @@ APHandler ( =20 if (!(*mSmmMpSyncData->InsideSmm)) { // // Give up since BSP is unable to enter SMM // and signal the completion of this AP - // Reduce the mSmmMpSyncData->Counter! + // Reduce the CPU arrival count! // - WaitForSemaphore (mSmmMpSyncData->Counter); + SmmCpuSyncCheckOutCpu (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex); return; } } else { // // Don't know BSP index. Give up without sending IPI to BSP. - // Reduce the mSmmMpSyncData->Counter! + // Reduce the CPU arrival count! // - WaitForSemaphore (mSmmMpSyncData->Counter); + SmmCpuSyncCheckOutCpu (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex); return; } } =20 // @@ -942,50 +840,50 @@ APHandler ( =20 if ((SyncMode =3D=3D SmmCpuSyncModeTradition) || SmmCpuFeaturesNeedConfi= gureMtrrs ()) { // // Notify BSP of arrival at this point // - ReleaseBsp (mSmmMpSyncData->CpuData[BspIndex].Run); + SmmCpuSyncReleaseBsp (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex, BspInde= x); } =20 if (SmmCpuFeaturesNeedConfigureMtrrs ()) { // // Wait for the signal from BSP to backup MTRRs // - WaitForBsp (mSmmMpSyncData->CpuData[CpuIndex].Run); + SmmCpuSyncWaitForBsp (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex, BspInde= x); =20 // // Backup OS MTRRs // MtrrGetAllMtrrs (&Mtrrs); =20 // // Signal BSP the completion of this AP // - ReleaseBsp (mSmmMpSyncData->CpuData[BspIndex].Run); + SmmCpuSyncReleaseBsp (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex, BspInde= x); =20 // // Wait for BSP's signal to program MTRRs // - WaitForBsp (mSmmMpSyncData->CpuData[CpuIndex].Run); + SmmCpuSyncWaitForBsp (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex, BspInde= x); =20 // // Replace OS MTRRs with SMI MTRRs // ReplaceOSMtrrs (CpuIndex); =20 // // Signal BSP the completion of this AP // - ReleaseBsp (mSmmMpSyncData->CpuData[BspIndex].Run); + SmmCpuSyncReleaseBsp (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex, BspInde= x); } =20 while (TRUE) { // // Wait for something to happen // - WaitForBsp (mSmmMpSyncData->CpuData[CpuIndex].Run); + SmmCpuSyncWaitForBsp (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex, BspInde= x); =20 // // Check if BSP wants to exit SMM // if (!(*mSmmMpSyncData->InsideSmm)) { @@ -1021,16 +919,16 @@ APHandler ( =20 if (SmmCpuFeaturesNeedConfigureMtrrs ()) { // // Notify BSP the readiness of this AP to program MTRRs // - ReleaseBsp (mSmmMpSyncData->CpuData[BspIndex].Run); + SmmCpuSyncReleaseBsp (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex, BspInde= x); =20 // // Wait for the signal from BSP to program MTRRs // - WaitForBsp (mSmmMpSyncData->CpuData[CpuIndex].Run); + SmmCpuSyncWaitForBsp (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex, BspInde= x); =20 // // Restore OS MTRRs // SmmCpuFeaturesReenableSmrr (); @@ -1038,26 +936,26 @@ APHandler ( } =20 // // Notify BSP the readiness of this AP to Reset states/semaphore for thi= s processor // - ReleaseBsp (mSmmMpSyncData->CpuData[BspIndex].Run); + SmmCpuSyncReleaseBsp (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex, BspIndex); =20 // // Wait for the signal from BSP to Reset states/semaphore for this proce= ssor // - WaitForBsp (mSmmMpSyncData->CpuData[CpuIndex].Run); + SmmCpuSyncWaitForBsp (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex, BspIndex); =20 // // Reset states/semaphore for this processor // *(mSmmMpSyncData->CpuData[CpuIndex].Present) =3D FALSE; =20 // // Notify BSP the readiness of this AP to exit SMM // - ReleaseBsp (mSmmMpSyncData->CpuData[BspIndex].Run); + SmmCpuSyncReleaseBsp (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex, BspIndex); } =20 /** Checks whether the input token is the current used token. =20 @@ -1321,11 +1219,11 @@ InternalSmmStartupThisAp ( mSmmMpSyncData->CpuData[CpuIndex].Status =3D CpuStatus; if (mSmmMpSyncData->CpuData[CpuIndex].Status !=3D NULL) { *mSmmMpSyncData->CpuData[CpuIndex].Status =3D EFI_NOT_READY; } =20 - ReleaseOneAp (mSmmMpSyncData->CpuData[CpuIndex].Run); + SmmCpuSyncReleaseOneAp (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex, gSmmCpu= Private->SmmCoreEntryContext.CurrentlyExecutingCpu); =20 if (Token =3D=3D NULL) { AcquireSpinLock (mSmmMpSyncData->CpuData[CpuIndex].Busy); ReleaseSpinLock (mSmmMpSyncData->CpuData[CpuIndex].Busy); } @@ -1450,11 +1348,11 @@ InternalSmmStartupAllAPs ( =20 // // Decrease the count to mark this processor(AP or BSP) as finished. // if (ProcToken !=3D NULL) { - WaitForSemaphore (&ProcToken->RunningApCount); + InterlockedDecrement (&ProcToken->RunningApCount); } } } =20 ReleaseAllAPs (); @@ -1725,14 +1623,15 @@ SmiRendezvous ( // goto Exit; } else { // // Signal presence of this processor - // mSmmMpSyncData->Counter is increased here! - // "ReleaseSemaphore (mSmmMpSyncData->Counter) =3D=3D 0" means BSP has= already ended the synchronization. + // CPU check in here! + // "SmmCpuSyncCheckInCpu (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex)" re= turn error means failed + // to check in CPU. BSP has already ended the synchronization. // - if (ReleaseSemaphore (mSmmMpSyncData->Counter) =3D=3D 0) { + if (RETURN_ERROR (SmmCpuSyncCheckInCpu (mSmmMpSyncData->SmmCpuSyncCtx,= CpuIndex))) { // // BSP has already ended the synchronization, so QUIT!!! // Existing AP is too late now to enter SMI since BSP has already en= ded the synchronization!!! // =20 @@ -1824,12 +1723,10 @@ SmiRendezvous ( } else { APHandler (CpuIndex, ValidSmi, mSmmMpSyncData->EffectiveSyncMode); } } =20 - ASSERT (*mSmmMpSyncData->CpuData[CpuIndex].Run =3D=3D 0); - // // Wait for BSP's signal to exit SMI // while (*mSmmMpSyncData->AllCpusInSync) { CpuPause (); @@ -1945,12 +1842,10 @@ InitializeSmmCpuSemaphores ( SemaphoreBlock =3D AllocatePages (Pages); ASSERT (SemaphoreBlock !=3D NULL); ZeroMem (SemaphoreBlock, TotalSize); =20 SemaphoreAddr =3D (UINTN)SemaphoreBloc= k; - mSmmCpuSemaphores.SemaphoreGlobal.Counter =3D (UINT32 *)SemaphoreA= ddr; - SemaphoreAddr +=3D SemaphoreSize; mSmmCpuSemaphores.SemaphoreGlobal.InsideSmm =3D (BOOLEAN *)Semaphore= Addr; SemaphoreAddr +=3D SemaphoreSize; mSmmCpuSemaphores.SemaphoreGlobal.AllCpusInSync =3D (BOOLEAN *)Semaphore= Addr; SemaphoreAddr +=3D SemaphoreSize; mSmmCpuSemaphores.SemaphoreGlobal.PFLock =3D (SPIN_LOCK *)Semapho= reAddr; @@ -1960,12 +1855,10 @@ InitializeSmmCpuSemaphores ( SemaphoreAddr +=3D SemaphoreSize; =20 SemaphoreAddr =3D (UINTN)SemaphoreBlock + Globa= lSemaphoresSize; mSmmCpuSemaphores.SemaphoreCpu.Busy =3D (SPIN_LOCK *)SemaphoreAddr; SemaphoreAddr +=3D ProcessorCount * SemaphoreSiz= e; - mSmmCpuSemaphores.SemaphoreCpu.Run =3D (UINT32 *)SemaphoreAddr; - SemaphoreAddr +=3D ProcessorCount * SemaphoreSiz= e; mSmmCpuSemaphores.SemaphoreCpu.Present =3D (BOOLEAN *)SemaphoreAddr; =20 mPFLock =3D mSmmCpuSemaphores.SemaphoreGlobal.PFLo= ck; mConfigSmmCodeAccessCheckLock =3D mSmmCpuSemaphores.SemaphoreGlobal.Code= AccessCheckLock; =20 @@ -1980,10 +1873,12 @@ VOID EFIAPI InitializeMpSyncData ( VOID ) { + RETURN_STATUS Status; + UINTN CpuIndex; =20 if (mSmmMpSyncData !=3D NULL) { // // mSmmMpSyncDataSize includes one structure of SMM_DISPATCHER_MP_SYNC= _DATA, one @@ -2009,32 +1904,34 @@ InitializeMpSyncData ( } } =20 mSmmMpSyncData->EffectiveSyncMode =3D mCpuSmmSyncMode; =20 - mSmmMpSyncData->Counter =3D mSmmCpuSemaphores.SemaphoreGlobal.Co= unter; + Status =3D SmmCpuSyncContextInit (gSmmCpuPrivate->SmmCoreEntryContext.= NumberOfCpus, &(mSmmMpSyncData->SmmCpuSyncCtx)); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "InitializeMpSyncData: SmmCpuSyncContextInit re= turn error %r!\n", Status)); + CpuDeadLoop (); + return; + } + mSmmMpSyncData->InsideSmm =3D mSmmCpuSemaphores.SemaphoreGlobal.In= sideSmm; mSmmMpSyncData->AllCpusInSync =3D mSmmCpuSemaphores.SemaphoreGlobal.Al= lCpusInSync; ASSERT ( - mSmmMpSyncData->Counter !=3D NULL && mSmmMpSyncData->InsideSmm !=3D = NULL && + mSmmMpSyncData->SmmCpuSyncCtx !=3D NULL && mSmmMpSyncData->InsideSmm= !=3D NULL && mSmmMpSyncData->AllCpusInSync !=3D NULL ); - *mSmmMpSyncData->Counter =3D 0; *mSmmMpSyncData->InsideSmm =3D FALSE; *mSmmMpSyncData->AllCpusInSync =3D FALSE; =20 mSmmMpSyncData->AllApArrivedWithException =3D FALSE; =20 for (CpuIndex =3D 0; CpuIndex < gSmmCpuPrivate->SmmCoreEntryContext.Nu= mberOfCpus; CpuIndex++) { mSmmMpSyncData->CpuData[CpuIndex].Busy =3D (SPIN_LOCK *)((UINTN)mSmmCpuSemaphores.SemaphoreCpu.Busy + mSemaph= oreSize * CpuIndex); - mSmmMpSyncData->CpuData[CpuIndex].Run =3D - (UINT32 *)((UINTN)mSmmCpuSemaphores.SemaphoreCpu.Run + mSemaphoreS= ize * CpuIndex); mSmmMpSyncData->CpuData[CpuIndex].Present =3D (BOOLEAN *)((UINTN)mSmmCpuSemaphores.SemaphoreCpu.Present + mSemap= horeSize * CpuIndex); *(mSmmMpSyncData->CpuData[CpuIndex].Busy) =3D 0; - *(mSmmMpSyncData->CpuData[CpuIndex].Run) =3D 0; *(mSmmMpSyncData->CpuData[CpuIndex].Present) =3D FALSE; } } } =20 diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmC= puDxeSmm/PiSmmCpuDxeSmm.h index 20ada465c2..607d5d8b74 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h @@ -52,10 +52,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include #include #include +#include =20 #include #include =20 #include @@ -403,11 +404,10 @@ SmmRelocationSemaphoreComplete ( /// typedef struct { SPIN_LOCK *Busy; volatile EFI_AP_PROCEDURE2 Procedure; volatile VOID *Parameter; - volatile UINT32 *Run; volatile BOOLEAN *Present; PROCEDURE_TOKEN *Token; EFI_STATUS *Status; } SMM_CPU_DATA_BLOCK; =20 @@ -421,29 +421,28 @@ typedef struct { // // Pointer to an array. The array should be located immediately after th= is structure // so that UC cache-ability can be set together. // SMM_CPU_DATA_BLOCK *CpuData; - volatile UINT32 *Counter; volatile UINT32 BspIndex; volatile BOOLEAN *InsideSmm; volatile BOOLEAN *AllCpusInSync; volatile SMM_CPU_SYNC_MODE EffectiveSyncMode; volatile BOOLEAN SwitchBsp; volatile BOOLEAN *CandidateBsp; volatile BOOLEAN AllApArrivedWithException; EFI_AP_PROCEDURE StartupProcedure; VOID *StartupProcArgs; + SMM_CPU_SYNC_CTX *SmmCpuSyncCtx; } SMM_DISPATCHER_MP_SYNC_DATA; =20 #define SMM_PSD_OFFSET 0xfb00 =20 /// /// All global semaphores' pointer /// typedef struct { - volatile UINT32 *Counter; volatile BOOLEAN *InsideSmm; volatile BOOLEAN *AllCpusInSync; SPIN_LOCK *PFLock; SPIN_LOCK *CodeAccessCheckLock; } SMM_CPU_SEMAPHORE_GLOBAL; @@ -451,11 +450,10 @@ typedef struct { /// /// All semaphores for each processor /// typedef struct { SPIN_LOCK *Busy; - volatile UINT32 *Run; volatile BOOLEAN *Present; SPIN_LOCK *Token; } SMM_CPU_SEMAPHORE_CPU; =20 /// diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf b/UefiCpuPkg/PiSm= mCpuDxeSmm/PiSmmCpuDxeSmm.inf index 5d52ed7d13..e92b8c747d 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf @@ -101,10 +101,11 @@ SmmCpuFeaturesLib PeCoffGetEntryPointLib PerformanceLib CpuPageTableLib MmSaveStateLib + SmmCpuSyncLib =20 [Protocols] gEfiSmmAccess2ProtocolGuid ## CONSUMES gEfiMpServiceProtocolGuid ## CONSUMES gEfiSmmConfigurationProtocolGuid ## PRODUCES --=20 2.16.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 (#111898): https://edk2.groups.io/g/devel/message/111898 Mute This Topic: https://groups.io/mt/102889296/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-