From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web08.35053.1661503888309914100 for ; Fri, 26 Aug 2022 01:51:28 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=WVyminGE; spf=pass (domain: intel.com, ip: 192.55.52.43, mailfrom: ray.ni@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661503888; x=1693039888; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=1v0q1XCRj155+wDpoVpKKqxSif0+XTQ8+EMl/jxFiJM=; b=WVyminGEMgh/AH8f1O0GSvSuTE4cHr+ucrbM90fQtzUeXnEYbeyBTMaI Lz5dka275nP348RN9i5Pegx9CpWBG8QlKjrllaZNWZUwErWqFklFXh87t 8au+64weoGHFRd/GuzlvDokfTsDZ8lumFnlU9pvheV6K8+kuCWc4XV1Z2 OP+5av80+1evPykIuxATPxSfT3/whuDn5yrhVk4REj97ksbYlRKPvpa25 LRbA8IPfLN9bt0UKuuoz0XVO0h2PxuR5+BZ5OVQ+hLswmE79CrOjV8hQM 3QujWCq7WX1aBpQGu5gA3vfVAd15FHBk5n4oWJW9dS1YOeDS+8uJHEkqV w==; X-IronPort-AV: E=McAfee;i="6500,9779,10450"; a="380753894" X-IronPort-AV: E=Sophos;i="5.93,264,1654585200"; d="scan'208";a="380753894" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2022 01:51:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,264,1654585200"; d="scan'208";a="643587390" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orsmga001.jf.intel.com with ESMTP; 26 Aug 2022 01:51:19 -0700 Received: from orsmsx607.amr.corp.intel.com (10.22.229.20) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 26 Aug 2022 01:51:19 -0700 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx607.amr.corp.intel.com (10.22.229.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31 via Frontend Transport; Fri, 26 Aug 2022 01:51:19 -0700 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.103) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2375.31; Fri, 26 Aug 2022 01:51:18 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KxUSi5FGFR23lE6g7dvbCckNXkdsHiBJY2jvWEh5HTnzr7l8DPWrbmWfZCnCoHfAPwpXsJf/MQhdaDy1pVzdKI8OsgDt+2ZVKLLNrChYHphKwPfSPYOV1GcRgz5Auiu273S66BkH8V26j4itG+svRIUtU5iWHlCEWZSnSa9rkxPqlSjj+m4k0fjqMI0yqSouVb+C36llBgl+Y/9n7+6kQBS9Tv+GMHGjVLkng3U7d1DpZAP48vdd8oZZZqBzuOXsHbQvkOQXXAwTJouY2i70go90N6Sg3qnl7YxfJNP+CExUVyaz11LaW+RtxwszlJbtM6pjxDzs42wt49X2/hgUNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=L0cmEEKvLVX4R+kO1SpIn9+kBBvnihrqXDSzeL6L97M=; b=Jqiqwomtsd7uBflf+q4oRVHrxz/8O3nIdoQBCfOFcKokGHNegd9XuSa84b4Q+QInm9MMBOK+471Vo3UTupJLk+EfKGrhaQp2j/n+bPicj1jmwgBd+GvD6PUT10R3kWCbCGXY9dcbhQI+Ct/Psgmd4j+Rq4dtUDcy1LfmBVNR9PjCzN3ahNm5l+yPP2OoPby7InctB0tpWzt+Qz/+8C6+VgPm/txBMWrCYygrhaOrKsXdvyNagnOwAl2myYH1/EoAPskadL8OKMMpwK8v/oeoBg9EOl8qLCmPWev9CPnfAh1kiEZxuhdg8K6CXMkNJAZjfSKl2ISdpZygn6BWz5L7ZQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from MWHPR11MB1631.namprd11.prod.outlook.com (2603:10b6:301:10::10) by BL1PR11MB6001.namprd11.prod.outlook.com (2603:10b6:208:385::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.15; Fri, 26 Aug 2022 08:51:17 +0000 Received: from MWHPR11MB1631.namprd11.prod.outlook.com ([fe80::958b:cc9d:ac3:288a]) by MWHPR11MB1631.namprd11.prod.outlook.com ([fe80::958b:cc9d:ac3:288a%10]) with mapi id 15.20.5566.015; Fri, 26 Aug 2022 08:51:17 +0000 From: "Ni, Ray" To: "Liu, Zhiguang" , "devel@edk2.groups.io" CC: "Dong, Eric" , "Kumar, Rahul R" Subject: Re: [PATCH v4] UefiCpuPkg: Enhance logic in InitializeMpExceptionStackSwitchHandlers Thread-Topic: [PATCH v4] UefiCpuPkg: Enhance logic in InitializeMpExceptionStackSwitchHandlers Thread-Index: AQHYuR71XfUKfdh5bEqbaTcodFuCsq3A31Lw Date: Fri, 26 Aug 2022 08:51:17 +0000 Message-ID: References: <20220826073901.2634-1-zhiguang.liu@intel.com> In-Reply-To: <20220826073901.2634-1-zhiguang.liu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e8c07bb2-e64d-41c5-b737-08da874023b9 x-ms-traffictypediagnostic: BL1PR11MB6001:EE_ x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: nzLrylvo31FMjTPpj8EASlvqUIj4MnlIrzcahc9LVcB4sMspBUhFfH0dmSntmLtcgWogF6DjPaR8Sv43Mo4tWDyvk69sabWa+6xUKyLveuLJrNujNldNOyQlBPpXqqvYyJ9WDzR14TX3ZStMZQD5KfohpPNZLlQxc+rFZv+A+pKDy6j6baBB6nxUYuQ1SCwN62ZAFa4YXy9pDoHYZQ32xzE61i+pPVoBlfxCoGMZ7LobAIJmP9tqh892rclviLOolIWUQzNl2GRl4BRK+rVPeyOpJY/cW4zXeSHPoKRnjcK3d0dM4sh2zUG7Kvdj1dzyDjT4IRFT7PSMq2ryUZeR9TS7p3pu485svAy8ty33EyaO+yzjMkIjR4DBXQp5kuYKsu5PICqoT+bGt8r3SajPZ5xHKBlao7qjsrx3UgjrXn36ywGRE9znlp1GqUIaPX+NftGOcXs+IPBmrhPPtuXavT6hXEGLphbk9znjfR5FdZdmGjdYgav9C5Ud2kDUg29WHAJ7vVnNYH7l9d57JMY7U9x25IXQjRfrjh8UxpWtvV8MJyANOSqlxuDlMh/bu93BMhibYGwlGy/GMWnEmaYfwJ1X+T3R2laEGnzvjiyt9HG7fAzQxUlUuZkuKb7nQraVY/GWOmoZlH4raDTxruioZ8m4aex8FSYTsnCGOM4AKdUNYSm7hxOtYmTDhrIWakEE+u4MNNdHcZ4XTqmuD1FQ4IlBerEyW2Ak8sePTG//a1uQ+Z6Syv6alSEyFusTKGd82PAPVZnb9rhCLnzscCn2FQ== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR11MB1631.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(6029001)(136003)(376002)(39860400002)(396003)(346002)(366004)(66946007)(316002)(54906003)(110136005)(64756008)(38100700002)(66476007)(8676002)(4326008)(66556008)(30864003)(55016003)(66446008)(76116006)(8936002)(2906002)(5660300002)(122000001)(33656002)(86362001)(107886003)(82960400001)(38070700005)(52536014)(53546011)(6506007)(26005)(41300700001)(478600001)(71200400001)(9686003)(7696005)(186003)(83380400001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?BKGW2FxFtEBAE/VhoJlLzwmaP8YaAekMsGtEx2fZQeKBnLffbUqmaIizJOGo?= =?us-ascii?Q?P3+1ZOnhFPDYdvpUgJ+lgZUSt9eavqVgdPsMY6gOEoo/RQ0jHyRI0iRR/8f7?= =?us-ascii?Q?nbsBCgJeFaLFmDD7UkL8g1muFc7m8q+EUq1HCgzDS9gNo8mKi2vI4bBBmNFa?= =?us-ascii?Q?MoYizT2JnRrdtgOjmqEdAKqIKXyuC24isQjo2trJY1BWzTFkWJ1EMcA5bKgT?= =?us-ascii?Q?t0g6mmJbs18UPwvIfxMsMkclYUp0ep42DIIr4/B5CXJnsfGPQBNFNQiD1ZC/?= =?us-ascii?Q?cSwLxH8L2nYlCjNHkLE1yPtC1KkZH/oqWUYbyOXLn9DsOxlUNTOwFa0PsP0Q?= =?us-ascii?Q?INsapMDIE3S5fwGdQj4jYsahqA6jmMtjbxApsD47uwnFwiiVWCGt8t04q4W2?= =?us-ascii?Q?YrUWIHwQ2sZbyUWLTPLV0OqLnbGhcSNjAxTVdTKvJ+TvGMCWbjiTH8Wr/eQ1?= =?us-ascii?Q?zvj5RHCGx5wsLZFxKXyE/5lo0+y4YsSoKb4DXtokhx0adM3145zSAfMpSRLN?= =?us-ascii?Q?OaWZNkmrAiqPBkPW1U0DNsAdfw2c+ybEV3bS/zCdtWavtp2jvkjZmizo07sU?= =?us-ascii?Q?o4wodwIVjtEQLKLM8vXc9iuwHMJKiAutmL5a5a/9R8OeQLyeK2m21d2sjec3?= =?us-ascii?Q?cjYfX+C3CCYjAscNzfBeWBR8kaoTXE3KG+HMtfdvcNOvKhg4T5S9uw6gOtyK?= =?us-ascii?Q?zUBKkojjA5khS9UD6ipCb/QsFp74LmBDkswrXOXSNcj/BP3gEgyzxgpkBK9u?= =?us-ascii?Q?QpLPh3wGGmH7aK3lRuUfNZ8Yb50moqH95Pn0uiNHibsyNAAX24770nJJd3yU?= =?us-ascii?Q?DfIr8axmKrn/194CIs6pQvEzlm6232aZDnM7JtwREAhBpcjKcS6ANYU4APPs?= =?us-ascii?Q?8u0y2uO3nnjOU1ejDOIWVKVT+6b3bCskmsgIs9/ahEkVw5wjsAF543i8g11J?= =?us-ascii?Q?obhszLek4ypKXUEGTr3/3WQY69vjzpQkf6m5GINSIqGWzgfp02evSEveOeVQ?= =?us-ascii?Q?UqpKtX4dpCX0kB60ZF7ufRJJ2v2KOPztgchCA5PsXr2TyUSROa9tq0FM0oVg?= =?us-ascii?Q?9Aj9jqIcKHRQFKhgX4b4T8bvy3MDbyDnRYZ6eQhWiWdax6orhr+VH3AKCOsB?= =?us-ascii?Q?d+LkOOczsqKIeLBj1onIBVbH/9gc1eJ6Bll+MBx0xAA6PBD2CqaSiqvLBVqn?= =?us-ascii?Q?p4pSIAtxIE3Yce7TVeThfGXp/RJ6hFkWeNqwPs+Q6JsdL/b58z/NY3J8InwG?= =?us-ascii?Q?pjyVIP9/jaJtRrm5ULdKo/LornDu4eJuCGWjblaUINjGLAu6LR5PoovtEXQ6?= =?us-ascii?Q?WyizKvL73iMGYmrLRZcJg93jpCMoAUauGazWFKlOS1mrt8bSvrILV0ZQlAPX?= =?us-ascii?Q?8k1kIuwKv0MjD/X/omcbTG8k1a2f6sFnVeC8lwdqHff0Om5GRIFKveaNjzdQ?= =?us-ascii?Q?K2e2y4HU4asI3GldIkiWhklMdhLvgrREhV3ssMECGqWM5l88yHR3e/B3oi+J?= =?us-ascii?Q?e5R2d0FxSGlaC1f7z97qA/eVJ7TVauILJ1kfEShG1pGi0sXtCmU3mGPmCgnh?= =?us-ascii?Q?Kv0K7GOLHv1kMWFKcDKZm/6Hg09qR4/5L3BnnwQT?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MWHPR11MB1631.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e8c07bb2-e64d-41c5-b737-08da874023b9 X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Aug 2022 08:51:17.3220 (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: ANlvi2+4nmdBmIXQNa918V6qQo2wsKrn4L0UerbIlRxm/QwArd71eqwjfJ89xdUTXAaXaIo3FzPcADAZ7s/TXw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR11MB6001 Return-Path: ray.ni@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Ray Ni > -----Original Message----- > From: Liu, Zhiguang > Sent: Friday, August 26, 2022 3:39 PM > To: devel@edk2.groups.io > Cc: Liu, Zhiguang ; Dong, Eric > ; Ni, Ray ; Kumar, Rahul R > > Subject: [PATCH v4] UefiCpuPkg: Enhance logic in > InitializeMpExceptionStackSwitchHandlers >=20 > Parallelly run the function to SeparateExceptionStacks for all CPUs and > allocate buffers together for better performance. >=20 > Cc: Eric Dong > Cc: Ray Ni > Cc: Rahul Kumar > Signed-off-by: Zhiguang Liu > --- > UefiCpuPkg/CpuDxe/CpuMp.c | 104 +++++++++++++++++++------------ > UefiCpuPkg/CpuMpPei/CpuMpPei.c | 108 ++++++++++++++++++++--------- > ---- > 2 files changed, 132 insertions(+), 80 deletions(-) >=20 > diff --git a/UefiCpuPkg/CpuDxe/CpuMp.c b/UefiCpuPkg/CpuDxe/CpuMp.c > index f3ca813d2a..e7575d9b80 100644 > --- a/UefiCpuPkg/CpuDxe/CpuMp.c > +++ b/UefiCpuPkg/CpuDxe/CpuMp.c > @@ -600,8 +600,9 @@ CollectBistDataFromHob ( > // Structure for InitializeSeparateExceptionStacks > // > typedef struct { > - VOID *Buffer; > - UINTN *BufferSize; > + VOID *Buffer; > + UINTN BufferSize; > + EFI_STATUS Status; > } EXCEPTION_STACK_SWITCH_CONTEXT; >=20 > /** > @@ -620,9 +621,18 @@ InitializeExceptionStackSwitchHandlers ( > ) > { > EXCEPTION_STACK_SWITCH_CONTEXT *SwitchStackData; > + UINTN Index; >=20 > + MpInitLibWhoAmI (&Index); > SwitchStackData =3D (EXCEPTION_STACK_SWITCH_CONTEXT *)Buffer; > - InitializeSeparateExceptionStacks (SwitchStackData->Buffer, > SwitchStackData->BufferSize); > + > + // > + // This may be called twice for each Cpu. Only run > InitializeSeparateExceptionStacks > + // if this is the first call or the first call failed because of size = too small. > + // > + if ((SwitchStackData[Index].Status =3D=3D EFI_NOT_STARTED) || > (SwitchStackData[Index].Status =3D=3D EFI_BUFFER_TOO_SMALL)) { > + SwitchStackData[Index].Status =3D InitializeSeparateExceptionStacks > (SwitchStackData[Index].Buffer, &SwitchStackData[Index].BufferSize); > + } > } >=20 > /** > @@ -638,53 +648,69 @@ InitializeMpExceptionStackSwitchHandlers ( > ) > { > UINTN Index; > - UINTN Bsp; > - EXCEPTION_STACK_SWITCH_CONTEXT SwitchStackData; > + EXCEPTION_STACK_SWITCH_CONTEXT *SwitchStackData; > UINTN BufferSize; > + EFI_STATUS Status; > + UINT8 *Buffer; >=20 > - SwitchStackData.BufferSize =3D &BufferSize; > - MpInitLibWhoAmI (&Bsp); > - > + SwitchStackData =3D AllocateZeroPool (mNumberOfProcessors * sizeof > (EXCEPTION_STACK_SWITCH_CONTEXT)); > + ASSERT (SwitchStackData !=3D NULL); > for (Index =3D 0; Index < mNumberOfProcessors; ++Index) { > - SwitchStackData.Buffer =3D NULL; > - BufferSize =3D 0; > + // > + // Because the procedure may runs multiple times, use the status > EFI_NOT_STARTED > + // to indicate the procedure haven't been run yet. > + // > + SwitchStackData[Index].Status =3D EFI_NOT_STARTED; > + } >=20 > - if (Index =3D=3D Bsp) { > - InitializeExceptionStackSwitchHandlers (&SwitchStackData); > + Status =3D MpInitLibStartupAllCPUs ( > + InitializeExceptionStackSwitchHandlers, > + 0, > + SwitchStackData > + ); > + ASSERT_EFI_ERROR (Status); > + > + BufferSize =3D 0; > + for (Index =3D 0; Index < mNumberOfProcessors; ++Index) { > + if (SwitchStackData[Index].Status =3D=3D EFI_BUFFER_TOO_SMALL) { > + ASSERT (SwitchStackData[Index].BufferSize !=3D 0); > + BufferSize +=3D SwitchStackData[Index].BufferSize; > } else { > - // > - // AP might need different buffer size from BSP. > - // > - MpInitLibStartupThisAP (InitializeExceptionStackSwitchHandlers, In= dex, > NULL, 0, (VOID *)&SwitchStackData, NULL); > + ASSERT (SwitchStackData[Index].Status =3D=3D EFI_SUCCESS); > + ASSERT (SwitchStackData[Index].BufferSize =3D=3D 0); > } > + } >=20 > - if (BufferSize =3D=3D 0) { > - continue; > + if (BufferSize !=3D 0) { > + Buffer =3D AllocateRuntimeZeroPool (BufferSize); > + ASSERT (Buffer !=3D NULL); > + BufferSize =3D 0; > + for (Index =3D 0; Index < mNumberOfProcessors; ++Index) { > + if (SwitchStackData[Index].Status =3D=3D EFI_BUFFER_TOO_SMALL) { > + SwitchStackData[Index].Buffer =3D (VOID *)(&Buffer[BufferSize]); > + BufferSize +=3D SwitchStackData[Index].BufferS= ize; > + DEBUG (( > + DEBUG_INFO, > + "Buffer[cpu%lu] for InitializeExceptionStackSwitchHandlers: 0x= %lX with > size 0x%lX\n", > + (UINT64)(UINTN)Index, > + (UINT64)(UINTN)SwitchStackData[Index].Buffer, > + (UINT64)(UINTN)SwitchStackData[Index].BufferSize > + )); > + } > } >=20 > - SwitchStackData.Buffer =3D AllocateRuntimeZeroPool (BufferSize); > - ASSERT (SwitchStackData.Buffer !=3D NULL); > - DEBUG (( > - DEBUG_INFO, > - "Buffer[cpu%lu] for InitializeExceptionStackSwitchHandlers: 0x%lX = with > size 0x%x\n", > - (UINT64)(UINTN)Index, > - (UINT64)(UINTN)SwitchStackData.Buffer, > - (UINT32)BufferSize > - )); > - > - if (Index =3D=3D Bsp) { > - InitializeExceptionStackSwitchHandlers (&SwitchStackData); > - } else { > - MpInitLibStartupThisAP ( > - InitializeExceptionStackSwitchHandlers, > - Index, > - NULL, > - 0, > - (VOID *)&SwitchStackData, > - NULL > - ); > + Status =3D MpInitLibStartupAllCPUs ( > + InitializeExceptionStackSwitchHandlers, > + 0, > + SwitchStackData > + ); > + ASSERT_EFI_ERROR (Status); > + for (Index =3D 0; Index < mNumberOfProcessors; ++Index) { > + ASSERT (SwitchStackData[Index].Status =3D=3D EFI_SUCCESS); > } > } > + > + FreePool (SwitchStackData); > } >=20 > /** > diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.c > b/UefiCpuPkg/CpuMpPei/CpuMpPei.c > index c0be11d3ad..e7f1fe9f42 100644 > --- a/UefiCpuPkg/CpuMpPei/CpuMpPei.c > +++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.c > @@ -415,8 +415,9 @@ PeiWhoAmI ( > // Structure for InitializeSeparateExceptionStacks > // > typedef struct { > - VOID *Buffer; > - UINTN *BufferSize; > + VOID *Buffer; > + UINTN BufferSize; > + EFI_STATUS Status; > } EXCEPTION_STACK_SWITCH_CONTEXT; >=20 > /** > @@ -435,9 +436,18 @@ InitializeExceptionStackSwitchHandlers ( > ) > { > EXCEPTION_STACK_SWITCH_CONTEXT *SwitchStackData; > + UINTN Index; >=20 > + MpInitLibWhoAmI (&Index); > SwitchStackData =3D (EXCEPTION_STACK_SWITCH_CONTEXT *)Buffer; > - InitializeSeparateExceptionStacks (SwitchStackData->Buffer, > SwitchStackData->BufferSize); > + > + // > + // This function may be called twice for each Cpu. Only run > InitializeSeparateExceptionStacks > + // if this is the first call or the first call failed because of size = too small. > + // > + if ((SwitchStackData[Index].Status =3D=3D EFI_NOT_STARTED) || > (SwitchStackData[Index].Status =3D=3D EFI_BUFFER_TOO_SMALL)) { > + SwitchStackData[Index].Status =3D InitializeSeparateExceptionStacks > (SwitchStackData[Index].Buffer, &SwitchStackData[Index].BufferSize); > + } > } >=20 > /** > @@ -453,60 +463,76 @@ InitializeMpExceptionStackSwitchHandlers ( > ) > { > UINTN Index; > - UINTN Bsp; > - EXCEPTION_STACK_SWITCH_CONTEXT SwitchStackData; > - UINTN BufferSize; > UINTN NumberOfProcessors; > + EXCEPTION_STACK_SWITCH_CONTEXT *SwitchStackData; > + UINTN BufferSize; > + EFI_STATUS Status; > + UINT8 *Buffer; >=20 > if (!PcdGetBool (PcdCpuStackGuard)) { > return; > } >=20 > - SwitchStackData.BufferSize =3D &BufferSize; > MpInitLibGetNumberOfProcessors (&NumberOfProcessors, NULL); > - MpInitLibWhoAmI (&Bsp); > - > + SwitchStackData =3D AllocatePages (EFI_SIZE_TO_PAGES > (NumberOfProcessors * sizeof (EXCEPTION_STACK_SWITCH_CONTEXT))); > + ASSERT (SwitchStackData !=3D NULL); > + ZeroMem (SwitchStackData, NumberOfProcessors * sizeof > (EXCEPTION_STACK_SWITCH_CONTEXT)); > for (Index =3D 0; Index < NumberOfProcessors; ++Index) { > - SwitchStackData.Buffer =3D NULL; > - BufferSize =3D 0; > + // > + // Because the procedure may runs multiple times, use the status > EFI_NOT_STARTED > + // to indicate the procedure haven't been run yet. > + // > + SwitchStackData[Index].Status =3D EFI_NOT_STARTED; > + } > + > + Status =3D MpInitLibStartupAllCPUs ( > + InitializeExceptionStackSwitchHandlers, > + 0, > + SwitchStackData > + ); > + ASSERT_EFI_ERROR (Status); >=20 > - if (Index =3D=3D Bsp) { > - InitializeExceptionStackSwitchHandlers (&SwitchStackData); > + BufferSize =3D 0; > + for (Index =3D 0; Index < NumberOfProcessors; ++Index) { > + if (SwitchStackData[Index].Status =3D=3D EFI_BUFFER_TOO_SMALL) { > + ASSERT (SwitchStackData[Index].BufferSize !=3D 0); > + BufferSize +=3D SwitchStackData[Index].BufferSize; > } else { > - // > - // AP might need different buffer size from BSP. > - // > - MpInitLibStartupThisAP (InitializeExceptionStackSwitchHandlers, In= dex, > NULL, 0, (VOID *)&SwitchStackData, NULL); > + ASSERT (SwitchStackData[Index].Status =3D=3D EFI_SUCCESS); > + ASSERT (SwitchStackData[Index].BufferSize =3D=3D 0); > } > + } >=20 > - if (BufferSize =3D=3D 0) { > - continue; > + if (BufferSize !=3D 0) { > + Buffer =3D AllocatePages (EFI_SIZE_TO_PAGES (BufferSize)); > + ASSERT (Buffer !=3D NULL); > + BufferSize =3D 0; > + for (Index =3D 0; Index < NumberOfProcessors; ++Index) { > + if (SwitchStackData[Index].Status =3D=3D EFI_BUFFER_TOO_SMALL) { > + SwitchStackData[Index].Buffer =3D (VOID *)(&Buffer[BufferSize]); > + BufferSize +=3D SwitchStackData[Index].BufferS= ize; > + DEBUG (( > + DEBUG_INFO, > + "Buffer[cpu%lu] for InitializeExceptionStackSwitchHandlers: 0x= %lX with > size 0x%lX\n", > + (UINT64)(UINTN)Index, > + (UINT64)(UINTN)SwitchStackData[Index].Buffer, > + (UINT64)(UINTN)SwitchStackData[Index].BufferSize > + )); > + } > } >=20 > - SwitchStackData.Buffer =3D AllocatePages (EFI_SIZE_TO_PAGES > (BufferSize)); > - ASSERT (SwitchStackData.Buffer !=3D NULL); > - ZeroMem (SwitchStackData.Buffer, EFI_PAGES_TO_SIZE > (EFI_SIZE_TO_PAGES (BufferSize))); > - DEBUG (( > - DEBUG_INFO, > - "Buffer[cpu%lu] for InitializeExceptionStackSwitchHandlers: 0x%lX = with > size 0x%x\n", > - (UINT64)(UINTN)Index, > - (UINT64)(UINTN)SwitchStackData.Buffer, > - (UINT32)BufferSize > - )); > - > - if (Index =3D=3D Bsp) { > - InitializeExceptionStackSwitchHandlers (&SwitchStackData); > - } else { > - MpInitLibStartupThisAP ( > - InitializeExceptionStackSwitchHandlers, > - Index, > - NULL, > - 0, > - (VOID *)&SwitchStackData, > - NULL > - ); > + Status =3D MpInitLibStartupAllCPUs ( > + InitializeExceptionStackSwitchHandlers, > + 0, > + SwitchStackData > + ); > + ASSERT_EFI_ERROR (Status); > + for (Index =3D 0; Index < NumberOfProcessors; ++Index) { > + ASSERT (SwitchStackData[Index].Status =3D=3D EFI_SUCCESS); > } > } > + > + FreePages (SwitchStackData, EFI_SIZE_TO_PAGES (NumberOfProcessors * > sizeof (EXCEPTION_STACK_SWITCH_CONTEXT))); > } >=20 > /** > -- > 2.31.1.windows.1