From nobody Sun Feb 8 14:35:28 2026 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+108166+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+108166+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1693437553; cv=none; d=zohomail.com; s=zohoarc; b=n8kOXV3e0J3GNP12lic0aGV9d49H/98gUZf5qtPDtdMCK1jUgj1uROWVjgrb08QklX+mZ/LVU9pF2+/k+hamxPNc+Yf0s9X/L6E0XgMVeEKpfsxmJ6DXeraXg1qHygSpoHTaFVBxrIJTYR81zOlTVlg7brm+N2xufOxYsjU8aHE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693437553; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=ufs2sFicpo4dhXwBPG0uReY2KRQiuz1cVg8zcJmmWfE=; b=Ny6l4PeNz5BLQJGPjH7wYvGxWdNjEv0L8ec06NABxe+H0WD1tjkbKn+ZTlk2/ptBFklW6t2IhZ4B1J/D66gUEGOqO7n0qK1iw1rb+Y3k56mxuHoYVOTc5sj7WvHkHpwucTjsIQ6f4MbKcRcV5SYCTovqRXk6sa3/2pXZWGsvFoY= 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+108166+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 1693437553100799.5035979078291; Wed, 30 Aug 2023 16:19:13 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=wmLRqBrWJtH65GdbaXgdP2AjEbZ5c9vv+jMW55kgmSs=; 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=1693437552; v=1; b=rKjtEU5m8sUN49SP2jlotnkb+IoTG/oSLnQYCKKNgjgXQ12ZAmdcF6MsE3dc7LM06QowbIBL GtqlaWWDnpBuigDFt81+5DN9U1E0caPotlf5ek1j0o6cpt2G9izbrT4B/F7QhvxmkA7IRpQ1/Ur PN1czIt8Wx4KH4VcszVXH4Nc= X-Received: by 127.0.0.2 with SMTP id 7t90YY1788612xAkPMDD7uv4; Wed, 30 Aug 2023 16:19:12 -0700 X-Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by mx.groups.io with SMTP id smtpd.web10.4866.1693437552256788388 for ; Wed, 30 Aug 2023 16:19:12 -0700 X-Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-68bec3a9bdbso137070b3a.3 for ; Wed, 30 Aug 2023 16:19:12 -0700 (PDT) X-Gm-Message-State: a2fKBvkRbyGj1dSOsfhW17q9x1787277AA= X-Google-Smtp-Source: AGHT+IGHvvQJw9iuSx1k6XObgNf+wIdvGu9AqYf8pt0vuaKU0FBLvTvGlA7xpFHkxghGLUE4Pt6Jbg== X-Received: by 2002:a05:6a00:1a8f:b0:68b:dbbc:dcea with SMTP id e15-20020a056a001a8f00b0068bdbbcdceamr3485909pfv.9.1693437551492; Wed, 30 Aug 2023 16:19:11 -0700 (PDT) X-Received: from localhost.localdomain ([50.46.253.1]) by smtp.gmail.com with ESMTPSA id x16-20020a62fb10000000b0064398fe3451sm102550pfm.217.2023.08.30.16.19.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 16:19:11 -0700 (PDT) From: "Taylor Beebe" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann Subject: [edk2-devel] [PATCH v3 12/26] OvmfPkg: Update PeilessStartupLib to use SetMemoryProtectionsLib Date: Wed, 30 Aug 2023 16:18:20 -0700 Message-ID: <20230830231851.779-13-taylor.d.beebe@gmail.com> In-Reply-To: <20230830231851.779-1-taylor.d.beebe@gmail.com> References: <20230830231851.779-1-taylor.d.beebe@gmail.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,taylor.d.beebe@gmail.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1693437554952100050 Content-Type: text/plain; charset="utf-8" This patch updates the DXE Handoff in PEI-less Startup to use SetMemoryProtectionsLib to get the platform memory protection settings and build the page tables based on the applied protections. Signed-off-by: Taylor Beebe Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann --- OvmfPkg/Library/PeilessStartupLib/DxeLoad.c | 6 +++++- OvmfPkg/Library/PeilessStartupLib/X64/VirtualMemory.c | 13 ++++++++----- OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf | 4 ---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/OvmfPkg/Library/PeilessStartupLib/DxeLoad.c b/OvmfPkg/Library/= PeilessStartupLib/DxeLoad.c index d34690eb8a0b..f8ff53876369 100644 --- a/OvmfPkg/Library/PeilessStartupLib/DxeLoad.c +++ b/OvmfPkg/Library/PeilessStartupLib/DxeLoad.c @@ -20,9 +20,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include "X64/PageTables.h" #include +#include =20 #define STACK_SIZE 0x20000 -extern EFI_GUID gEfiNonCcFvGuid; +extern EFI_GUID gEfiNonCcFvGuid; +MEMORY_PROTECTION_SETTINGS mMps =3D { 0 }; =20 /** Transfers control to DxeCore. @@ -42,6 +44,8 @@ HandOffToDxeCore ( VOID *TopOfStack; UINTN PageTables; =20 + GetCurrentMemoryProtectionSettings (&mMps); + // // Clear page 0 and mark it as allocated if NULL pointer detection is en= abled. // diff --git a/OvmfPkg/Library/PeilessStartupLib/X64/VirtualMemory.c b/OvmfPk= g/Library/PeilessStartupLib/X64/VirtualMemory.c index e2c1bac5e059..41521e3d3d71 100644 --- a/OvmfPkg/Library/PeilessStartupLib/X64/VirtualMemory.c +++ b/OvmfPkg/Library/PeilessStartupLib/X64/VirtualMemory.c @@ -17,6 +17,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include #include #include #include "PageTables.h" @@ -45,6 +46,8 @@ UINT64 mLevelSize[5] =3D { SIZE_512GB }; =20 +extern MEMORY_PROTECTION_SETTINGS mMps; + BOOLEAN IsSetNxForStack ( VOID @@ -142,7 +145,7 @@ IsNullDetectionEnabled ( VOID ) { - return ((PcdGet8 (PcdNullPointerDetectionPropertyMask) & BIT0) !=3D 0); + return mMps.Dxe.NullPointerDetection.Enabled; } =20 /** @@ -197,8 +200,8 @@ IsEnableNonExecNeeded ( // Features controlled by Following PCDs need this feature to be enabled. // return (IsSetNxForStack () || - FixedPcdGet64 (PcdDxeNxMemoryProtectionPolicy) !=3D 0 || - PcdGet32 (PcdImageProtectionPolicy) !=3D 0); + !IsZeroBuffer (&mMps.Dxe.ExecutionProtection.EnabledForType, MPS= _MEMORY_TYPE_BUFFER_SIZE) || + (mMps.Dxe.ImageProtection.ProtectImageFromFv || mMps.Dxe.ImagePr= otection.ProtectImageFromUnknown)); } =20 /** @@ -241,7 +244,7 @@ ToSplitPageTable ( return TRUE; } =20 - if (FixedPcdGetBool (PcdCpuStackGuard)) { + if (mMps.Dxe.CpuStackGuardEnabled) { if ((StackBase >=3D Address) && (StackBase < (Address + Size))) { return TRUE; } @@ -427,7 +430,7 @@ Split2MPageTo4K ( PageTableEntry->Bits.ReadWrite =3D 1; =20 if ((IsNullDetectionEnabled () && (PhysicalAddress4K =3D=3D 0)) || - (FixedPcdGetBool (PcdCpuStackGuard) && (PhysicalAddress4K =3D=3D S= tackBase))) + (mMps.Dxe.CpuStackGuardEnabled && (PhysicalAddress4K =3D=3D StackB= ase))) { PageTableEntry->Bits.Present =3D 0; } else { diff --git a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf b/Ovmf= Pkg/Library/PeilessStartupLib/PeilessStartupLib.inf index f0a8a5a56df4..47bd42d23d11 100644 --- a/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf +++ b/OvmfPkg/Library/PeilessStartupLib/PeilessStartupLib.inf @@ -77,12 +77,8 @@ [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplBuildPageTables ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable ## SOMETIM= ES_CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdDxeNxMemoryProtectionPolicy ## SOMETIM= ES_CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdImageProtectionPolicy ## SOMETIM= ES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask ##= CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdNullPointerDetectionPropertyMask ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ##= CONSUMES gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvSize --=20 2.42.0.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 (#108166): https://edk2.groups.io/g/devel/message/108166 Mute This Topic: https://groups.io/mt/101064084/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-