From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 94917941A4A for ; Thu, 9 Nov 2023 10:35:24 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=h4qkhs+w9LYeeS69TZAZv+nf+6ca/y2XfXoduyDzEVc=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1699526123; v=1; b=PGt3jVdrIeEmv/iL9GiGC/BQ89/WJ5RsVmWIvolBMYieVfARJlOOLwDkR7It/2UAuGsznALE B8ObtMMOO/8jaaG2ITclmQ+GwNd0NbPsNd7/Ai/gZNQYnccrSRz9ERPKo5pg6w8k3xbWDcTBy9V r9+flgouHgF5u+l/8LWlq/aQ= X-Received: by 127.0.0.2 with SMTP id RQzEYY7687511xRwnUHal9Uj; Thu, 09 Nov 2023 02:35:23 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web10.118600.1699526121894573187 for ; Thu, 09 Nov 2023 02:35:22 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10888"; a="454263097" X-IronPort-AV: E=Sophos;i="6.03,289,1694761200"; d="scan'208";a="454263097" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2023 02:35:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10888"; a="766956200" X-IronPort-AV: E=Sophos;i="6.03,289,1694761200"; d="scan'208";a="766956200" X-Received: from shwdeopenlab813.ccr.corp.intel.com ([10.239.55.230]) by fmsmga007.fm.intel.com with ESMTP; 09 Nov 2023 02:35:18 -0800 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: YuanhaoXie , Zhihao Li , Ray Ni , Rahul Kumar , Gerd Hoffmann , Jiaxin Wu Subject: [edk2-devel] [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: SmmCpuRendezvous ensure all Aps in Present. Date: Thu, 9 Nov 2023 18:35:16 +0800 Message-Id: <20231109103516.906-1-yuanhao.xie@intel.com> MIME-Version: 1.0 Precedence: Bulk 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,yuanhao.xie@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 8mzkOPdNA335EnAgQmFYomQzx7686176AA= Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=PGt3jVdr; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io From: YuanhaoXie SmmCpuRendezvous has a issue in that it summons all APs into SMM, but there is a time gap before they are set as "present." During this window, if using the "setVariable" operation, it can cause issues since "setVariable" requires all APs to be in SMM and marked as "present." Therefore, this patch adds extra logic to "SmmCpuRendezvous" to check if the APs are already "present" before proceeding. Signed-off-by: Zhihao Li Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann Cc: Jiaxin Wu --- UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c | 25 ++++++++++++++++++++++ UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 13 +++++++++++ 2 files changed, 38 insertions(+) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c b/UefiCpuPkg/PiSmmCpuDx= eSmm/CpuService.c index 391b64e9f2..cdc7021ee9 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c @@ -406,8 +406,15 @@ SmmCpuRendezvous ( IN BOOLEAN BlockingMode=0D )=0D {=0D + UINTN Index;=0D + UINTN PresentCount;=0D + UINT32 BlockedCount;=0D + UINT32 DisabledCount;=0D EFI_STATUS Status;=0D =0D + BlockedCount =3D 0;=0D + DisabledCount =3D 0;=0D +=0D //=0D // Return success immediately if all CPUs are already synchronized.=0D //=0D @@ -426,6 +433,24 @@ SmmCpuRendezvous ( // There are some APs outside SMM, Wait for all avaiable APs to arrive= .=0D //=0D SmmWaitForApArrival ();=0D +=0D + //=0D + // Make sure all APs have their Present flag set=0D + //=0D + while (TRUE) {=0D + PresentCount =3D 0;=0D + for (Index =3D 0; Index < mMaxNumberOfCpus; Index++) {=0D + if (*(mSmmMpSyncData->CpuData[Index].Present)) {=0D + PresentCount++;=0D + }=0D + }=0D +=0D + GetSmmDelayedBlockedDisabledCount (NULL, &BlockedCount, &DisabledCou= nt);=0D + if (PresentCount =3D=3D mMaxNumberOfCpus - BlockedCount - DisabledCo= unt ) {=0D + break;=0D + }=0D + }=0D +=0D Status =3D mSmmMpSyncData->AllApArrivedWithException ? EFI_SUCCESS : E= FI_TIMEOUT;=0D } else {=0D //=0D diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmC= puDxeSmm/PiSmmCpuDxeSmm.h index 654935dc76..0a227d86b2 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h @@ -1552,6 +1552,19 @@ SmmWaitForApArrival ( VOID=0D );=0D =0D +/**=0D + Returns the Number of SMM Delayed & Blocked & Disabled Thread Count.=0D + @param[in,out] DelayedCount The Number of SMM Delayed Thread Count.=0D + @param[in,out] BlockedCount The Number of SMM Blocked Thread Count.=0D + @param[in,out] DisabledCount The Number of SMM Disabled Thread Count.=0D +**/=0D +VOID=0D +GetSmmDelayedBlockedDisabledCount (=0D + IN OUT UINT32 *DelayedCount,=0D + IN OUT UINT32 *BlockedCount,=0D + IN OUT UINT32 *DisabledCount=0D + );=0D +=0D /**=0D Disable Write Protect on pages marked as read-only if Cr0.Bits.WP is 1.= =0D =0D --=20 2.39.1.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#110965): https://edk2.groups.io/g/devel/message/110965 Mute This Topic: https://groups.io/mt/102482983/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-