From nobody Thu May 2 22:04:19 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+89745+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+89745+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1652685269; cv=none; d=zohomail.com; s=zohoarc; b=GSM6EzpP8Lrrsx/YGlj+3yaS3uZ3nMFozzLoj88/K4PJnBYxs1HelQz3BMQrAMLPauiWjjuwz4Jmv5RDekSsRCngRCP1ek0vxcbQcqWCbwLLD4hZZWnasOU3x5c1lEppuV17AKZkk4lxF0XcawwQ0eHNT+T1Lwpzr+NxZKGlpE4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652685269; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=bVqHi4KAa2EHJCJ6eKepyqeDrz2CreblMePwr++/Jtk=; b=Esq+Lux3Z94DQdz75ITv8UcqhhyWOAbGIGDCQ3v25aXdYmY02VWouyzLCQwSsGJ7+NLZ2aQLY437zZTp4OCanVrbGKKcz+rW6urlENY7DujViEIPPhQ0N4HBPtw+BasV/XJ0pvx9UruMcyMKaT4ObwDdhSDd99kU9ECpsEib6fI= 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+89745+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 1652685269477614.400850400995; Mon, 16 May 2022 00:14:29 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id QE2TYY1788612xT5D1L8m9ia; Mon, 16 May 2022 00:14:29 -0700 X-Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web09.26058.1652685263921678640 for ; Mon, 16 May 2022 00:14:27 -0700 X-IronPort-AV: E=McAfee;i="6400,9594,10348"; a="270451768" X-IronPort-AV: E=Sophos;i="5.91,229,1647327600"; d="scan'208";a="270451768" X-Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 May 2022 00:14:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,229,1647327600"; d="scan'208";a="555129003" X-Received: from shwdeopenlab706.ccr.corp.intel.com ([10.239.183.102]) by orsmga002.jf.intel.com with ESMTP; 16 May 2022 00:14:19 -0700 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Eric Dong Subject: [edk2-devel] [PATCH v3 1/5] MpInitLib: Allocate code buffer for PEI phase Date: Mon, 16 May 2022 15:14:08 +0800 Message-Id: <20220516071412.359-2-ray.ni@intel.com> In-Reply-To: <20220516071412.359-1-ray.ni@intel.com> References: <20220516071412.359-1-ray.ni@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ray.ni@intel.com X-Gm-Message-State: xdDVt7ShmFYySW0AKNAszBgSx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1652685269; bh=HSAWrtIKTb18V+NPZ53o81BqaN/grIJwIYjCQiU3iic=; h=Cc:Date:From:Reply-To:Subject:To; b=K0ZeoxURTDjbUiTBx49uxke5SCM8IYXj89mx4M00TLkaP5XJuAk+ajaWQ27fxmm4XwI 8FpkESyxGx4Ibk3OPJxK0OlRZsKMy7e6C7ks8WiQSeEUS/n3LP9WdpIXPHhqqJjYuXH2F E1JtpdvKQQoNUxyaBklYRPI3K4dy+qPXHLY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1652685270734100011 Content-Type: text/plain; charset="utf-8" Today's implementation assumes PEI phase runs at 32bit so the execution-disable feature is not applicable. It's not always TRUE. The patch allocates 32bit&64bit code buffer for PEI phase as well. Signed-off-by: Ray Ni Cc: Eric Dong Reviewed-by: Eric Dong for this serial. --- UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 2 +- UefiCpuPkg/Library/MpInitLib/MpLib.c | 2 +- UefiCpuPkg/Library/MpInitLib/MpLib.h | 2 +- UefiCpuPkg/Library/MpInitLib/PeiMpLib.c | 15 ++++++++++----- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/M= pInitLib/DxeMpLib.c index 60d14a5a0e..78cc3e2b93 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c @@ -162,7 +162,7 @@ GetWakeupBuffer ( @retval 0 Cannot find free memory below 4GB. **/ UINTN -GetModeTransitionBuffer ( +AllocateCodeBuffer ( IN UINTN BufferSize ) { diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 4a73787ee4..d761bdc487 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -1056,7 +1056,7 @@ AllocateResetVector ( (CpuMpData->WakeupBuffer + CpuMpData->AddressMap.RendezvousFunnel= Size + CpuMpData->AddressMap.SwitchToRealSize= ); - CpuMpData->WakeupBufferHigh =3D GetModeTransitionBuffer ( + CpuMpData->WakeupBufferHigh =3D AllocateCodeBuffer ( CpuMpData->AddressMap.RendezvousFunnel= Size + CpuMpData->AddressMap.SwitchToRealSize= - CpuMpData->AddressMap.ModeTransitionOf= fset diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index f8c52426dd..59ab960897 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -442,7 +442,7 @@ GetWakeupBuffer ( @retval 0 Cannot find free memory below 4GB. **/ UINTN -GetModeTransitionBuffer ( +AllocateCodeBuffer ( IN UINTN BufferSize ); =20 diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c b/UefiCpuPkg/Library/M= pInitLib/PeiMpLib.c index efce574727..65400b95a2 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c @@ -299,14 +299,19 @@ GetWakeupBuffer ( @retval 0 Cannot find free memory below 4GB. **/ UINTN -GetModeTransitionBuffer ( +AllocateCodeBuffer ( IN UINTN BufferSize ) { - // - // PEI phase doesn't need to do such transition. So simply return 0. - // - return 0; + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS Address; + + Status =3D PeiServicesAllocatePages (EfiBootServicesCode, EFI_SIZE_TO_PA= GES (BufferSize), &Address); + if (EFI_ERROR (Status)) { + Address =3D 0; + } + + return (UINTN)Address; } =20 /** --=20 2.35.1.windows.2 -=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 (#89745): https://edk2.groups.io/g/devel/message/89745 Mute This Topic: https://groups.io/mt/91134931/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 Thu May 2 22:04:19 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+89744+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+89744+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1652685267; cv=none; d=zohomail.com; s=zohoarc; b=g4sTmLN7otMVHsDWZmiE/06Rsw/FBQ8kvatxBe27O+kzf65Zk22PZCy9bQstBT9Gl2tOd3qxNQRsuFJpPpNeJ2a5yMKfNP6g82gF9AFW//ulk0AYj4UyxjxL0A72ZOtilHUdOkXwlcK46O0fD8Wu3nvzmA/YqCDzHyeduBBGbEg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652685267; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=mtHlpsSAD5/j/kzA2fdB6zm3U1UCIRcCjJ21pnJg9u0=; b=bm/iIktP0dVEK4FNV1685SvuMoNjmq4qyPPc2yn6z+ds/APLIWGBJaX2rJcXIGIRpARXXNwvswS1tJulR4J3j7AHk7lt2maEV7ZTqaCaK9FZAG7vy8pWjXwAvlVjQIyqvZ8x/xCZZwZDvltEHbnPUEhEJBJ5MwiR9Wp8s6rkzNA= 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+89744+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 1652685267474302.98217202845217; Mon, 16 May 2022 00:14:27 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id knetYY1788612xNaKcqVRKcM; Mon, 16 May 2022 00:14:27 -0700 X-Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web09.26060.1652685265461479831 for ; Mon, 16 May 2022 00:14:26 -0700 X-IronPort-AV: E=McAfee;i="6400,9594,10348"; a="270451772" X-IronPort-AV: E=Sophos;i="5.91,229,1647327600"; d="scan'208";a="270451772" X-Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 May 2022 00:14:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,229,1647327600"; d="scan'208";a="555129007" X-Received: from shwdeopenlab706.ccr.corp.intel.com ([10.239.183.102]) by orsmga002.jf.intel.com with ESMTP; 16 May 2022 00:14:20 -0700 From: "Ni, Ray" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v3 2/5] MpInitLib: remove unneeded global ASM_PFX Date: Mon, 16 May 2022 15:14:09 +0800 Message-Id: <20220516071412.359-3-ray.ni@intel.com> In-Reply-To: <20220516071412.359-1-ray.ni@intel.com> References: <20220516071412.359-1-ray.ni@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ray.ni@intel.com X-Gm-Message-State: JRXJZJcJLOXaJ6gwhpqSAaNdx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1652685267; bh=vgkKVCnfIgbnCuwvIM6LmYVYkQDrEPcQpaIymvQkEDI=; h=Date:From:Reply-To:Subject:To; b=ui5fM6QsqvKcgfiubsEb+LMxy3P6iymBtvSwoOzOj7FnCkaCzFJk3QDTi3mv2z832Df 8JKDY8s51uOWX3CK/qNwm14EBtLr9ZurWm6xkm/9wqcmV0e/rZl0Us0FIUfG41RE84seG s76YXTdl0R0t6MrTJwVzroZQNwfLRz+ueSQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1652685268755100005 Content-Type: text/plain; charset="utf-8" global in NASM file is used for symbols that are referenced in C files. Remove unneeded global keyword in NASM file. Signed-off-by: Ray Ni Reviewed-by: Eric Dong for this serial. --- UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm | 8 +------- UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 10 ++-------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm b/UefiCpuPkg/Li= brary/MpInitLib/Ia32/MpFuncs.nasm index 7bd2415670..8981c32722 100644 --- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm +++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm @@ -1,5 +1,5 @@ ;-------------------------------------------------------------------------= ----- ; -; Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.
+; Copyright (c) 2015 - 2022, Intel Corporation. All rights reserved.
; SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Module Name: @@ -24,8 +24,6 @@ SECTION .text ;ALSO THIS PROCEDURE IS EXECUTED BY APs ONLY ON 16 BIT MODE. HENCE THIS PR= OC ;IS IN MACHINE CODE. ;-------------------------------------------------------------------------= ------------ -global ASM_PFX(RendezvousFunnelProc) -ASM_PFX(RendezvousFunnelProc): RendezvousFunnelProcStart: ; At this point CS =3D 0x(vv00) and ip=3D 0x0. BITS 16 @@ -207,8 +205,6 @@ RendezvousFunnelProcEnd: ;SwitchToRealProc procedure follows. ;NOT USED IN 32 BIT MODE. ;-------------------------------------------------------------------------= ------------ -global ASM_PFX(SwitchToRealProc) -ASM_PFX(SwitchToRealProc): SwitchToRealProcStart: jmp $ ; Never reach here SwitchToRealProcEnd: @@ -219,8 +215,6 @@ SwitchToRealProcEnd: ; The last three parameters (Pm16CodeSegment, SevEsAPJumpTable and Wakeup= Buffer) are ; specific to SEV-ES support and are not applicable on IA32. ;-------------------------------------------------------------------------= ------------ -global ASM_PFX(AsmRelocateApLoop) -ASM_PFX(AsmRelocateApLoop): AsmRelocateApLoopStart: mov eax, esp mov esp, [eax + 16] ; TopOfApStack diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm b/UefiCpuPkg/Lib= rary/MpInitLib/X64/MpFuncs.nasm index f1422fd30a..d7e0e1fabd 100644 --- a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm +++ b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm @@ -35,8 +35,6 @@ SECTION .text ;ALSO THIS PROCEDURE IS EXECUTED BY APs ONLY ON 16 BIT MODE. HENCE THIS PR= OC ;IS IN MACHINE CODE. ;-------------------------------------------------------------------------= ------------ -global ASM_PFX(RendezvousFunnelProc) -ASM_PFX(RendezvousFunnelProc): RendezvousFunnelProcStart: ; At this point CS =3D 0x(vv00) and ip=3D 0x0. ; Save BIST information to ebp firstly @@ -279,8 +277,6 @@ RendezvousFunnelProcEnd: ; r8 - Code32 Selector Offset ; r9 - Stack Start ;-------------------------------------------------------------------------= ------------ -global ASM_PFX(SwitchToRealProc) -ASM_PFX(SwitchToRealProc): SwitchToRealProcStart: BITS 64 cli @@ -421,8 +417,6 @@ SwitchToRealProcEnd: ;-------------------------------------------------------------------------= ------------ ; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfAp= Stack, CountTofinish, Pm16CodeSegment, SevEsAPJumpTable, WakeupBuffer); ;-------------------------------------------------------------------------= ------------ -global ASM_PFX(AsmRelocateApLoop) -ASM_PFX(AsmRelocateApLoop): AsmRelocateApLoopStart: BITS 64 cmp qword [rsp + 56], 0 ; SevEsAPJumpTable @@ -594,11 +588,11 @@ AsmRelocateApLoopEnd: ;-------------------------------------------------------------------------= ------------ global ASM_PFX(AsmGetAddressMap) ASM_PFX(AsmGetAddressMap): - lea rax, [ASM_PFX(RendezvousFunnelProc)] + lea rax, [RendezvousFunnelProcStart] mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.RendezvousFunnelAddres= s], rax mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.ModeEntryOffset], Long= ModeStart - RendezvousFunnelProcStart mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.RendezvousFunnelSize],= RendezvousFunnelProcEnd - RendezvousFunnelProcStart - lea rax, [ASM_PFX(AsmRelocateApLoop)] + lea rax, [AsmRelocateApLoopStart] mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.RelocateApLoopFuncAddr= ess], rax mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.RelocateApLoopFuncSize= ], AsmRelocateApLoopEnd - AsmRelocateApLoopStart mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.ModeTransitionOffset],= Flat32Start - RendezvousFunnelProcStart --=20 2.35.1.windows.2 -=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 (#89744): https://edk2.groups.io/g/devel/message/89744 Mute This Topic: https://groups.io/mt/91134930/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 Thu May 2 22:04:19 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+89746+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+89746+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1652685268; cv=none; d=zohomail.com; s=zohoarc; b=Z/nnIo7+HZJtgiR+Sn/ZQt+OPX3d5h7xC2lrJaItZ11rREku4sFqU4f2Wcf+85oNpMNy4sUVfHBre8/k0+FFSy9KivW7D+ILj90JSr/deBmzkNbW86h0QUgHImEu7h28xkW6YJ+K4KYDPMGtWa4Qq28zizwVG1v1elhXRMobN74= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652685268; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=zjUsTvXxaPp+kgMwn00xBq05W5sAWrb5acmLhdnxD8M=; b=K3UDjNGKgtFoLxjqcs2geB5GWd4NoZov18GDg5OJtBcsBfzZM9FbhrvQiikbNQQfOF6WhyY9TgXthxeocL3t7drApTC86c2s/+oxxCzLHygMRN3fvgo69es6WsXrDtFBgEMJDbULcq4ZiypdjSyp0QdVi3oBn5H1Es8Y/jTu2y8= 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+89746+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 165268526851415.272592488661985; Mon, 16 May 2022 00:14:28 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 1YgpYY1788612xZ2DnS6zujt; Mon, 16 May 2022 00:14:28 -0700 X-Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web09.26060.1652685265461479831 for ; Mon, 16 May 2022 00:14:27 -0700 X-IronPort-AV: E=McAfee;i="6400,9594,10348"; a="270451779" X-IronPort-AV: E=Sophos;i="5.91,229,1647327600"; d="scan'208";a="270451779" X-Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 May 2022 00:14:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,229,1647327600"; d="scan'208";a="555129038" X-Received: from shwdeopenlab706.ccr.corp.intel.com ([10.239.183.102]) by orsmga002.jf.intel.com with ESMTP; 16 May 2022 00:14:22 -0700 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Eric Dong , Rahul Kumar , Michael Roth , James Bottomley , Min Xu , Jiewen Yao , Tom Lendacky , Jordan Justen , Ard Biesheuvel , Erdem Aktas , Gerd Hoffmann Subject: [edk2-devel] [PATCH v3 3/5] MpInitLib: Put SEV logic in separate file Date: Mon, 16 May 2022 15:14:10 +0800 Message-Id: <20220516071412.359-4-ray.ni@intel.com> In-Reply-To: <20220516071412.359-1-ray.ni@intel.com> References: <20220516071412.359-1-ray.ni@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ray.ni@intel.com X-Gm-Message-State: 1Hr4kV5AjAFyJRUKF2MYYHVMx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1652685268; bh=QSab90+d0YNIP5Vfk/ARB9ekVBChdTWYswVdzrbds9c=; h=Cc:Date:From:Reply-To:Subject:To; b=ZiFWIvnvDztBTIY6fy4cS9DDam+1MmWGhId5T8zJboHumfbhsKM/u3CJGcgLY1qveCH tZJb+8jbODrDJuphUmM42XX53M9E7lpz/u3Df7Wo+WhaGKhBfMsYLam7xUe3GRCSk5eUi A55WiRn9W3CYZMS0IMLZ5dRklYbbd1xo9G4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1652686171352100001 Content-Type: text/plain; charset="utf-8" The patch does several simplifications: 1. Treat SwitchToRealProc as part of RendezvousFunnelProc. So the common logic in MpLib.c doesn't need to be aware of SwitchToRealProc. As a result, SwitchToRealSize/Offset are removed from MP_ASSEMBLY_ADDRESS_MAP. 2. Move SwitchToRealProc to AmdSev.nasm. All other assembly code in AmdSev.nasm is called through OneTimeCall. Signed-off-by: Ray Ni Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Michael Roth Cc: James Bottomley Cc: Min Xu Cc: Jiewen Yao Cc: Tom Lendacky Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Erdem Aktas Cc: Gerd Hoffmann Reviewed-by: Eric Dong for this serial. Reviewed-by: Tom Lendacky Tested-by: Tom Lendacky --- .../Library/MpInitLib/Ia32/MpFuncs.nasm | 5 +- UefiCpuPkg/Library/MpInitLib/MpEqu.inc | 4 +- UefiCpuPkg/Library/MpInitLib/MpLib.c | 13 +- UefiCpuPkg/Library/MpInitLib/MpLib.h | 4 +- UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm | 148 ++++++++++++++++ UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 159 +----------------- 6 files changed, 161 insertions(+), 172 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm b/UefiCpuPkg/Li= brary/MpInitLib/Ia32/MpFuncs.nasm index 8981c32722..28301bb8f0 100644 --- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm +++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm @@ -199,7 +199,6 @@ CProcedureInvoke: call eax ; Invoke C function =20 jmp $ ; Never reach here -RendezvousFunnelProcEnd: =20 ;-------------------------------------------------------------------------= ------------ ;SwitchToRealProc procedure follows. @@ -209,6 +208,8 @@ SwitchToRealProcStart: jmp $ ; Never reach here SwitchToRealProcEnd: =20 +RendezvousFunnelProcEnd: + ;-------------------------------------------------------------------------= ------------ ; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfAp= Stack, CountTofinish, Pm16CodeSegment, SevEsAPJumpTable, WakeupBuffer); ; @@ -258,8 +259,6 @@ ASM_PFX(AsmGetAddressMap): mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.RelocateApLoopFuncAddr= ess], AsmRelocateApLoopStart mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.RelocateApLoopFuncSize= ], AsmRelocateApLoopEnd - AsmRelocateApLoopStart mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.ModeTransitionOffset],= Flat32Start - RendezvousFunnelProcStart - mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealSize], Swi= tchToRealProcEnd - SwitchToRealProcStart - mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealOffset], S= witchToRealProcStart - RendezvousFunnelProcStart mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealNoNxOffset= ], SwitchToRealProcStart - Flat32Start mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealPM16ModeOf= fset], 0 mov dword [ebx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealPM16ModeSi= ze], 0 diff --git a/UefiCpuPkg/Library/MpInitLib/MpEqu.inc b/UefiCpuPkg/Library/Mp= InitLib/MpEqu.inc index aba53f5720..1cc071cf7b 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpEqu.inc +++ b/UefiCpuPkg/Library/MpInitLib/MpEqu.inc @@ -1,5 +1,5 @@ ;-------------------------------------------------------------------------= ----- ; -; Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.
+; Copyright (c) 2015 - 2022, Intel Corporation. All rights reserved.
; SPDX-License-Identifier: BSD-2-Clause-Patent ; ; Module Name: @@ -27,8 +27,6 @@ struc MP_ASSEMBLY_ADDRESS_MAP .RelocateApLoopFuncAddress CTYPE_UINTN 1 .RelocateApLoopFuncSize CTYPE_UINTN 1 .ModeTransitionOffset CTYPE_UINTN 1 - .SwitchToRealSize CTYPE_UINTN 1 - .SwitchToRealOffset CTYPE_UINTN 1 .SwitchToRealNoNxOffset CTYPE_UINTN 1 .SwitchToRealPM16ModeOffset CTYPE_UINTN 1 .SwitchToRealPM16ModeSize CTYPE_UINTN 1 diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index d761bdc487..aa0eb9a70b 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -936,8 +936,7 @@ FillExchangeInfoData ( // EfiBootServicesCode to avoid page fault if NX memory protection is en= abled. // if (CpuMpData->WakeupBufferHigh !=3D 0) { - Size =3D CpuMpData->AddressMap.RendezvousFunnelSize + - CpuMpData->AddressMap.SwitchToRealSize - + Size =3D CpuMpData->AddressMap.RendezvousFunnelSize - CpuMpData->AddressMap.ModeTransitionOffset; CopyMem ( (VOID *)CpuMpData->WakeupBufferHigh, @@ -991,8 +990,7 @@ BackupAndPrepareWakeupBuffer ( CopyMem ( (VOID *)CpuMpData->WakeupBuffer, (VOID *)CpuMpData->AddressMap.RendezvousFunnelAddress, - CpuMpData->AddressMap.RendezvousFunnelSize + - CpuMpData->AddressMap.SwitchToRealSize + CpuMpData->AddressMap.RendezvousFunnelSize ); } =20 @@ -1029,7 +1027,6 @@ GetApResetVectorSize ( UINTN Size; =20 Size =3D AddressMap->RendezvousFunnelSize + - AddressMap->SwitchToRealSize + sizeof (MP_CPU_EXCHANGE_INFO); =20 return Size; @@ -1054,11 +1051,9 @@ AllocateResetVector ( CpuMpData->WakeupBuffer =3D GetWakeupBuffer (ApResetVectorSize); CpuMpData->MpCpuExchangeInfo =3D (MP_CPU_EXCHANGE_INFO *)(UINTN) (CpuMpData->WakeupBuffer + - CpuMpData->AddressMap.RendezvousFunnel= Size + - CpuMpData->AddressMap.SwitchToRealSize= ); + CpuMpData->AddressMap.RendezvousFunnel= Size); CpuMpData->WakeupBufferHigh =3D AllocateCodeBuffer ( - CpuMpData->AddressMap.RendezvousFunnel= Size + - CpuMpData->AddressMap.SwitchToRealSize= - + CpuMpData->AddressMap.RendezvousFunnel= Size - CpuMpData->AddressMap.ModeTransitionOf= fset ); // diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index 59ab960897..974fb76019 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -1,7 +1,7 @@ /** @file Common header file for MP Initialize Library. =20 - Copyright (c) 2016 - 2021, Intel Corporation. All rights reserved.
+ Copyright (c) 2016 - 2022, Intel Corporation. All rights reserved.
Copyright (c) 2020, AMD Inc. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent @@ -181,8 +181,6 @@ typedef struct { UINT8 *RelocateApLoopFuncAddress; UINTN RelocateApLoopFuncSize; UINTN ModeTransitionOffset; - UINTN SwitchToRealSize; - UINTN SwitchToRealOffset; UINTN SwitchToRealNoNxOffset; UINTN SwitchToRealPM16ModeOffset; UINTN SwitchToRealPM16ModeSize; diff --git a/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm b/UefiCpuPkg/Libr= ary/MpInitLib/X64/AmdSev.nasm index 8bb1161fa0..7c2469f9c5 100644 --- a/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm +++ b/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.nasm @@ -198,3 +198,151 @@ RestoreGhcb: =20 SevEsGetApicIdExit: OneTimeCallRet SevEsGetApicId + + +;-------------------------------------------------------------------------= ------------ +;SwitchToRealProc procedure follows. +;ALSO THIS PROCEDURE IS EXECUTED BY APs TRANSITIONING TO 16 BIT MODE. HENC= E THIS PROC +;IS IN MACHINE CODE. +; SwitchToRealProc (UINTN BufferStart, UINT16 Code16, UINT16 Code32, UINT= N StackStart) +; rcx - Buffer Start +; rdx - Code16 Selector Offset +; r8 - Code32 Selector Offset +; r9 - Stack Start +;-------------------------------------------------------------------------= ------------ +SwitchToRealProcStart: +BITS 64 + cli + + ; + ; Get RDX reset value before changing stacks since the + ; new stack won't be able to accomodate a #VC exception. + ; + push rax + push rbx + push rcx + push rdx + + mov rax, 1 + cpuid + mov rsi, rax ; Save off the reset value for = RDX + + pop rdx + pop rcx + pop rbx + pop rax + + ; + ; Establish stack below 1MB + ; + mov rsp, r9 + + ; + ; Push ultimate Reset Vector onto the stack + ; + mov rax, rcx + shr rax, 4 + push word 0x0002 ; RFLAGS + push ax ; CS + push word 0x0000 ; RIP + push word 0x0000 ; For alignment, will be discar= ded + + ; + ; Get address of "16-bit operand size" label + ; + lea rbx, [PM16Mode] + + ; + ; Push addresses used to change to compatibility mode + ; + lea rax, [CompatMode] + push r8 + push rax + + ; + ; Clear R8 - R15, for reset, before going into 32-bit mode + ; + xor r8, r8 + xor r9, r9 + xor r10, r10 + xor r11, r11 + xor r12, r12 + xor r13, r13 + xor r14, r14 + xor r15, r15 + + ; + ; Far return into 32-bit mode + ; + retfq + +BITS 32 +CompatMode: + ; + ; Set up stack to prepare for exiting protected mode + ; + push edx ; Code16 CS + push ebx ; PM16Mode label address + + ; + ; Disable paging + ; + mov eax, cr0 ; Read CR0 + btr eax, 31 ; Set PG=3D0 + mov cr0, eax ; Write CR0 + + ; + ; Disable long mode + ; + mov ecx, 0c0000080h ; EFER MSR number + rdmsr ; Read EFER + btr eax, 8 ; Set LME=3D0 + wrmsr ; Write EFER + + ; + ; Disable PAE + ; + mov eax, cr4 ; Read CR4 + btr eax, 5 ; Set PAE=3D0 + mov cr4, eax ; Write CR4 + + mov edx, esi ; Restore RDX reset value + + ; + ; Switch to 16-bit operand size + ; + retf + +BITS 16 + ; + ; At entry to this label + ; - RDX will have its reset value + ; - On the top of the stack + ; - Alignment data (two bytes) to be discarded + ; - IP for Real Mode (two bytes) + ; - CS for Real Mode (two bytes) + ; + ; This label is also used with AsmRelocateApLoop. During MP finalizati= on, + ; the code from PM16Mode to SwitchToRealProcEnd is copied to the start= of + ; the WakeupBuffer, allowing a parked AP to be booted by an OS. + ; +PM16Mode: + mov eax, cr0 ; Read CR0 + btr eax, 0 ; Set PE=3D0 + mov cr0, eax ; Write CR0 + + pop ax ; Discard alignment data + + ; + ; Clear registers (except RDX and RSP) before going into 16-bit mode + ; + xor eax, eax + xor ebx, ebx + xor ecx, ecx + xor esi, esi + xor edi, edi + xor ebp, ebp + + iret + +SwitchToRealProcEnd: diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm b/UefiCpuPkg/Lib= rary/MpInitLib/X64/MpFuncs.nasm index d7e0e1fabd..1daaa72b1e 100644 --- a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm +++ b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm @@ -152,11 +152,6 @@ SkipEnable5LevelPaging: =20 BITS 64 =20 -; -; Required for the AMD SEV helper functions -; -%include "AmdSev.nasm" - LongModeStart: mov esi, ebx lea edi, [esi + MP_CPU_EXCHANGE_INFO_FIELD (InitFlag)] @@ -265,154 +260,12 @@ CProcedureInvoke: add rsp, 20h jmp $ ; Should never reach here =20 -RendezvousFunnelProcEnd: - -;-------------------------------------------------------------------------= ------------ -;SwitchToRealProc procedure follows. -;ALSO THIS PROCEDURE IS EXECUTED BY APs TRANSITIONING TO 16 BIT MODE. HENC= E THIS PROC -;IS IN MACHINE CODE. -; SwitchToRealProc (UINTN BufferStart, UINT16 Code16, UINT16 Code32, UINT= N StackStart) -; rcx - Buffer Start -; rdx - Code16 Selector Offset -; r8 - Code32 Selector Offset -; r9 - Stack Start -;-------------------------------------------------------------------------= ------------ -SwitchToRealProcStart: -BITS 64 - cli - - ; - ; Get RDX reset value before changing stacks since the - ; new stack won't be able to accomodate a #VC exception. - ; - push rax - push rbx - push rcx - push rdx - - mov rax, 1 - cpuid - mov rsi, rax ; Save off the reset value for = RDX - - pop rdx - pop rcx - pop rbx - pop rax - - ; - ; Establish stack below 1MB - ; - mov rsp, r9 - - ; - ; Push ultimate Reset Vector onto the stack - ; - mov rax, rcx - shr rax, 4 - push word 0x0002 ; RFLAGS - push ax ; CS - push word 0x0000 ; RIP - push word 0x0000 ; For alignment, will be discar= ded - - ; - ; Get address of "16-bit operand size" label - ; - lea rbx, [PM16Mode] - - ; - ; Push addresses used to change to compatibility mode - ; - lea rax, [CompatMode] - push r8 - push rax - - ; - ; Clear R8 - R15, for reset, before going into 32-bit mode - ; - xor r8, r8 - xor r9, r9 - xor r10, r10 - xor r11, r11 - xor r12, r12 - xor r13, r13 - xor r14, r14 - xor r15, r15 - - ; - ; Far return into 32-bit mode - ; - retfq - -BITS 32 -CompatMode: - ; - ; Set up stack to prepare for exiting protected mode - ; - push edx ; Code16 CS - push ebx ; PM16Mode label address - - ; - ; Disable paging - ; - mov eax, cr0 ; Read CR0 - btr eax, 31 ; Set PG=3D0 - mov cr0, eax ; Write CR0 - - ; - ; Disable long mode - ; - mov ecx, 0c0000080h ; EFER MSR number - rdmsr ; Read EFER - btr eax, 8 ; Set LME=3D0 - wrmsr ; Write EFER - - ; - ; Disable PAE - ; - mov eax, cr4 ; Read CR4 - btr eax, 5 ; Set PAE=3D0 - mov cr4, eax ; Write CR4 - - mov edx, esi ; Restore RDX reset value - - ; - ; Switch to 16-bit operand size - ; - retf - -BITS 16 - ; - ; At entry to this label - ; - RDX will have its reset value - ; - On the top of the stack - ; - Alignment data (two bytes) to be discarded - ; - IP for Real Mode (two bytes) - ; - CS for Real Mode (two bytes) - ; - ; This label is also used with AsmRelocateApLoop. During MP finalizati= on, - ; the code from PM16Mode to SwitchToRealProcEnd is copied to the start= of - ; the WakeupBuffer, allowing a parked AP to be booted by an OS. - ; -PM16Mode: - mov eax, cr0 ; Read CR0 - btr eax, 0 ; Set PE=3D0 - mov cr0, eax ; Write CR0 - - pop ax ; Discard alignment data - - ; - ; Clear registers (except RDX and RSP) before going into 16-bit mode - ; - xor eax, eax - xor ebx, ebx - xor ecx, ecx - xor esi, esi - xor edi, edi - xor ebp, ebp - - iret +; +; Required for the AMD SEV helper functions +; +%include "AmdSev.nasm" =20 -SwitchToRealProcEnd: +RendezvousFunnelProcEnd: =20 ;-------------------------------------------------------------------------= ------------ ; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfAp= Stack, CountTofinish, Pm16CodeSegment, SevEsAPJumpTable, WakeupBuffer); @@ -596,8 +449,6 @@ ASM_PFX(AsmGetAddressMap): mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.RelocateApLoopFuncAddr= ess], rax mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.RelocateApLoopFuncSize= ], AsmRelocateApLoopEnd - AsmRelocateApLoopStart mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.ModeTransitionOffset],= Flat32Start - RendezvousFunnelProcStart - mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealSize], Swi= tchToRealProcEnd - SwitchToRealProcStart - mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealOffset], S= witchToRealProcStart - RendezvousFunnelProcStart mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealNoNxOffset= ], SwitchToRealProcStart - Flat32Start mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealPM16ModeOf= fset], PM16Mode - RendezvousFunnelProcStart mov qword [rcx + MP_ASSEMBLY_ADDRESS_MAP.SwitchToRealPM16ModeSi= ze], SwitchToRealProcEnd - PM16Mode --=20 2.35.1.windows.2 -=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 (#89746): https://edk2.groups.io/g/devel/message/89746 Mute This Topic: https://groups.io/mt/91134932/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 Thu May 2 22:04:19 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+89747+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+89747+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1652685269; cv=none; d=zohomail.com; s=zohoarc; b=IPS/htN7o7aNYjExHDXCOcGOVfI+zznw1bK/OCnBfJlM2w9+0DIMPDqC54XppTklBGUe9Aka7eP5KB7/GXrExQ0MybdCLro2T+7g4Vbum6DmvUNHyUyaOFfV5KtwN7BPuYOq4NKSyrad26Zi+z06I+XKWMw3HzA+NKY4FPi+Qqc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652685269; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=8BiTa2fMdAidb3lgeENj1v5paN4sqX1q/BiYR+PDUm8=; b=JtU26ts8H69ciHN5RM7DHeYr+lcb9Z1t2wmei7PA9NgLPdpxkuzm5Y2tIvwdQZX4HOIo993IElZEwjgxPKT08FaFn3lVc5IhRg80Mp/TTqpJeN0uwP0hg3XOjdRM+SaBo7Xlevv1XZgazq97C7Rdgttg0WzIg0T/by4WLdFgXvE= 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+89747+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 165268526915884.64952446401139; Mon, 16 May 2022 00:14:29 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id S0TVYY1788612xhdV5AJhinE; Mon, 16 May 2022 00:14:28 -0700 X-Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web09.26058.1652685263921678640 for ; Mon, 16 May 2022 00:14:28 -0700 X-IronPort-AV: E=McAfee;i="6400,9594,10348"; a="270451791" X-IronPort-AV: E=Sophos;i="5.91,229,1647327600"; d="scan'208";a="270451791" X-Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 May 2022 00:14:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,229,1647327600"; d="scan'208";a="555129046" X-Received: from shwdeopenlab706.ccr.corp.intel.com ([10.239.183.102]) by orsmga002.jf.intel.com with ESMTP; 16 May 2022 00:14:25 -0700 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Eric Dong Subject: [edk2-devel] [PATCH v3 4/5] MpInitLib: Only allocate below 1MB memory for 16bit code Date: Mon, 16 May 2022 15:14:11 +0800 Message-Id: <20220516071412.359-5-ray.ni@intel.com> In-Reply-To: <20220516071412.359-1-ray.ni@intel.com> References: <20220516071412.359-1-ray.ni@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ray.ni@intel.com X-Gm-Message-State: JmYyeKJjmD8V8DQCKTEFd7IVx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1652685268; bh=oc06yTe021mfYFYuBlAsuelXchSNhys5WsFA+5sGRFM=; h=Cc:Date:From:Reply-To:Subject:To; b=lF65YndxrClM2irIs+dCUX0hVrVktHNuq0GT7DVC/ZM4i46JDnTc7YqXPaXJugl0E3d zvs5Pk/y4xE58bwoDN5Pq5Kb/cCqQLpaTJlI09K8Vg3e++QKFFjV/2wL7r+V9jXJA0V2t o5p1qD6T3NgZ8z+5dp+2PJovDAgOXH/OMXg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1652685270781100012 Content-Type: text/plain; charset="utf-8" Today's implementation allocates below 1MB memory for the 16bit, 32bit and 64bit code. But it's not necessary since now the 32bit and 64bit code run at high memory no matter in PEI and DXE phase. The patch simplifies the logic to remove the code that handles the case when WakeupBufferHigh is 0. It also reduce the memory foot print under 1MB by allocating memory for 16bit code only. MP_CPU_EXCHANGE_INFO is still under 1MB which is immediate after the 16bit code. Signed-off-by: Ray Ni Cc: Eric Dong Reviewed-by: Eric Dong for this serial. --- UefiCpuPkg/Library/MpInitLib/AmdSev.c | 6 +- UefiCpuPkg/Library/MpInitLib/MpEqu.inc | 2 +- UefiCpuPkg/Library/MpInitLib/MpLib.c | 94 ++++++++++++-------------- 3 files changed, 46 insertions(+), 56 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/AmdSev.c b/UefiCpuPkg/Library/MpI= nitLib/AmdSev.c index b4a344ee6b..4e4c63a52d 100644 --- a/UefiCpuPkg/Library/MpInitLib/AmdSev.c +++ b/UefiCpuPkg/Library/MpInitLib/AmdSev.c @@ -110,11 +110,7 @@ MpInitLibSevEsAPReset ( Code16 =3D GetProtectedMode16CS (); Code32 =3D GetProtectedMode32CS (); =20 - if (CpuMpData->WakeupBufferHigh !=3D 0) { - APResetFn =3D (AP_RESET *)(CpuMpData->WakeupBufferHigh + CpuMpData->Ad= dressMap.SwitchToRealNoNxOffset); - } else { - APResetFn =3D (AP_RESET *)(CpuMpData->MpCpuExchangeInfo->BufferStart += CpuMpData->AddressMap.SwitchToRealOffset); - } + APResetFn =3D (AP_RESET *)(CpuMpData->WakeupBufferHigh + CpuMpData->Addr= essMap.SwitchToRealNoNxOffset); =20 BufferStart =3D CpuMpData->MpCpuExchangeInfo->BufferStart; StackStart =3D CpuMpData->SevEsAPResetStackStart - diff --git a/UefiCpuPkg/Library/MpInitLib/MpEqu.inc b/UefiCpuPkg/Library/Mp= InitLib/MpEqu.inc index 1cc071cf7b..ebadcc6fb3 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpEqu.inc +++ b/UefiCpuPkg/Library/MpInitLib/MpEqu.inc @@ -95,5 +95,5 @@ struc MP_CPU_EXCHANGE_INFO .ExtTopoAvail: CTYPE_BOOLEAN 1 endstruc =20 -MP_CPU_EXCHANGE_INFO_OFFSET equ (SwitchToRealProcEnd - RendezvousFunnelPro= cStart) +MP_CPU_EXCHANGE_INFO_OFFSET equ (Flat32Start - RendezvousFunnelProcStart) %define MP_CPU_EXCHANGE_INFO_FIELD(Field) (MP_CPU_EXCHANGE_INFO_OFFSET + M= P_CPU_EXCHANGE_INFO. %+ Field) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index aa0eb9a70b..e4edbb618d 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -848,6 +848,30 @@ WaitApWakeup ( } } =20 +/** + Calculate the size of the reset vector. + + @param[in] AddressMap The pointer to Address Map structure. + + @return Total amount of memory required for the AP reset= area +**/ +STATIC +VOID +GetApResetVectorSize ( + IN MP_ASSEMBLY_ADDRESS_MAP *AddressMap, + OUT UINTN *SizeBelow1Mb OPTIONAL, + OUT UINTN *SizeAbove1Mb OPTIONAL + ) +{ + if (SizeBelow1Mb !=3D NULL) { + *SizeBelow1Mb =3D AddressMap->ModeTransitionOffset + sizeof (MP_CPU_EX= CHANGE_INFO); + } + + if (SizeAbove1Mb !=3D NULL) { + *SizeAbove1Mb =3D AddressMap->RendezvousFunnelSize - AddressMap->ModeT= ransitionOffset; + } +} + /** This function will fill the exchange info structure. =20 @@ -935,21 +959,15 @@ FillExchangeInfoData ( // Copy all 32-bit code and 64-bit code into memory with type of // EfiBootServicesCode to avoid page fault if NX memory protection is en= abled. // - if (CpuMpData->WakeupBufferHigh !=3D 0) { - Size =3D CpuMpData->AddressMap.RendezvousFunnelSize - - CpuMpData->AddressMap.ModeTransitionOffset; - CopyMem ( - (VOID *)CpuMpData->WakeupBufferHigh, - CpuMpData->AddressMap.RendezvousFunnelAddress + - CpuMpData->AddressMap.ModeTransitionOffset, - Size - ); + GetApResetVectorSize (&CpuMpData->AddressMap, NULL, &Size); + CopyMem ( + (VOID *)CpuMpData->WakeupBufferHigh, + CpuMpData->AddressMap.RendezvousFunnelAddress + + CpuMpData->AddressMap.ModeTransitionOffset, + Size + ); =20 - ExchangeInfo->ModeTransitionMemory =3D (UINT32)CpuMpData->WakeupBuffer= High; - } else { - ExchangeInfo->ModeTransitionMemory =3D (UINT32) - (ExchangeInfo->BufferStart + CpuM= pData->AddressMap.ModeTransitionOffset); - } + ExchangeInfo->ModeTransitionMemory =3D (UINT32)CpuMpData->WakeupBufferHi= gh; =20 ExchangeInfo->ModeHighMemory =3D ExchangeInfo->ModeTransitionMemory + (UINT32)ExchangeInfo->ModeOffset - @@ -990,7 +1008,7 @@ BackupAndPrepareWakeupBuffer ( CopyMem ( (VOID *)CpuMpData->WakeupBuffer, (VOID *)CpuMpData->AddressMap.RendezvousFunnelAddress, - CpuMpData->AddressMap.RendezvousFunnelSize + CpuMpData->BackupBufferSize - sizeof (MP_CPU_EXCHANGE_INFO) ); } =20 @@ -1011,27 +1029,6 @@ RestoreWakeupBuffer ( ); } =20 -/** - Calculate the size of the reset vector. - - @param[in] AddressMap The pointer to Address Map structure. - - @return Total amount of memory required for the AP reset= area -**/ -STATIC -UINTN -GetApResetVectorSize ( - IN MP_ASSEMBLY_ADDRESS_MAP *AddressMap - ) -{ - UINTN Size; - - Size =3D AddressMap->RendezvousFunnelSize + - sizeof (MP_CPU_EXCHANGE_INFO); - - return Size; -} - /** Allocate reset vector buffer. =20 @@ -1042,20 +1039,17 @@ AllocateResetVector ( IN OUT CPU_MP_DATA *CpuMpData ) { - UINTN ApResetVectorSize; + UINTN ApResetVectorSizeBelow1Mb; + UINTN ApResetVectorSizeAbove1Mb; UINTN ApResetStackSize; =20 if (CpuMpData->WakeupBuffer =3D=3D (UINTN)-1) { - ApResetVectorSize =3D GetApResetVectorSize (&CpuMpData->AddressMap); + GetApResetVectorSize (&CpuMpData->AddressMap, &ApResetVectorSizeBelow1= Mb, &ApResetVectorSizeAbove1Mb); =20 - CpuMpData->WakeupBuffer =3D GetWakeupBuffer (ApResetVectorSize); + CpuMpData->WakeupBuffer =3D GetWakeupBuffer (ApResetVectorSizeBel= ow1Mb); CpuMpData->MpCpuExchangeInfo =3D (MP_CPU_EXCHANGE_INFO *)(UINTN) - (CpuMpData->WakeupBuffer + - CpuMpData->AddressMap.RendezvousFunnel= Size); - CpuMpData->WakeupBufferHigh =3D AllocateCodeBuffer ( - CpuMpData->AddressMap.RendezvousFunnel= Size - - CpuMpData->AddressMap.ModeTransitionOf= fset - ); + (CpuMpData->WakeupBuffer + ApResetVecto= rSizeBelow1Mb - sizeof (MP_CPU_EXCHANGE_INFO)); + CpuMpData->WakeupBufferHigh =3D AllocateCodeBuffer (ApResetVectorSizeA= bove1Mb); // // The AP reset stack is only used by SEV-ES guests. Do not allocate it // if SEV-ES is not enabled. An SEV-SNP guest is also considered @@ -1794,7 +1788,7 @@ MpInitLibInitialize ( UINT8 ApLoopMode; UINT8 *MonitorBuffer; UINTN Index; - UINTN ApResetVectorSize; + UINTN ApResetVectorSizeBelow1Mb; UINTN BackupBufferAddr; UINTN ApIdtBase; =20 @@ -1808,7 +1802,7 @@ MpInitLibInitialize ( ASSERT (MaxLogicalProcessorNumber !=3D 0); =20 AsmGetAddressMap (&AddressMap); - ApResetVectorSize =3D GetApResetVectorSize (&AddressMap); + GetApResetVectorSize (&AddressMap, &ApResetVectorSizeBelow1Mb, NULL); ApStackSize =3D PcdGet32 (PcdCpuApStackSize); ApLoopMode =3D GetApLoopMode (&MonitorFilterSize); =20 @@ -1819,7 +1813,7 @@ MpInitLibInitialize ( =20 BufferSize =3D ApStackSize * MaxLogicalProcessorNumber; BufferSize +=3D MonitorFilterSize * MaxLogicalProcessorNumber; - BufferSize +=3D ApResetVectorSize; + BufferSize +=3D ApResetVectorSizeBelow1Mb; BufferSize =3D ALIGN_VALUE (BufferSize, 8); BufferSize +=3D VolatileRegisters.Idtr.Limit + 1; BufferSize +=3D sizeof (CPU_MP_DATA); @@ -1852,12 +1846,12 @@ MpInitLibInitialize ( // MonitorBuffer =3D (UINT8 *)(Buffer + ApStackSize * MaxLogi= calProcessorNumber); BackupBufferAddr =3D (UINTN)MonitorBuffer + MonitorFilterSize= * MaxLogicalProcessorNumber; - ApIdtBase =3D ALIGN_VALUE (BackupBufferAddr + ApResetV= ectorSize, 8); + ApIdtBase =3D ALIGN_VALUE (BackupBufferAddr + ApResetV= ectorSizeBelow1Mb, 8); CpuMpData =3D (CPU_MP_DATA *)(ApIdtBase + VolatileRegi= sters.Idtr.Limit + 1); CpuMpData->Buffer =3D Buffer; CpuMpData->CpuApStackSize =3D ApStackSize; CpuMpData->BackupBuffer =3D BackupBufferAddr; - CpuMpData->BackupBufferSize =3D ApResetVectorSize; + CpuMpData->BackupBufferSize =3D ApResetVectorSizeBelow1Mb; CpuMpData->WakeupBuffer =3D (UINTN)-1; CpuMpData->CpuCount =3D 1; CpuMpData->BspNumber =3D 0; --=20 2.35.1.windows.2 -=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 (#89747): https://edk2.groups.io/g/devel/message/89747 Mute This Topic: https://groups.io/mt/91134933/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 Thu May 2 22:04:19 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+89748+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+89748+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1652685271; cv=none; d=zohomail.com; s=zohoarc; b=OdPjWYsNgrch9Dc5i8KqG5gkvK3pz3E6jkrTp+3/ivNj1Cd8R8OaNbjR09BqB8KFCIBqIQ2pmpEu27UPo3aMParjrPJLYqdjriExf5Pf/IwKZi02cSgwltbtR6pyLCnMni9me1bGXqMSS+U4YSvLI9s0pC5V1CeaUwtYpf7ba3Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652685271; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=K2MbErLQ/kCr0lLVbHELy0wYBtm729tUyZIoeAYPyZU=; b=EhUNjl+D7C3xFa8hSWLwRALbz7Tl9UOj0axsGruKVWMm/zBdh1Y9rMPhb4sCr28yJ46t5Z1RORkSmIwjQRsOcAn1tE4VaX+Y/mhSA6cWqXqbto9mThcGc5lDcpu7MMCTg1MFVOK0Rk68pDEw+Gwhi03wwD37TvCKPWGmNGV+3mk= 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+89748+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 1652685271297655.3267620270266; Mon, 16 May 2022 00:14:31 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id bBauYY1788612xlM5OLAXE7p; Mon, 16 May 2022 00:14:31 -0700 X-Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web10.25684.1652685269359705253 for ; Mon, 16 May 2022 00:14:30 -0700 X-IronPort-AV: E=McAfee;i="6400,9594,10348"; a="270451800" X-IronPort-AV: E=Sophos;i="5.91,229,1647327600"; d="scan'208";a="270451800" X-Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 May 2022 00:14:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,229,1647327600"; d="scan'208";a="555129056" X-Received: from shwdeopenlab706.ccr.corp.intel.com ([10.239.183.102]) by orsmga002.jf.intel.com with ESMTP; 16 May 2022 00:14:27 -0700 From: "Ni, Ray" To: devel@edk2.groups.io Cc: Eric Dong Subject: [edk2-devel] [PATCH v3 5/5] MpInitLib: Move the Above1Mb vector allocation to MpInitLibInitialize Date: Mon, 16 May 2022 15:14:12 +0800 Message-Id: <20220516071412.359-6-ray.ni@intel.com> In-Reply-To: <20220516071412.359-1-ray.ni@intel.com> References: <20220516071412.359-1-ray.ni@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,ray.ni@intel.com X-Gm-Message-State: pWSOJMseC0vfCzIsDIXB0GHfx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1652685271; bh=ftD1D99n6Jpn4ARpa7TinW2mz7cXRkjfnmPhAIkmtwA=; h=Cc:Date:From:Reply-To:Subject:To; b=Dk46gabKI6ALIs7GOFIXsz3kUI2zwzIxwopKN9C1ggi+O/A7q/tGf3PF3e8EnYtCsnX NNBglX3GOScfWWNtmn/qXkF2o1LQ8Y+sRkkKL+QxfwnogJGPCZLbLOU9O/NhqQNkp9Ry0 Mx4mrwbl6zqQ4e8dtNAwdMH9y/WOvE7obL4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1652685272752100021 Content-Type: text/plain; charset="utf-8" The AP vector consists of 2 parts: 1. the initial 16-bit code that should be under 1MB and page aligned. 2. the 32-bit/64-bit code that can be anywhere in the memory with any alignment. The need of part #2 is because the memory under 1MB is temporary "stolen" for use and will "give" back after all AP wake up. The range of memory is not marked as code page in page table. CPU may trigger exception as soon as NX is enabled. The part #2 memory allocation can be done in the MpInitLibInitialize. Signed-off-by: Ray Ni Cc: Eric Dong Reviewed-by: Eric Dong for this serial. --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 53 +++++++++++++++------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index e4edbb618d..66e0f94f03 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -955,18 +955,6 @@ FillExchangeInfoData ( Size -=3D sizeof (IA32_SEGMENT_DESCRIPTOR); } =20 - // - // Copy all 32-bit code and 64-bit code into memory with type of - // EfiBootServicesCode to avoid page fault if NX memory protection is en= abled. - // - GetApResetVectorSize (&CpuMpData->AddressMap, NULL, &Size); - CopyMem ( - (VOID *)CpuMpData->WakeupBufferHigh, - CpuMpData->AddressMap.RendezvousFunnelAddress + - CpuMpData->AddressMap.ModeTransitionOffset, - Size - ); - ExchangeInfo->ModeTransitionMemory =3D (UINT32)CpuMpData->WakeupBufferHi= gh; =20 ExchangeInfo->ModeHighMemory =3D ExchangeInfo->ModeTransitionMemory + @@ -1035,21 +1023,24 @@ RestoreWakeupBuffer ( @param[in, out] CpuMpData The pointer to CPU MP Data structure. **/ VOID -AllocateResetVector ( +AllocateResetVectorBelow1Mb ( IN OUT CPU_MP_DATA *CpuMpData ) { - UINTN ApResetVectorSizeBelow1Mb; - UINTN ApResetVectorSizeAbove1Mb; UINTN ApResetStackSize; =20 if (CpuMpData->WakeupBuffer =3D=3D (UINTN)-1) { - GetApResetVectorSize (&CpuMpData->AddressMap, &ApResetVectorSizeBelow1= Mb, &ApResetVectorSizeAbove1Mb); - - CpuMpData->WakeupBuffer =3D GetWakeupBuffer (ApResetVectorSizeBel= ow1Mb); + CpuMpData->WakeupBuffer =3D GetWakeupBuffer (CpuMpData->BackupBuf= ferSize); CpuMpData->MpCpuExchangeInfo =3D (MP_CPU_EXCHANGE_INFO *)(UINTN) - (CpuMpData->WakeupBuffer + ApResetVecto= rSizeBelow1Mb - sizeof (MP_CPU_EXCHANGE_INFO)); - CpuMpData->WakeupBufferHigh =3D AllocateCodeBuffer (ApResetVectorSizeA= bove1Mb); + (CpuMpData->WakeupBuffer + CpuMpData->B= ackupBufferSize - sizeof (MP_CPU_EXCHANGE_INFO)); + DEBUG (( + DEBUG_INFO, + "AP Vector: 16-bit =3D %p/%x, ExchangeInfo =3D %p/%x\n", + CpuMpData->WakeupBuffer, + CpuMpData->BackupBufferSize - sizeof (MP_CPU_EXCHANGE_INFO), + CpuMpData->MpCpuExchangeInfo, + sizeof (MP_CPU_EXCHANGE_INFO) + )); // // The AP reset stack is only used by SEV-ES guests. Do not allocate it // if SEV-ES is not enabled. An SEV-SNP guest is also considered @@ -1148,7 +1139,7 @@ WakeUpAP ( (CpuMpData->InitFlag !=3D ApInitDone)) { ResetVectorRequired =3D TRUE; - AllocateResetVector (CpuMpData); + AllocateResetVectorBelow1Mb (CpuMpData); AllocateSevEsAPMemory (CpuMpData); FillExchangeInfoData (CpuMpData); SaveLocalApicTimerSetting (CpuMpData); @@ -1789,6 +1780,7 @@ MpInitLibInitialize ( UINT8 *MonitorBuffer; UINTN Index; UINTN ApResetVectorSizeBelow1Mb; + UINTN ApResetVectorSizeAbove1Mb; UINTN BackupBufferAddr; UINTN ApIdtBase; =20 @@ -1802,9 +1794,9 @@ MpInitLibInitialize ( ASSERT (MaxLogicalProcessorNumber !=3D 0); =20 AsmGetAddressMap (&AddressMap); - GetApResetVectorSize (&AddressMap, &ApResetVectorSizeBelow1Mb, NULL); - ApStackSize =3D PcdGet32 (PcdCpuApStackSize); - ApLoopMode =3D GetApLoopMode (&MonitorFilterSize); + GetApResetVectorSize (&AddressMap, &ApResetVectorSizeBelow1Mb, &ApResetV= ectorSizeAbove1Mb); + ApStackSize =3D PcdGet32 (PcdCpuApStackSize); + ApLoopMode =3D GetApLoopMode (&MonitorFilterSize); =20 // // Save BSP's Control registers for APs. @@ -1913,6 +1905,19 @@ MpInitLibInitialize ( (UINT32 *)(MonitorBuffer + MonitorFilterSize * Index); } =20 + // + // Copy all 32-bit code and 64-bit code into memory with type of + // EfiBootServicesCode to avoid page fault if NX memory protection is en= abled. + // + CpuMpData->WakeupBufferHigh =3D AllocateCodeBuffer (ApResetVectorSizeAbo= ve1Mb); + CopyMem ( + (VOID *)CpuMpData->WakeupBufferHigh, + CpuMpData->AddressMap.RendezvousFunnelAddress + + CpuMpData->AddressMap.ModeTransitionOffset, + ApResetVectorSizeAbove1Mb + ); + DEBUG ((DEBUG_INFO, "AP Vector: non-16-bit =3D %p/%x\n", CpuMpData->Wake= upBufferHigh, ApResetVectorSizeAbove1Mb)); + // // Enable the local APIC for Virtual Wire Mode. // --=20 2.35.1.windows.2 -=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 (#89748): https://edk2.groups.io/g/devel/message/89748 Mute This Topic: https://groups.io/mt/91134934/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-