From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mx.groups.io with SMTP id smtpd.web08.6155.1615280967805096422 for ; Tue, 09 Mar 2021 01:09:27 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.120, mailfrom: ray.ni@intel.com) IronPort-SDR: Ow3mn8W38PoAw95en0oOvjJgBdHSAOcrSh0p78+ePucLB3LxG7lUU8p9MHzympT60J6MUWL/4H 2CCKmYPKu7WA== X-IronPort-AV: E=McAfee;i="6000,8403,9917"; a="185810827" X-IronPort-AV: E=Sophos;i="5.81,234,1610438400"; d="scan'208";a="185810827" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Mar 2021 01:09:25 -0800 IronPort-SDR: /6fUEZcS/StJIpqsBYwgTM1GHlbWfp9OBJuqQRiiG/LD/prPPnGMKZrUbJmPNLPsKuHKs11DH6 KcZ+/JVt2nVA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,234,1610438400"; d="scan'208";a="599240063" Received: from ray-dev.ccr.corp.intel.com ([10.239.158.87]) by fmsmga006.fm.intel.com with ESMTP; 09 Mar 2021 01:09:24 -0800 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Eric Dong , Laszlo Ersek , Rahul Kumar Subject: [PATCH v3] UefiCpuPkg/PiSmmCpu: Don't allocate Token for SmmStartupThisAp Date: Tue, 9 Mar 2021 17:09:16 +0800 Message-Id: <20210309090916.1815-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 | 30 ++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxe= Smm/MpService.c index 6227b2428a..4f3c5f60a1 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,26 @@ 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 3 overh= eads=0D + // can be avoided:=0D + // 1. Call AllocateTokenBuffer() when there is no free token.=0D + // 2. Get a free token from the token buffer.=0D + // 3. Call ReleaseToken() in APHandler().=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 +1492,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 +1502,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