X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=UefiCpuPkg%2FPiSmmCpuDxeSmm%2FSmmCpuMemoryManagement.c;h=9c5a92af6479d54e913bdd285cef01eb15875b45;hb=ef62da4ff742a0b9f4b718ccc2a03f5497115c9f;hp=069be3aaa5a5ed529593cf652b53e5f07092f1a2;hpb=0acd869796ded1266e69487dff717cd69d6031f9;p=mirror_edk2.git diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c index 069be3aaa5..9c5a92af64 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c @@ -125,18 +125,36 @@ GetPageTableEntry ( UINTN Index2; UINTN Index3; UINTN Index4; + UINTN Index5; UINT64 *L1PageTable; UINT64 *L2PageTable; UINT64 *L3PageTable; UINT64 *L4PageTable; + UINT64 *L5PageTable; + IA32_CR4 Cr4; + BOOLEAN Enable5LevelPaging; + Index5 = ((UINTN)RShiftU64 (Address, 48)) & PAGING_PAE_INDEX_MASK; Index4 = ((UINTN)RShiftU64 (Address, 39)) & PAGING_PAE_INDEX_MASK; Index3 = ((UINTN)Address >> 30) & PAGING_PAE_INDEX_MASK; Index2 = ((UINTN)Address >> 21) & PAGING_PAE_INDEX_MASK; Index1 = ((UINTN)Address >> 12) & PAGING_PAE_INDEX_MASK; + Cr4.UintN = AsmReadCr4 (); + Enable5LevelPaging = (BOOLEAN) (Cr4.Bits.LA57 == 1); + if (sizeof(UINTN) == sizeof(UINT64)) { - L4PageTable = (UINT64 *)GetPageTableBase (); + if (Enable5LevelPaging) { + L5PageTable = (UINT64 *)GetPageTableBase (); + if (L5PageTable[Index5] == 0) { + *PageAttribute = PageNone; + return NULL; + } + + L4PageTable = (UINT64 *)(UINTN)(L5PageTable[Index5] & ~mAddressEncMask & PAGING_4K_ADDRESS_MASK_64); + } else { + L4PageTable = (UINT64 *)GetPageTableBase (); + } if (L4PageTable[Index4] == 0) { *PageAttribute = PageNone; return NULL; @@ -447,7 +465,7 @@ ConvertMemoryPageAttributes ( } // - // Below logic is to check 2M/4K page to make sure we donot waist memory. + // Below logic is to check 2M/4K page to make sure we do not waste memory. // while (Length != 0) { PageEntry = GetPageTableEntry (BaseAddress, &PageAttribute); @@ -1047,7 +1065,7 @@ IsUefiPageNotPresent ( } /** - Merge continous memory map entries whose type is + Merge continuous memory map entries whose type is EfiLoaderCode/Data, EfiBootServicesCode/Data, EfiConventionalMemory, EfiUnusableMemory, EfiACPIReclaimMemory, because the memory described by these entries will be set as NOT present in SMM page table.