From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id 5A728D81194 for ; Fri, 26 Apr 2024 12:17:48 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=JfPkDxHSQdMMKb0wYY6mUibKYaKnFYBO9OxPSyHfRV8=; 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:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe; s=20240206; t=1714133867; v=1; b=YEF6Hbqh/kgXDb4ZLU6wKYOwJn+QHzJd23zlsZIgVVlP8KCJNFwTCKsnF2xnoYkNt13yKIR9 agfHSeToZ71+dh9xfXqnJzgiZYAvdV1cpSXtHLM8vwh8XYMROePXCL1KIN1kdQo4D0vEGUio6mt Kt4SBKxc0MIFBg3e3XLRu1GAfJllvqoVd8Laiz8IJKX4lojUANKK7pAdlyx5aqH5a48BszZ8RFg 9VRdiWy7lwEVv+z1C0d4icBH2z4E3om0udN+bFDpfj1oApdTESrtHdVYPe2H67UaPiGkRe7lWZ1 QNtYQuaZCHf1ulD+SefWJ9th8H3A3QatJ2llIDTl1PQkA== X-Received: by 127.0.0.2 with SMTP id 67GdYY7687511xrqLpruLbff; Fri, 26 Apr 2024 05:17:47 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) by mx.groups.io with SMTP id smtpd.web11.12554.1714133857432549514 for ; Fri, 26 Apr 2024 05:17:46 -0700 X-CSE-ConnectionGUID: 4hKFCBRfQ7yV7PLDaW7YsQ== X-CSE-MsgGUID: HGAUpj3RQb+4yv5QA5qrUw== X-IronPort-AV: E=McAfee;i="6600,9927,11055"; a="10027145" X-IronPort-AV: E=Sophos;i="6.07,232,1708416000"; d="scan'208";a="10027145" X-Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2024 05:17:47 -0700 X-CSE-ConnectionGUID: fxJwrGK5TH6PvU7Oa7N8Gw== X-CSE-MsgGUID: YSZ9+o5JQhuEZXm8/h3K6Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,232,1708416000"; d="scan'208";a="62879100" X-Received: from sh1gapp1009.ccr.corp.intel.com ([10.239.189.219]) by orviesa001.jf.intel.com with ESMTP; 26 Apr 2024 05:17:44 -0700 From: "Wu, Jiaxin" To: devel@edk2.groups.io Cc: Ray Ni , Zeng Star , Gerd Hoffmann , Rahul Kumar Subject: [edk2-devel] [PATCH v4 05/14] UefiCpuPkg/SmmRelocationLib: Remove unnecessary global variable Date: Fri, 26 Apr 2024 20:17:11 +0800 Message-Id: <20240426121720.54308-6-jiaxin.wu@intel.com> In-Reply-To: <20240426121720.54308-1-jiaxin.wu@intel.com> References: <20240426121720.54308-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 Resent-Date: Fri, 26 Apr 2024 05:17:46 -0700 Resent-From: jiaxin.wu@intel.com Reply-To: devel@edk2.groups.io,jiaxin.wu@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: n1HIkxBxohUNPQzHehVrvvrQx7686176AA= X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=YEF6Hbqh; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none) This patch aims on mProcessorInfo global variable, which can be defined as local variable in SmmRelocateBases(). With this patch, no need to allocate the memory for all CPUs to store the Processor Info. Cc: Ray Ni Cc: Zeng Star Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu --- .../Library/SmmRelocationLib/SmmRelocationLib.c | 88 ++++++++-------------- 1 file changed, 32 insertions(+), 56 deletions(-) diff --git a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c b/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c index 3694a07cbb..86df66a280 100644 --- a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c +++ b/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c @@ -14,15 +14,10 @@ #include "InternalSmmRelocationLib.h" UINTN mMaxNumberOfCpus = 1; UINTN mNumberOfCpus = 1; -// -// Record all Processors Info -// -EFI_PROCESSOR_INFORMATION *mProcessorInfo = NULL; - // // IDT used during SMM Init // IA32_DESCRIPTOR gcSmmInitIdtr; @@ -34,10 +29,15 @@ UINT64 mSmBase; // // SmBase Rebased flag for current CPU // volatile BOOLEAN mRebased; +// +// CpuIndex for current CPU +// +UINTN mCpuIndex; + /** This function will get the SmBase for CpuIndex. @param[in] CpuIndex The processor index. @param[in] SmmRelocationStart The start address of Smm relocated memory in SMRAM. @@ -138,37 +138,26 @@ VOID EFIAPI SmmInitHandler ( VOID ) { - UINT32 ApicId; - UINTN Index; - // // Update SMM IDT entries' code segment and load IDT // AsmWriteIdtr (&gcSmmInitIdtr); - ApicId = GetApicId (); - for (Index = 0; Index < mNumberOfCpus; Index++) { - if (ApicId == (UINT32)mProcessorInfo[Index].ProcessorId) { - // - // Configure SmBase. - // - ConfigureSmBase (mSmBase); - - // - // Hook return after RSM to set SMM re-based flag - // SMM re-based flag can't be set before RSM, because SMM save state context might be override - // by next AP flow before it take effect. - // - SemaphoreHook (Index, &mRebased); - return; - } - } + // + // Configure SmBase. + // + ConfigureSmBase (mSmBase); - ASSERT (FALSE); + // + // Hook return after RSM to set SMM re-based flag + // SMM re-based flag can't be set before RSM, because SMM save state context might be override + // by next AP flow before it take effect. + // + SemaphoreHook (mCpuIndex, &mRebased); } /** Relocate SmmBases for each processor. Execute on first boot and all S3 resumes @@ -185,17 +174,19 @@ SmmRelocateBases ( IN EDKII_PEI_MP_SERVICES2_PPI *MpServices2, IN EFI_PHYSICAL_ADDRESS SmmRelocationStart, IN UINTN TileSize ) { - UINT8 BakBuf[BACK_BUF_SIZE]; - SMRAM_SAVE_STATE_MAP BakBuf2; - SMRAM_SAVE_STATE_MAP *CpuStatePtr; - UINT8 *U8Ptr; - UINTN Index; - UINTN BspIndex; - UINT32 BspApicId; + EFI_STATUS Status; + UINT8 BakBuf[BACK_BUF_SIZE]; + SMRAM_SAVE_STATE_MAP BakBuf2; + SMRAM_SAVE_STATE_MAP *CpuStatePtr; + UINT8 *U8Ptr; + UINTN Index; + UINTN BspIndex; + UINT32 BspApicId; + EFI_PROCESSOR_INFORMATION ProcessorInfo; // // Make sure the reserved size is large enough for procedure SmmInitTemplate. // ASSERT (sizeof (BakBuf) >= gcSmmInitSize); @@ -230,14 +221,18 @@ SmmRelocateBases ( // Relocate SM bases for all APs // This is APs' 1st SMI - rebase will be done here, and APs' default SMI handler will be overridden by gcSmmInitTemplate // BspIndex = (UINTN)-1; for (Index = 0; Index < mNumberOfCpus; Index++) { - if (BspApicId != (UINT32)mProcessorInfo[Index].ProcessorId) { - mRebased = FALSE; - mSmBase = GetSmBase (Index, SmmRelocationStart, TileSize); - SendSmiIpi ((UINT32)mProcessorInfo[Index].ProcessorId); + Status = MpServices2->GetProcessorInfo (MpServices2, Index | CPU_V2_EXTENDED_TOPOLOGY, &ProcessorInfo); + ASSERT_EFI_ERROR (Status); + + if (BspApicId != (UINT32)ProcessorInfo.ProcessorId) { + mRebased = FALSE; + mSmBase = GetSmBase (Index, SmmRelocationStart, TileSize); + mCpuIndex = Index; + SendSmiIpi ((UINT32)ProcessorInfo.ProcessorId); // // Wait for this AP to finish its 1st SMI // while (!mRebased) { } @@ -443,11 +438,10 @@ SmmRelocationInit ( UINTN TileSize; UINT64 SmmRelocationSize; EFI_PHYSICAL_ADDRESS SmmRelocationStart; UINTN SmmStackSize; UINT8 *SmmStacks; - UINTN Index; SmmRelocationStart = 0; SmmStacks = NULL; DEBUG ((DEBUG_INFO, "SmmRelocationInit Start \n")); @@ -473,28 +467,10 @@ SmmRelocationInit ( mMaxNumberOfCpus = mNumberOfCpus; } ASSERT (mNumberOfCpus <= mMaxNumberOfCpus); - // - // Retrieve the Processor Info for all CPUs - // - mProcessorInfo = (EFI_PROCESSOR_INFORMATION *)AllocatePool (sizeof (EFI_PROCESSOR_INFORMATION) * mMaxNumberOfCpus); - if (mProcessorInfo == NULL) { - Status = EFI_OUT_OF_RESOURCES; - goto ON_EXIT; - } - - for (Index = 0; Index < mMaxNumberOfCpus; Index++) { - if (Index < mNumberOfCpus) { - Status = MpServices2->GetProcessorInfo (MpServices2, Index | CPU_V2_EXTENDED_TOPOLOGY, &mProcessorInfo[Index]); - if (EFI_ERROR (Status)) { - goto ON_EXIT; - } - } - } - // // Calculate SmmRelocationSize for all of the tiles. // // The CPU save state and code for the SMI entry point are tiled within an SMRAM // allocated buffer. The minimum size of this buffer for a uniprocessor system -- 2.16.2.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118329): https://edk2.groups.io/g/devel/message/118329 Mute This Topic: https://groups.io/mt/105748916/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-