From nobody Tue May 14 01:18:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+110965+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+110965+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1699526123; cv=none; d=zohomail.com; s=zohoarc; b=e7/RWqsVYIIQOsgyTMT7AXNBZgYPPskTaT3Yt/GvP7rY+BffOjpfv7oNMv77PZFB+3sS8crjpgpiZ6EWOhRjeoaqq2jDsrW1ppnoEAnZeuHKdjyAd4VhTcmCL3aUrxVGmL9NPKeRr4R7pac4FDBNRlnzNyXt6Yjmj4hBruzmxfM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699526123; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=qrYHN4icvHfF7l72MrSXkoT+5oVBf+rCYtvLq561mOs=; b=Dswm6wKCRbEyVELwYvVexH0ggHSaYeZ5MDpcZvyo5EXAJXODeUDZ5R9RZPA9A47gmpHi/c0qU4dGyMXtQx1BKlJ4ZZ1fgZ7nCgHHkaNmkfKYLuoamZ1cxaZCkCG8Sw94u5P6iQbN+pZ9JyyY9HeXxjdK5fxCGBqDreaGsLvIkgY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+110965+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1699526123534764.6996610249729; Thu, 9 Nov 2023 02:35:23 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=vWpuiEU4VlLO4KG0mnN6zwVoTb2aXLRqoBNtr2JJioA=; 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=F5cBcvF5G53b9wArZ/sU7wmi66QhW1vex3uul7RTIcS9dp3EzAU000yQh9prTo+e4MbFUcgI Gn8JDRlUk4Pz8knAkRYPke6Kprg7TPrMiSf/Esepk7XYVkd9K0vHiJzx4qDakVX51GPDOi9HzpG qCWO1fGgY8iOXw4eE2HGEM08= X-Received: by 127.0.0.2 with SMTP id OfOWYY1788612xof88RLqsCN; 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: pXnx2d9qMnnlz9FStFttXywwx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1699526125433100003 Content-Type: text/plain; charset="utf-8" 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 ) { + UINTN Index; + UINTN PresentCount; + UINT32 BlockedCount; + UINT32 DisabledCount; EFI_STATUS Status; =20 + BlockedCount =3D 0; + DisabledCount =3D 0; + // // Return success immediately if all CPUs are already synchronized. // @@ -426,6 +433,24 @@ SmmCpuRendezvous ( // There are some APs outside SMM, Wait for all avaiable APs to arrive. // SmmWaitForApArrival (); + + // + // Make sure all APs have their Present flag set + // + while (TRUE) { + PresentCount =3D 0; + for (Index =3D 0; Index < mMaxNumberOfCpus; Index++) { + if (*(mSmmMpSyncData->CpuData[Index].Present)) { + PresentCount++; + } + } + + GetSmmDelayedBlockedDisabledCount (NULL, &BlockedCount, &DisabledCou= nt); + if (PresentCount =3D=3D mMaxNumberOfCpus - BlockedCount - DisabledCo= unt ) { + break; + } + } + Status =3D mSmmMpSyncData->AllApArrivedWithException ? EFI_SUCCESS : E= FI_TIMEOUT; } else { // 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 ); =20 +/** + Returns the Number of SMM Delayed & Blocked & Disabled Thread Count. + @param[in,out] DelayedCount The Number of SMM Delayed Thread Count. + @param[in,out] BlockedCount The Number of SMM Blocked Thread Count. + @param[in,out] DisabledCount The Number of SMM Disabled Thread Count. +**/ +VOID +GetSmmDelayedBlockedDisabledCount ( + IN OUT UINT32 *DelayedCount, + IN OUT UINT32 *BlockedCount, + IN OUT UINT32 *DisabledCount + ); + /** Disable Write Protect on pages marked as read-only if Cr0.Bits.WP is 1. =20 --=20 2.39.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- 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/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-