From nobody Thu May 9 16:22:41 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+111508+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+111508+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700534179; cv=none; d=zohomail.com; s=zohoarc; b=b6mtKSFz1/zic5/fst/0QYzP3Ukt8oUIVCFvRrunmjcewksU8MnfugvPJxSF/fxdYRYUr+9mjoAahV6YMPZPcnQSQZYVRKW3JNxOmU7/VZcP9s5LgMgTvIiSQaTWkO2JgQWVzn0Uyp4XiRngZUfkqGLZeP9lDpXjIKGg3oH5GR4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700534179; 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=X1RoW0EcPYWyF519Bm9oLKxjam3jgf+gJhspHp3vnUc=; b=WoZYTiQpg4P+DRn/yzSaX1TbB4eY25ObKa9uy3O75ClOxNGfLFn9aH03UgescKNqD4yKYjf7Egr1r5f7lBlPpxqdaL1JYwUAZQc4H+nidg3wuZFI/foZHRswQmcFs01nyuhtd6Zvjuuj/EmmkVbZOcojQTvWPT3oJRAVeul6mPY= 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+111508+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 1700534179216661.5825876429808; Mon, 20 Nov 2023 18:36:19 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=1yYbAryEb5EgOAnixnv1Ab4fDL6D1wE5+nLAZNAejbU=; 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=1700534178; v=1; b=qOlXuabiun01taK7q47BQrkJT3R1CIbEbsC4z4ECXaCaGCKkVM/FLHMTC0iNEYekdBacCAz3 4JB2j2GMoUzfsfLTjR4Fg32EzFrx97eCIi+t84v0/JasLBn9IKPlLgB5+AmVkH71fYhFnPxqB4V cYPaMsAr110zVUPbEVxPkQe8= X-Received: by 127.0.0.2 with SMTP id el4BYY1788612xpwVnj9SZca; Mon, 20 Nov 2023 18:36:18 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by mx.groups.io with SMTP id smtpd.web11.26388.1700534178224900933 for ; Mon, 20 Nov 2023 18:36:18 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="4868736" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="4868736" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 18:36:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="770098819" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="770098819" X-Received: from shwdeopenlab813.ccr.corp.intel.com ([10.239.55.230]) by fmsmga007.fm.intel.com with ESMTP; 20 Nov 2023 18:36:01 -0800 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: Yuanhao Xie , Laszlo Ersek , Ray Ni , Eric Dong , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [Patch V7 1/2] UefiCpuPkg/MpInitLib: Enable execute disable bit. Date: Tue, 21 Nov 2023 10:35:45 +0800 Message-Id: <20231121023546.2405-2-yuanhao.xie@intel.com> In-Reply-To: <20231121023546.2405-1-yuanhao.xie@intel.com> References: <20231121023546.2405-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: rx0TIjtp6n8Az5NAqlXZv85Sx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1700534180768100006 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 Reviewed-by: Ray Ni 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..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 (#111508): https://edk2.groups.io/g/devel/message/111508 Mute This Topic: https://groups.io/mt/102721680/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 9 16:22:41 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+111509+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+111509+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1700534179; cv=none; d=zohomail.com; s=zohoarc; b=QaTzdlRzXkMW63wkQaAiKPyGjM6ovfGAJlfMYThaKnfTYw5qz0XppdKjeyEHg/RC9lCTmYiLmljhqrPICWiAXEO50c5jC3QCzj/FtxiTR1qsVDFYvyGtBN8N/cTMjU3FWv122rwUtxMcSYanzdm+2hLl8dXAi3/k+z3OVqxcA60= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700534179; 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=iSp46j/G1X3eS5LKA1qjokCI2XqhOAEIqH3T4bKmstQ=; b=kkTs7rr4WOtgKUUX31mJZ3hCnMlaGafzYwOcVEuLhxcdJ4XTfa6kxRbMCctmFJ/s2sg2ISYbL2+aLKYy9p/F7z/WRBykGLrMPYXBbGdwHKwQL7mr4xkASxPEVJ0oVkgDg+SPiDagkyEMwxRJUGdf9w1sCeFEggRMSpfmni6PRmc= 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+111509+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 170053417970361.8864748873342; Mon, 20 Nov 2023 18:36:19 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=2td6wGz8s+La/oiNX1S6i2liaSJc97jVVv3ELopYeFA=; 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=1700534179; v=1; b=sfmxeChCqLkQJd9PrmA0Tw/K3fPWpA80O35go744cO7IZPUb+7V7EkWv7BrCpWUl4zgwRzl+ shRxYxHpRDDednI+HCjlpcUylVvxtel9hk7osbaMhdUA2lhX8hjQ9ECqCRlAuZnTCbrlelNBauY ZaGobA4IM9XzOE/gkeqUhGvo= X-Received: by 127.0.0.2 with SMTP id HqQtYY1788612x13FDqEOXaC; Mon, 20 Nov 2023 18:36:19 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by mx.groups.io with SMTP id smtpd.web11.26388.1700534178224900933 for ; Mon, 20 Nov 2023 18:36:18 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="4868742" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="4868742" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 18:36:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="770098824" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="770098824" X-Received: from shwdeopenlab813.ccr.corp.intel.com ([10.239.55.230]) by fmsmga007.fm.intel.com with ESMTP; 20 Nov 2023 18:36:04 -0800 From: "Yuanhao Xie" To: devel@edk2.groups.io Cc: xieyuanh , Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [Patch V7 2/2] UefiCpuPkg/MpInitLib: Update the comments of _CPU_MP_DATA. Date: Tue, 21 Nov 2023 10:35:46 +0800 Message-Id: <20231121023546.2405-3-yuanhao.xie@intel.com> In-Reply-To: <20231121023546.2405-1-yuanhao.xie@intel.com> References: <20231121023546.2405-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: 9WZ7b8zdJfg5LYkmuN2aXdTCx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1700534180757100005 Content-Type: text/plain; charset="utf-8" No functional changes in this patch. Updates 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. This patch deletes the unnecessary comments in CpuMpData, since CpuMpData is no longer responsible for passing information from PEI to DXE. 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/MpEqu.inc | 2 ++ UefiCpuPkg/Library/MpInitLib/MpLib.h | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpEqu.inc b/UefiCpuPkg/Library/Mp= InitLib/MpEqu.inc index 72af196513..317e627b58 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpEqu.inc +++ b/UefiCpuPkg/Library/MpInitLib/MpEqu.inc @@ -67,6 +67,8 @@ endstruc =20 ; ; Equivalent NASM structure of MP_CPU_EXCHANGE_INFO +; Assembly routines should refrain from directly interacting with +; the internal details of CPU_MP_DATA. ; struc MP_CPU_EXCHANGE_INFO .StackStart: CTYPE_UINTN 1 diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index af296f6ac0..a96a6389c1 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -203,6 +203,8 @@ typedef struct _CPU_MP_DATA CPU_MP_DATA; // MP CPU exchange information for AP reset code // This structure is required to be packed because fixed field offsets // into this structure are used in assembly code in this module +// Assembly routines should refrain from directly interacting with +// the internal details of CPU_MP_DATA. // typedef struct { UINTN StackStart; @@ -239,17 +241,16 @@ 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; UINT32 CpuCount; UINT32 BspNumber; - // - // The above fields data will be passed from PEI to DXE - // Please make sure the fields offset same in the different - // architecture. - // SPIN_LOCK MpLock; UINTN Buffer; UINTN CpuApStackSize; --=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 (#111509): https://edk2.groups.io/g/devel/message/111509 Mute This Topic: https://groups.io/mt/102721681/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-