From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=RGqDyBZm; spf=pass (domain: intel.com, ip: 134.134.136.24, mailfrom: ray.ni@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652685269; x=1684221269; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zeEMjB9pmNcu1pp9dzMc8Gp1YEJuL42b+mrJbhg01IQ=; b=RGqDyBZm6QEc3aQun+D3YiPORd5bmX1lAFo2qftLUawx+DzNrGkqO3OO +uFY721jN/8yyoxdFaLiWwSuHyo1HIn8UUP8dC92wnaIuV/Uk86/L+6wm 4fdD2f0mSuPzh7qsnXibdeURdXZRnvNSof5I/WiQm7FXsfxDgV5/NHybN QOA16/dRwK9UgSbDxVrEJDVg6TcO2Yd+IN97dKrNqPxGzP1NrNDb5HTi3 bcLZiWw652Scc0TzasquZiPy9Ims73Svh/iVbat4W2W2TL32moTBtxicn jIOX4l7MyKLsYyi7ayB/o3LJW9i3kVUJP5ubunht1rY1kULPT+SaiHv/s g==; 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" 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" 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: [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> X-Mailer: git-send-email 2.35.1.windows.2 In-Reply-To: <20220516071412.359-1-ray.ni@intel.com> References: <20220516071412.359-1-ray.ni@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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 --- 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);=0D }=0D =0D - //=0D - // Copy all 32-bit code and 64-bit code into memory with type of=0D - // EfiBootServicesCode to avoid page fault if NX memory protection is en= abled.=0D - //=0D - GetApResetVectorSize (&CpuMpData->AddressMap, NULL, &Size);=0D - CopyMem (=0D - (VOID *)CpuMpData->WakeupBufferHigh,=0D - CpuMpData->AddressMap.RendezvousFunnelAddress +=0D - CpuMpData->AddressMap.ModeTransitionOffset,=0D - Size=0D - );=0D -=0D ExchangeInfo->ModeTransitionMemory =3D (UINT32)CpuMpData->WakeupBufferHi= gh;=0D =0D ExchangeInfo->ModeHighMemory =3D ExchangeInfo->ModeTransitionMemory +=0D @@ -1035,21 +1023,24 @@ RestoreWakeupBuffer ( @param[in, out] CpuMpData The pointer to CPU MP Data structure.=0D **/=0D VOID=0D -AllocateResetVector (=0D +AllocateResetVectorBelow1Mb (=0D IN OUT CPU_MP_DATA *CpuMpData=0D )=0D {=0D - UINTN ApResetVectorSizeBelow1Mb;=0D - UINTN ApResetVectorSizeAbove1Mb;=0D UINTN ApResetStackSize;=0D =0D if (CpuMpData->WakeupBuffer =3D=3D (UINTN)-1) {=0D - GetApResetVectorSize (&CpuMpData->AddressMap, &ApResetVectorSizeBelow1= Mb, &ApResetVectorSizeAbove1Mb);=0D -=0D - CpuMpData->WakeupBuffer =3D GetWakeupBuffer (ApResetVectorSizeBel= ow1Mb);=0D + CpuMpData->WakeupBuffer =3D GetWakeupBuffer (CpuMpData->BackupBuf= ferSize);=0D CpuMpData->MpCpuExchangeInfo =3D (MP_CPU_EXCHANGE_INFO *)(UINTN)=0D - (CpuMpData->WakeupBuffer + ApResetVecto= rSizeBelow1Mb - sizeof (MP_CPU_EXCHANGE_INFO));=0D - CpuMpData->WakeupBufferHigh =3D AllocateCodeBuffer (ApResetVectorSizeA= bove1Mb);=0D + (CpuMpData->WakeupBuffer + CpuMpData->B= ackupBufferSize - sizeof (MP_CPU_EXCHANGE_INFO));=0D + DEBUG ((=0D + DEBUG_INFO,=0D + "AP Vector: 16-bit =3D %p/%x, ExchangeInfo =3D %p/%x\n",=0D + CpuMpData->WakeupBuffer,=0D + CpuMpData->BackupBufferSize - sizeof (MP_CPU_EXCHANGE_INFO),=0D + CpuMpData->MpCpuExchangeInfo,=0D + sizeof (MP_CPU_EXCHANGE_INFO)=0D + ));=0D //=0D // The AP reset stack is only used by SEV-ES guests. Do not allocate i= t=0D // if SEV-ES is not enabled. An SEV-SNP guest is also considered=0D @@ -1148,7 +1139,7 @@ WakeUpAP ( (CpuMpData->InitFlag !=3D ApInitDone))=0D {=0D ResetVectorRequired =3D TRUE;=0D - AllocateResetVector (CpuMpData);=0D + AllocateResetVectorBelow1Mb (CpuMpData);=0D AllocateSevEsAPMemory (CpuMpData);=0D FillExchangeInfoData (CpuMpData);=0D SaveLocalApicTimerSetting (CpuMpData);=0D @@ -1789,6 +1780,7 @@ MpInitLibInitialize ( UINT8 *MonitorBuffer;=0D UINTN Index;=0D UINTN ApResetVectorSizeBelow1Mb;=0D + UINTN ApResetVectorSizeAbove1Mb;=0D UINTN BackupBufferAddr;=0D UINTN ApIdtBase;=0D =0D @@ -1802,9 +1794,9 @@ MpInitLibInitialize ( ASSERT (MaxLogicalProcessorNumber !=3D 0);=0D =0D AsmGetAddressMap (&AddressMap);=0D - GetApResetVectorSize (&AddressMap, &ApResetVectorSizeBelow1Mb, NULL);=0D - ApStackSize =3D PcdGet32 (PcdCpuApStackSize);=0D - ApLoopMode =3D GetApLoopMode (&MonitorFilterSize);=0D + GetApResetVectorSize (&AddressMap, &ApResetVectorSizeBelow1Mb, &ApResetV= ectorSizeAbove1Mb);=0D + ApStackSize =3D PcdGet32 (PcdCpuApStackSize);=0D + ApLoopMode =3D GetApLoopMode (&MonitorFilterSize);=0D =0D //=0D // Save BSP's Control registers for APs.=0D @@ -1913,6 +1905,19 @@ MpInitLibInitialize ( (UINT32 *)(MonitorBuffer + MonitorFilterSize * Index);=0D }=0D =0D + //=0D + // Copy all 32-bit code and 64-bit code into memory with type of=0D + // EfiBootServicesCode to avoid page fault if NX memory protection is en= abled.=0D + //=0D + CpuMpData->WakeupBufferHigh =3D AllocateCodeBuffer (ApResetVectorSizeAbo= ve1Mb);=0D + CopyMem (=0D + (VOID *)CpuMpData->WakeupBufferHigh,=0D + CpuMpData->AddressMap.RendezvousFunnelAddress +=0D + CpuMpData->AddressMap.ModeTransitionOffset,=0D + ApResetVectorSizeAbove1Mb=0D + );=0D + DEBUG ((DEBUG_INFO, "AP Vector: non-16-bit =3D %p/%x\n", CpuMpData->Wake= upBufferHigh, ApResetVectorSizeAbove1Mb));=0D +=0D //=0D // Enable the local APIC for Virtual Wire Mode.=0D //=0D --=20 2.35.1.windows.2