From b3631ca944bda812f51db3f833f18d82d8e0e761 Mon Sep 17 00:00:00 2001 From: Dun Tan Date: Thu, 25 Jul 2024 13:58:38 +0800 Subject: [PATCH] UefiCpuPkg: remove unnecessary manipulation for smm page table In this commit, we only set some special bits in paging entry content when SMM profile is enabled. Previously, we set Pml4Entry sub-entries number and set the IA32_PG_PMNT bit for first 4 PdptEntry. It's to make sure that the paging structures cover [0, 4G] won't be reclaimed during dynamic page table creation. In last commit, we always create full mapping SMM page table regardless PcdCpuSmmRestrictedMemoryAccess. With this change, we only need to dynamic create SMM page table in smm PF handler when PcdCpuSmmProfileEnable is TRUE. So the sub-entries number and IA32_PG_PMNT bit in paging entry is only needed to set when PcdCpuSmmProfileEnable is TRUE. Signed-off-by: Dun Tan --- UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c | 36 ++++++++++++------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c index 14b0b1981b..a7b02981dc 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c @@ -228,26 +228,26 @@ SmmInitPageTable ( // PageTable = GenSmmPageTable (mPagingMode, mPhysicalAddressBits); - if (m5LevelPagingNeeded) { - Pml5Entry = (UINT64 *)PageTable; - // - // Set Pml5Entry sub-entries number for smm PF handler usage. - // - SetSubEntriesNum (Pml5Entry, 1); - Pml4Entry = (UINT64 *)((*Pml5Entry) & ~mAddressEncMask & gPhyMask); - } else { - Pml4Entry = (UINT64 *)PageTable; - } + if (FeaturePcdGet (PcdCpuSmmProfileEnable)) { + if (m5LevelPagingNeeded) { + Pml5Entry = (UINT64 *)PageTable; + // + // Set Pml5Entry sub-entries number for smm PF handler usage. + // + SetSubEntriesNum (Pml5Entry, 1); + Pml4Entry = (UINT64 *)((*Pml5Entry) & ~mAddressEncMask & gPhyMask); + } else { + Pml4Entry = (UINT64 *)PageTable; + } - // - // Set IA32_PG_PMNT bit to mask first 4 PdptEntry. - // - PdptEntry = (UINT64 *)((*Pml4Entry) & ~mAddressEncMask & gPhyMask); - for (Index = 0; Index < 4; Index++) { - PdptEntry[Index] |= IA32_PG_PMNT; - } + // + // Set IA32_PG_PMNT bit to mask first 4 PdptEntry. + // + PdptEntry = (UINT64 *)((*Pml4Entry) & ~mAddressEncMask & gPhyMask); + for (Index = 0; Index < 4; Index++) { + PdptEntry[Index] |= IA32_PG_PMNT; + } - if (!mCpuSmmRestrictedMemoryAccess) { // // Set Pml4Entry sub-entries number for smm PF handler usage. //