]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Core/Dxe/Mem/Page.c
MdeModulePkg DxeCore: Fix for missing Memory Attributes Table (MAT) update
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Mem / Page.c
index bd9e116aa59cb620045c8fbc2a9278d130da990e..1f0e3d94b93d3cc1c1c55e54be4912250e417add 100644 (file)
@@ -1265,12 +1265,13 @@ CoreInternalAllocatePages (
   IN BOOLEAN                NeedGuard\r
   )\r
 {\r
-  EFI_STATUS      Status;\r
-  UINT64          Start;\r
-  UINT64          NumberOfBytes;\r
-  UINT64          End;\r
-  UINT64          MaxAddress;\r
-  UINTN           Alignment;\r
+  EFI_STATUS       Status;\r
+  UINT64           Start;\r
+  UINT64           NumberOfBytes;\r
+  UINT64           End;\r
+  UINT64           MaxAddress;\r
+  UINTN            Alignment;\r
+  EFI_MEMORY_TYPE  CheckType;\r
 \r
   if ((UINT32)Type >= MaxAllocateType) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -1321,6 +1322,7 @@ CoreInternalAllocatePages (
   // if (Start + NumberOfBytes) rolls over 0 or\r
   // if Start is above MAX_ALLOC_ADDRESS or\r
   // if End is above MAX_ALLOC_ADDRESS,\r
+  // if Start..End overlaps any tracked MemoryTypeStatistics range\r
   // return EFI_NOT_FOUND.\r
   //\r
   if (Type == AllocateAddress) {\r
@@ -1336,6 +1338,33 @@ CoreInternalAllocatePages (
         (End > MaxAddress)) {\r
       return EFI_NOT_FOUND;\r
     }\r
+\r
+    //\r
+    // A driver is allowed to call AllocatePages using an AllocateAddress type.  This type of\r
+    // AllocatePage request the exact physical address if it is not used.  The existing code\r
+    // will allow this request even in 'special' pages.  The problem with this is that the\r
+    // reason to have 'special' pages for OS hibernate/resume is defeated as memory is\r
+    // fragmented.\r
+    //\r
+\r
+    for (CheckType = (EFI_MEMORY_TYPE) 0; CheckType < EfiMaxMemoryType; CheckType++) {\r
+      if (MemoryType != CheckType &&\r
+          mMemoryTypeStatistics[CheckType].Special &&\r
+          mMemoryTypeStatistics[CheckType].NumberOfPages > 0) {\r
+        if (Start >= mMemoryTypeStatistics[CheckType].BaseAddress &&\r
+            Start <= mMemoryTypeStatistics[CheckType].MaximumAddress) {\r
+          return EFI_NOT_FOUND;\r
+        }\r
+        if (End >= mMemoryTypeStatistics[CheckType].BaseAddress &&\r
+            End <= mMemoryTypeStatistics[CheckType].MaximumAddress) {\r
+          return EFI_NOT_FOUND;\r
+        }\r
+        if (Start < mMemoryTypeStatistics[CheckType].BaseAddress &&\r
+            End   > mMemoryTypeStatistics[CheckType].MaximumAddress) {\r
+          return EFI_NOT_FOUND;\r
+        }\r
+      }\r
+    }\r
   }\r
 \r
   if (Type == AllocateMaxAddress) {\r