From nobody Mon May 13 18:23:36 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+112702+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+112702+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1702970328; cv=none; d=zohomail.com; s=zohoarc; b=mX7kCT48xefsuLkCZHuzgZjJr/3i3nCA1LL9jQ1Lpz5q+lm0wdQN7ih8VaIB4udH3D/Z+ybcdnOpwDiDxBr0dDSTWM9rOuAGRnbTjQmlNHQ+q5JDRSFwfC0YX1hFQKsb1Dy5KScgz4xwJG1EsNvOz4Go1ZSHoVM2bLZaHarWU2w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702970328; 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=kEWqs5w7rYIC5Y9Y4bspWe2nSjyCIHmoLiRTGNZhliA=; b=bw9NQOkBHH4xlwfsdjbgdL5kv8lifbKftEyk5bMba6JpkmCbit0bYghfZEi08wsabd3p3WR0NAA4NMgE3Gmgxa82ag8ixNiTkPskMPQe/nMTwAL7dlGf7VFQ17jVLlK96ri8kW9e8w3RQfmiJ4h5U+sXaXNw6BGQwC6R+9JLE4k= 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+112702+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 1702970328069364.55446147065527; Mon, 18 Dec 2023 23:18:48 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=FVrJ5sNfuAbVvqmo3wCyAUFNolQQH6X0txY7Y8ZdfRM=; 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=1702970327; v=1; b=b93UDWgYDZd7oL2qQyILEtIPLA8h3swF37v5TVXhSxHDkU4x6IqRe0sK+fL2zZHEUQbHGJ81 UXyfdSeHRXDVzyt0sGTIm+l0Gm2h+0EOrQVV76V/el+qe44i1Goi0XxHSEmHZfqZ2HLoHixtuNU dHNuNlIhwukRzI2S04dyUXH4= X-Received: by 127.0.0.2 with SMTP id PwvFYY1788612xws6xefjcSq; Mon, 18 Dec 2023 23:18:47 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) by mx.groups.io with SMTP id smtpd.web10.7322.1702970325397750965 for ; Mon, 18 Dec 2023 23:18:47 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="2830903" X-IronPort-AV: E=Sophos;i="6.04,287,1695711600"; d="scan'208";a="2830903" X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2023 23:18:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="899262022" X-IronPort-AV: E=Sophos;i="6.04,287,1695711600"; d="scan'208";a="899262022" X-Received: from sh1gapp1009.ccr.corp.intel.com ([10.239.189.219]) by orsmga004.jf.intel.com with ESMTP; 18 Dec 2023 23:18:44 -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 v5 1/8] UefiCpuPkg/PiSmmCpuDxeSmm: Optimize Semaphore Sync between BSP and AP Date: Tue, 19 Dec 2023 15:18:32 +0800 Message-Id: <20231219071839.4248-2-jiaxin.wu@intel.com> In-Reply-To: <20231219071839.4248-1-jiaxin.wu@intel.com> References: <20231219071839.4248-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: 7HzuhnKCzLjfvcnkfLLMGtrLx1787277AA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1702970329756100007 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 Reviewed-by: Laszlo Ersek Reviewed-by: Ray Ni --- 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 (#112702): https://edk2.groups.io/g/devel/message/112702 Mute This Topic: https://groups.io/mt/103259033/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 Mon May 13 18:23:36 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+112703+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+112703+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1702970330; cv=none; d=zohomail.com; s=zohoarc; b=Vp1RS0Z2ndvbvOdRm/DUMGHTH0idgMaqgBUqCL/bVdGnQqwE3yUbLDl/xa+ONVp2gNkEeyKtU5uuqzPWT3CIyZV756TRtSmYrzgl/6sFeADDvv+pbgjfjyKcwQJvFuswGjPw0Ij+tp9nmGXBfHK4Xzvivvnc/RiMc33GefLqLNk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702970330; 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=63pGks/ITd01/quBXJQf8ALt9jfaypB1sVy0AVnuAWY=; b=bfO8FaGwQxUuUoln2w1N1bJlimLBeJPdrY0Y2JXW1OjDfl3HAvDwRArds7OFwWrg1KkG4jS5jtVXel+TcEBganxiWXr48lWVJxTqtws0RCwlXHJO7hTCd4Omlbbb+HjbLk9eBl4zDUOgs/KV0g15ihZRmzJ2tLTwXO4qiO1fPHg= 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+112703+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 1702970330588168.83637109152232; Mon, 18 Dec 2023 23:18:50 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=jXZ7GVs6IgPRz+tj/VYaHdPzS+Jkk7ObuEWvPJ9MGtw=; 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=1702970330; v=1; b=X9rGeHbxBSyKGKDDt0zwQ3zA/+e3gnHVJ9uBs2Jbigq7uBw5vdexjbeLGaJ8TtmfcmBzW48c eB2o3UxpXWPOV8OwZiNy7XvhAhEvzJ0PncsYf9Y975jQClFi9r0CmdpP8pfIh+9WUSMXemoXnba 1+/QSb/9X7DnF73o640FflMo= X-Received: by 127.0.0.2 with SMTP id KX9nYY1788612xDp4QA0N92i; Mon, 18 Dec 2023 23:18:50 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) by mx.groups.io with SMTP id smtpd.web10.7322.1702970325397750965 for ; Mon, 18 Dec 2023 23:18:49 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="2830916" X-IronPort-AV: E=Sophos;i="6.04,287,1695711600"; d="scan'208";a="2830916" X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2023 23:18:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="899262037" X-IronPort-AV: E=Sophos;i="6.04,287,1695711600"; d="scan'208";a="899262037" X-Received: from sh1gapp1009.ccr.corp.intel.com ([10.239.189.219]) by orsmga004.jf.intel.com with ESMTP; 18 Dec 2023 23:18:47 -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 v5 2/8] UefiCpuPkg: Adds SmmCpuSyncLib library class Date: Tue, 19 Dec 2023 15:18:33 +0800 Message-Id: <20231219071839.4248-3-jiaxin.wu@intel.com> In-Reply-To: <20231219071839.4248-1-jiaxin.wu@intel.com> References: <20231219071839.4248-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: isPbo1N4SCBukoBklNBnSCqix1787277AA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1702970331748100009 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 Reviewed-by: Ray Ni --- UefiCpuPkg/Include/Library/SmmCpuSyncLib.h | 290 +++++++++++++++++++++++++= ++++ UefiCpuPkg/UefiCpuPkg.dec | 3 + 2 files changed, 293 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..4d273095c9 --- /dev/null +++ b/UefiCpuPkg/Include/Library/SmmCpuSyncLib.h @@ -0,0 +1,290 @@ +/** @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 initial= ize the SMM CPU Sync context. + ContextDeinit() is called in driver's unload function to deinitialize = the SMM CPU Sync context. + ContextReset() is called by one of CPUs after all CPUs are ready to ex= it 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 ca= lling CheckInCpu(). + CheckOutCpu() can be called in error handling flow for the CPU who cal= ls CheckInCpu() earlier. + The elected BSP calls LockDoor() so that CheckInCpu() and CheckOutCpu(= ) will return the error code after that. + GetArrivedCpuCount() returns the number of checked-in CPUs. + + 3. WaitForAPs/ReleaseOneAp/WaitForBsp/ReleaseBsp + WaitForAPs() & ReleaseOneAp() are called from BSP to wait the number o= f APs and release one specific AP. + WaitForBsp() & ReleaseBsp() are called from APs to wait and release BS= P. + 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_CONTEXT SMM_CPU_SYNC_CONTEXT; + +/** + Create and initialize the SMM CPU Sync context. It is to allocate and in= itialize the + SMM CPU Sync context. + + If Context is NULL, then ASSERT(). + + @param[in] NumberOfCpus The number of Logical Processors in th= e system. + @param[out] Context 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_OUT_OF_RESOURCES There are not enough resources availab= le to create and initialize SMM CPU Sync context. + @retval RETURN_BUFFER_TOO_SMALL Overflow happen + +**/ +RETURN_STATUS +EFIAPI +SmmCpuSyncContextInit ( + IN UINTN NumberOfCpus, + OUT SMM_CPU_SYNC_CONTEXT **Context + ); + +/** + Deinit an allocated SMM CPU Sync context. The resources allocated in Smm= CpuSyncContextInit() will + be freed. + + If Context is NULL, then ASSERT(). + + @param[in,out] Context Pointer to the SMM CPU Sync context object t= o be deinitialized. + +**/ +VOID +EFIAPI +SmmCpuSyncContextDeinit ( + IN OUT SMM_CPU_SYNC_CONTEXT *Context + ); + +/** + Reset SMM CPU Sync context. SMM CPU Sync context will be reset to the in= itialized state. + + This function is called by one of CPUs after all CPUs are ready to exit = SMI, which allows CPU to + check into the next SMI from this point. + + If Context is NULL, then ASSERT(). + + @param[in,out] Context Pointer to the SMM CPU Sync context object t= o be reset. + +**/ +VOID +EFIAPI +SmmCpuSyncContextReset ( + IN OUT SMM_CPU_SYNC_CONTEXT *Context + ); + +/** + Get current number of arrived CPU in SMI. + + BSP might need to know the current number of arrived CPU in SMI to make = sure all APs + in SMI. This API can be for that purpose. + + If Context is NULL, then ASSERT(). + + @param[in] Context Pointer to the SMM CPU Sync context object. + + @retval Current number of arrived CPU in SMI. + +**/ +UINTN +EFIAPI +SmmCpuSyncGetArrivedCpuCount ( + IN SMM_CPU_SYNC_CONTEXT *Context + ); + +/** + Performs an atomic operation to check in CPU. + + When SMI happens, all processors including BSP enter to SMM mode by call= ing SmmCpuSyncCheckInCpu(). + + If Context is NULL, then ASSERT(). + If CpuIndex exceeds the range of all CPUs in the system, then ASSERT(). + + @param[in,out] Context 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_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_CONTEXT *Context, + IN UINTN CpuIndex + ); + +/** + Performs an atomic operation to check out CPU. + + This function can be called in error handling flow for the CPU who calls= CheckInCpu() earlier. + The caller shall make sure the CPU specified by CpuIndex has already che= cked-in. + + If Context is NULL, then ASSERT(). + If CpuIndex exceeds the range of all CPUs in the system, then ASSERT(). + + @param[in,out] Context 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_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_CONTEXT *Context, + IN UINTN CpuIndex + ); + +/** + Performs an atomic operation lock door for CPU checkin and checkout. Aft= er this function: + CPU can not check in via SmmCpuSyncCheckInCpu(). + CPU can not check out via SmmCpuSyncCheckOutCpu(). + + The CPU specified by CpuIndex is elected to lock door. The caller shall = make sure the CpuIndex + is the actual CPU calling this function to avoid the undefined behavior. + + If Context is NULL, then ASSERT(). + If CpuCount is NULL, then ASSERT(). + If CpuIndex exceeds the range of all CPUs in the system, then ASSERT(). + + @param[in,out] Context Pointer to the SMM CPU Sync context ob= ject. + @param[in] CpuIndex Indicate which CPU to lock door. + @param[out] CpuCount Number of arrived CPU in SMI after loo= k door. + +**/ +VOID +EFIAPI +SmmCpuSyncLockDoor ( + IN OUT SMM_CPU_SYNC_CONTEXT *Context, + IN UINTN CpuIndex, + 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. + The caller shall make sure the BspIndex is the actual CPU calling this f= unction to avoid the undefined behavior. + The caller shall make sure the NumberOfAPs have already checked-in to av= oid the undefined behavior. + + If Context is NULL, then ASSERT(). + If NumberOfAPs >=3D All CPUs in system, then ASSERT(). + If BspIndex exceeds the range of all CPUs in the system, then ASSERT(). + + 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] Context 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. + +**/ +VOID +EFIAPI +SmmCpuSyncWaitForAPs ( + IN OUT SMM_CPU_SYNC_CONTEXT *Context, + 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. + The caller shall make sure the BspIndex is the actual CPU calling this f= unction to avoid the undefined behavior. + The caller shall make sure the CpuIndex has already checked-in to avoid = the undefined behavior. + + If Context is NULL, then ASSERT(). + If CpuIndex =3D=3D BspIndex, then ASSERT(). + If BspIndex or CpuIndex exceed the range of all CPUs in the system, then= ASSERT(). + + @param[in,out] Context 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. + +**/ +VOID +EFIAPI +SmmCpuSyncReleaseOneAp ( + IN OUT SMM_CPU_SYNC_CONTEXT *Context, + IN UINTN CpuIndex, + IN UINTN BspIndex + ); + +/** + Used by the AP to wait BSP. + + The AP is specified by CpuIndex. + The caller shall make sure the CpuIndex is the actual CPU calling this f= unction to avoid the undefined behavior. + The BSP is specified by BspIndex. + + If Context is NULL, then ASSERT(). + If CpuIndex =3D=3D BspIndex, then ASSERT(). + If BspIndex or CpuIndex exceed the range of all CPUs in the system, then= ASSERT(). + + Note: + This function is blocking mode, and it will return only after the AP rel= eased by + calling SmmCpuSyncReleaseOneAp(): + BSP: ReleaseOneAp --> AP: WaitForBsp + + @param[in,out] Context 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. + +**/ +VOID +EFIAPI +SmmCpuSyncWaitForBsp ( + IN OUT SMM_CPU_SYNC_CONTEXT *Context, + IN UINTN CpuIndex, + IN UINTN BspIndex + ); + +/** + Used by the AP to release BSP. + + The AP is specified by CpuIndex. + The caller shall make sure the CpuIndex is the actual CPU calling this f= unction to avoid the undefined behavior. + The BSP is specified by BspIndex. + + If Context is NULL, then ASSERT(). + If CpuIndex =3D=3D BspIndex, then ASSERT(). + If BspIndex or CpuIndex exceed the range of all CPUs in the system, then= ASSERT(). + + @param[in,out] Context 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. + +**/ +VOID +EFIAPI +SmmCpuSyncReleaseBsp ( + IN OUT SMM_CPU_SYNC_CONTEXT *Context, + IN UINTN CpuIndex, + IN UINTN BspIndex + ); + +#endif diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 61bd34ef17..cc785a3222 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 (#112703): https://edk2.groups.io/g/devel/message/112703 Mute This Topic: https://groups.io/mt/103259034/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 Mon May 13 18:23:36 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+112704+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+112704+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1702970332; cv=none; d=zohomail.com; s=zohoarc; b=ZihWYDijZbvJvJCStwwgs+DHfmBbyfjTg28P2aXSiNG3xqr5amq7TDumNtmvEMOf01XmWBz0xmaZnkAIU7LCvSJnA4A5O3d/frgOty8A+bhujg2FYCyXmE1j6l3YH7KIAQvbmBYLsiYEpXsd44JwW2NqzE4L918f3M8AjcVKnaE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702970332; 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=q2pLG77YqSq1nyIEHYvQYIbjLGg0LYDWdr2PWCG21vE=; b=iLFIuXO6mnsN91bPG0efZqjMn9ZNQ3igDtBboQh83d/c8QhIltvQVHg66kf0F5DgTTONZOaGx4R3WsclpbnlBz/2v/9hr2MjMZ12wC/W+Ib2akFNC3Xfwic7tMBc0ZmloveoBjy6OXWodjNV0Bf7dl9nmSzU13475uz1BbZbP04= 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+112704+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 17029703326006.3433188279279875; Mon, 18 Dec 2023 23:18:52 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=q375EFZCvyw/4kAESvlXnP8NjNha/RRvMaNmfxn9KDE=; 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=1702970332; v=1; b=ikVwtcURDdeZRFnhNWpR9iGGPK73V0zQ+9LZ+19RuHcGrmiY6LA98ZYROlbebIwNDxQk6ZkC jnGQmF22uLM86ny1rp89dYr72LzSySIWWIyy9X9WfNlhSHhqJUpbjPRM0eT4GrShUFVhuO9hBqo 1sX1bs202gsXDmqUzcMcRuJM= X-Received: by 127.0.0.2 with SMTP id Myw5YY1788612xszXjUguLAe; Mon, 18 Dec 2023 23:18:52 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) by mx.groups.io with SMTP id smtpd.web10.7322.1702970325397750965 for ; Mon, 18 Dec 2023 23:18:51 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="2830919" X-IronPort-AV: E=Sophos;i="6.04,287,1695711600"; d="scan'208";a="2830919" X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2023 23:18:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="899262041" X-IronPort-AV: E=Sophos;i="6.04,287,1695711600"; d="scan'208";a="899262041" X-Received: from sh1gapp1009.ccr.corp.intel.com ([10.239.189.219]) by orsmga004.jf.intel.com with ESMTP; 18 Dec 2023 23:18:49 -0800 From: "Wu, Jiaxin" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Laszlo Ersek , Ray Ni , Zeng Star Subject: [edk2-devel] [PATCH v5 3/8] MdePkg/MdeLibs.dsc.inc: Add SafeIntLib instance Date: Tue, 19 Dec 2023 15:18:34 +0800 Message-Id: <20231219071839.4248-4-jiaxin.wu@intel.com> In-Reply-To: <20231219071839.4248-1-jiaxin.wu@intel.com> References: <20231219071839.4248-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: aXd7VNhhG2CmRagcrMyCNVS2x1787277AA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1702970333725100013 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch is to add SafeIntLib in MdeLibs.dsc.inc Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: Laszlo Ersek Cc: Ray Ni Cc: Zeng Star Signed-off-by: Jiaxin Wu Reviewed-by: Michael D Kinney --- MdePkg/MdeLibs.dsc.inc | 1 + 1 file changed, 1 insertion(+) diff --git a/MdePkg/MdeLibs.dsc.inc b/MdePkg/MdeLibs.dsc.inc index 4580481cb5..deb35c1a18 100644 --- a/MdePkg/MdeLibs.dsc.inc +++ b/MdePkg/MdeLibs.dsc.inc @@ -14,5 +14,6 @@ [LibraryClasses] ArmTrngLib|MdePkg/Library/BaseArmTrngLibNull/BaseArmTrngLibNull.inf RegisterFilterLib|MdePkg/Library/RegisterFilterLibNull/RegisterFilterLib= Null.inf CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf SmmCpuRendezvousLib|MdePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezv= ousLibNull.inf + SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.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 (#112704): https://edk2.groups.io/g/devel/message/112704 Mute This Topic: https://groups.io/mt/103259035/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 Mon May 13 18:23:36 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+112705+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+112705+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1702970335; cv=none; d=zohomail.com; s=zohoarc; b=j92L6SIYxkIG4G5TD/ili3uBFKutaFe5fMkRZUHLbh9eTODZKGTzqc168jVCDY9QRkpJwhTBbTOl9KjEtpws8fp/cgyH/ioNVrm5b/9Dd+Ec405WAT7ODyR0JWp2EDr2kpqgAG90+VPuu5O8Z890T7aehWN3OJ7Nl56ow17nN8A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702970335; 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=fRCW91OORNg35ePC8kg1ukrfIonll0Zs/HQmAPFa3NM=; b=ZPPzSATlKVKz9y6lYHOkKOyDWZb1NX2fUFEETW+SaZp9kDjcB3LiKeK8y07JAR0SKmTdvwRbArRSRJa+4nmV9VgdbaeHuVtIBLxDfciq1ZxedUps7UlCfGBRn18tdWR1GLkbxoGabSfVofQivCM6DG/ihwNl86p6v2KftARfIgg= 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+112705+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 1702970335069289.4566447897539; Mon, 18 Dec 2023 23:18:55 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=if4UBCs45x+CzwF6QDWIIiCc3GMwgNTAn5td7dGr8X8=; 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=1702970334; v=1; b=ViYuquXWNpH6KR+klpO+PWyRGizVba8jDWlAI/YeK2NkHdApYdVFTot+w1TS85D2TXYFJ8He 0Nnp0baat4FVNKTzctegb43KXa1a/DRRbKBSBKQD5Qhgyf2M8mUIK+pHE1JvAGc04Tj+pS8BM08 ZxNLBDUPNensUdt94baMaKgg= X-Received: by 127.0.0.2 with SMTP id Cz4NYY1788612x23DjVkswaO; Mon, 18 Dec 2023 23:18:54 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) by mx.groups.io with SMTP id smtpd.web10.7322.1702970325397750965 for ; Mon, 18 Dec 2023 23:18:54 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="2830925" X-IronPort-AV: E=Sophos;i="6.04,287,1695711600"; d="scan'208";a="2830925" X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2023 23:18:54 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="899262054" X-IronPort-AV: E=Sophos;i="6.04,287,1695711600"; d="scan'208";a="899262054" X-Received: from sh1gapp1009.ccr.corp.intel.com ([10.239.189.219]) by orsmga004.jf.intel.com with ESMTP; 18 Dec 2023 23:18:51 -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 v5 4/8] UefiCpuPkg: Implements SmmCpuSyncLib library instance Date: Tue, 19 Dec 2023 15:18:35 +0800 Message-Id: <20231219071839.4248-5-jiaxin.wu@intel.com> In-Reply-To: <20231219071839.4248-1-jiaxin.wu@intel.com> References: <20231219071839.4248-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: uSSDBVA8ddIzNzDAC7024KFYx1787277AA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1702970335775100017 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 Reviewed-by: Ray Ni --- UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.c | 652 +++++++++++++++++= ++++ UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf | 34 ++ UefiCpuPkg/UefiCpuPkg.dsc | 2 + 3 files changed, 688 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..d517d4b706 --- /dev/null +++ b/UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.c @@ -0,0 +1,652 @@ +/** @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 initial= ize the SMM CPU Sync context. + ContextDeinit() is called in driver's unload function to deinitialize = the SMM CPU Sync context. + ContextReset() is called by one of CPUs after all CPUs are ready to ex= it 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 ca= lling CheckInCpu(). + CheckOutCpu() can be called in error handling flow for the CPU who cal= ls CheckInCpu() earlier. + The elected BSP calls LockDoor() so that CheckInCpu() and CheckOutCpu(= ) will return the error code after that. + GetArrivedCpuCount() returns the number of checked-in CPUs. + + 3. WaitForAPs/ReleaseOneAp/WaitForBsp/ReleaseBsp + WaitForAPs() & ReleaseOneAp() are called from BSP to wait the number o= f APs and release one specific AP. + WaitForBsp() & ReleaseBsp() are called from APs to wait and release BS= P. + 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 + +**/ +#include +#include +#include +#include +#include +#include +#include + +/// +/// The implementation shall place one semaphore on exclusive cache line f= or good performance. +/// +typedef volatile UINT32 SMM_CPU_SYNC_SEMAPHORE; + +typedef struct { + /// + /// Used for control each CPU continue run or wait for signal + /// + SMM_CPU_SYNC_SEMAPHORE *Run; +} SMM_CPU_SYNC_SEMAPHORE_FOR_EACH_CPU; + +struct SMM_CPU_SYNC_CONTEXT { + /// + /// Indicate all CPUs in the system. + /// + UINTN NumberOfCpus; + /// + /// Address of semaphores. + /// + VOID *SemBuffer; + /// + /// Size of semaphores. + /// + UINTN SemBufferPages; + /// + /// Before the door is locked, CpuCount stores the arrived CPU count. + /// After the door is locked, CpuCount is set to -1 indicating the door = is locked. + /// ArrivedCpuCountUponLock stores the arrived CPU count then. + /// + UINTN ArrivedCpuCountUponLock; + /// + /// Indicate CPUs entered SMM before lock door. + /// + SMM_CPU_SYNC_SEMAPHORE *CpuCount; + /// + /// Define an array of structure for each CPU semaphore due to the size = alignment + /// requirement. With the array of structure for each CPU semaphore, it'= s easy to + /// reach the specific CPU with CPU Index for its own semaphore access: = CpuSem[CpuIndex]. + /// + SMM_CPU_SYNC_SEMAPHORE_FOR_EACH_CPU CpuSem[]; +}; + +/** + 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 if Sem is not locked. + OUT: MAX_UINT32 if Sem is locked. + + @retval Original integer - 1 if Sem is not locked. + MAX_UINT32 if Sem is locked. + +**/ +STATIC +UINT32 +InternalWaitForSemaphore ( + IN OUT volatile UINT32 *Sem + ) +{ + UINT32 Value; + + for ( ; ;) { + Value =3D *Sem; + if (Value =3D=3D MAX_UINT32) { + return Value; + } + + 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 if Sem is not locked. + OUT: MAX_UINT32 if Sem is locked. + + @retval Original integer + 1 if Sem is not locked. + MAX_UINT32 if Sem is locked. + +**/ +STATIC +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); + + if (Value =3D=3D MAX_UINT32) { + return 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 + +**/ +STATIC +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. It is to allocate and in= itialize the + SMM CPU Sync context. + + If Context is NULL, then ASSERT(). + + @param[in] NumberOfCpus The number of Logical Processors in th= e system. + @param[out] Context 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_OUT_OF_RESOURCES There are not enough resources availab= le to create and initialize SMM CPU Sync context. + @retval RETURN_BUFFER_TOO_SMALL Overflow happen + +**/ +RETURN_STATUS +EFIAPI +SmmCpuSyncContextInit ( + IN UINTN NumberOfCpus, + OUT SMM_CPU_SYNC_CONTEXT **Context + ) +{ + RETURN_STATUS Status; + UINTN ContextSize; + UINTN OneSemSize; + UINTN NumSem; + UINTN TotalSemSize; + UINTN SemAddr; + UINTN CpuIndex; + SMM_CPU_SYNC_SEMAPHORE_FOR_EACH_CPU *CpuSem; + + ASSERT (Context !=3D NULL); + + // + // Calculate ContextSize + // + Status =3D SafeUintnMult (NumberOfCpus, sizeof (SMM_CPU_SYNC_SEMAPHORE_F= OR_EACH_CPU), &ContextSize); + if (RETURN_ERROR (Status)) { + return Status; + } + + Status =3D SafeUintnAdd (ContextSize, sizeof (SMM_CPU_SYNC_CONTEXT), &Co= ntextSize); + if (RETURN_ERROR (Status)) { + return Status; + } + + // + // Allocate Buffer for Context + // + *Context =3D AllocatePool (ContextSize); + if (*Context =3D=3D NULL) { + return RETURN_OUT_OF_RESOURCES; + } + + (*Context)->ArrivedCpuCountUponLock =3D 0; + + // + // Save NumberOfCpus + // + (*Context)->NumberOfCpus =3D NumberOfCpus; + + // + // Calculate total semaphore size + // + OneSemSize =3D GetSpinLockProperties (); + ASSERT (sizeof (SMM_CPU_SYNC_SEMAPHORE) <=3D OneSemSize); + + Status =3D SafeUintnAdd (1, NumberOfCpus, &NumSem); + if (RETURN_ERROR (Status)) { + goto ON_ERROR; + } + + Status =3D SafeUintnMult (NumSem, OneSemSize, &TotalSemSize); + if (RETURN_ERROR (Status)) { + goto ON_ERROR; + } + + // + // Allocate for Semaphores in the *Context + // + (*Context)->SemBufferPages =3D EFI_SIZE_TO_PAGES (TotalSemSize); + (*Context)->SemBuffer =3D AllocatePages ((*Context)->SemBufferPages= ); + if ((*Context)->SemBuffer =3D=3D NULL) { + Status =3D RETURN_OUT_OF_RESOURCES; + goto ON_ERROR; + } + + // + // Assign Global Semaphore pointer + // + SemAddr =3D (UINTN)(*Context)->SemBuffer; + (*Context)->CpuCount =3D (SMM_CPU_SYNC_SEMAPHORE *)SemAddr; + *(*Context)->CpuCount =3D 0; + + SemAddr +=3D OneSemSize; + + // + // Assign CPU Semaphore pointer + // + CpuSem =3D (*Context)->CpuSem; + for (CpuIndex =3D 0; CpuIndex < NumberOfCpus; CpuIndex++) { + CpuSem->Run =3D (SMM_CPU_SYNC_SEMAPHORE *)SemAddr; + *CpuSem->Run =3D 0; + + CpuSem++; + SemAddr +=3D OneSemSize; + } + + return RETURN_SUCCESS; + +ON_ERROR: + FreePool (*Context); + return Status; +} + +/** + Deinit an allocated SMM CPU Sync context. The resources allocated in Smm= CpuSyncContextInit() will + be freed. + + If Context is NULL, then ASSERT(). + + @param[in,out] Context Pointer to the SMM CPU Sync context object t= o be deinitialized. + +**/ +VOID +EFIAPI +SmmCpuSyncContextDeinit ( + IN OUT SMM_CPU_SYNC_CONTEXT *Context + ) +{ + ASSERT (Context !=3D NULL); + + FreePages (Context->SemBuffer, Context->SemBufferPages); + + FreePool (Context); +} + +/** + Reset SMM CPU Sync context. SMM CPU Sync context will be reset to the in= itialized state. + + This function is called by one of CPUs after all CPUs are ready to exit = SMI, which allows CPU to + check into the next SMI from this point. + + If Context is NULL, then ASSERT(). + + @param[in,out] Context Pointer to the SMM CPU Sync context object t= o be reset. + +**/ +VOID +EFIAPI +SmmCpuSyncContextReset ( + IN OUT SMM_CPU_SYNC_CONTEXT *Context + ) +{ + ASSERT (Context !=3D NULL); + + Context->ArrivedCpuCountUponLock =3D 0; + *Context->CpuCount =3D 0; +} + +/** + Get current number of arrived CPU in SMI. + + BSP might need to know the current number of arrived CPU in SMI to make = sure all APs + in SMI. This API can be for that purpose. + + If Context is NULL, then ASSERT(). + + @param[in] Context Pointer to the SMM CPU Sync context object. + + @retval Current number of arrived CPU in SMI. + +**/ +UINTN +EFIAPI +SmmCpuSyncGetArrivedCpuCount ( + IN SMM_CPU_SYNC_CONTEXT *Context + ) +{ + UINT32 Value; + + ASSERT (Context !=3D NULL); + + Value =3D *Context->CpuCount; + + if (Value =3D=3D (UINT32)-1) { + return Context->ArrivedCpuCountUponLock; + } + + return Value; +} + +/** + Performs an atomic operation to check in CPU. + + When SMI happens, all processors including BSP enter to SMM mode by call= ing SmmCpuSyncCheckInCpu(). + + If Context is NULL, then ASSERT(). + If CpuIndex exceeds the range of all CPUs in the system, then ASSERT(). + + @param[in,out] Context 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_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_CONTEXT *Context, + IN UINTN CpuIndex + ) +{ + ASSERT (Context !=3D NULL); + + ASSERT (CpuIndex < Context->NumberOfCpus); + + // + // Check to return if CpuCount has already been locked. + // + if (InternalReleaseSemaphore (Context->CpuCount) =3D=3D MAX_UINT32) { + return RETURN_ABORTED; + } + + return RETURN_SUCCESS; +} + +/** + Performs an atomic operation to check out CPU. + + This function can be called in error handling flow for the CPU who calls= CheckInCpu() earlier. + The caller shall make sure the CPU specified by CpuIndex has already che= cked-in. + + If Context is NULL, then ASSERT(). + If CpuIndex exceeds the range of all CPUs in the system, then ASSERT(). + + @param[in,out] Context 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_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_CONTEXT *Context, + IN UINTN CpuIndex + ) +{ + ASSERT (Context !=3D NULL); + + ASSERT (CpuIndex < Context->NumberOfCpus); + + if (InternalWaitForSemaphore (Context->CpuCount) =3D=3D MAX_UINT32) { + return RETURN_ABORTED; + } + + return RETURN_SUCCESS; +} + +/** + Performs an atomic operation lock door for CPU checkin and checkout. Aft= er this function: + CPU can not check in via SmmCpuSyncCheckInCpu(). + CPU can not check out via SmmCpuSyncCheckOutCpu(). + + The CPU specified by CpuIndex is elected to lock door. The caller shall = make sure the CpuIndex + is the actual CPU calling this function to avoid the undefined behavior. + + If Context is NULL, then ASSERT(). + If CpuCount is NULL, then ASSERT(). + If CpuIndex exceeds the range of all CPUs in the system, then ASSERT(). + + @param[in,out] Context Pointer to the SMM CPU Sync context ob= ject. + @param[in] CpuIndex Indicate which CPU to lock door. + @param[out] CpuCount Number of arrived CPU in SMI after loo= k door. + +**/ +VOID +EFIAPI +SmmCpuSyncLockDoor ( + IN OUT SMM_CPU_SYNC_CONTEXT *Context, + IN UINTN CpuIndex, + OUT UINTN *CpuCount + ) +{ + ASSERT (Context !=3D NULL); + + ASSERT (CpuCount !=3D NULL); + + ASSERT (CpuIndex < Context->NumberOfCpus); + + // + // Temporarily record the CpuCount into the ArrivedCpuCountUponLock befo= re lock door. + // Recording before lock door is to avoid the Context->CpuCount is locke= d but possible + // Context->ArrivedCpuCountUponLock is not updated. + // + Context->ArrivedCpuCountUponLock =3D *Context->CpuCount; + + // + // Lock door operation + // + *CpuCount =3D InternalLockdownSemaphore (Context->CpuCount); + + // + // Update the ArrivedCpuCountUponLock + // + Context->ArrivedCpuCountUponLock =3D *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. + The caller shall make sure the BspIndex is the actual CPU calling this f= unction to avoid the undefined behavior. + The caller shall make sure the NumberOfAPs have already checked-in to av= oid the undefined behavior. + + If Context is NULL, then ASSERT(). + If NumberOfAPs >=3D All CPUs in system, then ASSERT(). + If BspIndex exceeds the range of all CPUs in the system, then ASSERT(). + + 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] Context 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. + +**/ +VOID +EFIAPI +SmmCpuSyncWaitForAPs ( + IN OUT SMM_CPU_SYNC_CONTEXT *Context, + IN UINTN NumberOfAPs, + IN UINTN BspIndex + ) +{ + UINTN Arrived; + + ASSERT (Context !=3D NULL); + + ASSERT (NumberOfAPs < Context->NumberOfCpus); + + ASSERT (BspIndex < Context->NumberOfCpus); + + for (Arrived =3D 0; Arrived < NumberOfAPs; Arrived++) { + InternalWaitForSemaphore (Context->CpuSem[BspIndex].Run); + } +} + +/** + Used by the BSP to release one AP. + + The AP is specified by CpuIndex. The BSP is specified by BspIndex. + The caller shall make sure the BspIndex is the actual CPU calling this f= unction to avoid the undefined behavior. + The caller shall make sure the CpuIndex has already checked-in to avoid = the undefined behavior. + + If Context is NULL, then ASSERT(). + If CpuIndex =3D=3D BspIndex, then ASSERT(). + If BspIndex or CpuIndex exceed the range of all CPUs in the system, then= ASSERT(). + + @param[in,out] Context 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. + +**/ +VOID +EFIAPI +SmmCpuSyncReleaseOneAp ( + IN OUT SMM_CPU_SYNC_CONTEXT *Context, + IN UINTN CpuIndex, + IN UINTN BspIndex + ) +{ + ASSERT (Context !=3D NULL); + + ASSERT (BspIndex !=3D CpuIndex); + + ASSERT (CpuIndex < Context->NumberOfCpus); + + ASSERT (BspIndex < Context->NumberOfCpus); + + InternalReleaseSemaphore (Context->CpuSem[CpuIndex].Run); +} + +/** + Used by the AP to wait BSP. + + The AP is specified by CpuIndex. + The caller shall make sure the CpuIndex is the actual CPU calling this f= unction to avoid the undefined behavior. + The BSP is specified by BspIndex. + + If Context is NULL, then ASSERT(). + If CpuIndex =3D=3D BspIndex, then ASSERT(). + If BspIndex or CpuIndex exceed the range of all CPUs in the system, then= ASSERT(). + + Note: + This function is blocking mode, and it will return only after the AP rel= eased by + calling SmmCpuSyncReleaseOneAp(): + BSP: ReleaseOneAp --> AP: WaitForBsp + + @param[in,out] Context 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. + +**/ +VOID +EFIAPI +SmmCpuSyncWaitForBsp ( + IN OUT SMM_CPU_SYNC_CONTEXT *Context, + IN UINTN CpuIndex, + IN UINTN BspIndex + ) +{ + ASSERT (Context !=3D NULL); + + ASSERT (BspIndex !=3D CpuIndex); + + ASSERT (CpuIndex < Context->NumberOfCpus); + + ASSERT (BspIndex < Context->NumberOfCpus); + + InternalWaitForSemaphore (Context->CpuSem[CpuIndex].Run); +} + +/** + Used by the AP to release BSP. + + The AP is specified by CpuIndex. + The caller shall make sure the CpuIndex is the actual CPU calling this f= unction to avoid the undefined behavior. + The BSP is specified by BspIndex. + + If Context is NULL, then ASSERT(). + If CpuIndex =3D=3D BspIndex, then ASSERT(). + If BspIndex or CpuIndex exceed the range of all CPUs in the system, then= ASSERT(). + + @param[in,out] Context 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. + +**/ +VOID +EFIAPI +SmmCpuSyncReleaseBsp ( + IN OUT SMM_CPU_SYNC_CONTEXT *Context, + IN UINTN CpuIndex, + IN UINTN BspIndex + ) +{ + ASSERT (Context !=3D NULL); + + ASSERT (BspIndex !=3D CpuIndex); + + ASSERT (CpuIndex < Context->NumberOfCpus); + + ASSERT (BspIndex < Context->NumberOfCpus); + + InternalReleaseSemaphore (Context->CpuSem[BspIndex].Run); +} diff --git a/UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf b/UefiCpuPk= g/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf new file mode 100644 index 0000000000..6b0d49c30a --- /dev/null +++ b/UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf @@ -0,0 +1,34 @@ +## @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 + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + MemoryAllocationLib + SafeIntLib + SynchronizationLib + +[Pcd] + +[Protocols] diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index 074fd77461..28eed85bce 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -54,10 +54,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 +155,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 (#112705): https://edk2.groups.io/g/devel/message/112705 Mute This Topic: https://groups.io/mt/103259036/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 Mon May 13 18:23:36 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+112706+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+112706+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1702970338; cv=none; d=zohomail.com; s=zohoarc; b=mJr70IjzmO9b76rptGUMBwoU/iyDUzY7RhUHXGPPvRLolgyJInr4H5xaf9OWxFP5LbPyPNjF7X2aBD4UYbBeTqUbYg7Ffp+rEzGcMd176P17qY6gyocZ548lGo3d6ZBaDGufU7lpBii7O1TayvRWi14OyUzM2d/FXMTVTpF1Aq0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702970338; 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=EwI2uOUKvkYAuMX4TB/owdwBfnpHDZqmWFOGJnGGecc=; b=YdI76NjfFYP09Tto5CtvWIOBeHlfsWQHx/Cu5CNaaZBC8gPYJ8UUfJCKgYRzkukt5x7b5DlS9YsmTiV6Pu3bQ7Lmmb/x6M3mWGYTs/5RWzq/e/EhxiKnCuFL7QytgXlvg3/DSIbOyvOUml6SEYtvBcBZzyYWPmqGJnCTZfgPnbY= 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+112706+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 1702970338252368.28627520625594; Mon, 18 Dec 2023 23:18:58 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=5ar7XLufuKwg8EiEcKqAtRtJEHhhgSVZpbL6CbAf+A0=; 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=1702970337; v=1; b=LJWdofOrpDPN/6Q55bp/v3gVFahVCw51al2hF3/zNMntHmWeP5ZVAo81vJ80yUubcmYj4JtG 7+kFZ4pCZARuW1zHxLgBCPZhlE3owAQ6i85FqvvzR8M+xhSGwpX+n9/Lbn82dBOhGws8xiPA9zF Rb+L19PYypxhorvMV/zHjwwQ= X-Received: by 127.0.0.2 with SMTP id ddM3YY1788612xFDOEOlowrn; Mon, 18 Dec 2023 23:18:57 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) by mx.groups.io with SMTP id smtpd.web10.7322.1702970325397750965 for ; Mon, 18 Dec 2023 23:18:57 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="2830930" X-IronPort-AV: E=Sophos;i="6.04,287,1695711600"; d="scan'208";a="2830930" X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2023 23:18:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="899262074" X-IronPort-AV: E=Sophos;i="6.04,287,1695711600"; d="scan'208";a="899262074" X-Received: from sh1gapp1009.ccr.corp.intel.com ([10.239.189.219]) by orsmga004.jf.intel.com with ESMTP; 18 Dec 2023 23:18:54 -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 v5 5/8] OvmfPkg: Specifies SmmCpuSyncLib instance Date: Tue, 19 Dec 2023 15:18:36 +0800 Message-Id: <20231219071839.4248-6-jiaxin.wu@intel.com> In-Reply-To: <20231219071839.4248-1-jiaxin.wu@intel.com> References: <20231219071839.4248-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: YdAa8QSqt9eevbQNTmc2QEQFx1787277AA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1702970339751100023 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 Reviewed-by: Ray Ni --- OvmfPkg/CloudHv/CloudHvX64.dsc | 1 + OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + 4 files changed, 4 insertions(+) diff --git a/OvmfPkg/CloudHv/CloudHvX64.dsc b/OvmfPkg/CloudHv/CloudHvX64.dsc index 1660548e07..af594959a9 100644 --- a/OvmfPkg/CloudHv/CloudHvX64.dsc +++ b/OvmfPkg/CloudHv/CloudHvX64.dsc @@ -907,10 +907,11 @@ } UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf { SmmCpuPlatformHookLib|OvmfPkg/Library/SmmCpuPlatformHookLibQemu/SmmC= puPlatformHookLibQemu.inf SmmCpuFeaturesLib|OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLi= b.inf + SmmCpuSyncLib|UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf } =20 # # Variable driver stack (SMM) # diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 6e8488007c..28379961a7 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -952,10 +952,11 @@ UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf { SmmCpuPlatformHookLib|OvmfPkg/Library/SmmCpuPlatformHookLibQemu/SmmC= puPlatformHookLibQemu.inf SmmCpuFeaturesLib|OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLi= b.inf MmSaveStateLib|UefiCpuPkg/Library/MmSaveStateLib/AmdMmSaveStateLib.i= nf + SmmCpuSyncLib|UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf } =20 # # Variable driver stack (SMM) # diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 413ea71984..5e9eee628a 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -970,10 +970,11 @@ UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf { SmmCpuPlatformHookLib|OvmfPkg/Library/SmmCpuPlatformHookLibQemu/SmmC= puPlatformHookLibQemu.inf SmmCpuFeaturesLib|OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLi= b.inf MmSaveStateLib|UefiCpuPkg/Library/MmSaveStateLib/AmdMmSaveStateLib.i= nf + SmmCpuSyncLib|UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf } =20 # # Variable driver stack (SMM) # diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index f000092d70..bf4c7906c4 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -1040,10 +1040,11 @@ UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf { SmmCpuPlatformHookLib|OvmfPkg/Library/SmmCpuPlatformHookLibQemu/SmmC= puPlatformHookLibQemu.inf SmmCpuFeaturesLib|OvmfPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLi= b.inf MmSaveStateLib|UefiCpuPkg/Library/MmSaveStateLib/AmdMmSaveStateLib.i= nf + SmmCpuSyncLib|UefiCpuPkg/Library/SmmCpuSyncLib/SmmCpuSyncLib.inf } =20 # # Variable driver stack (SMM) # --=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 (#112706): https://edk2.groups.io/g/devel/message/112706 Mute This Topic: https://groups.io/mt/103259037/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 Mon May 13 18:23:36 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+112707+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+112707+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1702970340; cv=none; d=zohomail.com; s=zohoarc; b=BfoSbsgyK5ZcXTZP6jCbslhzZVPcG6+/f12XGt3J3F7qEjOoBlrbvS9JM4Gk7/EeE3UFDHaE+I1taTVtZS54+LudryKLTteBwBwi74FDj76DXTCv4p2vH8l2uL7Y4DiTjBraOQRGf7aih/hIlYKk1b//VHqBGfJGXvR1WZR+UEQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702970340; 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=eBso+JYv6x8+K/mK6JmGYosBoP5XHBj0GqnQ5G+4EiU=; b=c6+hy1zZiktg8aVgyyFz8V2cAEIcdwRXThCvDdmGJ/19/Ti2OriFUFsEt9hxFnrWBrKqiOd2qIzk7/pGX8JA8ob8TRmNBReVfcB0g5dua9vtmQ6HdcM4acRMkCuNff1LxmWYA6iFkPPQJLODvYLAr2wd/dj1tVxEfH/+0UtA1kI= 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+112707+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 1702970340815553.2488392132926; Mon, 18 Dec 2023 23:19:00 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=xKFY8xzXH9uiyzKOpEHq3j8xUuem3duonnTYKwHf0Y8=; 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=1702970340; v=1; b=H5Msfs0cZnipFVMR/pI1O5kmCtLd3hWqERNxdp9frPz93fXpPVqOk68tDGPuIF9dmNRu5RfP XgFmOB6nryZSNz11+DmcTxsqivAXDyWWTyOsTvtNe9VJ+lUr6fwqQCgnW+ShYcc5bROj4dEAq7H JrHBTAI6s0n9aHe7MJ2c5BJw= X-Received: by 127.0.0.2 with SMTP id dBqHYY1788612xLYZmzO6O5i; Mon, 18 Dec 2023 23:19:00 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) by mx.groups.io with SMTP id smtpd.web10.7322.1702970325397750965 for ; Mon, 18 Dec 2023 23:19:00 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="2830935" X-IronPort-AV: E=Sophos;i="6.04,287,1695711600"; d="scan'208";a="2830935" X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2023 23:18:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="899262082" X-IronPort-AV: E=Sophos;i="6.04,287,1695711600"; d="scan'208";a="899262082" X-Received: from sh1gapp1009.ccr.corp.intel.com ([10.239.189.219]) by orsmga004.jf.intel.com with ESMTP; 18 Dec 2023 23:18:57 -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 v5 6/8] UefiPayloadPkg: Specifies SmmCpuSyncLib instance Date: Tue, 19 Dec 2023 15:18:37 +0800 Message-Id: <20231219071839.4248-7-jiaxin.wu@intel.com> In-Reply-To: <20231219071839.4248-1-jiaxin.wu@intel.com> References: <20231219071839.4248-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: 2UICxabhpuSh4xDbMjXcGxl5x1787277AA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1702970341756100025 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 Reviewed-by: Ray Ni --- 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 (#112707): https://edk2.groups.io/g/devel/message/112707 Mute This Topic: https://groups.io/mt/103259038/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 Mon May 13 18:23:36 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+112708+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+112708+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1702970343; cv=none; d=zohomail.com; s=zohoarc; b=myA5ECJSK9OE5e7qP4f8SDRhZUwBxVUC51hlS9OZH4mqezlSFn5OcDimB45HUW6wFh7208C/ADMB3jkX8kA6q1ufpmdi7h+O9RlPP5gYEF17Hm9preHKRa6TKmsGvHio5S1VIfVek6OVDe/ukFMbNXZY2gwRf0iXC+gaigb0pEk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702970343; 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=rJjvFmZ+6R4eUN0Ak21GxvEEsWlyA8OTHanvteei5yE=; b=NCdp0KCeA2y1H/ML8E2RerdUq88ytHU8pXroA7Dm0rXJSLKCsdBXC1ssJQAjvbIwuM+t7BBcvBeQLmwvutseb9cOiLQ2LMs7+f0ZBnkugAksMN/aK3ClTkBfVb1GhJURiAWMj42jLln36r90aN7DEUjA4uTmSlqu06vr/ZlHrXo= 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+112708+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 1702970343232879.6761655415891; Mon, 18 Dec 2023 23:19:03 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=PGOc/hUYAGu58YGDjCFIdyvfbrYqe5S0kvWOTyh6SkI=; 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=1702970342; v=1; b=lAVRDg4sw4bTykJoheAVbW5iU+sueOXm7KMXUu8fDjpPOQQjuK9SlQCoLDN+WA5p5DjTD4jV 6gCCENNhOt59/mr2z1DFB6KuNh08OmRsDC0HzdChf1STeOW8BLBOWYCmspGenOgiULY4gR8XwMU d2DNV49OINB09WtEzBIyPoj4= X-Received: by 127.0.0.2 with SMTP id QvTqYY1788612xfg5PDcaNBO; Mon, 18 Dec 2023 23:19:02 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) by mx.groups.io with SMTP id smtpd.web10.7322.1702970325397750965 for ; Mon, 18 Dec 2023 23:19:02 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="2830939" X-IronPort-AV: E=Sophos;i="6.04,287,1695711600"; d="scan'208";a="2830939" X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2023 23:19:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="899262088" X-IronPort-AV: E=Sophos;i="6.04,287,1695711600"; d="scan'208";a="899262088" X-Received: from sh1gapp1009.ccr.corp.intel.com ([10.239.189.219]) by orsmga004.jf.intel.com with ESMTP; 18 Dec 2023 23:18:59 -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 v5 7/8] UefiCpuPkg/PiSmmCpuDxeSmm: Simplify RunningApCount decrement Date: Tue, 19 Dec 2023 15:18:38 +0800 Message-Id: <20231219071839.4248-8-jiaxin.wu@intel.com> In-Reply-To: <20231219071839.4248-1-jiaxin.wu@intel.com> References: <20231219071839.4248-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: JvaszO00pNThtuY9SA4wXWkZx1787277AA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1702970343757100029 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" To decrease the count of RunningApCount, InterlockedDecrement is enough to achieve that. This patch is to simplify RunningApCount decrement. Cc: Laszlo Ersek Cc: Eric Dong Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu Reviewed-by: Ray Ni --- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxe= Smm/MpService.c index 54542262a2..9b477b6695 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -1450,11 +1450,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 (); --=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 (#112708): https://edk2.groups.io/g/devel/message/112708 Mute This Topic: https://groups.io/mt/103259039/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 Mon May 13 18:23:36 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+112709+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+112709+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1702970345; cv=none; d=zohomail.com; s=zohoarc; b=lv9ggcpkkJp+Y3+B/YAJJsqFtfqcox4Y6ljsAtYY2CaTJjtZ3QrSEYJ/H7OqsXHEonz8qHTcFQQJDc+KRaaWhTdkfF2NwoVwreceXWIm+Gmf2EL/uTOHON99qDhnXCkpqxo/3u7i2zB/VMrnT7wFHZjYyIx7P/fu3YBiIhmKlGs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702970345; 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=t5d8r3zpAcgoq7pNeH0B2kXdpxvzTdgNDh1rUjjUU/0=; b=IgJHGuQu286lu6p+T7QTOO2a1INl+p6EyJtX3zjcPaJhU3udkeIRYrxcu8a5BSn0oaOwU9IuswT3UBOEp8hafSybCgnXtlQnMeKkQJEqhuuOjHyBC0Bwn6LiW+HV1Y5qnnYRGfV1IByu9GqImvRmPps19NPI3Lutt9OqbaUDsUY= 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+112709+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 1702970345668670.5289428267928; Mon, 18 Dec 2023 23:19:05 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=IfXJDq3b5Mp2TSNxAKH+LWCA4s6S80UpagZyToaFyak=; 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=1702970345; v=1; b=ZlcN4C65l/MXJygcD5ujRsX4IrrfP2izOr/ZEljK7j0F6WIWzTOH2uUIKpHEM1tGKMiyRMX9 PzS8NtIP+Is61Qd4LTKgM7MVjf7YMuYS2JnfX1+7lFkR1juvUWDFpF/Z2uGZwzhi0Obv6Zyxj3w 5JFBnUFgeOkkothbgyiMaaWM= X-Received: by 127.0.0.2 with SMTP id earTYY1788612xokpEnZABV4; Mon, 18 Dec 2023 23:19:05 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) by mx.groups.io with SMTP id smtpd.web10.7322.1702970325397750965 for ; Mon, 18 Dec 2023 23:19:04 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="2830944" X-IronPort-AV: E=Sophos;i="6.04,287,1695711600"; d="scan'208";a="2830944" X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Dec 2023 23:19:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10928"; a="899262094" X-IronPort-AV: E=Sophos;i="6.04,287,1695711600"; d="scan'208";a="899262094" X-Received: from sh1gapp1009.ccr.corp.intel.com ([10.239.189.219]) by orsmga004.jf.intel.com with ESMTP; 18 Dec 2023 23:19:02 -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 v5 8/8] UefiCpuPkg/PiSmmCpuDxeSmm: Consume SmmCpuSyncLib Date: Tue, 19 Dec 2023 15:18:39 +0800 Message-Id: <20231219071839.4248-9-jiaxin.wu@intel.com> In-Reply-To: <20231219071839.4248-1-jiaxin.wu@intel.com> References: <20231219071839.4248-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: RGvKqOQaXAbJNYqiWxzfgIWDx1787277AA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1702970347836100035 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 Reviewed-by: Ray Ni --- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 274 +++++++----------------= ---- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 6 +- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 1 + 3 files changed, 68 insertions(+), 213 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxe= Smm/MpService.c index 9b477b6695..4fbb0bba87 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->SyncContext, Index, gSmmCpuP= rivate->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] @@ -292,35 +138,35 @@ AllCpusInSmmExceptBlockedDisabled ( =20 BlockedCount =3D 0; DisabledCount =3D 0; =20 // - // 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 (SmmCpuSyncGetArrivedCpuCount (mSmmMpSyncData->SyncContext) <=3D = mNumberOfCpus); =20 // // Check whether all CPUs in SMM. // - if (*mSmmMpSyncData->Counter =3D=3D mNumberOfCpus) { + if (SmmCpuSyncGetArrivedCpuCount (mSmmMpSyncData->SyncContext) =3D=3D mN= umberOfCpus) { 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 (SmmCpuSyncGetArrivedCpuCount (mSmmMpSyncData->SyncContext) + Blocked= Count + DisabledCount >=3D mNumberOfCpus) { return TRUE; } =20 return FALSE; } @@ -396,11 +242,11 @@ SmmWaitForApArrival ( PERF_FUNCTION_BEGIN (); =20 DelayedCount =3D 0; BlockedCount =3D 0; =20 - ASSERT (*mSmmMpSyncData->Counter <=3D mNumberOfCpus); + ASSERT (SmmCpuSyncGetArrivedCpuCount (mSmmMpSyncData->SyncContext) <=3D = mNumberOfCpus); =20 LmceEn =3D FALSE; LmceSignal =3D FALSE; if (mMachineCheckSupported) { LmceEn =3D IsLmceOsEnabled (); @@ -447,11 +293,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 (SmmCpuSyncGetArrivedCpuCount (mSmmMpSyncData->SyncContext) < mNumber= OfCpus) { // // 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 +456,20 @@ VOID BSPHandler ( IN UINTN CpuIndex, IN SMM_CPU_SYNC_MODE SyncMode ) { + 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 +507,31 @@ BSPHandler ( // Wait for APs to arrive // SmmWaitForApArrival (); =20 // - // Lock the counter down and retrieve the number of APs + // Lock door for late coming CPU checkin and retrieve the Arrived numb= er of APs // *mSmmMpSyncData->AllCpusInSync =3D TRUE; - ApCount =3D LockdownSemaphore (mSmmMpSyncData->= Counter) - 1; + + SmmCpuSyncLockDoor (mSmmMpSyncData->SyncContext, CpuIndex, &CpuCount); + + ApCount =3D CpuCount - 1; =20 // // Wait for all APs to get ready for programming MTRRs // - WaitForAllAPs (ApCount); + SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, 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 +539,28 @@ BSPHandler ( MtrrGetAllMtrrs (&Mtrrs); =20 // // Wait for all APs to complete their MTRR saving // - WaitForAllAPs (ApCount); + SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex= ); =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->SyncContext, ApCount, CpuIndex= ); } } =20 // // The BUSY lock is initialized to Acquired state @@ -741,14 +592,18 @@ 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 coming CPU checkin and retrieve the Arrived numb= er of APs // *mSmmMpSyncData->AllCpusInSync =3D TRUE; - ApCount =3D LockdownSemaphore (mSmmMpSyncData->= Counter) - 1; + + SmmCpuSyncLockDoor (mSmmMpSyncData->SyncContext, CpuIndex, &CpuCount); + + ApCount =3D CpuCount - 1; + // // Make sure all APs have their Present flag set // while (TRUE) { PresentCount =3D 0; @@ -771,11 +626,11 @@ BSPHandler ( ReleaseAllAPs (); =20 // // Wait for all APs to complete their pending tasks // - WaitForAllAPs (ApCount); + SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); =20 if (SmmCpuFeaturesNeedConfigureMtrrs ()) { // // Signal APs to restore MTRRs // @@ -788,11 +643,11 @@ BSPHandler ( MtrrSetAllMtrrs (&Mtrrs); =20 // // Wait for all APs to complete MTRR programming // - WaitForAllAPs (ApCount); + SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); } =20 // // Stop source level debug in BSP handler, the code below will not be // debugged. @@ -816,11 +671,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->SyncContext, 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 +697,11 @@ BSPHandler ( } =20 // // Allow APs to check in from this point on // - *mSmmMpSyncData->Counter =3D 0; + SmmCpuSyncContextReset (mSmmMpSyncData->SyncContext); *mSmmMpSyncData->AllCpusInSync =3D FALSE; mSmmMpSyncData->AllApArrivedWithException =3D FALSE; =20 PERF_FUNCTION_END (); } @@ -912,21 +767,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->SyncContext, 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->SyncContext, CpuIndex); return; } } =20 // @@ -942,50 +797,50 @@ APHandler ( =20 if ((SyncMode =3D=3D SmmCpuSyncModeTradition) || SmmCpuFeaturesNeedConfi= gureMtrrs ()) { // // Notify BSP of arrival at this point // - ReleaseBsp (mSmmMpSyncData->CpuData[BspIndex].Run); + SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); } =20 if (SmmCpuFeaturesNeedConfigureMtrrs ()) { // // Wait for the signal from BSP to backup MTRRs // - WaitForBsp (mSmmMpSyncData->CpuData[CpuIndex].Run); + SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); =20 // // Backup OS MTRRs // MtrrGetAllMtrrs (&Mtrrs); =20 // // Signal BSP the completion of this AP // - ReleaseBsp (mSmmMpSyncData->CpuData[BspIndex].Run); + SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); =20 // // Wait for BSP's signal to program MTRRs // - WaitForBsp (mSmmMpSyncData->CpuData[CpuIndex].Run); + SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); =20 // // Replace OS MTRRs with SMI MTRRs // ReplaceOSMtrrs (CpuIndex); =20 // // Signal BSP the completion of this AP // - ReleaseBsp (mSmmMpSyncData->CpuData[BspIndex].Run); + SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); } =20 while (TRUE) { // // Wait for something to happen // - WaitForBsp (mSmmMpSyncData->CpuData[CpuIndex].Run); + SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); =20 // // Check if BSP wants to exit SMM // if (!(*mSmmMpSyncData->InsideSmm)) { @@ -1021,16 +876,16 @@ APHandler ( =20 if (SmmCpuFeaturesNeedConfigureMtrrs ()) { // // Notify BSP the readiness of this AP to program MTRRs // - ReleaseBsp (mSmmMpSyncData->CpuData[BspIndex].Run); + SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); =20 // // Wait for the signal from BSP to program MTRRs // - WaitForBsp (mSmmMpSyncData->CpuData[CpuIndex].Run); + SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); =20 // // Restore OS MTRRs // SmmCpuFeaturesReenableSmrr (); @@ -1038,26 +893,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->SyncContext, CpuIndex, BspIndex); =20 // // Wait for the signal from BSP to Reset states/semaphore for this proce= ssor // - WaitForBsp (mSmmMpSyncData->CpuData[CpuIndex].Run); + SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, 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->SyncContext, CpuIndex, BspIndex); } =20 /** Checks whether the input token is the current used token. =20 @@ -1321,11 +1176,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->SyncContext, CpuIndex, gSmmCpuPr= ivate->SmmCoreEntryContext.CurrentlyExecutingCpu); =20 if (Token =3D=3D NULL) { AcquireSpinLock (mSmmMpSyncData->CpuData[CpuIndex].Busy); ReleaseSpinLock (mSmmMpSyncData->CpuData[CpuIndex].Busy); } @@ -1725,14 +1580,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->SyncContext, CpuIndex)" retu= rn 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->SyncContext, C= puIndex))) { // // 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 +1680,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 +1799,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 +1812,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 +1830,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 +1861,36 @@ InitializeMpSyncData ( } } =20 mSmmMpSyncData->EffectiveSyncMode =3D mCpuSmmSyncMode; =20 - mSmmMpSyncData->Counter =3D mSmmCpuSemaphores.SemaphoreGlobal.Co= unter; + Status =3D SmmCpuSyncContextInit (gSmmCpuPrivate->SmmCoreEntryContext.= NumberOfCpus, &mSmmMpSyncData->SyncContext); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "InitializeMpSyncData: SmmCpuSyncContextInit re= turn error %r!\n", Status)); + CpuDeadLoop (); + return; + } + + ASSERT (mSmmMpSyncData->SyncContext !=3D NULL); + mSmmMpSyncData->InsideSmm =3D mSmmCpuSemaphores.SemaphoreGlobal.In= sideSmm; mSmmMpSyncData->AllCpusInSync =3D mSmmCpuSemaphores.SemaphoreGlobal.Al= lCpusInSync; ASSERT ( - mSmmMpSyncData->Counter !=3D NULL && mSmmMpSyncData->InsideSmm !=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 f18345881b..a2fa4f6734 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_CONTEXT *SyncContext; } 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 372596f24c..793220aba3 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 gEfiSmmConfigurationProtocolGuid ## PRODUCES gEfiSmmCpuProtocolGuid ## 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 (#112709): https://edk2.groups.io/g/devel/message/112709 Mute This Topic: https://groups.io/mt/103259040/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-