From nobody Tue May 14 01:56:36 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+110052+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+110052+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1698234155; cv=none; d=zohomail.com; s=zohoarc; b=CPmCt79rfzGtiXaoLBX+fqzHt2Jq4N33XbM+9+sCKGLktheq8F1DhsmilnT0cBcN/MsjmBAYXuJxEq8yEmxLFC1ZwpWh7zwN0ZbSyKrorS/HP7clJLcRMmmfYIDRz+q3ZorFfdg8vTzaiKFXJwZqP625nAGU2LKH/Ea2o1k9yQo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698234155; 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=eXr1MlR6pOimSlzRSa0L26GQJkj2PeIDhOw7cn9Yrw8=; b=K1kromcsFNS1pl+eEmKS5HEEH803TlR/NBUN2qs8gEBvLSaptUMr3PyyWprlEmdM9popddukWXrTG0YeYEsldpvYDhK15mGfAEJofF9JGuwS6Uz+ox9U7OSiEVNS/7BkZi3rxE7FlXiK54dQ+GrFgiyA+V1uShby5spU/HbqN7s= 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+110052+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 1698234155131168.9821618501528; Wed, 25 Oct 2023 04:42:35 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=SFOS6b1tCZX50i/ip7vgZQNk2tDkZJzo7E5azmhiLCk=; 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=RdQyuS+mZOG9VvAFXQX9Kbqw8rDnx5SuqXnH5epX0TeWFQYhscjyhgVS/NW4FdReifWShZ8/ VRncSYRe4AhN6lcIzsN/ua9KO4USrvjnipfj+543yMyNG49NIgYxELJd9PxWtIHUBWaoYfbq3o8 xzvEWCKG2XgdzyyI2zNTgEUg= X-Received: by 127.0.0.2 with SMTP id cMjAYY1788612xGVX9LCpsqB; 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: xG2ygPnvcBBkA0ro0Y5PeygOx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1698234155879100001 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Laszlo Ersek --- 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 (#110052): https://edk2.groups.io/g/devel/message/110052 Mute This Topic: https://groups.io/mt/102176057/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-