From nobody Wed May 15 17:02:57 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+111120+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+111120+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1699854613; cv=none; d=zohomail.com; s=zohoarc; b=h+NAfcKYlTiIo8vQvAv3y8quUSAHRtpp2tanRrZNCfuO+DwYwez3jpe7fP71rze7wbaka+yFcEf+zFPs4Y4FDsvtaOn5fh/JeYJT8nQzGMAgk2eX5UXVFVHy8u1tLAgE/k2KuOH79NeZB5KPSy8idy8WIZWtvVp80gaWbLyn56I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699854613; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=rFaioAdvkYLI6RhGUFhXxvY1mYx1N5zeH5rbA4jlXnk=; b=EHoC52pEGwIMJH4rLfS48RJWxzZlDoWROA6fcZ7/ZGBMeyQrOFrp/iDPHLj3ea86tI8fFf1wml81U+Ydb4rihwfvkGsZbtx5RM+Ygue6m6XSKk2lT9nc8moV+gUsfoIDhKO/clZ4PBXaKKaEZcBxK8GCfMp45QYHZyZdb7jNLzc= 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+111120+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 1699854613190279.27860821781667; Sun, 12 Nov 2023 21:50:13 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=fE0Pq9LwClXBEfVBSw6ej3b7lZrFUpV3i6vJcpxHZlE=; 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=1699854612; v=1; b=YUDli667HVfOaIOAuwykdHJmMwPVfJlbmKKeGmxReSQfzg74usEF38sAxC5WJNdW1yL3AjMn CEY2JURdfEr7HDZ1cYsMnj3qGYb/7JWhQcYPPR+Je9fIugGu5HY1ozLvZbXyktCK+Ji41+V+Cij iacoQA6evDoWHrHBJ7yQlW6A= X-Received: by 127.0.0.2 with SMTP id TY02YY1788612xAekXKSfYDW; Sun, 12 Nov 2023 21:50:12 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by mx.groups.io with SMTP id smtpd.web11.31546.1699854612068658659 for ; Sun, 12 Nov 2023 21:50:12 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10892"; a="11931042" X-IronPort-AV: E=Sophos;i="6.03,298,1694761200"; d="scan'208";a="11931042" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Nov 2023 21:50:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10892"; a="767810564" X-IronPort-AV: E=Sophos;i="6.03,298,1694761200"; d="scan'208";a="767810564" X-Received: from shwdeopenlab813.ccr.corp.intel.com ([10.239.55.230]) by fmsmga007.fm.intel.com with ESMTP; 12 Nov 2023 21:50:09 -0800 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: Yuanhao Xie , Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [Patch V3] UefiCpuPkg/MpInitLib: Enable execute disable bit. Date: Mon, 13 Nov 2023 13:50:06 +0800 Message-Id: <20231113055006.1747-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: 7Ac1lCtswB5Q6PkH5ZDv7nbTx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1699854615168100003 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 Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann --- UefiCpuPkg/Library/MpInitLib/MpLib.c | 17 +++++++++++++---- UefiCpuPkg/Library/MpInitLib/MpLib.h | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 9a6ec5db5c..c7527f8662 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -910,11 +910,19 @@ DxeApEntryPoint ( CPU_MP_DATA *CpuMpData ) { - UINTN ProcessorNumber; + UINTN ProcessorNumber; + MSR_IA32_EFER_REGISTER EferMsr; =20 GetProcessorNumber (CpuMpData, &ProcessorNumber); - RestoreVolatileRegisters (&CpuMpData->CpuData[0].VolatileRegisters, FALS= E); InterlockedIncrement ((UINT32 *)&CpuMpData->FinishedCount); + + 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); PlaceAPInMwaitLoopOrRunLoop ( CpuMpData->ApLoopMode, CpuMpData->CpuData[ProcessorNumber].StartupApSignal, @@ -2188,8 +2196,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..af296f6ac0 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 (#111120): https://edk2.groups.io/g/devel/message/111120 Mute This Topic: https://groups.io/mt/102556553/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-