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 11036740037 for ; Wed, 25 Oct 2023 11:42:35 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=GOsEE4aC+yIPfnwm+NyF4sSThAzFN47pqkTaQZJoUjw=; 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=1698234154; v=1; b=P8cz9TdOvZXuMVdV0KWL6xUF+BNPUf9VmwNMHUMETvLaEEiT4DCYR5aBH5uJYFT9+BgX7jpk 3lzNTKcDJvFnDUMvEdV6fNKbNjfmFw4jm8DeH53n9QR+um9Dp/R8PZ5H1/TNNwBBI/lahCsjXoV 4q83km0iiUQ/d08oR6iDlBfY= X-Received: by 127.0.0.2 with SMTP id J3bSYY7687511xPpw30pXLwd; Wed, 25 Oct 2023 04:42:34 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by mx.groups.io with SMTP id smtpd.web11.41400.1698234153337770020 for ; Wed, 25 Oct 2023 04:42:33 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10873"; a="43254" X-IronPort-AV: E=Sophos;i="6.03,250,1694761200"; d="scan'208";a="43254" X-Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2023 04:42:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10873"; a="758846392" X-IronPort-AV: E=Sophos;i="6.03,250,1694761200"; d="scan'208";a="758846392" X-Received: from shwdeopenlab705.ccr.corp.intel.com ([10.239.55.100]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Oct 2023 04:42:28 -0700 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: Yuanhao Xie , Ray Ni , Eric Dong , Rahul Kumar , Tom Lendacky Subject: [edk2-devel] [Patch V3] UefiCpuPkg/MpInitLib: Wait for all APs to finish initialization Date: Wed, 25 Oct 2023 19:42:16 +0800 Message-Id: <20231025114216.2824-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: ACw8YYhFRiIorLeYg4NK6yabx7686176AA= 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=P8cz9TdO; 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: - To solve the assertion that checks if CpuMpData->FinishedCount equals (CpuMpData->CpuCount - 1). The assertion arises from a timing discrepancy between the BSP's completion of startup signal checks and the APs' incrementation of the FinishedCount. - This patch also ensures that "finished" reporting from the APs is as later as possible. More specifially: In the SwitchApContext() function, the BSP trigers the startup signal and check whether the APs have received it. After completing this check, the BSP then verifies if the FinishedCount is equal to CpuCount-1. On the AP side, upon receiving the startup signal, they invoke SwitchContextPerAp() and increase the FinishedCount to indicate their activation. However, even when all APs have received the startup signal, they might not have finished incrementing the FinishedCount. This timing gap results in the triggering of the assertion. Solution: Instead of assertion, use while loop to waits until all the APs have incremented the FinishedCount. Fixes: 964a4f032dcd Signed-off-by: Yuanhao Xie Cc: Ray Ni Cc: Eric Dong Cc: Rahul Kumar Cc: Tom Lendacky --- 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 (#110052): https://edk2.groups.io/g/devel/message/110052 Mute This Topic: https://groups.io/mt/102176057/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-