From nobody Sat Feb 7 06:39:19 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+100263+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+100263+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1676515605; cv=none; d=zohomail.com; s=zohoarc; b=cVWsWcAtTWoHKO7G9bTf07QzYlMGZ5VswJv9Yj019OnqhFEKP0/RZ3TDiUp3Y8m3Tx78FWABhlHWacze6B6JTiruFXqoCK1rU+RHvfkQVQ/mfqfsWIjmcfzLhrzkZP7ljhqmxomYGAv5UM8ZTQVDQAV4LIvIigomyreM9mDtfMM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676515605; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=q0eJuImR0Bq1TmMKrpewn8pqbGZbULhJHrBoVu5kRUE=; b=mXOVWn0GfL6cSwdLWRIEXdRur+9wvTZkyQT51kwQ71WlrJf/v6+YzHbqNNyRfbWfxyYs80Ue5D52VDZ7sSq/bfuKjCF9FPqNnxwTVWBXWXWTB1hOfTARm+b4lk34eKxWR6EMCQsWSnQ0+XJiJ1soI0gTuaew3uXm+hzT9KVhCJg= 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+100263+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 1676515605256519.9333535764217; Wed, 15 Feb 2023 18:46:45 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id qeJkYY1788612xVuBwcemTtc; Wed, 15 Feb 2023 18:46:44 -0800 X-Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mx.groups.io with SMTP id smtpd.web11.1668.1676515600234036658 for ; Wed, 15 Feb 2023 18:46:44 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10622"; a="329331587" X-IronPort-AV: E=Sophos;i="5.97,301,1669104000"; d="scan'208";a="329331587" X-Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Feb 2023 18:46:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10622"; a="758759769" X-IronPort-AV: E=Sophos;i="5.97,301,1669104000"; d="scan'208";a="758759769" X-Received: from sh1gapp1009.ccr.corp.intel.com ([10.239.189.79]) by FMSMGA003.fm.intel.com with ESMTP; 15 Feb 2023 18:46:41 -0800 From: "Wu, Jiaxin" To: devel@edk2.groups.io Cc: Eric Dong , Ray Ni , Zeng Star , Laszlo Ersek , Gerd Hoffmann , Rahul Kumar Subject: [edk2-devel] [PATCH v8 2/6] UefiCpuPkg/PiSmmCpuDxeSmm: Replace mIsBsp by mBspApicId check Date: Thu, 16 Feb 2023 10:46:31 +0800 Message-Id: <20230216024635.9316-3-jiaxin.wu@intel.com> In-Reply-To: <20230216024635.9316-1-jiaxin.wu@intel.com> References: <20230216024635.9316-1-jiaxin.wu@intel.com> Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: N3iofwCYzbgyGAJJCz9WhMbBx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1676515604; bh=JhRyEfc+pjmqyur+pV0kk6kLhWv+OPznJaC38u/wYfs=; h=Cc:Date:From:Reply-To:Subject:To; b=o309H4i40a/MpMwWYzAu5AaXY+WZ7oTCksVv1QEeNlTp4WEFA/CUDrPBaMxR4E2SmBe af/MbjktA4WzXG3pwwQ0Mcte9WIX2Jciw3RAJB3ttUF0sBHoUP5EYtMUpm3QWDoqEoLZ2 80SdZYUxmlgyJ32+KjUvMACypsk1Wk7GbRA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1676515607101100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch is to replace mIsBsp by mBspApicId check. mIsBsp becomes the local variable (IsBsp), then it can be checked dynamically in the function. Instead, we define the mBspApicId, which is to record the BSP ApicId used for compare in SmmInitHandler. With this change, SmmInitHandler can be run in parallel during SMM init. Note: This patch is the per-prepared work by refining the SmmInitHandler, then, we can do the next step to combine 2 SMIs (gcSmmInitTemplate & gcSmiHandlerTemplate) into one (gcSmiHandlerTemplate), the new SMI handler will call the SmmInitHandler in parallel to do the init. Cc: Eric Dong Cc: Ray Ni Cc: Zeng Star Cc: Laszlo Ersek Cc: Gerd Hoffmann Cc: Rahul Kumar Signed-off-by: Jiaxin Wu Reviewed-by: Ray Ni Reviewed-by: Gerd Hoffmann --- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmC= puDxeSmm/PiSmmCpuDxeSmm.c index 2ac655d032..6e795d1756 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c @@ -57,11 +57,10 @@ SMM_CPU_PRIVATE_DATA *gSmmCpuPrivate =3D &mSmmCpuPriva= teData; =20 // // SMM Relocation variables // volatile BOOLEAN *mRebased; -volatile BOOLEAN mIsBsp; =20 /// /// Handle for the SMM CPU Protocol /// EFI_HANDLE mSmmCpuHandle =3D NULL; @@ -83,10 +82,12 @@ EDKII_SMM_MEMORY_ATTRIBUTE_PROTOCOL mSmmMemoryAttribut= e =3D { EdkiiSmmClearMemoryAttributes }; =20 EFI_CPU_INTERRUPT_HANDLER mExternalVectorTable[EXCEPTION_VECTOR_NUMBER]; =20 +UINT32 mBspApicId =3D 0; + // // SMM stack information // UINTN mSmmStackArrayBase; UINTN mSmmStackArrayEnd; @@ -341,39 +342,42 @@ VOID EFIAPI SmmInitHandler ( VOID ) { - UINT32 ApicId; - UINTN Index; + UINT32 ApicId; + UINTN Index; + BOOLEAN IsBsp; =20 // // Update SMM IDT entries' code segment and load IDT // AsmWriteIdtr (&gcSmiIdtr); ApicId =3D GetApicId (); =20 + IsBsp =3D (BOOLEAN)(mBspApicId =3D=3D ApicId); + ASSERT (mNumberOfCpus <=3D mMaxNumberOfCpus); =20 for (Index =3D 0; Index < mNumberOfCpus; Index++) { if (ApicId =3D=3D (UINT32)gSmmCpuPrivate->ProcessorInfo[Index].Process= orId) { // // Initialize SMM specific features on the currently executing CPU // SmmCpuFeaturesInitializeProcessor ( Index, - mIsBsp, + IsBsp, gSmmCpuPrivate->ProcessorInfo, &mCpuHotPlugData ); =20 if (!mSmmS3Flag) { // // Check XD and BTS features on each processor on normal boot // CheckFeatureSupported (); - } else if (mIsBsp) { + } else if (IsBsp) { // // BSP rebase is already done above. // Initialize private data during S3 resume // InitializeMpSyncData (); @@ -405,11 +409,10 @@ SmmRelocateBases ( { UINT8 BakBuf[BACK_BUF_SIZE]; SMRAM_SAVE_STATE_MAP BakBuf2; SMRAM_SAVE_STATE_MAP *CpuStatePtr; UINT8 *U8Ptr; - UINT32 ApicId; UINTN Index; UINTN BspIndex; =20 // // Make sure the reserved size is large enough for procedure SmmInitTemp= late. @@ -446,21 +449,20 @@ SmmRelocateBases ( CopyMem (U8Ptr, gcSmmInitTemplate, gcSmmInitSize); =20 // // Retrieve the local APIC ID of current processor // - ApicId =3D GetApicId (); + mBspApicId =3D GetApicId (); =20 // // 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 // - mIsBsp =3D FALSE; BspIndex =3D (UINTN)-1; for (Index =3D 0; Index < mNumberOfCpus; Index++) { mRebased[Index] =3D FALSE; - if (ApicId !=3D (UINT32)gSmmCpuPrivate->ProcessorInfo[Index].Processor= Id) { + if (mBspApicId !=3D (UINT32)gSmmCpuPrivate->ProcessorInfo[Index].Proce= ssorId) { SendSmiIpi ((UINT32)gSmmCpuPrivate->ProcessorInfo[Index].ProcessorId= ); // // Wait for this AP to finish its 1st SMI // while (!mRebased[Index]) { @@ -475,12 +477,11 @@ SmmRelocateBases ( =20 // // Relocate BSP's SMM base // ASSERT (BspIndex !=3D (UINTN)-1); - mIsBsp =3D TRUE; - SendSmiIpi (ApicId); + SendSmiIpi (mBspApicId); // // Wait for the BSP to finish its 1st SMI // while (!mRebased[BspIndex]) { } --=20 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 (#100263): https://edk2.groups.io/g/devel/message/100263 Mute This Topic: https://groups.io/mt/96998931/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-