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 EA90E94107E for ; Mon, 6 May 2024 03:30:47 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=uNtuCV96QTcPFIxUFrAP5Cx9tvY2zSUyOb9hLii1/rs=; c=relaxed/simple; d=groups.io; h=From:To:CC:Subject:Thread-Topic:Thread-Index:Date:Message-ID:References:In-Reply-To:Accept-Language:msip_labels:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type; s=20240206; t=1714966246; v=1; b=AD21j0f90cKBtYKdjmczpnFe+tE9XvyAOuJ/zZ5imWEaHkKotQ0R8YOildG2/95HiXzluMTJ afC76Aa/4j50F+jZbXVLR0BbEPUc2O8TpI+HeoGDyBI16ytqCt1HdG3ZrZsBTy+4BRLMKeMb6/n NhbmZiqIlSqKG+8gW6/ZUFauCkGq8ZoYjwlC8y8Z3ZogOx7aYRk/MOvWhPnbZjLhhBPdEA6rbbo 4mmrp1AdjfVCJ78Acc0zKTRhzcUMNTtDIujPBfFMMjllNIM7AT3y5inUNMqoQ8oFBU2IX95kKco 9U+LXf+h/YnYPu3bHEJHxg881y4BBz5gds2IBXODUpgMg== X-Received: by 127.0.0.2 with SMTP id OzAoYY7687511xlKgpL1jFMF; Sun, 05 May 2024 20:30:46 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) by mx.groups.io with SMTP id smtpd.web10.12800.1714966245648083658 for ; Sun, 05 May 2024 20:30:45 -0700 X-CSE-ConnectionGUID: ZKqkLfMEQBKWnLhslZmLhg== X-CSE-MsgGUID: PMLW8gIRSkmbw4LxQG70BA== X-IronPort-AV: E=McAfee;i="6600,9927,11064"; a="10850875" X-IronPort-AV: E=Sophos;i="6.07,257,1708416000"; d="scan'208,217";a="10850875" X-Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2024 20:30:45 -0700 X-CSE-ConnectionGUID: fppUV3NOSOuBnnIwXsjwuw== X-CSE-MsgGUID: WRohK3L3Q/KXPVq1cddHfQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,257,1708416000"; d="scan'208,217";a="32639312" X-Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by fmviesa004.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 05 May 2024 20:30:45 -0700 X-Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Sun, 5 May 2024 20:30:44 -0700 X-Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Sun, 5 May 2024 20:30:44 -0700 X-Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35 via Frontend Transport; Sun, 5 May 2024 20:30:44 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.168) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Sun, 5 May 2024 20:30:44 -0700 X-Received: from MN6PR11MB8244.namprd11.prod.outlook.com (2603:10b6:208:470::14) by IA0PR11MB7815.namprd11.prod.outlook.com (2603:10b6:208:404::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.41; Mon, 6 May 2024 03:30:42 +0000 X-Received: from MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::41a4:c775:32e6:76a8]) by MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::41a4:c775:32e6:76a8%4]) with mapi id 15.20.7544.041; Mon, 6 May 2024 03:30:42 +0000 From: "Ni, Ray" To: "Wu, Jiaxin" , "devel@edk2.groups.io" CC: "Zeng, Star" , Gerd Hoffmann , "Kumar, Rahul R" Subject: Re: [edk2-devel] [PATCH v4 05/14] UefiCpuPkg/SmmRelocationLib: Remove unnecessary global variable Thread-Topic: [PATCH v4 05/14] UefiCpuPkg/SmmRelocationLib: Remove unnecessary global variable Thread-Index: AQHal9PC99zr7hdS9UyVrLannfdeZrGJm82Q Date: Mon, 6 May 2024 03:30:42 +0000 Message-ID: References: <20240426121720.54308-1-jiaxin.wu@intel.com> <20240426121720.54308-6-jiaxin.wu@intel.com> In-Reply-To: <20240426121720.54308-6-jiaxin.wu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MN6PR11MB8244:EE_|IA0PR11MB7815:EE_ x-ms-office365-filtering-correlation-id: 8fa78fba-9b38-4610-7de3-08dc6d7ce854 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: =?us-ascii?Q?I8q2JhOVYTJ2sJRF1Irc4Wq3wonuEsD+6Oioz3LzJRqYuNiqc1kofI686zPI?= =?us-ascii?Q?PvB6p/0qfoUrqO3gA5uPepDm81+aRQtl5u2CKivkAisgSxIJdwvAs6QcCy4D?= =?us-ascii?Q?BBT2IWa7tkTgQU63xcqwrjE0bL1bZ0Xa122zcNI6UVsasv6tMBnCGe0CLKph?= =?us-ascii?Q?jBOIVRSVV8+Yt91ifd+3pozox079f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VFvF9CuQVPG7+0Ty6YzwM5hqBTeiRZ03+HErgQDQEo3RrsnBXf3A2k8?= =?us-ascii?Q?oZKsaaObbvZgZpaMDUZTlvU+xndPfec857tu+mhAOCfOQj/MhXhc1qAndKKs?= =?us-ascii?Q?q4QBXrODTDWe2Tv5GnBZZ4MV+Fjd5oxISk6VtevguxSNIJMMfKHSb5r+bKOY?= =?us-ascii?Q?F3dM4x+bT4CMr+IW8M0NL0LYITxTjKyqPN+HvG06QrjloZNmCchn1bISDDeZ?= =?us-ascii?Q?yh6eaXWIq9zkwLBhQ6g2ZjKhBQHij8dMliY1e6Vk1/yqTw=3D=3D?= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?CdvVgBEH1iZKwZT6RdAFKPdHpW1g4AhJLpUKQ93F0n3ZDKgYMrSKmLvYmQM0?= =?us-ascii?Q?vpTPB9ggge8sVhcvoVyiL/ZCcRPvA10/Q28moHvdIGU5Sg6dn9F9d6CqTjNo?= =?us-ascii?Q?g5xUMm3HShDeDNi8o/5CuQLwRx0qY+BF3DK2SCzu5o0MnU7Nzl3OlpkHSl2A?= =?us-ascii?Q?yaELUw81rg/acPGHjw2BRQO1GypgWMtKHdaQGMUXoICytFcBxW7LKI5xvwYO?= =?us-ascii?Q?aq15TkXtpnY2s75AZpXR7ol1S/O9MLh2eO1mZFm3Aj/f2DeGSyygku4ts1ti?= =?us-ascii?Q?fKUD9UxSjt8IHfv9BjezzJNQnYDvw/Sv2J+YOHusCD2imfc1JoHVqSppUa8a?= =?us-ascii?Q?9RmIJHpNZEr7qPmfeQp2vYg0XEex6D4/vud3PFkZx0CW4sNgdXOrbbWrxO2a?= =?us-ascii?Q?rnGI7+V9gRfsfbMWBk493BwQo/e4NO8RjI3QiZjLrltsXTOuo/KEklOyHxIy?= =?us-ascii?Q?W4h5CYE4BS6AQ2KUd9MfWsDSKNQC5RPvRfDPh2aTq+Qidm1fZiOi+LjhZ2KL?= =?us-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o4Nh7v4n/?= =?us-ascii?Q?B4riQgC9gSMYoHqaEIzBXn1KlU6EQHkig8ExecyNNUNkBuBAQp2z4PPMjp12?= =?us-ascii?Q?7OAqprTT/5Mz2k1Ozldrr+WbzWqv9LRGanNL+6QSvFI0ZFy/uyrQqSJghg4v?= =?us-ascii?Q?R13c7A/2zmFqERTGSWI=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN6PR11MB8244.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8fa78fba-9b38-4610-7de3-08dc6d7ce854 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 May 2024 03:30:42.0622 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: NX1LfrXTi5UTkosHxodJ3mDYdQozNllwJqldTTItTcXNwABeNAY3BT+QMsI/Ll1wHjQuM0QFsswsq18O7o+c9Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR11MB7815 X-OriginatorOrg: 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: Sun, 05 May 2024 20:30:45 -0700 Resent-From: ray.ni@intel.com Reply-To: devel@edk2.groups.io,ray.ni@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: A2wWlAV0TFqTEXpTgvoDoqxxx7686176AA= Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_MN6PR11MB8244127B0C2FF76A9F606B3A8C1C2MN6PR11MB8244namp_" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=AD21j0f9; 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 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io --_000_MN6PR11MB8244127B0C2FF76A9F606B3A8C1C2MN6PR11MB8244namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Ray Ni Thanks, Ray ________________________________ From: Wu, Jiaxin Sent: Friday, April 26, 2024 20:17 To: devel@edk2.groups.io Cc: Ni, Ray ; Zeng, Star ; Gerd Hoff= mann ; Kumar, Rahul R Subject: [PATCH v4 05/14] UefiCpuPkg/SmmRelocationLib: Remove unnecessary g= lobal variable 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/UefiC= puPkg/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 =3D 1; UINTN mNumberOfCpus =3D 1; -// -// Record all Processors Info -// -EFI_PROCESSOR_INFORMATION *mProcessorInfo =3D 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 memo= ry 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 =3D GetApicId (); - for (Index =3D 0; Index < mNumberOfCpus; Index++) { - if (ApicId =3D=3D (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 con= text 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 SmmInitTemp= late. // ASSERT (sizeof (BakBuf) >=3D 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 =3D (UINTN)-1; for (Index =3D 0; Index < mNumberOfCpus; Index++) { - if (BspApicId !=3D (UINT32)mProcessorInfo[Index].ProcessorId) { - mRebased =3D FALSE; - mSmBase =3D GetSmBase (Index, SmmRelocationStart, TileSize); - SendSmiIpi ((UINT32)mProcessorInfo[Index].ProcessorId); + Status =3D MpServices2->GetProcessorInfo (MpServices2, Index | CPU_V2_= EXTENDED_TOPOLOGY, &ProcessorInfo); + ASSERT_EFI_ERROR (Status); + + if (BspApicId !=3D (UINT32)ProcessorInfo.ProcessorId) { + mRebased =3D FALSE; + mSmBase =3D GetSmBase (Index, SmmRelocationStart, TileSize); + mCpuIndex =3D 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 =3D 0; SmmStacks =3D NULL; DEBUG ((DEBUG_INFO, "SmmRelocationInit Start \n")); @@ -473,28 +467,10 @@ SmmRelocationInit ( mMaxNumberOfCpus =3D mNumberOfCpus; } ASSERT (mNumberOfCpus <=3D mMaxNumberOfCpus); - // - // Retrieve the Processor Info for all CPUs - // - mProcessorInfo =3D (EFI_PROCESSOR_INFORMATION *)AllocatePool (sizeof (EF= I_PROCESSOR_INFORMATION) * mMaxNumberOfCpus); - if (mProcessorInfo =3D=3D NULL) { - Status =3D EFI_OUT_OF_RESOURCES; - goto ON_EXIT; - } - - for (Index =3D 0; Index < mMaxNumberOfCpus; Index++) { - if (Index < mNumberOfCpus) { - Status =3D MpServices2->GetProcessorInfo (MpServices2, Index | CPU_V= 2_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 -=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 (#118586): https://edk2.groups.io/g/devel/message/118586 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] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- --_000_MN6PR11MB8244127B0C2FF76A9F606B3A8C1C2MN6PR11MB8244namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
Reviewed-by: Ray Ni <ray.ni@intel.com>

