From nobody Thu May 2 04:46:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+41727+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+41727+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1559295789; cv=none; d=zoho.com; s=zohoarc; b=LUiiWBMhYHB3kxPfGg0aK+eo7vtcRbct/U/b9gbaSkPW0FzWa91Fip7E3PRSm+guJjvJguyzNdj60lcEPor9zoAJ/6ETvkZb3vF1HjtkhgDzNiiZ9s8dsjuuPjW2NsqQYUvc7UBbDDgItFpluQPWnc+lVfFEmt26bTRYszm6wWo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559295789; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To:ARC-Authentication-Results; bh=27zFsWUvE+gEojZ8aqpvVZQ0i03+ekQQ8xeifbOWt0M=; b=aVCYDuxJhrMddJVAmOBS19fVywbz9p5urVUpKgTz1FOh3UytrcA9HOfl8Qdwefw7vOzHtYbx8b9KzaxpU2L6v7Q4SQhVLLfxS/URoOG93cDuiHjL5RUZPWPp+1cP2ACI8e5B4UzfVdnMG2baa5FZKl/VGfeMdQslNRtAMfTTVk0= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+41727+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 155929578926529.297008650924113; Fri, 31 May 2019 02:43:09 -0700 (PDT) Return-Path: X-Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by groups.io with SMTP; Fri, 31 May 2019 02:43:08 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 May 2019 02:43:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,534,1549958400"; d="scan'208";a="180270550" X-Received: from ray-dev.ccr.corp.intel.com ([10.239.9.16]) by fmsmga002.fm.intel.com with ESMTP; 31 May 2019 02:43:06 -0700 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Eric Dong , Nandagopal Sathyanarayanan Subject: [edk2-devel] [PATCH] UefiCpuPkg/MpInitLib: Decrease NumApsExecuting only for ApInitConfig Date: Fri, 31 May 2019 17:42:54 +0800 Message-Id: <20190531094254.248276-1-ray.ni@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ray.ni@intel.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1559295788; bh=dPfHCFbQ50rjpHhb2fM4YBs9JhYif78aTadMeS1HgsI=; h=Cc:Date:From:Reply-To:Subject:To; b=tqAFoPBsuV26iNlX0qSXFA92XR7YtwgLHYTNqu8OcCJddubDKFFGx8C8u5VrAkbgHkY TMtIQ79roMT3/0qyCMOltxTmrfAW3oTiTsJUxxXOPxF/exUzK78syCSB0ugp/dofzXY/v G1w5ihp3gQarIoEAxPN2+8gl7nuWPhCQHCA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" The patch fixes the bug that the memory under 1MB is modified by firmware in S3 boot. Root cause is a racing condition in MpInitLib: 1. BSP: WakeUpByInitSipiSipi is set by NotifyOnS3SmmInitDonePpi() 2. BSP: WakeUpAP() wakes all APs to run certain procedure. 2.1. AllocateResetVector() uses <1MB memory for wake up vector. 2.1. FillExchangeInfoData() resets NumApsExecuting to 0. 2.2. WaitApWakeup() waits AP to clear WAKEUP_AP_SIGNAL. 3. AP: ApWakeupFunction() clears WAKEUP_AP_SIGNAL to inform BSP. 5. BSP: FreeResetVector() restores the <1MB memory 4. AP: ApWakeupFunction() calls the certain procedure. 4.1. NumApsExecuting is decreased. #4.1 happens after the 1MB memory is restored so the result is memory below 1MB is changed by #4.1 It happens only when the AP executes procedure a bit longer. AP returns back to ApWakeupFunction() from procedure after BSP restores the <1MB memory. Since NumApsExecuting is only used when InitFlag =3D=3D ApInitConfig for counting the processor count. The patch moves the NumApsExecuting decrease to the path when InitFlag =3D=3D ApInitConfig. Signed-off-by: Ray Ni Cc: Eric Dong Cc: Nandagopal Sathyanarayanan --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 3337488892..84f1cb92e3 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -1,7 +1,7 @@ /** @file CPU MP Initialize Library common functions. =20 - Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -619,6 +619,8 @@ ApWakeupFunction ( RestoreVolatileRegisters (&CpuMpData->CpuData[0].VolatileRegisters, = FALSE); InitializeApData (CpuMpData, ProcessorNumber, BistData, ApTopOfStack= ); ApStartupSignalBuffer =3D CpuMpData->CpuData[ProcessorNumber].Startu= pApSignal; + + InterlockedDecrement ((UINT32 *) &CpuMpData->MpCpuExchangeInfo->NumA= psExecuting); } else { // // Execute AP function if AP is ready @@ -698,7 +700,6 @@ ApWakeupFunction ( // AP finished executing C code // InterlockedIncrement ((UINT32 *) &CpuMpData->FinishedCount); - InterlockedDecrement ((UINT32 *) &CpuMpData->MpCpuExchangeInfo->NumAps= Executing); =20 // // Place AP is specified loop mode @@ -805,6 +806,7 @@ FillExchangeInfoData ( ExchangeInfo->CFunction =3D (UINTN) ApWakeupFunction; ExchangeInfo->ApIndex =3D 0; ExchangeInfo->NumApsExecuting =3D 0; + DEBUG ((DEBUG_ERROR, "NumApsExecuting =3D %p\n", &ExchangeInfo->NumApsEx= ecuting)); ExchangeInfo->InitFlag =3D (UINTN) CpuMpData->InitFlag; ExchangeInfo->CpuInfo =3D (CPU_INFO_IN_HOB *) (UINTN) CpuMpData-= >CpuInfoInHob; ExchangeInfo->CpuMpData =3D CpuMpData; @@ -1598,6 +1600,7 @@ MpInitLibInitialize ( CpuMpData->Buffer =3D Buffer; CpuMpData->CpuApStackSize =3D ApStackSize; CpuMpData->BackupBuffer =3D BackupBufferAddr; + DEBUG ((DEBUG_ERROR, "BackupBuffer =3D %p\n", BackupBufferAddr)); CpuMpData->BackupBufferSize =3D ApResetVectorSize; CpuMpData->WakeupBuffer =3D (UINTN) -1; CpuMpData->CpuCount =3D 1; --=20 2.21.0.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 (#41727): https://edk2.groups.io/g/devel/message/41727 Mute This Topic: https://groups.io/mt/31878551/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-