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 3FB11AC105E for ; Fri, 10 Nov 2023 10:37:41 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=ZVnbpMhSXDR/WX0tOFN+N9qV3JMXx7OW81/Yyypa3aI=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1699612659; v=1; b=f49Oj2lEONagrZQ2925PRJTtBPMnaTThDjPLG0Gw0NYI8g2FIZr7SUGnnGWoCT+KmcL/bkEH 8KlItOtyyz2eOJ6zkTxKJW8tVNlAd04tOD7niXlyXqrTV1NaQb+v58xNJu2W5HsaIw9liy874Nj a+evVCClEDu5YWVz6e82WQG4= X-Received: by 127.0.0.2 with SMTP id ZPtFYY7687511xAwtfQu1Xmz; Fri, 10 Nov 2023 02:37:39 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web10.24636.1699612658910708948 for ; Fri, 10 Nov 2023 02:37:39 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10889"; a="375207137" X-IronPort-AV: E=Sophos;i="6.03,291,1694761200"; d="scan'208";a="375207137" X-Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Nov 2023 02:37:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10889"; a="798587408" X-IronPort-AV: E=Sophos;i="6.03,291,1694761200"; d="scan'208";a="798587408" X-Received: from shwdeopenlab813.ccr.corp.intel.com ([10.239.55.230]) by orsmga001.jf.intel.com with ESMTP; 10 Nov 2023 02:37:35 -0800 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: Yuanhao Xie , Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH] UefiCpuPkg/MpInitLib: Enable execute disable bit. Date: Fri, 10 Nov 2023 18:37:32 +0800 Message-Id: <20231110103732.1399-1-yuanhao.xie@intel.com> MIME-Version: 1.0 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 Reply-To: devel@edk2.groups.io,yuanhao.xie@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 7Wz8LnQNQJ0WFfbbz2rqRx15x7686176AA= 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=f49Oj2lE; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.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 From: Yuanhao Xie This patch synchronizes the No-Execute bit in the IA32_EFER register for the APs before the RestoreVolatileRegisters operation. The commit 964a4f0, titled "Eliminate the second INIT-SIPI-SIPI sequence," replaces the second INIT-SIPI-SIPI sequence with the BSP calling the SwitchApContext function to initiate a specialized start-up signal, waking up APs in the DXE instead of using INIT-SIPI-SIPI. Due to this change, the logic for "Enable execute disable bit" in MpFuncs.nasm is no longer executed. However, to ensure the proper setup of the page table, it is necessary to synchronize the IA32_EFER.NXE for APs before executing RestoreVolatileRegisters . Based on SDM: If IA32_EFER.NXE is set to 1, it signifies execute-disable, meaning instruction fetches are not allowed from the 4-KByte page controlled by this entry. Conversely, if it is set to 0, it is reserved. Signed-off-by: Yuanhao Xie Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 33 ++++++++++++++++++---------- UefiCpuPkg/Library/MpInitLib/MpLib.h | 1 + 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 9a6ec5db5c..a5ff7ef91f 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -906,21 +906,29 @@ ApWakeupFunction ( **/=0D VOID=0D EFIAPI=0D -DxeApEntryPoint (=0D - CPU_MP_DATA *CpuMpData=0D +DxeApEntryPoint(=0D + CPU_MP_DATA *CpuMpData=0D )=0D {=0D - UINTN ProcessorNumber;=0D + UINTN ProcessorNumber;=0D + MSR_IA32_EFER_REGISTER EferMsr;=0D =0D - GetProcessorNumber (CpuMpData, &ProcessorNumber);=0D - RestoreVolatileRegisters (&CpuMpData->CpuData[0].VolatileRegisters, FALS= E);=0D - InterlockedIncrement ((UINT32 *)&CpuMpData->FinishedCount);=0D - PlaceAPInMwaitLoopOrRunLoop (=0D - CpuMpData->ApLoopMode,=0D - CpuMpData->CpuData[ProcessorNumber].StartupApSignal,=0D - CpuMpData->ApTargetCState=0D - );=0D - ApWakeupFunction (CpuMpData, ProcessorNumber);=0D + GetProcessorNumber(CpuMpData, &ProcessorNumber);=0D + InterlockedIncrement((UINT32 *)&CpuMpData->FinishedCount);=0D +=0D + if (CpuMpData->EnableExecuteDisableForSwitchContext)=0D + {=0D + EferMsr.Uint64 =3D AsmReadMsr64(MSR_IA32_EFER);=0D + EferMsr.Bits.NXE =3D 1;=0D + AsmWriteMsr64(MSR_IA32_EFER, EferMsr.Uint64);=0D + }=0D +=0D + RestoreVolatileRegisters(&CpuMpData->CpuData[0].VolatileRegisters, FALSE= );=0D + PlaceAPInMwaitLoopOrRunLoop(=0D + CpuMpData->ApLoopMode,=0D + CpuMpData->CpuData[ProcessorNumber].StartupApSignal,=0D + CpuMpData->ApTargetCState);=0D + ApWakeupFunction(CpuMpData, ProcessorNumber);=0D }=0D =0D /**=0D @@ -2190,6 +2198,7 @@ MpInitLibInitialize ( =0D CpuMpData->FinishedCount =3D 0;=0D CpuMpData->InitFlag =3D ApInitDone;=0D + CpuMpData->EnableExecuteDisableForSwitchContext =3D IsBspExecuteDisa= bleEnabled ();=0D SaveCpuMpData (CpuMpData);=0D //=0D // In scenarios where both the PEI and DXE phases run in the same=0D diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index d2f411f006..bf86a13820 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -265,6 +265,7 @@ struct _CPU_MP_DATA { UINT64 TotalTime;=0D EFI_EVENT WaitEvent;=0D UINTN **FailedCpuList;=0D + BOOLEAN EnableExecuteDisableForSwitchContext;=0D =0D AP_INIT_STATE InitFlag;=0D BOOLEAN SwitchBspFlag;=0D --=20 2.39.1.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111027): https://edk2.groups.io/g/devel/message/111027 Mute This Topic: https://groups.io/mt/102504353/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-