From nobody Wed May 15 12:12:40 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+110035+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+110035+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1698231054; cv=none; d=zohomail.com; s=zohoarc; b=WNjNVAwICtEv186okzh19yZg9u4GzS6jHVOPqDXWVrfAHWqqJoilAeHE0rVSeoH2gsxcqJig+q3UN2kCy5q9fvRon68NrJk1v1ZY0375Vt6VxEnegRyWpBQ9qxu4cU/J+ou9n49VewMPPs7fs0Y1DTWAVcj+2GkftdJYdtxVem4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698231054; 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=ByQnMHrNgldLs24I236AHHF3Bm+7bc998znyuhrRz1M=; b=grLlhfbfVNwcbb0QeKl7HmPofhEFbVpx9xGnGQ5mFdYH8ufunxjYiBVjSXh1v539+JLc0smao8ODinjIQn2+7CNkkVoK1HGuwdLflhM2CPgDHM4moZ2cWOXICQiS6o81R+9y4MOhjxHyJhKNirMd6bvdZcb3EZLYWqUJ3RCkFLg= 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+110035+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 1698231054371201.97089586256675; Wed, 25 Oct 2023 03:50:54 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=gc7XCY234hOY/8FIHqTQxEQvfmFKU/Q0MTPL1iK+U6I=; 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=1698231053; v=1; b=F2x5m+9CZQsBSxLf3047dNrFmertzyA+oF+wvKi/bH4jtB7yhhKq14CfDpfG0agCHb6WRsKj JRWCJcglnI3CieUz/uQwdg6nvnFgfpJ4VP984XXZh5O4RXKzfmVwZtIgE6P7ehLDeL8z5DaJYcO Z42ZQMvzjMSlPnFzERSSDZio= X-Received: by 127.0.0.2 with SMTP id NPf9YY1788612xRabS6mlqUZ; Wed, 25 Oct 2023 03:50:53 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by mx.groups.io with SMTP id smtpd.web10.170459.1698231050186573960 for ; Wed, 25 Oct 2023 03:50:53 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10873"; a="5896117" X-IronPort-AV: E=Sophos;i="6.03,250,1694761200"; d="scan'208";a="5896117" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2023 03:50:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10873"; a="762416943" X-IronPort-AV: E=Sophos;i="6.03,250,1694761200"; d="scan'208";a="762416943" X-Received: from shwdeopenlab705.ccr.corp.intel.com ([10.239.55.100]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2023 03:50:45 -0700 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: Ray Ni , Eric Dong , Rahul Kumar , Tom Lendacky , Yuanhao Xie Subject: [edk2-devel] [Patch V2] UefiCpuPkg: Remove ASSERT checking if FinishedCount equal to CpuCount-1 Date: Wed, 25 Oct 2023 18:50:31 +0800 Message-Id: <20231025105031.2670-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: Iqf1tsqPyjaYZlJKxYtvuUmdx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1698231055777100003 Content-Type: text/plain; charset="utf-8" Aim: This patch aims to solve an assertion happens after SwitchApContext() on checking if CpuMpData->FinishedCount =3D=3D (CpuMpData->CpuCount - 1). The assertion issue due to a timing discrepancy between the BSP completing its Start-up signal checking and the APs incrementing the FinishedCount. In the SwitchApContext(), the BSP triggers the startup signal and checks if the APs have received it to awaken. After completing this check, the BSP then verifies if the FinishedCount is equal to CpuCount-1. For the APs, upon receiving the startup signal, they call the SwitchContextPerAp() and increment the FinishedCount to indicate their awakening. However, due to a timing discrepancy, even when all APs have received the startup signal, they might not have finished incrementing the FinishedCount. This timing issue results in the triggering of the assertion. Solution: Instead of assertion, use while loop to waits until all the APs have incremented the FinishedCount. Related Patches: This patch is a group of following patch series which is to eliminate the second INIT-SIPI-SIPI sequence. More detials could be seen in the comments in the following patches: UefiCpuPkg: Refactor the logic for placing APs in HltLoop. UefiCpuPkg: Refactor the logic for placing APs in Mwait/Runloop. UefiCpuPkg: Create MpHandOff. UefiCpuPkg: ApWakeupFunction directly use CpuMpData. UefiCpuPkg: Eliminate the second INIT-SIPI-SIPI sequence. UefiCpuPkg: Decouple the SEV-ES functionality. Cc: Ray Ni Cc: Eric Dong Cc: Rahul Kumar Cc: Tom Lendacky Signed-off-by: Yuanhao Xie --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 6f1456cfe1..9a6ec5db5c 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -913,8 +913,8 @@ DxeApEntryPoint ( UINTN ProcessorNumber; =20 GetProcessorNumber (CpuMpData, &ProcessorNumber); - InterlockedIncrement ((UINT32 *)&CpuMpData->FinishedCount); RestoreVolatileRegisters (&CpuMpData->CpuData[0].VolatileRegisters, FALS= E); + InterlockedIncrement ((UINT32 *)&CpuMpData->FinishedCount); PlaceAPInMwaitLoopOrRunLoop ( CpuMpData->ApLoopMode, CpuMpData->CpuData[ProcessorNumber].StartupApSignal, @@ -2201,7 +2201,12 @@ MpInitLibInitialize ( // looping process there. // SwitchApContext (MpHandOff); - ASSERT (CpuMpData->FinishedCount =3D=3D (CpuMpData->CpuCount - 1)); + // + // Wait for all APs finished initialization + // + while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) { + CpuPause (); + } =20 // // Set Apstate as Idle, otherwise Aps cannot be waken-up again. --=20 2.36.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 (#110035): https://edk2.groups.io/g/devel/message/110035 Mute This Topic: https://groups.io/mt/102175355/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-