From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web10.30412.1615169817052534143 for ; Sun, 07 Mar 2021 18:16:57 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.88, mailfrom: ray.ni@intel.com) IronPort-SDR: SPT5uFyg58+LAKbkskbik3e6WJmtjW0ic6Ru9ZnwJ7zD8qTdm4onEsSCXHBiSJztpsb8YAtiCK Wi9x9kkBmHrg== X-IronPort-AV: E=McAfee;i="6000,8403,9916"; a="207707885" X-IronPort-AV: E=Sophos;i="5.81,231,1610438400"; d="scan'208";a="207707885" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Mar 2021 18:16:55 -0800 IronPort-SDR: 5DKoLvNpnlSlOWIKGSFeAeLl3Mfe4zlXpF+ZaNPIIyBRTHCFP3wX57MBcGe97iJBE1I5jI0AVl veKor7tabn3w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,231,1610438400"; d="scan'208";a="369273797" Received: from ray-dev.ccr.corp.intel.com ([10.239.158.87]) by orsmga003.jf.intel.com with ESMTP; 07 Mar 2021 18:16:54 -0800 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Eric Dong , Laszlo Ersek , Rahul Kumar Subject: [PATCH] UefiCpuPkg/PiSmmCpu: Don't allocate Token for SmmStartupThisAp Date: Mon, 8 Mar 2021 10:16:47 +0800 Message-Id: <20210308021647.528-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 2 overheads can be avoided: 1. Call AllocateTokenBuffer() when there is no free token. 2. Get a free token from the token buffer. Signed-off-by: Ray Ni Cc: Eric Dong Cc: 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..efb89832ca 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