diff --git a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c index bdc411338f9..72989667130 100644 --- a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c +++ b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c @@ -390,6 +390,17 @@ PageTableLibMapInLevel ( if (RETURN_ERROR (Status)) { return Status; } + + OneOfPagingEntry.Pnle.Uint64 = 0; + // MU_CHANGE Start - Populate base address bits for non present pages + // TODO: Author unit test to verify the split pages meet expected attribute bits. + if ((Level != 1) && (Level != 2) && (Level != 3)) { + PageTableLibSetPnle (&OneOfPagingEntry.Pnle, &PleBAttribute, &AllOneMask); + } else { + PageTableLibSetPle (Level, &OneOfPagingEntry, 0, &PleBAttribute, &AllOneMask); + } + + // MU_CHANGE End - Populate base address bits for non present pages } else { PageTableLibSetPle (Level, &OneOfPagingEntry, 0, &PleBAttribute, &AllOneMask); } @@ -426,16 +437,17 @@ PageTableLibMapInLevel ( PagingEntry = (IA32_PAGING_ENTRY *)((UINTN)Buffer + *BufferSize); ZeroMem (PagingEntry, SIZE_4KB); - if (ParentPagingEntry->Pce.Present) { - // - // Create 512 child-level entries that map to 2M/4K. - // - for (SubOffset = 0, Index = 0; Index < 512; Index++) { - PagingEntry[Index].Uint64 = OneOfPagingEntry.Uint64 + SubOffset; - SubOffset += RegionLength; - } + // MU_CHANGE Start - Populate contents for both present and non-present pages + // + // Create 512 child-level entries that map to 2M/4K. + // + for (SubOffset = 0, Index = 0; Index < 512; Index++) { + PagingEntry[Index].Uint64 = OneOfPagingEntry.Uint64 + SubOffset; + SubOffset += RegionLength; } + // MU_CHANGE End - Populate contents for both present and non-present pages + // // Set NOP attributes // Note: Should NOT inherit the attributes from the original entry because a zero RW bit @@ -519,9 +531,11 @@ PageTableLibMapInLevel ( // e.g.: Set PDE[0-255].ReadWrite = 0 // for (Index = 0; Index < 512; Index++) { - if (PagingEntry[Index].Pce.Present == 0) { - continue; - } + // MU_CHANGE Start - Count the space for non-present pages as well. + // if (PagingEntry[Index].Pce.Present == 0) { + // continue; + // } + // MU_CHANGE End - Count the space for non-present pages as well. if (IsPle (&PagingEntry[Index], Level)) { PageTableLibSetPle (Level, &PagingEntry[Index], 0, &ChildAttribute, &ChildMask);