From nobody Mon Feb 9 10:48:24 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+112065+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+112065+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1701755364; cv=none; d=zohomail.com; s=zohoarc; b=LAxKJNTK02Sc+vio9m9bf5HTro4UQyQNKTfkXcmweGpu0fVUvWQEOyOHKJmxFKfG2xTDLZom/koa2/xUQA4Zrsae81w4JQuBs7/T06eoRXIFJ+GL5os4EYJoj7I5Kw46BJ2xhw+mcQHDQzbR3YeBNVpk6aVAt4rLqN0Euhl8t3A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701755364; 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=plGElTqyVDnVKwep5fdR1zbGowG8ysu5ZTD9h8VE/PI=; b=hp4keypfnw4iDg/KSabhMcoUeFTPywYISR5SEJJgpYf5SfqlB++HxOLr/aQBu85j0G8dGN3h7X7gJVPYms81dvNpwonF9ukG8JGSAOdrhhjMlfv9t+5/6MBfqdrEHxnGKxTF/x9OMyUjrICkPVTRhjwEosvq1AfqpU8vYoFFpIc= 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+112065+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 1701755364616295.7924576790916; Mon, 4 Dec 2023 21:49:24 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=Cs3JDZMLIoChGNDVdmAU7rHNV1+rMwwLqr1lKPPm9Xs=; 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=1701755364; v=1; b=Kl7kCNnHel/6BfAGgWmTJCzQePwB/8dQeRMlnRfp9W+zDOAnRcXI48mr9xfIH3XRU8zKUJhp gB6VW65H6yNVrv5oPTjx92ggWi/CywOfgvljLEH4zyuMKG1AR2Ex3l2jOkgdjGVcIlGFMLk8Lfv J82U6hsU6YT2uuhiOZ5H39uU= X-Received: by 127.0.0.2 with SMTP id 7FebYY1788612xosMP4mpLVB; Mon, 04 Dec 2023 21:49:24 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web11.93095.1701755355027796431 for ; Mon, 04 Dec 2023 21:49:23 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="378875432" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="378875432" X-Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 21:49:23 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="720580533" X-IronPort-AV: E=Sophos;i="6.04,251,1695711600"; d="scan'208";a="720580533" X-Received: from shwdeopenlab702.ccr.corp.intel.com ([10.239.55.43]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2023 21:49:21 -0800 From: "duntan" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH 3/6] UefiCpuPkg: Consume MpInfo2Hob in PiSmmCpuDxe Date: Tue, 5 Dec 2023 13:48:57 +0800 Message-Id: <20231205054900.926-4-dun.tan@intel.com> In-Reply-To: <20231205054900.926-1-dun.tan@intel.com> References: <20231205054900.926-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: NtcVdSz337y9P2jSKbBBlB3xx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1701755366371100001 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 Cc: 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, 171 insertions(+), 48 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmC= puDxeSmm/PiSmmCpuDxeSmm.c index 1d022a7051..d8d488b253 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c @@ -586,6 +586,152 @@ 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. + @param[out] ProcessorInfoPointer Pointer to EFI_PROCESSOR_INFORMATION = buffer pointer. + + @retval EFI_SUCCESS Successfully extract information from= MpInformation2 HOB. + @retval RETURN_BUFFER_TOO_SMALL Fail to allocate memory. +**/ +EFI_STATUS +GetMpInfoFromMpInfo2Hob ( + OUT UINTN *NumberOfCpus, + OUT UINTN *MaxNumberOfCpus, + OUT EFI_PROCESSOR_INFORMATION **ProcessorInfoPointer + ) +{ + EFI_HOB_GUID_TYPE *GuidHob; + EFI_HOB_GUID_TYPE *FirstMpInfor2Hob; + MP_INFORMATION2_HOB_DATA *MpInformation2HobData; + UINTN CpuCount; + UINTN HobCount; + UINTN Index; + MP_INFORMATION2_HOB_DATA **MpInfomation2Buffer; + UINTN SortBuffer; + UINTN ProcessorIndex; + UINT64 PrevProcessorIndex; + MP_INFORMATION2_ENTRY *MpInformation2Entry; + EFI_PROCESSOR_INFORMATION *ProcessorInfo; + + GuidHob =3D NULL; + MpInformation2HobData =3D NULL; + FirstMpInfor2Hob =3D NULL; + MpInfomation2Buffer =3D NULL; + CpuCount =3D 0; + Index =3D 0; + HobCount =3D 0; + PrevProcessorIndex =3D 0; + + FirstMpInfor2Hob =3D GetFirstGuidHob (&gMpInformationHobGuid2); + ASSERT (FirstMpInfor2Hob !=3D NULL); + GuidHob =3D FirstMpInfor2Hob; + 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++; + CpuCount +=3D MpInformation2HobData->NumberOfProcessors; + GuidHob =3D GetNextGuidHob (&gMpInformationHobGuid2, GET_NEXT_HOB (G= uidHob)); + } + + ASSERT (CpuCount <=3D PcdGet32 (PcdCpuMaxLogicalProcessorNumber)); + *NumberOfCpus =3D CpuCount; + + // + // 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 CpuCount; + } + + MpInfomation2Buffer =3D AllocatePool (sizeof (MP_INFORMATION2_HOB_DATA *= ) * HobCount); + ASSERT (MpInfomation2Buffer !=3D NULL); + if (MpInfomation2Buffer =3D=3D NULL) { + return EFI_BUFFER_TOO_SMALL; + } + + // + // Record each MpInformation2Hob pointer in the MpInfomation2Buffer. + // + GuidHob =3D FirstMpInfor2Hob; + ASSERT (GuidHob !=3D NULL); + while (Index < HobCount) { + MpInfomation2Buffer[Index++] =3D GET_GUID_HOB_DATA (GuidHob); + GuidHob =3D GetNextGuidHob (&gMpInformationHobGui= d2, GET_NEXT_HOB (GuidHob)); + } + + ProcessorInfo =3D (EFI_PROCESSOR_INFORMATION *)AllocatePool (sizeof (EFI= _PROCESSOR_INFORMATION) * (*MaxNumberOfCpus)); + ASSERT (ProcessorInfo !=3D NULL); + if (ProcessorInfo =3D=3D NULL) { + return EFI_BUFFER_TOO_SMALL; + } + + QuickSort (MpInfomation2Buffer, HobCount, sizeof (MP_INFORMATION2_HOB_DA= TA *), (BASE_SORT_COMPARE)MpInformation2HobCompare, &SortBuffer); + for (Index =3D 0; Index < HobCount; Index++) { + // + // Make sure no overlap and no gap in the CPU range covered by each HOB + // + ASSERT (MpInfomation2Buffer[Index]->ProcessorIndex =3D=3D PrevProcesso= rIndex); + + // + // Cache each EFI_PROCESSOR_INFORMATION in order. + // + for (ProcessorIndex =3D 0; ProcessorIndex < MpInfomation2Buffer[Index]= ->NumberOfProcessors; ProcessorIndex++) { + MpInformation2Entry =3D GET_MP_INFORMATION_ENTRY (MpInfomation2Buffe= r[Index], ProcessorIndex); + CopyMem ( + ProcessorInfo + PrevProcessorIndex + ProcessorIndex, + &MpInformation2Entry->ProcessorInfo, + sizeof (EFI_PROCESSOR_INFORMATION) + ); + } + + PrevProcessorIndex +=3D MpInfomation2Buffer[Index]->NumberOfProcessors; + } + + *ProcessorInfoPointer =3D ProcessorInfo; + + FreePool (MpInfomation2Buffer); + return EFI_SUCCESS; +} + /** The module Entry Point of the CPU SMM driver. =20 @@ -603,26 +749,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 +798,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); + Status =3D GetMpInfoFromMpInfo2Hob (&mNumberOfCpus, &mMaxNumberOfCpus, &= gSmmCpuPrivate->ProcessorInfo); ASSERT_EFI_ERROR (Status); - ASSERT (mNumberOfCpus <=3D PcdGet32 (PcdCpuMaxLogicalProcessorNumber)); =20 // // If support CPU hot plug, PcdCpuSmmEnableBspElection should be set to = TRUE. @@ -690,15 +827,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 +1036,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 +1070,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..b8aa2442cd 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 =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 (#112065): https://edk2.groups.io/g/devel/message/112065 Mute This Topic: https://groups.io/mt/102987139/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-