From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web08.6092.1615280261753160583 for ; Tue, 09 Mar 2021 00:57:41 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.115, mailfrom: ray.ni@intel.com) IronPort-SDR: RrpXQl1AtOiBkQOefAeNOKMWgckz2WrEDf4AIqpUVKKMKxWjiPj65yCsDGSqvDJSCCEqljI+iH xJPuq7Vj8WFg== X-IronPort-AV: E=McAfee;i="6000,8403,9917"; a="187554980" X-IronPort-AV: E=Sophos;i="5.81,234,1610438400"; d="scan'208";a="187554980" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Mar 2021 00:57:40 -0800 IronPort-SDR: 6KC/0zrLUoyUKVlTd9Xigh09pqc/8n6uRcuxyF8IYXSF6RM5WxdvTG3bCN+4gIcXz8dRrPQwDc UjtbBXByISEg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,234,1610438400"; d="scan'208";a="599233619" Received: from ray-dev.ccr.corp.intel.com ([10.239.158.87]) by fmsmga006.fm.intel.com with ESMTP; 09 Mar 2021 00:57:39 -0800 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Eric Dong , Laszlo Ersek , Rahul Kumar Subject: [PATCH v2] UefiCpuPkg/PiSmmCpu: Don't allocate Token for SmmStartupThisAp Date: Tue, 9 Mar 2021 16:57:30 +0800 Message-Id: <20210309085730.1720-1-ray.ni@intel.com> X-Mailer: git-send-email 2.27.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3199 When Token points to mSmmStartupThisApToken, this routine is called from SmmStartupThisAp() in non-blocking mode due to PcdCpuSmmBlockStartupThisAp =3D=3D FALSE. In this case, caller wants to startup AP procedure in non-blocking mode and cannot get the completion status from the Token because there is no way to return the Token to caller from SmmStartupThisAp(). Caller needs to use its specific way to query the completion status. There is no need to allocate a token for such case so the 3 overheads can be avoided: 1. Call AllocateTokenBuffer() when there is no free token. 2. Get a free token from the token buffer. 3. Call ReleaseToken() in APHandler(). Signed-off-by: Ray Ni Cc: Eric Dong Reviewed-by: Laszlo Ersek Cc: Rahul Kumar --- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxe= Smm/MpService.c index 6227b2428a..91452ec398 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -1,7 +1,7 @@ /** @file=0D SMM MP service implementation=0D =0D -Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.
=0D +Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.
=0D Copyright (c) 2017, AMD Incorporated. All rights reserved.
=0D =0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D @@ -22,6 +22,7 @@ UINTN mSemaphoreSiz= e; SPIN_LOCK *mPFLock =3D NULL;=0D SMM_CPU_SYNC_MODE mCpuSmmSyncMode;=0D BOOLEAN mMachineCheckSupported =3D FAL= SE;=0D +MM_COMPLETION mSmmStartupThisApToken;=0D =0D extern UINTN mSmmShadowStackSize;=0D =0D @@ -1240,9 +1241,23 @@ InternalSmmStartupThisAp ( mSmmMpSyncData->CpuData[CpuIndex].Procedure =3D Procedure;=0D mSmmMpSyncData->CpuData[CpuIndex].Parameter =3D ProcArguments;=0D if (Token !=3D NULL) {=0D - ProcToken=3D GetFreeToken (1);=0D - mSmmMpSyncData->CpuData[CpuIndex].Token =3D ProcToken;=0D - *Token =3D (MM_COMPLETION)ProcToken->SpinLock;=0D + if (Token !=3D &mSmmStartupThisApToken) {=0D + //=0D + // When Token points to mSmmStartupThisApToken, this routine is call= ed=0D + // from SmmStartupThisAp() in non-blocking mode (PcdCpuSmmBlockStart= upThisAp =3D=3D FALSE).=0D + //=0D + // In this case, caller wants to startup AP procedure in non-blockin= g=0D + // mode and cannot get the completion status from the Token because = there=0D + // is no way to return the Token to caller from SmmStartupThisAp().= =0D + // Caller needs to use its implementation specific way to query the = completion status.=0D + //=0D + // There is no need to allocate a token for such case so the overhea= d of SMRAM and=0D + // the allocation operation can be avoided.=0D + //=0D + ProcToken=3D GetFreeToken (1);=0D + mSmmMpSyncData->CpuData[CpuIndex].Token =3D ProcToken;=0D + *Token =3D (MM_COMPLETION)ProcToken->SpinLock;=0D + }=0D }=0D mSmmMpSyncData->CpuData[CpuIndex].Status =3D CpuStatus;=0D if (mSmmMpSyncData->CpuData[CpuIndex].Status !=3D NULL) {=0D @@ -1474,8 +1489,6 @@ SmmStartupThisAp ( IN OUT VOID *ProcArguments OPTIONAL=0D )=0D {=0D - MM_COMPLETION Token;=0D -=0D gSmmCpuPrivate->ApWrapperFunc[CpuIndex].Procedure =3D Procedure;=0D gSmmCpuPrivate->ApWrapperFunc[CpuIndex].ProcedureArgument =3D ProcArgume= nts;=0D =0D @@ -1486,7 +1499,7 @@ SmmStartupThisAp ( ProcedureWrapper,=0D CpuIndex,=0D &gSmmCpuPrivate->ApWrapperFunc[CpuIndex],=0D - FeaturePcdGet (PcdCpuSmmBlockStartupThisAp) ? NULL : &Token,=0D + FeaturePcdGet (PcdCpuSmmBlockStartupThisAp) ? NULL : &mSmmStartupThisA= pToken,=0D 0,=0D NULL=0D );=0D --=20 2.27.0.windows.1