Reviewed-by: Ray Ni <[email protected]> Thanks, Ray > -----Original Message----- > From: Tan, Dun <[email protected]> > Sent: Wednesday, January 10, 2024 4:06 PM > To: [email protected] > Cc: Ni, Ray <[email protected]>; Laszlo Ersek <[email protected]>; Kumar, > Rahul R <[email protected]>; Gerd Hoffmann <[email protected]> > Subject: [PATCH] UefiCpuPkg:Limit PhysicalAddressBits in speicial case > > When creating smm page table, limit maximum > supported physical address bits returned by > CalculateMaximumSupportAddress() to 48 if > 5-Level Paging is disabled. > When 5-Level Paging is disabled and the > PhysicalAddressBits retrived from CPU HOB or > CpuId is bigger than 48, only [0, 2^48 -1] > range in 52-bit physical address is mapped > in page table. > > Signed-off-by: Dun Tan <[email protected]> > Cc: Ray Ni <[email protected]> > Cc: Laszlo Ersek <[email protected]> > Cc: Rahul Kumar <[email protected]> > Cc: Gerd Hoffmann <[email protected]> > --- > UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c | 15 +++++++++++++-- > 1 file changed, 13 insertions(+), 2 deletions(-) > > diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c > b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c > index ddd9be66b5..e6f174ca10 100644 > --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c > +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c > @@ -137,11 +137,13 @@ GetSubEntriesNum ( > /** > Calculate the maximum support address. > > + @param[in] Is5LevelPagingNeeded If 5-level paging enabling is needed. > + > @return the maximum support address. > **/ > UINT8 > CalculateMaximumSupportAddress ( > - VOID > + BOOLEAN Is5LevelPagingNeeded > ) > { > UINT32 RegEax; > @@ -164,6 +166,15 @@ CalculateMaximumSupportAddress ( > } > } > > + // > + // Only [0, 2^48 -1] in 52-bit physical addresses is mapped in page table > + // when 5-Level Paging is disabled. > + // > + ASSERT (PhysicalAddressBits <= 52); > + if (!Is5LevelPagingNeeded && (PhysicalAddressBits > 48)) { > + PhysicalAddressBits = 48; > + } > + > return PhysicalAddressBits; > } > > @@ -197,7 +208,7 @@ SmmInitPageTable ( > mCpuSmmRestrictedMemoryAccess = PcdGetBool > (PcdCpuSmmRestrictedMemoryAccess); > m1GPageTableSupport = Is1GPageSupport (); > m5LevelPagingNeeded = Is5LevelPagingNeeded (); > - mPhysicalAddressBits = CalculateMaximumSupportAddress (); > + mPhysicalAddressBits = CalculateMaximumSupportAddress > (m5LevelPagingNeeded); > PatchInstructionX86 (gPatch5LevelPagingNeeded, m5LevelPagingNeeded, > 1); > if (m5LevelPagingNeeded) { > mPagingMode = m1GPageTableSupport ? Paging5Level1GB : Paging5Level; > -- > 2.31.1.windows.1
-=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#113519): https://edk2.groups.io/g/devel/message/113519 Mute This Topic: https://groups.io/mt/103637402/21656 Group Owner: [email protected] Unsubscribe: https://edk2.groups.io/g/devel/leave/9847357/21656/1706620634/xyzzy [[email protected]] -=-=-=-=-=-=-=-=-=-=-=-
