Skip to content

Commit

Permalink
UefiCpuPkg CpuPageTableMap: Fixing page table handling for non-presen…
Browse files Browse the repository at this point in the history
…t pages.

This change will add logic to populate the address and propagate bits
for the non-present pages.

Without this change, the issue can be seen as when a smaller page is
marked present from a big non-present page, the remainder of the
non-present pages will return `EFI_UNSUPPORTED` when using get
attributes function though protocols like CPU arch.
  • Loading branch information
kuqin12 authored and apop5 committed Aug 1, 2024
1 parent 433da20 commit c7f6228
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,16 @@ PageTableLibMapInLevel (
if (RETURN_ERROR (Status)) {
return Status;
}

// MU_CHANGE Start - Populate base address bits for non present pages
OneOfPagingEntry.Pnle.Uint64 = 0;
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);
}
Expand Down Expand Up @@ -426,16 +436,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
Expand Down Expand Up @@ -519,9 +530,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);
Expand Down

0 comments on commit c7f6228

Please sign in to comment.