Changeset 85718 in vbox for trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c
- Timestamp:
- Aug 12, 2020 4:09:12 PM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 139865
- Location:
- trunk/src/VBox/Devices/EFI/FirmwareNew
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/FirmwareNew
-
Property svn:mergeinfo
changed from (toggle deleted branches)
to (toggle deleted branches)/vendor/edk2/current 103735-103757,103769-103776,129194-133213 /vendor/edk2/current 103735-103757,103769-103776,129194-139864
-
Property svn:mergeinfo
changed from (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c
r80721 r85718 16 16 LIST_ENTRY mPagePool = INITIALIZE_LIST_HEAD_VARIABLE (mPagePool); 17 17 BOOLEAN m1GPageTableSupport = FALSE; 18 BOOLEAN mCpuSmm StaticPageTable;19 BOOLEAN m5LevelPaging Support;20 X86_ASSEMBLY_PATCH_LABEL gPatch5LevelPaging Support;18 BOOLEAN mCpuSmmRestrictedMemoryAccess; 19 BOOLEAN m5LevelPagingNeeded; 20 X86_ASSEMBLY_PATCH_LABEL gPatch5LevelPagingNeeded; 21 21 22 22 /** … … 64 64 65 65 /** 66 Check if 5-level paging is supported by processor or not. 67 68 @retval TRUE 5-level paging is supported. 69 @retval FALSE 5-level paging is not supported. 70 66 The routine returns TRUE when CPU supports it (CPUID[7,0].ECX.BIT[16] is set) and 67 the max physical address bits is bigger than 48. Because 4-level paging can support 68 to address physical address up to 2^48 - 1, there is no need to enable 5-level paging 69 with max physical address bits <= 48. 70 71 @retval TRUE 5-level paging enabling is needed. 72 @retval FALSE 5-level paging enabling is not needed. 71 73 **/ 72 74 BOOLEAN 73 Is5LevelPaging Support(75 Is5LevelPagingNeeded ( 74 76 VOID 75 77 ) 76 78 { 77 CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS_ECX EcxFlags; 78 79 CPUID_VIR_PHY_ADDRESS_SIZE_EAX VirPhyAddressSize; 80 CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS_ECX ExtFeatureEcx; 81 UINT32 MaxExtendedFunctionId; 82 83 AsmCpuid (CPUID_EXTENDED_FUNCTION, &MaxExtendedFunctionId, NULL, NULL, NULL); 84 if (MaxExtendedFunctionId >= CPUID_VIR_PHY_ADDRESS_SIZE) { 85 AsmCpuid (CPUID_VIR_PHY_ADDRESS_SIZE, &VirPhyAddressSize.Uint32, NULL, NULL, NULL); 86 } else { 87 VirPhyAddressSize.Bits.PhysicalAddressBits = 36; 88 } 79 89 AsmCpuidEx ( 80 90 CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS, 81 91 CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS_SUB_LEAF_INFO, 82 NULL, 83 NULL, 84 &EcxFlags.Uint32, 85 NULL 92 NULL, NULL, &ExtFeatureEcx.Uint32, NULL 86 93 ); 87 return (BOOLEAN) (EcxFlags.Bits.FiveLevelPage != 0); 94 DEBUG (( 95 DEBUG_INFO, "PhysicalAddressBits = %d, 5LPageTable = %d.\n", 96 VirPhyAddressSize.Bits.PhysicalAddressBits, ExtFeatureEcx.Bits.FiveLevelPage 97 )); 98 99 if (VirPhyAddressSize.Bits.PhysicalAddressBits > 4 * 9 + 12) { 100 ASSERT (ExtFeatureEcx.Bits.FiveLevelPage == 1); 101 return TRUE; 102 } else { 103 return FALSE; 104 } 88 105 } 89 106 … … 191 208 // 192 209 ASSERT (mPhysicalAddressBits <= 52); 193 if (!m5LevelPaging Support&& mPhysicalAddressBits > 48) {210 if (!m5LevelPagingNeeded && mPhysicalAddressBits > 48) { 194 211 mPhysicalAddressBits = 48; 195 212 } … … 218 235 PageMapLevel4Entry = PageMap; 219 236 PageMapLevel5Entry = NULL; 220 if (m5LevelPaging Support) {237 if (m5LevelPagingNeeded) { 221 238 // 222 239 // By architecture only one PageMapLevel5 exists - so lets allocate storage for it. … … 234 251 // When 5-Level Paging is disabled, below allocation happens only once. 235 252 // 236 if (m5LevelPaging Support) {253 if (m5LevelPagingNeeded) { 237 254 PageMapLevel4Entry = (UINT64 *) ((*PageMapLevel5Entry) & ~mAddressEncMask & gPhyMask); 238 255 if (PageMapLevel4Entry == NULL) { … … 335 352 InitializeSpinLock (mPFLock); 336 353 337 mCpuSmm StaticPageTable = PcdGetBool (PcdCpuSmmStaticPageTable);338 m1GPageTableSupport = Is1GPageSupport ();339 m5LevelPaging Support = Is5LevelPagingSupport();340 mPhysicalAddressBits = CalculateMaximumSupportAddress ();341 PatchInstructionX86 (gPatch5LevelPaging Support, m5LevelPagingSupport, 1);342 DEBUG ((DEBUG_INFO, "5LevelPaging Support - %d\n", m5LevelPagingSupport));343 DEBUG ((DEBUG_INFO, "1GPageTable Support - %d\n", m1GPageTableSupport));344 DEBUG ((DEBUG_INFO, "PcdCpuSmm StaticPageTable - %d\n", mCpuSmmStaticPageTable));345 DEBUG ((DEBUG_INFO, "PhysicalAddressBits - %d\n", mPhysicalAddressBits));354 mCpuSmmRestrictedMemoryAccess = PcdGetBool (PcdCpuSmmRestrictedMemoryAccess); 355 m1GPageTableSupport = Is1GPageSupport (); 356 m5LevelPagingNeeded = Is5LevelPagingNeeded (); 357 mPhysicalAddressBits = CalculateMaximumSupportAddress (); 358 PatchInstructionX86 (gPatch5LevelPagingNeeded, m5LevelPagingNeeded, 1); 359 DEBUG ((DEBUG_INFO, "5LevelPaging Needed - %d\n", m5LevelPagingNeeded)); 360 DEBUG ((DEBUG_INFO, "1GPageTable Support - %d\n", m1GPageTableSupport)); 361 DEBUG ((DEBUG_INFO, "PcdCpuSmmRestrictedMemoryAccess - %d\n", mCpuSmmRestrictedMemoryAccess)); 362 DEBUG ((DEBUG_INFO, "PhysicalAddressBits - %d\n", mPhysicalAddressBits)); 346 363 // 347 364 // Generate PAE page table for the first 4GB memory space … … 371 388 PTEntry = Pml4Entry; 372 389 373 if (m5LevelPaging Support) {390 if (m5LevelPagingNeeded) { 374 391 // 375 392 // Fill PML5 entry … … 386 403 } 387 404 388 if (mCpuSmmStaticPageTable) { 405 if (mCpuSmmRestrictedMemoryAccess) { 406 // 407 // When access to non-SMRAM memory is restricted, create page table 408 // that covers all memory space. 409 // 389 410 SetStaticPageTable ((UINTN)PTEntry); 390 411 } else { … … 973 994 PFAddress = AsmReadCr2 (); 974 995 975 if (mCpuSmm StaticPageTable&& (PFAddress >= LShiftU64 (1, (mPhysicalAddressBits - 1)))) {996 if (mCpuSmmRestrictedMemoryAccess && (PFAddress >= LShiftU64 (1, (mPhysicalAddressBits - 1)))) { 976 997 DumpCpuContext (InterruptType, SystemContext); 977 998 DEBUG ((DEBUG_ERROR, "Do not support address 0x%lx by processor!\n", PFAddress)); … … 1050 1071 } 1051 1072 1052 if (mCpuSmm StaticPageTable&& IsSmmCommBufferForbiddenAddress (PFAddress)) {1073 if (mCpuSmmRestrictedMemoryAccess && IsSmmCommBufferForbiddenAddress (PFAddress)) { 1053 1074 DumpCpuContext (InterruptType, SystemContext); 1054 1075 DEBUG ((DEBUG_ERROR, "Access SMM communication forbidden address (0x%lx)!\n", PFAddress)); … … 1101 1122 1102 1123 // 1103 // Don't do thisif1104 // - no static page table; or1124 // Don't mark page table memory as read-only if 1125 // - no restriction on access to non-SMRAM memory; or 1105 1126 // - SMM heap guard feature enabled; or 1106 1127 // BIT2: SMM page guard enabled … … 1108 1129 // - SMM profile feature enabled 1109 1130 // 1110 if (!mCpuSmm StaticPageTable||1131 if (!mCpuSmmRestrictedMemoryAccess || 1111 1132 ((PcdGet8 (PcdHeapGuardPropertyMask) & (BIT3 | BIT2)) != 0) || 1112 1133 FeaturePcdGet (PcdCpuSmmProfileEnable)) { 1113 1134 // 1114 // Static pagingand heap guard could not be enabled at the same time.1115 // 1116 ASSERT (!(mCpuSmm StaticPageTable&&1135 // Restriction on access to non-SMRAM memory and heap guard could not be enabled at the same time. 1136 // 1137 ASSERT (!(mCpuSmmRestrictedMemoryAccess && 1117 1138 (PcdGet8 (PcdHeapGuardPropertyMask) & (BIT3 | BIT2)) != 0)); 1118 1139 1119 1140 // 1120 // Static pagingand SMM profile could not be enabled at the same time.1121 // 1122 ASSERT (!(mCpuSmm StaticPageTable&& FeaturePcdGet (PcdCpuSmmProfileEnable)));1141 // Restriction on access to non-SMRAM memory and SMM profile could not be enabled at the same time. 1142 // 1143 ASSERT (!(mCpuSmmRestrictedMemoryAccess && FeaturePcdGet (PcdCpuSmmProfileEnable))); 1123 1144 return ; 1124 1145 } … … 1224 1245 ) 1225 1246 { 1226 if (!mCpuSmmStaticPageTable) { 1247 if (!mCpuSmmRestrictedMemoryAccess) { 1248 // 1249 // On-demand paging is enabled when access to non-SMRAM is not restricted. 1250 // 1227 1251 *Cr2 = AsmReadCr2 (); 1228 1252 } … … 1239 1263 ) 1240 1264 { 1241 if (!mCpuSmmStaticPageTable) { 1265 if (!mCpuSmmRestrictedMemoryAccess) { 1266 // 1267 // On-demand paging is enabled when access to non-SMRAM is not restricted. 1268 // 1242 1269 AsmWriteCr2 (Cr2); 1243 1270 } 1244 1271 } 1272 1273 /** 1274 Return whether access to non-SMRAM is restricted. 1275 1276 @retval TRUE Access to non-SMRAM is restricted. 1277 @retval FALSE Access to non-SMRAM is not restricted. 1278 **/ 1279 BOOLEAN 1280 IsRestrictedMemoryAccess ( 1281 VOID 1282 ) 1283 { 1284 return mCpuSmmRestrictedMemoryAccess; 1285 }
Note:
See TracChangeset
for help on using the changeset viewer.