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 102B8941899 for ; Wed, 25 Oct 2023 10:50:54 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=8Osjfx+ur6pf9wAIScgeEcdWGntLq4erdTTOhaCd4Nw=; 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=ee946WTDQDOQYYf/+6nYESXHF0AVm7CJZgcgJf29yozVZDWpE5npRmUIedIpbi4KeQl5930D G9Zuvm9fsZAxauRfsAlv1HjG+5IlTf1qBbSt8+OzaZLm+GSYmM0F20ihtCIrCg1SLaKzjKTAs9V xpPX7i6/LMhbeFiaj9Gor+pU= X-Received: by 127.0.0.2 with SMTP id 0BG4YY7687511xhhZIjkcnFd; 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: qssJjNyYfRucGUOLW6nqLw69x7686176AA= Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=ee946WTD; 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 Aim: This patch aims to solve an assertion happens after SwitchApContext() on checking if CpuMpData->FinishedCount == (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/MpInitLib/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; GetProcessorNumber (CpuMpData, &ProcessorNumber); - InterlockedIncrement ((UINT32 *)&CpuMpData->FinishedCount); RestoreVolatileRegisters (&CpuMpData->CpuData[0].VolatileRegisters, FALSE); + InterlockedIncrement ((UINT32 *)&CpuMpData->FinishedCount); PlaceAPInMwaitLoopOrRunLoop ( CpuMpData->ApLoopMode, CpuMpData->CpuData[ProcessorNumber].StartupApSignal, @@ -2201,7 +2201,12 @@ MpInitLibInitialize ( // looping process there. // SwitchApContext (MpHandOff); - ASSERT (CpuMpData->FinishedCount == (CpuMpData->CpuCount - 1)); + // + // Wait for all APs finished initialization + // + while (CpuMpData->FinishedCount < (CpuMpData->CpuCount - 1)) { + CpuPause (); + } // // Set Apstate as Idle, otherwise Aps cannot be waken-up again. -- 2.36.1.windows.1 -=-=-=-=-=-=-=-=-=-=-=- 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/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-