VirtualBox

Ignore:
Timestamp:
Aug 12, 2020 4:09:12 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
139865
Message:

Devices/EFI: Merge edk-stable202005 and make it build, bugref:4643

Location:
trunk/src/VBox/Devices/EFI/FirmwareNew
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/FirmwareNew

  • trunk/src/VBox/Devices/EFI/FirmwareNew/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c

    r80721 r85718  
    1616LIST_ENTRY                          mPagePool = INITIALIZE_LIST_HEAD_VARIABLE (mPagePool);
    1717BOOLEAN                             m1GPageTableSupport = FALSE;
    18 BOOLEAN                             mCpuSmmStaticPageTable;
    19 BOOLEAN                             m5LevelPagingSupport;
    20 X86_ASSEMBLY_PATCH_LABEL            gPatch5LevelPagingSupport;
     18BOOLEAN                             mCpuSmmRestrictedMemoryAccess;
     19BOOLEAN                             m5LevelPagingNeeded;
     20X86_ASSEMBLY_PATCH_LABEL            gPatch5LevelPagingNeeded;
    2121
    2222/**
     
    6464
    6565/**
    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.
    7173**/
    7274BOOLEAN
    73 Is5LevelPagingSupport (
     75Is5LevelPagingNeeded (
    7476  VOID
    7577  )
    7678{
    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  }
    7989  AsmCpuidEx (
    8090    CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS,
    8191    CPUID_STRUCTURED_EXTENDED_FEATURE_FLAGS_SUB_LEAF_INFO,
    82     NULL,
    83     NULL,
    84     &EcxFlags.Uint32,
    85     NULL
     92    NULL, NULL, &ExtFeatureEcx.Uint32, NULL
    8693    );
    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  }
    88105}
    89106
     
    191208  //
    192209  ASSERT (mPhysicalAddressBits <= 52);
    193   if (!m5LevelPagingSupport && mPhysicalAddressBits > 48) {
     210  if (!m5LevelPagingNeeded && mPhysicalAddressBits > 48) {
    194211    mPhysicalAddressBits = 48;
    195212  }
     
    218235  PageMapLevel4Entry = PageMap;
    219236  PageMapLevel5Entry = NULL;
    220   if (m5LevelPagingSupport) {
     237  if (m5LevelPagingNeeded) {
    221238    //
    222239    // By architecture only one PageMapLevel5 exists - so lets allocate storage for it.
     
    234251    // When 5-Level Paging is disabled, below allocation happens only once.
    235252    //
    236     if (m5LevelPagingSupport) {
     253    if (m5LevelPagingNeeded) {
    237254      PageMapLevel4Entry = (UINT64 *) ((*PageMapLevel5Entry) & ~mAddressEncMask & gPhyMask);
    238255      if (PageMapLevel4Entry == NULL) {
     
    335352  InitializeSpinLock (mPFLock);
    336353
    337   mCpuSmmStaticPageTable = PcdGetBool (PcdCpuSmmStaticPageTable);
    338   m1GPageTableSupport    = Is1GPageSupport ();
    339   m5LevelPagingSupport   = Is5LevelPagingSupport ();
    340   mPhysicalAddressBits   = CalculateMaximumSupportAddress ();
    341   PatchInstructionX86 (gPatch5LevelPagingSupport, m5LevelPagingSupport, 1);
    342   DEBUG ((DEBUG_INFO, "5LevelPaging Support     - %d\n", m5LevelPagingSupport));
    343   DEBUG ((DEBUG_INFO, "1GPageTable Support      - %d\n", m1GPageTableSupport));
    344   DEBUG ((DEBUG_INFO, "PcdCpuSmmStaticPageTable - %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));
    346363  //
    347364  // Generate PAE page table for the first 4GB memory space
     
    371388  PTEntry = Pml4Entry;
    372389
    373   if (m5LevelPagingSupport) {
     390  if (m5LevelPagingNeeded) {
    374391    //
    375392    // Fill PML5 entry
     
    386403  }
    387404
    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    //
    389410    SetStaticPageTable ((UINTN)PTEntry);
    390411  } else {
     
    973994  PFAddress = AsmReadCr2 ();
    974995
    975   if (mCpuSmmStaticPageTable && (PFAddress >= LShiftU64 (1, (mPhysicalAddressBits - 1)))) {
     996  if (mCpuSmmRestrictedMemoryAccess && (PFAddress >= LShiftU64 (1, (mPhysicalAddressBits - 1)))) {
    976997    DumpCpuContext (InterruptType, SystemContext);
    977998    DEBUG ((DEBUG_ERROR, "Do not support address 0x%lx by processor!\n", PFAddress));
     
    10501071    }
    10511072
    1052     if (mCpuSmmStaticPageTable && IsSmmCommBufferForbiddenAddress (PFAddress)) {
     1073    if (mCpuSmmRestrictedMemoryAccess && IsSmmCommBufferForbiddenAddress (PFAddress)) {
    10531074      DumpCpuContext (InterruptType, SystemContext);
    10541075      DEBUG ((DEBUG_ERROR, "Access SMM communication forbidden address (0x%lx)!\n", PFAddress));
     
    11011122
    11021123  //
    1103   // Don't do this if
    1104   //  - no static page table; or
     1124  // Don't mark page table memory as read-only if
     1125  //  - no restriction on access to non-SMRAM memory; or
    11051126  //  - SMM heap guard feature enabled; or
    11061127  //      BIT2: SMM page guard enabled
     
    11081129  //  - SMM profile feature enabled
    11091130  //
    1110   if (!mCpuSmmStaticPageTable ||
     1131  if (!mCpuSmmRestrictedMemoryAccess ||
    11111132      ((PcdGet8 (PcdHeapGuardPropertyMask) & (BIT3 | BIT2)) != 0) ||
    11121133      FeaturePcdGet (PcdCpuSmmProfileEnable)) {
    11131134    //
    1114     // Static paging and heap guard could not be enabled at the same time.
    1115     //
    1116     ASSERT (!(mCpuSmmStaticPageTable &&
     1135    // Restriction on access to non-SMRAM memory and heap guard could not be enabled at the same time.
     1136    //
     1137    ASSERT (!(mCpuSmmRestrictedMemoryAccess &&
    11171138              (PcdGet8 (PcdHeapGuardPropertyMask) & (BIT3 | BIT2)) != 0));
    11181139
    11191140    //
    1120     // Static paging and SMM profile could not be enabled at the same time.
    1121     //
    1122     ASSERT (!(mCpuSmmStaticPageTable && 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)));
    11231144    return ;
    11241145  }
     
    12241245  )
    12251246{
    1226   if (!mCpuSmmStaticPageTable) {
     1247  if (!mCpuSmmRestrictedMemoryAccess) {
     1248    //
     1249    // On-demand paging is enabled when access to non-SMRAM is not restricted.
     1250    //
    12271251    *Cr2 = AsmReadCr2 ();
    12281252  }
     
    12391263  )
    12401264{
    1241   if (!mCpuSmmStaticPageTable) {
     1265  if (!mCpuSmmRestrictedMemoryAccess) {
     1266    //
     1267    // On-demand paging is enabled when access to non-SMRAM is not restricted.
     1268    //
    12421269    AsmWriteCr2 (Cr2);
    12431270  }
    12441271}
     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**/
     1279BOOLEAN
     1280IsRestrictedMemoryAccess (
     1281  VOID
     1282  )
     1283{
     1284  return mCpuSmmRestrictedMemoryAccess;
     1285}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette