From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 89942740047 for ; Fri, 3 Nov 2023 15:30:37 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=2Uh2AXaBxsryNkAxjV/9n5K4GOFYmKihMu+LxvH6JAA=; 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=1699025436; v=1; b=cwhTR+/U9xSAHQWQf+5TceleZvlXAPPOGrzTI6ckoP0tR2mP/UJKAKiyFfaiSOKvv0FJhkOU KIgt4BM5zCjyVQdcpp2NpVLN9JGtN2Bc/gnJod+m6UqxXEUUeY/Mv5cxSF5vBBi5iYcTt8haeHT a5e7cm8GgzzFaE1RNUg6vQo0= X-Received: by 127.0.0.2 with SMTP id 7Mz8YY7687511x40CGSNtGRZ; Fri, 03 Nov 2023 08:30:36 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by mx.groups.io with SMTP id smtpd.web10.56401.1699025420211463760 for ; Fri, 03 Nov 2023 08:30:35 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10883"; a="1898964" X-IronPort-AV: E=Sophos;i="6.03,273,1694761200"; d="scan'208";a="1898964" X-Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 08:30:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10883"; a="790793363" X-IronPort-AV: E=Sophos;i="6.03,273,1694761200"; d="scan'208";a="790793363" X-Received: from sh1gapp1009.ccr.corp.intel.com ([10.239.189.219]) by orsmga008.jf.intel.com with ESMTP; 03 Nov 2023 08:30:33 -0700 From: "Wu, Jiaxin" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Zeng Star , Gerd Hoffmann , Rahul Kumar Subject: [edk2-devel] [PATCH v1 7/7] UefiCpuPkg/PiSmmCpuDxeSmm: Consume SmmCpuSyncLib Date: Fri, 3 Nov 2023 23:30:12 +0800 Message-Id: <20231103153012.3704-8-jiaxin.wu@intel.com> In-Reply-To: <20231103153012.3704-1-jiaxin.wu@intel.com> References: <20231103153012.3704-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: 2Zwa3sxgwoe4E31XbpIPPFuRx7686176AA= X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b="cwhTR+/U"; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io 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. Change-Id: Id034de47b85743c125f0d76420947e0dd9e69518 Cc: Eric Dong Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 256 +++++---------------------- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 6 +- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 1 + 3 files changed, 49 insertions(+), 214 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c index 5a42a5dd12..a30b2aa234 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 the package-scope register check. // UINT32 *mPackageFirstThreadIndex = NULL; -/** - 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 = *Sem; - if ((Value != 0) && - (InterlockedCompareExchange32 ( - (UINT32 *)Sem, - Value, - Value - 1 - ) == 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 = *Sem; - } while (Value + 1 != 0 && - InterlockedCompareExchange32 ( - (UINT32 *)Sem, - Value, - Value + 1 - ) != 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 = *Sem; - } while (InterlockedCompareExchange32 ( - (UINT32 *)Sem, - Value, - (UINT32)-1 - ) != 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 = 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. @@ -154,57 +42,15 @@ ReleaseAllAPs ( { UINTN Index; for (Index = 0; Index < mMaxNumberOfCpus; Index++) { if (IsPresentAp (Index)) { - ReleaseSemaphore (mSmmMpSyncData->CpuData[Index].Run); + SmmCpuSyncReleaseOneAp (mSmmMpSyncData->SmmCpuSyncCtx, Index, gSmmCpuPrivate->SmmCoreEntryContext.CurrentlyExecutingCpu); } } } -/** - 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 0 -**/ -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. The index of Processor specified by mPackageFirstThreadIndex[PackageIndex] @@ -292,35 +138,35 @@ AllCpusInSmmExceptBlockedDisabled ( BlockedCount = 0; DisabledCount = 0; // - // 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 <= mNumberOfCpus); + ASSERT (SmmCpuSyncGetArrivedCpuCount (mSmmMpSyncData->SmmCpuSyncCtx) <= mNumberOfCpus); // // Check whether all CPUs in SMM. // - if (*mSmmMpSyncData->Counter == mNumberOfCpus) { + if (SmmCpuSyncGetArrivedCpuCount (mSmmMpSyncData->SmmCpuSyncCtx) == mNumberOfCpus) { return TRUE; } // // Check for the Blocked & Disabled Exceptions Case. // GetSmmDelayedBlockedDisabledCount (NULL, &BlockedCount, &DisabledCount); // - // *mSmmMpSyncData->Counter might be updated by all APs concurrently. The value + // The CPU arrival count might be updated by all APs concurrently. The value // can be dynamic changed. If some Aps enter the SMI after the BlockedCount & - // DisabledCount check, then the *mSmmMpSyncData->Counter will be increased, thus - // leading the *mSmmMpSyncData->Counter + BlockedCount + DisabledCount > mNumberOfCpus. + // DisabledCount check, then the CPU arrival count will be increased, thus + // leading the retrieved CPU arrival count + BlockedCount + DisabledCount > mNumberOfCpus. // since the BlockedCount & DisabledCount are local variable, it's ok here only for // the checking of all CPUs In Smm. // - if (*mSmmMpSyncData->Counter + BlockedCount + DisabledCount >= mNumberOfCpus) { + if (SmmCpuSyncGetArrivedCpuCount (mSmmMpSyncData->SmmCpuSyncCtx) + BlockedCount + DisabledCount >= mNumberOfCpus) { return TRUE; } return FALSE; } @@ -396,11 +242,11 @@ SmmWaitForApArrival ( PERF_FUNCTION_BEGIN (); DelayedCount = 0; BlockedCount = 0; - ASSERT (*mSmmMpSyncData->Counter <= mNumberOfCpus); + ASSERT (SmmCpuSyncGetArrivedCpuCount (mSmmMpSyncData->SmmCpuSyncCtx) <= mNumberOfCpus); LmceEn = FALSE; LmceSignal = FALSE; if (mMachineCheckSupported) { LmceEn = IsLmceOsEnabled (); @@ -447,11 +293,11 @@ SmmWaitForApArrival ( // d) We don't add code to check SMI disabling status to skip sending IPI to SMI disabled APs, because: // - In traditional flow, SMI disabling is discouraged. // - In relaxed flow, CheckApArrival() will check SMI disabling status before calling this function. // In both cases, adding SMI-disabling checking code increases overhead. // - if (*mSmmMpSyncData->Counter < mNumberOfCpus) { + if (SmmCpuSyncGetArrivedCpuCount (mSmmMpSyncData->SmmCpuSyncCtx) < mNumberOfCpus) { // // Send SMI IPIs to bring outside processors in // for (Index = 0; Index < mMaxNumberOfCpus; Index++) { if (!(*(mSmmMpSyncData->CpuData[Index].Present)) && (gSmmCpuPrivate->ProcessorInfo[Index].ProcessorId != INVALID_APIC_ID)) { @@ -548,11 +394,11 @@ WaitForAllAPsNotBusy ( Check whether it is an present AP. @param CpuIndex The AP index which calls this function. @retval TRUE It's a present AP. - @retval TRUE This is not an AP or it is not present. + @retval FALSE This is not an AP or it is not present. **/ BOOLEAN IsPresentAp ( IN UINTN CpuIndex @@ -659,30 +505,30 @@ BSPHandler ( // Wait for APs to arrive // SmmWaitForApArrival (); // - // Lock the counter down and retrieve the number of APs + // Lock door for late comming CPU checkin and retrieve the Arrived number of APs // *mSmmMpSyncData->AllCpusInSync = TRUE; - ApCount = LockdownSemaphore (mSmmMpSyncData->Counter) - 1; + ApCount = SmmCpuSyncLockDoor (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex) - 1; // // Wait for all APs: // 1. Make sure all Aps have set the Present. // 2. Get ready for programming MTRRs. // - WaitForAllAPs (ApCount); + SmmCpuSyncWaitForAllAPs (mSmmMpSyncData->SmmCpuSyncCtx, ApCount, CpuIndex); if (SmmCpuFeaturesNeedConfigureMtrrs ()) { // // Signal all APs it's time for backup MTRRs // ReleaseAllAPs (); // - // WaitForBsp() may wait for ever if an AP happens to enter SMM at + // SmmCpuSyncWaitForBsp() may wait for ever if an AP happens to enter SMM at // exactly this point. Please make sure PcdCpuSmmMaxSyncLoops has been set // to a large enough value to avoid this situation. // Note: For HT capable CPUs, threads within a core share the same set of MTRRs. // We do the backup first and then set MTRR to avoid race condition for threads // in the same core. @@ -690,28 +536,28 @@ BSPHandler ( MtrrGetAllMtrrs (&Mtrrs); // // Wait for all APs to complete their MTRR saving // - WaitForAllAPs (ApCount); + SmmCpuSyncWaitForAllAPs (mSmmMpSyncData->SmmCpuSyncCtx, ApCount, CpuIndex); // // Let all processors program SMM MTRRs together // ReleaseAllAPs (); // - // WaitForBsp() may wait for ever if an AP happens to enter SMM at + // SmmCpuSyncWaitForBsp() may wait for ever if an AP happens to enter SMM at // exactly this point. Please make sure PcdCpuSmmMaxSyncLoops has been set // to a large enough value to avoid this situation. // ReplaceOSMtrrs (CpuIndex); // // Wait for all APs to complete their MTRR programming // - WaitForAllAPs (ApCount); + SmmCpuSyncWaitForAllAPs (mSmmMpSyncData->SmmCpuSyncCtx, ApCount, CpuIndex); } } // // The BUSY lock is initialized to Acquired state @@ -743,14 +589,14 @@ BSPHandler ( // make those APs to exit SMI synchronously. APs which arrive later will be excluded and // will run through freely. // if ((SyncMode != SmmCpuSyncModeTradition) && !SmmCpuFeaturesNeedConfigureMtrrs ()) { // - // Lock the counter down and retrieve the number of APs + // Lock door for late comming CPU checkin and retrieve the Arrived number of APs // *mSmmMpSyncData->AllCpusInSync = TRUE; - ApCount = LockdownSemaphore (mSmmMpSyncData->Counter) - 1; + ApCount = SmmCpuSyncLockDoor (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex) - 1; // // Make sure all APs have their Present flag set // while (TRUE) { PresentCount = 0; @@ -774,11 +620,11 @@ BSPHandler ( if (SmmCpuFeaturesNeedConfigureMtrrs ()) { // // Wait for all APs to complete their pending tasks // - WaitForAllAPs (ApCount); + SmmCpuSyncWaitForAllAPs (mSmmMpSyncData->SmmCpuSyncCtx, ApCount, CpuIndex); // // Signal APs to restore MTRRs // ReleaseAllAPs (); @@ -790,11 +636,11 @@ BSPHandler ( MtrrSetAllMtrrs (&Mtrrs); // // Wait for all APs to complete MTRR programming // - WaitForAllAPs (ApCount); + SmmCpuSyncWaitForAllAPs (mSmmMpSyncData->SmmCpuSyncCtx, ApCount, CpuIndex); // // Signal APs to Reset states/semaphore for this processor // ReleaseAllAPs (); @@ -818,11 +664,11 @@ BSPHandler ( // // Gather APs to exit SMM synchronously. Note the Present flag is cleared by now but // WaitForAllAps does not depend on the Present flag. // - WaitForAllAPs (ApCount); + SmmCpuSyncWaitForAllAPs (mSmmMpSyncData->SmmCpuSyncCtx, ApCount, CpuIndex); // // At this point, all APs should have exited from APHandler(). // Migrate the SMM MP performance logging to standard SMM performance logging. // Any SMM MP performance logging after this point will be migrated in next SMI. @@ -844,11 +690,11 @@ BSPHandler ( } // // Allow APs to check in from this point on // - *mSmmMpSyncData->Counter = 0; + SmmCpuSyncContextReset (mSmmMpSyncData->SmmCpuSyncCtx); *mSmmMpSyncData->AllCpusInSync = FALSE; mSmmMpSyncData->AllApArrivedWithException = FALSE; PERF_FUNCTION_END (); } @@ -914,21 +760,21 @@ APHandler ( if (!(*mSmmMpSyncData->InsideSmm)) { // // Give up since BSP is unable to enter SMM // and signal the completion of this AP - // Reduce the mSmmMpSyncData->Counter! + // Reduce the CPU arrival count! // - WaitForSemaphore (mSmmMpSyncData->Counter); + SmmCpuSyncCheckOutCpu (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex); return; } } else { // // Don't know BSP index. Give up without sending IPI to BSP. - // Reduce the mSmmMpSyncData->Counter! + // Reduce the CPU arrival count! // - WaitForSemaphore (mSmmMpSyncData->Counter); + SmmCpuSyncCheckOutCpu (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex); return; } } // @@ -946,50 +792,50 @@ APHandler ( // // Notify BSP of arrival at this point // 1. Set the Present. // 2. Get ready for programming MTRRs. // - ReleaseBsp (mSmmMpSyncData->CpuData[BspIndex].Run); + SmmCpuSyncReleaseBsp (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex, BspIndex); } if (SmmCpuFeaturesNeedConfigureMtrrs ()) { // // Wait for the signal from BSP to backup MTRRs // - WaitForBsp (mSmmMpSyncData->CpuData[CpuIndex].Run); + SmmCpuSyncWaitForBsp (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex, BspIndex); // // Backup OS MTRRs // MtrrGetAllMtrrs (&Mtrrs); // // Signal BSP the completion of this AP // - ReleaseBsp (mSmmMpSyncData->CpuData[BspIndex].Run); + SmmCpuSyncReleaseBsp (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex, BspIndex); // // Wait for BSP's signal to program MTRRs // - WaitForBsp (mSmmMpSyncData->CpuData[CpuIndex].Run); + SmmCpuSyncWaitForBsp (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex, BspIndex); // // Replace OS MTRRs with SMI MTRRs // ReplaceOSMtrrs (CpuIndex); // // Signal BSP the completion of this AP // - ReleaseBsp (mSmmMpSyncData->CpuData[BspIndex].Run); + SmmCpuSyncReleaseBsp (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex, BspIndex); } while (TRUE) { // // Wait for something to happen // - WaitForBsp (mSmmMpSyncData->CpuData[CpuIndex].Run); + SmmCpuSyncWaitForBsp (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex, BspIndex); // // Check if BSP wants to exit SMM // if (!(*mSmmMpSyncData->InsideSmm)) { @@ -1025,43 +871,43 @@ APHandler ( if (SmmCpuFeaturesNeedConfigureMtrrs ()) { // // Notify BSP the readiness of this AP to program MTRRs // - ReleaseBsp (mSmmMpSyncData->CpuData[BspIndex].Run); + SmmCpuSyncReleaseBsp (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex, BspIndex); // // Wait for the signal from BSP to program MTRRs // - WaitForBsp (mSmmMpSyncData->CpuData[CpuIndex].Run); + SmmCpuSyncWaitForBsp (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex, BspIndex); // // Restore OS MTRRs // SmmCpuFeaturesReenableSmrr (); MtrrSetAllMtrrs (&Mtrrs); // // Notify BSP the readiness of this AP to Reset states/semaphore for this processor // - ReleaseBsp (mSmmMpSyncData->CpuData[BspIndex].Run); + SmmCpuSyncReleaseBsp (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex, BspIndex); // // Wait for the signal from BSP to Reset states/semaphore for this processor // - WaitForBsp (mSmmMpSyncData->CpuData[CpuIndex].Run); + SmmCpuSyncWaitForBsp (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex, BspIndex); } // // Reset states/semaphore for this processor // *(mSmmMpSyncData->CpuData[CpuIndex].Present) = FALSE; // // Notify BSP the readiness of this AP to exit SMM // - ReleaseBsp (mSmmMpSyncData->CpuData[BspIndex].Run); + SmmCpuSyncReleaseBsp (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex, BspIndex); } /** Checks whether the input token is the current used token. @@ -1325,11 +1171,11 @@ InternalSmmStartupThisAp ( mSmmMpSyncData->CpuData[CpuIndex].Status = CpuStatus; if (mSmmMpSyncData->CpuData[CpuIndex].Status != NULL) { *mSmmMpSyncData->CpuData[CpuIndex].Status = EFI_NOT_READY; } - ReleaseOneAp (mSmmMpSyncData->CpuData[CpuIndex].Run); + SmmCpuSyncReleaseOneAp (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex, gSmmCpuPrivate->SmmCoreEntryContext.CurrentlyExecutingCpu); if (Token == NULL) { AcquireSpinLock (mSmmMpSyncData->CpuData[CpuIndex].Busy); ReleaseSpinLock (mSmmMpSyncData->CpuData[CpuIndex].Busy); } @@ -1454,11 +1300,11 @@ InternalSmmStartupAllAPs ( // // Decrease the count to mark this processor(AP or BSP) as finished. // if (ProcToken != NULL) { - WaitForSemaphore (&ProcToken->RunningApCount); + InterlockedDecrement (&ProcToken->RunningApCount); } } } ReleaseAllAPs (); @@ -1729,14 +1575,14 @@ SmiRendezvous ( // goto Exit; } else { // // Signal presence of this processor - // mSmmMpSyncData->Counter is increased here! - // "ReleaseSemaphore (mSmmMpSyncData->Counter) == 0" means BSP has already ended the synchronization. + // CPU check in here! + // "RSmmCpuSyncIncreaseArrivalCount (mSmmMpSyncData->SmmCpuSyncCtx) <= 0" means BSP has already ended the synchronization. // - if (ReleaseSemaphore (mSmmMpSyncData->Counter) == 0) { + if (SmmCpuSyncCheckInCpu (mSmmMpSyncData->SmmCpuSyncCtx, CpuIndex) <= 0) { // // BSP has already ended the synchronization, so QUIT!!! // Existing AP is too late now to enter SMI since BSP has already ended the synchronization!!! // @@ -1828,12 +1674,10 @@ SmiRendezvous ( } else { APHandler (CpuIndex, ValidSmi, mSmmMpSyncData->EffectiveSyncMode); } } - ASSERT (*mSmmMpSyncData->CpuData[CpuIndex].Run == 0); - // // Wait for BSP's signal to exit SMI // while (*mSmmMpSyncData->AllCpusInSync) { CpuPause (); @@ -1949,12 +1793,10 @@ InitializeSmmCpuSemaphores ( SemaphoreBlock = AllocatePages (Pages); ASSERT (SemaphoreBlock != NULL); ZeroMem (SemaphoreBlock, TotalSize); SemaphoreAddr = (UINTN)SemaphoreBlock; - mSmmCpuSemaphores.SemaphoreGlobal.Counter = (UINT32 *)SemaphoreAddr; - SemaphoreAddr += SemaphoreSize; mSmmCpuSemaphores.SemaphoreGlobal.InsideSmm = (BOOLEAN *)SemaphoreAddr; SemaphoreAddr += SemaphoreSize; mSmmCpuSemaphores.SemaphoreGlobal.AllCpusInSync = (BOOLEAN *)SemaphoreAddr; SemaphoreAddr += SemaphoreSize; mSmmCpuSemaphores.SemaphoreGlobal.PFLock = (SPIN_LOCK *)SemaphoreAddr; @@ -1964,12 +1806,10 @@ InitializeSmmCpuSemaphores ( SemaphoreAddr += SemaphoreSize; SemaphoreAddr = (UINTN)SemaphoreBlock + GlobalSemaphoresSize; mSmmCpuSemaphores.SemaphoreCpu.Busy = (SPIN_LOCK *)SemaphoreAddr; SemaphoreAddr += ProcessorCount * SemaphoreSize; - mSmmCpuSemaphores.SemaphoreCpu.Run = (UINT32 *)SemaphoreAddr; - SemaphoreAddr += ProcessorCount * SemaphoreSize; mSmmCpuSemaphores.SemaphoreCpu.Present = (BOOLEAN *)SemaphoreAddr; mPFLock = mSmmCpuSemaphores.SemaphoreGlobal.PFLock; mConfigSmmCodeAccessCheckLock = mSmmCpuSemaphores.SemaphoreGlobal.CodeAccessCheckLock; @@ -2003,32 +1843,28 @@ InitializeMpSyncData ( mSmmMpSyncData->BspIndex = (UINT32)-1; } mSmmMpSyncData->EffectiveSyncMode = mCpuSmmSyncMode; - mSmmMpSyncData->Counter = mSmmCpuSemaphores.SemaphoreGlobal.Counter; + mSmmMpSyncData->SmmCpuSyncCtx = SmmCpuSyncContextInit (gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus); mSmmMpSyncData->InsideSmm = mSmmCpuSemaphores.SemaphoreGlobal.InsideSmm; mSmmMpSyncData->AllCpusInSync = mSmmCpuSemaphores.SemaphoreGlobal.AllCpusInSync; ASSERT ( - mSmmMpSyncData->Counter != NULL && mSmmMpSyncData->InsideSmm != NULL && + mSmmMpSyncData->SmmCpuSyncCtx != NULL && mSmmMpSyncData->InsideSmm != NULL && mSmmMpSyncData->AllCpusInSync != NULL ); - *mSmmMpSyncData->Counter = 0; *mSmmMpSyncData->InsideSmm = FALSE; *mSmmMpSyncData->AllCpusInSync = FALSE; mSmmMpSyncData->AllApArrivedWithException = FALSE; for (CpuIndex = 0; CpuIndex < gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus; CpuIndex++) { mSmmMpSyncData->CpuData[CpuIndex].Busy = (SPIN_LOCK *)((UINTN)mSmmCpuSemaphores.SemaphoreCpu.Busy + mSemaphoreSize * CpuIndex); - mSmmMpSyncData->CpuData[CpuIndex].Run = - (UINT32 *)((UINTN)mSmmCpuSemaphores.SemaphoreCpu.Run + mSemaphoreSize * CpuIndex); mSmmMpSyncData->CpuData[CpuIndex].Present = (BOOLEAN *)((UINTN)mSmmCpuSemaphores.SemaphoreCpu.Present + mSemaphoreSize * CpuIndex); *(mSmmMpSyncData->CpuData[CpuIndex].Busy) = 0; - *(mSmmMpSyncData->CpuData[CpuIndex].Run) = 0; *(mSmmMpSyncData->CpuData[CpuIndex].Present) = FALSE; } } } diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h index 654935dc76..b7bb937fbb 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 #include #include #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; @@ -421,29 +421,28 @@ typedef struct { // // Pointer to an array. The array should be located immediately after this 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; + VOID *SmmCpuSyncCtx; } SMM_DISPATCHER_MP_SYNC_DATA; #define SMM_PSD_OFFSET 0xfb00 /// /// 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; /// diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf index 5d52ed7d13..e92b8c747d 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf @@ -101,10 +101,11 @@ SmmCpuFeaturesLib PeCoffGetEntryPointLib PerformanceLib CpuPageTableLib MmSaveStateLib + SmmCpuSyncLib [Protocols] gEfiSmmAccess2ProtocolGuid ## CONSUMES gEfiMpServiceProtocolGuid ## CONSUMES gEfiSmmConfigurationProtocolGuid ## PRODUCES -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#110643): https://edk2.groups.io/g/devel/message/110643 Mute This Topic: https://groups.io/mt/102366305/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-