With following paging structure to map [2M-4K, 2M] as P = 1, RW = 0, [2M, 4M] as P = 1, RW = 1:
PML4[0] -> PDPTE[0] -> PDE[0](RW = 0) -> PTE[255](P = 0, RW = 0) -> PDE[1](RW = 1) When a new request to map [2M-4K, 2M+4K] as P = 1, RW = 1, CpuPageTableMap() wrongly requests 4K buffer size for the new mapping request. But in fact, for [2M-4K, 2M] request, PTE[255] can be changed in place, for [2M, 2M+4K], no change is needed because PDE[1].RW = 1 already. The change fixes the bug. Signed-off-by: Ray Ni <ray...@intel.com> Signed-off-by: Zhiguang Liu <zhiguang....@intel.com> Cc: Eric Dong <eric.d...@intel.com> --- .../Library/CpuPageTableLib/CpuPageTableMap.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c index 1205119fc8..16e6697ed4 100644 --- a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c +++ b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c @@ -272,6 +272,7 @@ PageTableLibMapInLevel ( IA32_MAP_ATTRIBUTE ChildAttribute; IA32_MAP_ATTRIBUTE ChildMask; IA32_MAP_ATTRIBUTE CurrentMask; + IA32_MAP_ATTRIBUTE LocalParentAttribute; ASSERT (Level != 0); ASSERT ((Attribute != NULL) && (Mask != NULL)); @@ -284,6 +285,9 @@ PageTableLibMapInLevel ( NopAttribute.Bits.ReadWrite = 1; NopAttribute.Bits.UserSupervisor = 1; + LocalParentAttribute.Uint64 = ParentAttribute->Uint64; + ParentAttribute = &LocalParentAttribute; + // // ParentPagingEntry ONLY is deferenced for checking Present and MustBeOne bits // when Modify is FALSE. @@ -420,7 +424,7 @@ PageTableLibMapInLevel ( } if (IsPle (&PagingEntry[Index], Level)) { - PageTableLibSetPle (Level - 1, &PagingEntry[Index], 0, &ChildAttribute, &ChildMask); + PageTableLibSetPle (Level, &PagingEntry[Index], 0, &ChildAttribute, &ChildMask); } else { PageTableLibSetPnle (&PagingEntry[Index].Pnle, &ChildAttribute, &ChildMask); } @@ -664,13 +668,6 @@ PageTableMap ( // // Update the page table when the supplied buffer is sufficient. // - ParentAttribute.Uint64 = 0; - ParentAttribute.Bits.PageTableBaseAddress = 1; - ParentAttribute.Bits.Present = 1; - ParentAttribute.Bits.ReadWrite = 1; - ParentAttribute.Bits.UserSupervisor = 1; - ParentAttribute.Bits.Nx = 0; - Status = PageTableLibMapInLevel ( &TopPagingEntry, &ParentAttribute, -- 2.35.1.windows.2 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#91458): https://edk2.groups.io/g/devel/message/91458 Mute This Topic: https://groups.io/mt/92458167/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-