From nobody Tue May 14 06:36:15 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+111447+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+111447+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700454083; cv=none; d=zohomail.com; s=zohoarc; b=isBz7CHbbwvAoB55Srp1Vwzi4FvFVwtewPORm2+ySyIUQyija+frby0fe46kd5x9lmocFyR3Odw/+2PXJMOKiCDwNUo+f69WdcmRn7m3C25kirKO5XUNuYSNHlmsn3AdmMfWwkxfj5j/1Sm6KLtbPUMF382FI/vlTguWgPEViRg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700454083; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=ArnEOkSAW5qRYCVVxCft67BwF0rqKzgU4fMBV3D+xbU=; b=BtHM9rdQbf3bqQQrN5YjHry1fgvWlPKovBZFXdR7cDLE7g0/uzGPIO6H0KPow0ycCSey0CNNtDk6p8aFcGG/nwGNYh9ebeXQSdERgkqKpLrs2oOzS17NAzrCZu9DgObi4oZf+zkZjyB4i1ek3dM4wkFR5t3outSuVm0DA4lohKA= 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+111447+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 1700454083204568.5366240956088; Sun, 19 Nov 2023 20:21:23 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=hmm6a63FW5VwAS/eAiZZX/9CNSN537j/MohIPB1hl+I=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: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=1700454082; v=1; b=gJzXtyPWECB1SPJyHfoI7QBvThgT4YL8vnICjnKI3yYY48Q0diOJOvn9XLe1IpTh1BgW351j 4lVYBM0A6kHD1QPRK8fDYJekCVwMqPB0Th9P9HWACVN/Cm5mE+r/bj+POzJDxxjwWnphbQVKXgh 3m9K7hHLta/AbUHx05Y8yc6U= X-Received: by 127.0.0.2 with SMTP id XJ99YY1788612xUUKaMk0B5O; Sun, 19 Nov 2023 20:21:22 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web10.43973.1700454081395369065 for ; Sun, 19 Nov 2023 20:21:22 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10899"; a="455871831" X-IronPort-AV: E=Sophos;i="6.04,212,1695711600"; d="scan'208";a="455871831" X-Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Nov 2023 20:19:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10899"; a="939678718" X-IronPort-AV: E=Sophos;i="6.04,212,1695711600"; d="scan'208";a="939678718" X-Received: from shwdeopenlab813.ccr.corp.intel.com ([10.239.55.230]) by orsmga005.jf.intel.com with ESMTP; 19 Nov 2023 20:18:59 -0800 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: Yuanhao Xie , Laszlo Ersek , Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [Patch V5 1/2] UefiCpuPkg/MpInitLib: Enable execute disable bit. Date: Mon, 20 Nov 2023 12:18:45 +0800 Message-Id: <20231120041846.2221-2-yuanhao.xie@intel.com> In-Reply-To: <20231120041846.2221-1-yuanhao.xie@intel.com> References: <20231120041846.2221-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: IGngynF2pSJr5LkNhonaJlgkx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1700454083698100002 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Laszlo Ersek Cc: Laszlo Ersek lersek@redhat.com Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 14 +++++++++++--- UefiCpuPkg/Library/MpInitLib/MpLib.h | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 9a6ec5db5c..f29e66a14f 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -910,9 +910,16 @@ DxeApEntryPoint ( CPU_MP_DATA *CpuMpData ) { - UINTN ProcessorNumber; + UINTN ProcessorNumber; + MSR_IA32_EFER_REGISTER EferMsr; =20 GetProcessorNumber (CpuMpData, &ProcessorNumber); + if (CpuMpData->EnableExecuteDisableForSwitchContext) { + EferMsr.Uint64 =3D AsmReadMsr64 (MSR_IA32_EFER); + EferMsr.Bits.NXE =3D 1; + AsmWriteMsr64 (MSR_IA32_EFER, EferMsr.Uint64); + } + RestoreVolatileRegisters (&CpuMpData->CpuData[0].VolatileRegisters, FALS= E); InterlockedIncrement ((UINT32 *)&CpuMpData->FinishedCount); PlaceAPInMwaitLoopOrRunLoop ( @@ -2188,8 +2195,9 @@ MpInitLibInitialize ( if (MpHandOff->WaitLoopExecutionMode =3D=3D sizeof (VOID *)) { ASSERT (CpuMpData->ApLoopMode !=3D ApInHltLoop); =20 - CpuMpData->FinishedCount =3D 0; - CpuMpData->InitFlag =3D ApInitDone; + CpuMpData->FinishedCount =3D 0; + CpuMpData->InitFlag =3D ApInitDone; + CpuMpData->EnableExecuteDisableForSwitchContext =3D IsBspExecuteDisa= bleEnabled (); SaveCpuMpData (CpuMpData); // // In scenarios where both the PEI and DXE phases run in the same diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index 763db4963d..0afac7c78c 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -270,6 +270,7 @@ struct _CPU_MP_DATA { UINT64 TotalTime; EFI_EVENT WaitEvent; UINTN **FailedCpuList; + BOOLEAN EnableExecuteDisableForSwitchContext =20 AP_INIT_STATE InitFlag; BOOLEAN SwitchBspFlag; --=20 2.39.1.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 (#111447): https://edk2.groups.io/g/devel/message/111447 Mute This Topic: https://groups.io/mt/102702056/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 May 14 06:36:15 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+111446+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+111446+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700454083; cv=none; d=zohomail.com; s=zohoarc; b=nKNOB9+BUr6rTa8nbOSKQoVq3MSNxOnAi7c/kRWIzTGej9K4hIxOHy9via6m6L2mkN6UeYHgOBAX3b5x0Jwj+tNhaELZfBKeIV60OhoOPpXOLIaLJvrgzPQ5aMDQVvf0lFmrOmcEwKu5jTqohZg34DpQ36l6CclPonIj1w3r+8w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700454083; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=Y7YcpTREccW6scolH/UQGTcQX7yZTRQFSWHSpRP3NcI=; b=XTlA2zUOM9Kl5MOaJTOw9oyuEvS1WWDNES3bDV/ivierQnI4bI5/kg+Dg9AYqskmfAEaWFrbhAa+RHJlqya77qKp2jaH3+KB0kKdOBVbdJBQxhNWTS3dZFER7QD6Mwy6pEGvzhNy1nfCP9MVPmbEr60QS4l7y1OtxFLqc9dIkBs= 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+111446+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 1700454083145481.4901344065139; Sun, 19 Nov 2023 20:21:23 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=BbP7Gn2eMtma/IKfq7IFF4QI7A5Q+b4oFFxw5eTgDjA=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: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=1700454082; v=1; b=c8rqNtfOD5fQwmn+tGl4d6JNrxpvJFIP+on2xGUZGiSVla48QVRROBn3YmKtilM9raHomeX6 +BqxJHAWq+Msew7fwZYG3dKPmbOt0tEwuCuGiHn5jtnbZHvL89ktuoEcilTIGUEdGBEM91Qj2Oi E2V6zDgaBYIITIM4ltvyyEHs= X-Received: by 127.0.0.2 with SMTP id jZ6vYY1788612xzB62Sylbnt; Sun, 19 Nov 2023 20:21:22 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web10.43973.1700454081395369065 for ; Sun, 19 Nov 2023 20:21:21 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10899"; a="455871836" X-IronPort-AV: E=Sophos;i="6.04,212,1695711600"; d="scan'208";a="455871836" X-Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Nov 2023 20:19:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10899"; a="939678754" X-IronPort-AV: E=Sophos;i="6.04,212,1695711600"; d="scan'208";a="939678754" X-Received: from shwdeopenlab813.ccr.corp.intel.com ([10.239.55.230]) by orsmga005.jf.intel.com with ESMTP; 19 Nov 2023 20:19:03 -0800 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: xieyuanh , Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [Patch V5 2/2] UefiCpuPkg/MpInitLib: Update the comments of _CPU_MP_DATA. Date: Mon, 20 Nov 2023 12:18:46 +0800 Message-Id: <20231120041846.2221-3-yuanhao.xie@intel.com> In-Reply-To: <20231120041846.2221-1-yuanhao.xie@intel.com> References: <20231120041846.2221-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: gd3dX7rAxxZCfXYYuECObrh0x1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1700454083691100001 Content-Type: text/plain; charset="utf-8" No functional changes in this patch. Updated the comments of _CPU_MP_DATA to delcared that duplications in CpuMpData are present to avoid to be direct accessed and comprehended in assembly code. CpuMpData: Intended for use in C code while ExchangeInfo are used in assembly code in this module. Signed-off-by: Yuanhao Xie Cc: Laszlo Ersek lersek@redhat.com Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann --- UefiCpuPkg/Library/MpInitLib/MpLib.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index 0afac7c78c..242935816c 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -239,7 +239,11 @@ typedef struct { #pragma pack() =20 // -// CPU MP Data save in memory +// CPU MP Data save in memory, and intended for use in C code. +// There are some duplicated fields, such as XD status, between +// CpuMpData and ExchangeInfo. These duplications in CpuMpData +// are present to avoid to be direct accessed and comprehended +// in assembly code. // struct _CPU_MP_DATA { UINT64 CpuInfoInHob; --=20 2.39.1.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 (#111446): https://edk2.groups.io/g/devel/message/111446 Mute This Topic: https://groups.io/mt/102702055/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-