From nobody Mon Feb 9 01:20:27 2026 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+112223+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+112223+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1702029317; cv=none; d=zohomail.com; s=zohoarc; b=JHyfj3JLPkBYxD45dr3UI8puMGKAeET1qxgUojXiOM1p27SXVSHsH+mHqFEmkd+m9Ty25t1nNYgeq1OQ69R40M3Y0JTNeUbY/z8IpBE7qeqSpLRhA2y9QtdxzskP12zJTqtL/P8EariwdKH/bHcFdKquWafZ0avJJhmyPJqmkPg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1702029317; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=r2qfWN5tYD9S5vGzBwie1vB0d/ZCpKKprQtcHGKXjak=; b=VnLAkZ38BgubT7fYB2ujlvzQdbo0Hg8KPvaGKYibeeFHNLNCIFvW2SM9HFD0ovS4x37lFHNoVjN3zRYnrpmRHxeExKS5CA5sOuuMg31hGbP/OQqEeq2wSCyN+W4JOsJZ2kbDQaM9AXWIXCJyaRGp21YUZIewlftojn+nNm0r6LI= 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+112223+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 1702029317245328.9267512691267; Fri, 8 Dec 2023 01:55:17 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=rONc+shwO+s0eRyUCM9aOZOwKKHyt0OzoEAbijF+jaU=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1702029316; v=1; b=TJu9WED73V0p5uHQaLg7ShjsuiKDz4oyLa3v/EcsSrfd4wFmJazypvb7J/5/a1CqcO0zJy+p W95NcGqGX41tM5Qo6Pt6ayV8biNZzy5FinFjiRSQaF2vNDBRAE62Y4A/1mbKWlyfn1v4AqJxAB3 Tq0n0edvSZ4pugzdiweB3Lc8= X-Received: by 127.0.0.2 with SMTP id nweEYY1788612xyZBYZlBvdy; Fri, 08 Dec 2023 01:55:16 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web11.16817.1702029313223455448 for ; Fri, 08 Dec 2023 01:55:16 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10917"; a="397176402" X-IronPort-AV: E=Sophos;i="6.04,260,1695711600"; d="scan'208";a="397176402" X-Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2023 01:55:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,260,1695711600"; d="scan'208";a="20028206" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.43]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Dec 2023 01:55:14 -0800 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [Patch V3 3/6] UefiCpuPkg: Consume MpInfo2Hob in PiSmmCpuDxe Date: Fri, 8 Dec 2023 17:54:42 +0800 Message-Id: <20231208095443.1328-3-dun.tan@intel.com> In-Reply-To: <20231208095443.1328-1-dun.tan@intel.com> References: <20231208095443.1328-1-dun.tan@intel.com> MIME-Version: 1.0 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,dun.tan@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 78QS5EmhgzBBBtnRjahHcYwTx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1702029318440100011 Content-Type: text/plain; charset="utf-8" Consume MpInfo2Hob in PiSmmCpuDxe driver to get NumberOfProcessors, MaxNumberOfCpus and EFI_PROCESSOR_INFORMATION for all CPU from the MpInformation2 HOB. This can avoid calling MP service. Signed-off-by: Dun Tan Cc: Eric Dong Reviewed-by: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann --- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 209 +++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------= ------------------------------------ UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 2 +- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 8 ++++---- 3 files changed, 168 insertions(+), 51 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmC= puDxeSmm/PiSmmCpuDxeSmm.c index 1d022a7051..53f67d544d 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c @@ -99,8 +99,8 @@ UINTN mSmmStackSize; UINTN mSmmShadowStackSize; BOOLEAN mCetSupported =3D TRUE; =20 -UINTN mMaxNumberOfCpus =3D 1; -UINTN mNumberOfCpus =3D 1; +UINTN mMaxNumberOfCpus =3D 0; +UINTN mNumberOfCpus =3D 0; =20 // // SMM ready to lock flag @@ -586,6 +586,146 @@ SmmReadyToLockEventNotify ( return EFI_SUCCESS; } =20 +/** + Function to compare 2 MP_INFORMATION2_HOB_DATA pointer based on Processo= rIndex. + + @param[in] Buffer1 pointer to MP_INFORMATION2_HOB_DATA poiner= to compare + @param[in] Buffer2 pointer to second MP_INFORMATION2_HOB_DATA= pointer to compare + + @retval 0 Buffer1 equal to Buffer2 + @retval <0 Buffer1 is less than Buffer2 + @retval >0 Buffer1 is greater than Buffer2 +**/ +INTN +EFIAPI +MpInformation2HobCompare ( + IN CONST VOID *Buffer1, + IN CONST VOID *Buffer2 + ) +{ + if ((*(MP_INFORMATION2_HOB_DATA **)Buffer1)->ProcessorIndex > (*(MP_INFO= RMATION2_HOB_DATA **)Buffer2)->ProcessorIndex) { + return 1; + } else if ((*(MP_INFORMATION2_HOB_DATA **)Buffer1)->ProcessorIndex < (*(= MP_INFORMATION2_HOB_DATA **)Buffer2)->ProcessorIndex) { + return -1; + } + + return 0; +} + +/** + Extract NumberOfCpus, MaxNumberOfCpus and EFI_PROCESSOR_INFORMATION for = all CPU from MpInformation2 HOB. + + @param[out] NumberOfCpus Pointer to NumberOfCpus. + @param[out] MaxNumberOfCpus Pointer to MaxNumberOfCpus. + + @retval ProcessorInfo Pointer to EFI_PROCESSOR_INFORMATION = buffer. +**/ +EFI_PROCESSOR_INFORMATION * +GetMpInformation ( + OUT UINTN *NumberOfCpus, + OUT UINTN *MaxNumberOfCpus + ) +{ + EFI_HOB_GUID_TYPE *GuidHob; + EFI_HOB_GUID_TYPE *FirstMpInfo2Hob; + MP_INFORMATION2_HOB_DATA *MpInformation2HobData; + UINTN HobCount; + UINTN HobIndex; + MP_INFORMATION2_HOB_DATA **MpInfo2Hobs; + UINTN SortBuffer; + UINTN ProcessorIndex; + UINT64 PrevProcessorIndex; + MP_INFORMATION2_ENTRY *MpInformation2Entry; + EFI_PROCESSOR_INFORMATION *ProcessorInfo; + + GuidHob =3D NULL; + MpInformation2HobData =3D NULL; + FirstMpInfo2Hob =3D NULL; + MpInfo2Hobs =3D NULL; + HobIndex =3D 0; + HobCount =3D 0; + + FirstMpInfo2Hob =3D GetFirstGuidHob (&gMpInformationHobGuid2); + ASSERT (FirstMpInfo2Hob !=3D NULL); + GuidHob =3D FirstMpInfo2Hob; + while (GuidHob !=3D NULL) { + MpInformation2HobData =3D GET_GUID_HOB_DATA (GuidHob); + + // + // This is the last MpInformationHob in the HOB list. + // + if (MpInformation2HobData->NumberOfProcessors =3D=3D 0) { + ASSERT (HobCount !=3D 0); + break; + } + + HobCount++; + *NumberOfCpus +=3D MpInformation2HobData->NumberOfProcessors; + GuidHob =3D GetNextGuidHob (&gMpInformationHobGuid2, GET_NEXT_H= OB (GuidHob)); + } + + ASSERT (*NumberOfCpus <=3D PcdGet32 (PcdCpuMaxLogicalProcessorNumber)); + + // + // If support CPU hot plug, we need to allocate resources for possibly h= ot-added processors + // + if (FeaturePcdGet (PcdCpuHotPlugSupport)) { + *MaxNumberOfCpus =3D PcdGet32 (PcdCpuMaxLogicalProcessorNumber); + } else { + *MaxNumberOfCpus =3D *NumberOfCpus; + } + + MpInfo2Hobs =3D AllocatePool (sizeof (MP_INFORMATION2_HOB_DATA *) * HobC= ount); + ASSERT (MpInfo2Hobs !=3D NULL); + if (MpInfo2Hobs =3D=3D NULL) { + return NULL; + } + + // + // Record each MpInformation2Hob pointer in the MpInfo2Hobs. + // The FirstMpInfo2Hob is to speed up this while-loop without + // needing to look for MpInfo2Hob from beginning. + // + GuidHob =3D FirstMpInfo2Hob; + while (HobIndex < HobCount) { + MpInfo2Hobs[HobIndex++] =3D GET_GUID_HOB_DATA (GuidHob); + GuidHob =3D GetNextGuidHob (&gMpInformationHobGuid2, G= ET_NEXT_HOB (GuidHob)); + } + + ProcessorInfo =3D (EFI_PROCESSOR_INFORMATION *)AllocatePool (sizeof (EFI= _PROCESSOR_INFORMATION) * (*MaxNumberOfCpus)); + ASSERT (ProcessorInfo !=3D NULL); + if (ProcessorInfo =3D=3D NULL) { + FreePool (MpInfo2Hobs); + return NULL; + } + + QuickSort (MpInfo2Hobs, HobCount, sizeof (MP_INFORMATION2_HOB_DATA *), (= BASE_SORT_COMPARE)MpInformation2HobCompare, &SortBuffer); + PrevProcessorIndex =3D 0; + for (HobIndex =3D 0; HobIndex < HobCount; HobIndex++) { + // + // Make sure no overlap and no gap in the CPU range covered by each HOB + // + ASSERT (MpInfo2Hobs[HobIndex]->ProcessorIndex =3D=3D PrevProcessorInde= x); + + // + // Cache each EFI_PROCESSOR_INFORMATION in order. + // + for (ProcessorIndex =3D 0; ProcessorIndex < MpInfo2Hobs[HobIndex]->Num= berOfProcessors; ProcessorIndex++) { + MpInformation2Entry =3D GET_MP_INFORMATION_ENTRY (MpInfo2Hobs[HobInd= ex], ProcessorIndex); + CopyMem ( + &ProcessorInfo[PrevProcessorIndex + ProcessorIndex], + &MpInformation2Entry->ProcessorInfo, + sizeof (EFI_PROCESSOR_INFORMATION) + ); + } + + PrevProcessorIndex +=3D MpInfo2Hobs[HobIndex]->NumberOfProcessors; + } + + FreePool (MpInfo2Hobs); + return ProcessorInfo; +} + /** The module Entry Point of the CPU SMM driver. =20 @@ -603,26 +743,24 @@ PiCpuSmmEntry ( IN EFI_SYSTEM_TABLE *SystemTable ) { - EFI_STATUS Status; - EFI_MP_SERVICES_PROTOCOL *MpServices; - UINTN NumberOfEnabledProcessors; - UINTN Index; - VOID *Buffer; - UINTN BufferPages; - UINTN TileCodeSize; - UINTN TileDataSize; - UINTN TileSize; - UINT8 *Stacks; - VOID *Registration; - UINT32 RegEax; - UINT32 RegEbx; - UINT32 RegEcx; - UINT32 RegEdx; - UINTN FamilyId; - UINTN ModelId; - UINT32 Cr3; - EFI_HOB_GUID_TYPE *GuidHob; - SMM_BASE_HOB_DATA *SmmBaseHobData; + EFI_STATUS Status; + UINTN Index; + VOID *Buffer; + UINTN BufferPages; + UINTN TileCodeSize; + UINTN TileDataSize; + UINTN TileSize; + UINT8 *Stacks; + VOID *Registration; + UINT32 RegEax; + UINT32 RegEbx; + UINT32 RegEcx; + UINT32 RegEdx; + UINTN FamilyId; + UINTN ModelId; + UINT32 Cr3; + EFI_HOB_GUID_TYPE *GuidHob; + SMM_BASE_HOB_DATA *SmmBaseHobData; =20 GuidHob =3D NULL; SmmBaseHobData =3D NULL; @@ -654,17 +792,10 @@ PiCpuSmmEntry ( FindSmramInfo (&mCpuHotPlugData.SmrrBase, &mCpuHotPlugData.SmrrSize); =20 // - // Get MP Services Protocol - // - Status =3D SystemTable->BootServices->LocateProtocol (&gEfiMpServiceProt= ocolGuid, NULL, (VOID **)&MpServices); - ASSERT_EFI_ERROR (Status); - - // - // Use MP Services Protocol to retrieve the number of processors and num= ber of enabled processors + // Retrive NumberOfProcessors, MaxNumberOfCpus and EFI_PROCESSOR_INFORMA= TION for all CPU from MpInformation2 HOB. // - Status =3D MpServices->GetNumberOfProcessors (MpServices, &mNumberOfCpus= , &NumberOfEnabledProcessors); - ASSERT_EFI_ERROR (Status); - ASSERT (mNumberOfCpus <=3D PcdGet32 (PcdCpuMaxLogicalProcessorNumber)); + gSmmCpuPrivate->ProcessorInfo =3D GetMpInformation (&mNumberOfCpus, &mMa= xNumberOfCpus); + ASSERT (gSmmCpuPrivate->ProcessorInfo !=3D NULL); =20 // // If support CPU hot plug, PcdCpuSmmEnableBspElection should be set to = TRUE. @@ -690,15 +821,6 @@ PiCpuSmmEntry ( mAddressEncMask =3D PcdGet64 (PcdPteMemoryEncryptionAddressOrMask) & PAG= ING_1G_ADDRESS_MASK_64; DEBUG ((DEBUG_INFO, "mAddressEncMask =3D 0x%lx\n", mAddressEncMask)); =20 - // - // If support CPU hot plug, we need to allocate resources for possibly h= ot-added processors - // - if (FeaturePcdGet (PcdCpuHotPlugSupport)) { - mMaxNumberOfCpus =3D PcdGet32 (PcdCpuMaxLogicalProcessorNumber); - } else { - mMaxNumberOfCpus =3D mNumberOfCpus; - } - gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus =3D mMaxNumberOfCpus; =20 PERF_CODE ( @@ -908,9 +1030,6 @@ PiCpuSmmEntry ( // // Allocate buffer for pointers to array in SMM_CPU_PRIVATE_DATA. // - gSmmCpuPrivate->ProcessorInfo =3D (EFI_PROCESSOR_INFORMATION *)AllocateP= ool (sizeof (EFI_PROCESSOR_INFORMATION) * mMaxNumberOfCpus); - ASSERT (gSmmCpuPrivate->ProcessorInfo !=3D NULL); - gSmmCpuPrivate->Operation =3D (SMM_CPU_OPERATION *)AllocatePool (sizeof = (SMM_CPU_OPERATION) * mMaxNumberOfCpus); ASSERT (gSmmCpuPrivate->Operation !=3D NULL); =20 @@ -945,8 +1064,6 @@ PiCpuSmmEntry ( gSmmCpuPrivate->Operation[Index] =3D SmmCpuNone; =20 if (Index < mNumberOfCpus) { - Status =3D MpServices->GetProcessorInfo (MpServices, Index | CPU_V2_= EXTENDED_TOPOLOGY, &gSmmCpuPrivate->ProcessorInfo[Index]); - ASSERT_EFI_ERROR (Status); mCpuHotPlugData.ApicId[Index] =3D gSmmCpuPrivate->ProcessorInfo[Inde= x].ProcessorId; =20 DEBUG (( diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmC= puDxeSmm/PiSmmCpuDxeSmm.h index 20ada465c2..f18345881b 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h @@ -14,7 +14,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include =20 -#include #include #include #include @@ -27,6 +26,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include =20 #include #include diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf b/UefiCpuPkg/PiSm= mCpuDxeSmm/PiSmmCpuDxeSmm.inf index 5d52ed7d13..372596f24c 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf @@ -106,7 +106,6 @@ =20 [Protocols] gEfiSmmAccess2ProtocolGuid ## CONSUMES - gEfiMpServiceProtocolGuid ## CONSUMES gEfiSmmConfigurationProtocolGuid ## PRODUCES gEfiSmmCpuProtocolGuid ## PRODUCES gEfiSmmReadyToLockProtocolGuid ## NOTIFY @@ -120,6 +119,7 @@ gEdkiiPiSmmMemoryAttributesTableGuid ## CONSUMES ## SystemTable gEfiMemoryAttributesTableGuid ## CONSUMES ## SystemTable gSmmBaseHobGuid ## CONSUMES + gMpInformationHobGuid2 ## CONSUMES # Assume the HOB mu= st has been created =20 [FeaturePcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmDebug ## CONS= UMES @@ -153,11 +153,11 @@ [FixedPcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmMpTokenCountPerChunk ##= CONSUMES =20 +[Depex] + TRUE + [Pcd.X64] gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmRestrictedMemoryAccess ## CONS= UMES =20 -[Depex] - gEfiMpServiceProtocolGuid - [UserExtensions.TianoCore."ExtraFiles"] PiSmmCpuDxeSmmExtra.uni --=20 2.31.1.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 (#112223): https://edk2.groups.io/g/devel/message/112223 Mute This Topic: https://groups.io/mt/103052270/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-