Thanks,
Ray

From: Wu, Jiaxin <jiaxin= .wu@intel.com>
Sent: Friday, April 26, 2024 20:17
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: Ni, Ray <ray.ni@intel.com>; Zeng, Star <star.zeng@intel= .com>; Gerd Hoffmann <kraxel@redhat.com>; Kumar, Rahul R <rahul= .r.kumar@intel.com>
Subject: [PATCH v4 05/14] UefiCpuPkg/SmmRelocationLib: Remove unnece= ssary global variable
 
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 <ray.ni@intel.com>
Cc: Zeng Star <star.zeng@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
---
 .../Library/SmmRelocationLib/SmmRelocationLib.c    | 8= 8 ++++++++--------------
 1 file changed, 32 insertions(+), 56 deletions(-)

diff --git a/UefiCpuPkg/Library/SmmRelocationLib/SmmRelocationLib.c b/UefiC= puPkg/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 =3D 1;
 UINTN  mNumberOfCpus    =3D 1;
 
-//
-// Record all Processors Info
-//
-EFI_PROCESSOR_INFORMATION  *mProcessorInfo =3D 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     &= nbsp;      The processor index.
   @param[in]   SmmRelocationStart  The start addr= ess 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 =3D GetApicId ();
 
-  for (Index =3D 0; Index < mNumberOfCpus; Index++) {
-    if (ApicId =3D=3D (UINT32)mProcessorInfo[Index].Process= orId) {
-      //
-      // Configure SmBase.
-      //
-      ConfigureSmBase (mSmBase);
-
-      //
-      // Hook return after RSM to set SMM re-base= d flag
-      // SMM re-based flag can't be set before RS= M, 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 stat= e 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      &nb= sp; SmmRelocationStart,
   IN UINTN         =             &nb= sp; TileSize
   )
 {
-  UINT8          &n= bsp;      BakBuf[BACK_BUF_SIZE];
-  SMRAM_SAVE_STATE_MAP  BakBuf2;
-  SMRAM_SAVE_STATE_MAP  *CpuStatePtr;
-  UINT8          &n= bsp;      *U8Ptr;
-  UINTN          &n= bsp;      Index;
-  UINTN          &n= bsp;      BspIndex;
-  UINT32          &= nbsp;     BspApicId;
+  EFI_STATUS         &nb= sp;       Status;
+  UINT8          &n= bsp;           BakBuf[BAC= K_BUF_SIZE];
+  SMRAM_SAVE_STATE_MAP       BakBuf2; +  SMRAM_SAVE_STATE_MAP       *CpuStateP= tr;
+  UINT8          &n= bsp;           *U8Ptr; +  UINTN          &n= bsp;           Index;
+  UINTN          &n= bsp;           BspIndex;<= br> +  UINT32          &= nbsp;          BspApicId;
+  EFI_PROCESSOR_INFORMATION  ProcessorInfo;
 
   //
   // Make sure the reserved size is large enough for procedure S= mmInitTemplate.
   //
   ASSERT (sizeof (BakBuf) >=3D gcSmmInitSize);
@@ -230,14 +221,18 @@ SmmRelocateBases (
   // Relocate SM bases for all APs
   // This is APs' 1st SMI - rebase will be done here, and APs' d= efault SMI handler will be overridden by gcSmmInitTemplate
   //
   BspIndex =3D (UINTN)-1;
   for (Index =3D 0; Index < mNumberOfCpus; Index++) {
-    if (BspApicId !=3D (UINT32)mProcessorInfo[Index].Proces= sorId) {
-      mRebased =3D FALSE;
-      mSmBase  =3D GetSmBase (Index, SmmRelo= cationStart, TileSize);
-      SendSmiIpi ((UINT32)mProcessorInfo[Index].P= rocessorId);
+    Status =3D MpServices2->GetProcessorInfo (MpServices= 2, Index | CPU_V2_EXTENDED_TOPOLOGY, &ProcessorInfo);
+    ASSERT_EFI_ERROR (Status);
+
+    if (BspApicId !=3D (UINT32)ProcessorInfo.ProcessorId) {=
+      mRebased  =3D FALSE;
+      mSmBase   =3D GetSmBase (Index, S= mmRelocationStart, TileSize);
+      mCpuIndex =3D Index;
+      SendSmiIpi ((UINT32)ProcessorInfo.Processor= Id);
       //
       // Wait for this AP to finish its 1st = SMI
       //
       while (!mRebased) {
       }
@@ -443,11 +438,10 @@ SmmRelocationInit (
   UINTN         &nb= sp;       TileSize;
   UINT64         &n= bsp;      SmmRelocationSize;
   EFI_PHYSICAL_ADDRESS  SmmRelocationStart;
   UINTN         &nb= sp;       SmmStackSize;
   UINT8         &nb= sp;       *SmmStacks;
-  UINTN          &n= bsp;      Index;
 
   SmmRelocationStart =3D 0;
   SmmStacks         = ; =3D NULL;
 
   DEBUG ((DEBUG_INFO, "SmmRelocationInit Start \n"));<= br> @@ -473,28 +467,10 @@ SmmRelocationInit (
     mMaxNumberOfCpus =3D mNumberOfCpus;
   }
 
   ASSERT (mNumberOfCpus <=3D mMaxNumberOfCpus);
 
-  //
-  // Retrieve the Processor Info for all CPUs
-  //
-  mProcessorInfo =3D (EFI_PROCESSOR_INFORMATION *)AllocatePool (sizeo= f (EFI_PROCESSOR_INFORMATION) * mMaxNumberOfCpus);
-  if (mProcessorInfo =3D=3D NULL) {
-    Status =3D EFI_OUT_OF_RESOURCES;
-    goto ON_EXIT;
-  }
-
-  for (Index =3D 0; Index < mMaxNumberOfCpus; Index++) {
-    if (Index < mNumberOfCpus) {
-      Status =3D 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 til= ed within an SMRAM
   // allocated buffer. The minimum size of this buffer for a uni= processor system
--
2.16.2.windows.1

_._,_._,_

Groups.io Links:

=20 You receive all messages sent to this group. =20 =20

View/Reply Online (#118586) | =20 | Mute= This Topic | New Topic
Your Subscriptio= n | Contact Group Owner | Unsubscribe [rebecca@openfw.io]

_._,_._,_
--_000_MN6PR11MB8244127B0C2FF76A9F606B3A8C1C2MN6PR11MB8244namp_--