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 DF181740040 for ; Thu, 26 Oct 2023 18:01:05 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=l69A9YWi//P5g0SuvTNSMbbaDkRRUPzPcW9OThWfHQU=; c=relaxed/simple; d=groups.io; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:Reply-To:References:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1698343264; v=1; b=iFM76TeKd7+n/TTMmg6QcfN7OC278Jz80UCZvZtOerUuCa7XMTQCT9/iuLdzGe4i0xYGc0G9 tu+6Mqq2PSx3o/xlZt9wRqQqqXFNWvD1WBF/GUswilryWH8OTYKpGk7iT0F+uQzwZtzdgITGDE/ CeA9ha3hs08ORX9iE1weWEeg= X-Received: by 127.0.0.2 with SMTP id 8JzQYY7687511xb1O9ADVAV0; Thu, 26 Oct 2023 11:01:04 -0700 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web11.78042.1698343263987524056 for ; Thu, 26 Oct 2023 11:01:04 -0700 X-Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-127-JEuJ-VFxM3WOnDgm6p0aMQ-1; Thu, 26 Oct 2023 14:00:57 -0400 X-MC-Unique: JEuJ-VFxM3WOnDgm6p0aMQ-1 X-Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1BEB5857F8C; Thu, 26 Oct 2023 18:00:57 +0000 (UTC) X-Received: from [10.39.192.119] (unknown [10.39.192.119]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 23BD1492BFA; Thu, 26 Oct 2023 18:00:55 +0000 (UTC) Message-ID: Date: Thu, 26 Oct 2023 20:00:54 +0200 MIME-Version: 1.0 Subject: Re: [edk2-devel] [Patch V3] UefiCpuPkg/MpInitLib: Wait for all APs to finish initialization From: "Laszlo Ersek" To: devel@edk2.groups.io, yuanhao.xie@intel.com Cc: Ray Ni , Eric Dong , Rahul Kumar , Tom Lendacky Reply-To: devel@edk2.groups.io,lersek@redhat.com References: <20231025114216.2824-1-yuanhao.xie@intel.com> <6a76e01b-b35e-dfdb-31ae-9d05697e9d8b@redhat.com> In-Reply-To: <6a76e01b-b35e-dfdb-31ae-9d05697e9d8b@redhat.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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 List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: WFJbf1qqGaASniVQ0C6Fm0gjx7686176AA= Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=iFM76TeK; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=redhat.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 On 10/26/23 15:41, Laszlo Ersek wrote: > On 10/25/23 13:42, Yuanhao Xie wrote: >> 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/M= pInitLib/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, F= ALSE); >> + 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 > https://github.com/tianocore/edk2/pull/4964 >=20 > (in progress) Commit 74c687cc2f2f. Laszlo -=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 (#110139): https://edk2.groups.io/g/devel/message/110139 Mute This Topic: https://groups.io/mt/102176057/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/19134562= 12/xyzzy [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-