From nobody Tue Apr 16 09:45:00 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+41910+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+41910+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1559713777; cv=none; d=zoho.com; s=zohoarc; b=lDReDq54YjBvOuwaek9yfW4prpk4BHp8ZqJ08IErDWy5U66W0gDepfTS0CHdS3Ul0n5GTxXtApbyXV9svFi6GjBUbMmuls06e0G5a75THOLXaaPxMhokzbgTHRFtxXdu2W333y/LTM1wu68qh/qmt0QyAOlARqFEwxaLJ4jcYoY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559713777; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=CONk3wMkKEjfbrSYzOCIO9NXykvJ1p5Rp+IXCE0aUKM=; b=cu+d+DOKdaIAw4qsW9xizG1J1Bz3001FIuA5p40iFSECllKTEBDjsm2ei6TyG3Li1bS6GTyJUWJBPcTnfT66IKfZdwjxSQ4ewdp+oUQssilZzqtiSK8TkXD3EH1Kv9WAKZEM+y2qtpJEbzlk3yN4qd1zbdePx5KhMpc2Jjh53Tk= 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+41910+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 1559713777464617.929945053168; Tue, 4 Jun 2019 22:49:37 -0700 (PDT) Return-Path: X-Received: from mga11.intel.com (mga11.intel.com []) by groups.io with SMTP; Tue, 04 Jun 2019 22:49:36 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Jun 2019 22:49:36 -0700 X-ExtLoop1: 1 X-Received: from ray-dev.ccr.corp.intel.com ([10.239.9.16]) by fmsmga006.fm.intel.com with ESMTP; 04 Jun 2019 22:49:35 -0700 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Laszlo Ersek , Eric Dong Subject: [edk2-devel] [PATCH v2 1/2] UefiCpuPkg/MpInitLib: increase NumApsExecuting only for ApInitConfig Date: Wed, 5 Jun 2019 13:49:19 +0800 Message-Id: <20190605054920.123184-2-ray.ni@intel.com> In-Reply-To: <20190605054920.123184-1-ray.ni@intel.com> References: <20190605054920.123184-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=1559713777; bh=0Jka0LNZGfeib69KefQoXX0GOfYsDm7oplXxad8UWLU=; h=Cc:Date:From:Reply-To:Subject:To; b=CkVG5/sXAPhiPRMV8qnJhk9J4gMWUQH1GM4c13Jk/b6Ki9Bh1YiePHNrH82M9FPelUK GpvqWs0PfRaqBLt9TV+poeUiG6dY1zemWTu9veLmsDLobYgrD+63jAtJcN4GzQG6dH/NE cQMh7zKT2dLb0+lEiqOjIHiF2u173tDx4EE= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" NumApsExecuting is only used when InitFlag =3D=3D ApInitConfig for counting the processor count. The patch changes Ia32 version of waking up vector assembly code to align to x64 version of waking up vector assembly code. After the change both versions of waking up vector increase NumApsExecuting when InitFlag =3D=3D ApInitConfig. Signed-off-by: Ray Ni Cc: Laszlo Ersek Cc: Eric Dong Reviewed-by: Eric Dong Reviewed-by: Laszlo Ersek --- UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm b/UefiCpuPkg/Li= brary/MpInitLib/Ia32/MpFuncs.nasm index 34b8705adb..b74046b76a 100644 --- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm +++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm @@ -1,5 +1,5 @@ ;-------------------------------------------------------------------------= ----- ; -; Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.
+; Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.
; SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Module Name: @@ -81,12 +81,6 @@ Flat32Start: ; protect= ed mode entry point =20 mov esi, ebx =20 - ; Increment the number of APs executing here as early as possible - ; This is decremented in C code when AP is finished executing - mov edi, esi - add edi, NumApsExecutingLocation - lock inc dword [edi] - mov edi, esi add edi, EnableExecuteDisableLocation cmp byte [edi], 0 @@ -120,6 +114,12 @@ SkipEnableExecuteDisable: cmp dword [edi], 1 ; 1 =3D=3D ApInitConfig jnz GetApicId =20 + ; Increment the number of APs executing here as early as possible + ; This is decremented in C code when AP is finished executing + mov edi, esi + add edi, NumApsExecutingLocation + lock inc dword [edi] + ; AP init mov edi, esi add edi, LockLocation --=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 (#41910): https://edk2.groups.io/g/devel/message/41910 Mute This Topic: https://groups.io/mt/31934505/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- From nobody Tue Apr 16 09:45:00 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+41911+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+41911+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1559713778; cv=none; d=zoho.com; s=zohoarc; b=WHJWvk0d3CdFK+twMXyCLUFUCsvmhx4a08aNUkPolCUqFuZYDSyt62FFx16JCTKvie5YTa+xuUGc7bQGjXlfyeVTzPark0kNY3i0Ajh9w8l/zq1VNJnPdYDSItlVpJAR0DYbFBQtBZGZ/53vtWdkAZG0aMhB6bmZzPcHora6ytI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559713778; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=IsMuXPA5ADpTwu22c9J9vb9+m1m3DR90wfGvJCZ3qBk=; b=V+YHbgZBjRyvc+xwJ67I36+zwEZqcjXiLjjcZRg86owCv6HBRJ9CTRRUWLa39DhibluFJjp5b2bRlGkZtiRp8DWZwenV7X3UEGPwkchTOjmnxevKxx0BMgCh6kliCQjov43tqYeDTKFs1UX2S8KCjZcTCxVxn94WsjXE+iDxAbM= 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+41911+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 1559713778223402.07594404484587; Tue, 4 Jun 2019 22:49:38 -0700 (PDT) Return-Path: X-Received: from mga11.intel.com (mga11.intel.com []) by groups.io with SMTP; Tue, 04 Jun 2019 22:49:37 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Jun 2019 22:49:37 -0700 X-ExtLoop1: 1 X-Received: from ray-dev.ccr.corp.intel.com ([10.239.9.16]) by fmsmga006.fm.intel.com with ESMTP; 04 Jun 2019 22:49:36 -0700 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Eric Dong , Nandagopal Sathyanarayanan Subject: [edk2-devel] [PATCH v2 2/2] UefiCpuPkg/MpInitLib: Decrease NumApsExecuting only for ApInitConfig Date: Wed, 5 Jun 2019 13:49:20 +0800 Message-Id: <20190605054920.123184-3-ray.ni@intel.com> In-Reply-To: <20190605054920.123184-1-ray.ni@intel.com> References: <20190605054920.123184-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=1559713777; bh=h2V1M+E892lGDM51xoV7x3d5m6DHnmt1x8bu4VfN29I=; h=Cc:Date:From:Reply-To:Subject:To; b=qX2f0bDlq2vPiyX7/L9V6xiT0szSvTtP/Zxk0kTjaEczrhn9mfkszaEa+ZZegAEN7NE EuDmjRd0OBDvzKn3XCwp/EVKj1cevUhoiXPSEO8jduUtqtzIbPzu7WNFLAuTeymKDDh4a 1ZDfrAMpTIVl/40fQpvNaK8bv8Ez5G01LOs= 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 Reviewed-by: Eric Dong Reviewed-by: Laszlo Ersek --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 3337488892..6f51bc4ebf 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 --=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 (#41911): https://edk2.groups.io/g/devel/message/41911 Mute This Topic: https://groups.io/mt/31934506/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-