]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/Core: fix guard page missing issue
authorJian J Wang <jian.j.wang@intel.com>
Fri, 26 Jan 2018 11:47:14 +0000 (19:47 +0800)
committerStar Zeng <star.zeng@intel.com>
Fri, 2 Feb 2018 01:50:15 +0000 (09:50 +0800)
This issue is a regression one caused by a patch at

    425d25699be83c35e12df8470b827d7fbcef3bce

That fix didn't take the 0 page to free into account, which still
needs to call UnsetGuardPage() even no memory needs to free.

The fix is just moving the calling of UnsetGuardPage() to the place
right after calling AdjustMemoryF().

Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
MdeModulePkg/Core/Dxe/Mem/HeapGuard.c
MdeModulePkg/Core/Dxe/Mem/Pool.c

index 92753c7269acc0315277436912e65b95db748801..392aeb8a0210f1cee6cf94029efe16e9890ca818 100644 (file)
@@ -1135,10 +1135,6 @@ CoreConvertPagesWithGuard (
     OldPages = NumberOfPages;\r
 \r
     AdjustMemoryF (&Start, &NumberOfPages);\r
     OldPages = NumberOfPages;\r
 \r
     AdjustMemoryF (&Start, &NumberOfPages);\r
-    if (NumberOfPages == 0) {\r
-      return EFI_SUCCESS;\r
-    }\r
-\r
     //\r
     // It's safe to unset Guard page inside memory lock because there should\r
     // be no memory allocation occurred in updating memory page attribute at\r
     //\r
     // It's safe to unset Guard page inside memory lock because there should\r
     // be no memory allocation occurred in updating memory page attribute at\r
@@ -1147,6 +1143,9 @@ CoreConvertPagesWithGuard (
     // marking it usable (from non-present to present).\r
     //\r
     UnsetGuardForMemory (OldStart, OldPages);\r
     // marking it usable (from non-present to present).\r
     //\r
     UnsetGuardForMemory (OldStart, OldPages);\r
+    if (NumberOfPages == 0) {\r
+      return EFI_SUCCESS;\r
+    }\r
   } else {\r
     AdjustMemoryA (&Start, &NumberOfPages);\r
   }\r
   } else {\r
     AdjustMemoryA (&Start, &NumberOfPages);\r
   }\r
index df9a1d28dff50006bb4128238e09ffdb92d2f9de..1ff2061f7f71e9b7da4fafefc320a68323a6bd97 100644 (file)
@@ -642,15 +642,15 @@ CoreFreePoolPagesWithGuard (
   NoPagesGuarded = NoPages;\r
 \r
   AdjustMemoryF (&Memory, &NoPages);\r
   NoPagesGuarded = NoPages;\r
 \r
   AdjustMemoryF (&Memory, &NoPages);\r
+  //\r
+  // It's safe to unset Guard page inside memory lock because there should\r
+  // be no memory allocation occurred in updating memory page attribute at\r
+  // this point. And unsetting Guard page before free will prevent Guard\r
+  // page just freed back to pool from being allocated right away before\r
+  // marking it usable (from non-present to present).\r
+  //\r
+  UnsetGuardForMemory (MemoryGuarded, NoPagesGuarded);\r
   if (NoPages > 0) {\r
   if (NoPages > 0) {\r
-    //\r
-    // It's safe to unset Guard page inside memory lock because there should\r
-    // be no memory allocation occurred in updating memory page attribute at\r
-    // this point. And unsetting Guard page before free will prevent Guard\r
-    // page just freed back to pool from being allocated right away before\r
-    // marking it usable (from non-present to present).\r
-    //\r
-    UnsetGuardForMemory (MemoryGuarded, NoPagesGuarded);\r
     CoreFreePoolPagesI (PoolType, Memory, NoPages);\r
   }\r
 }\r
     CoreFreePoolPagesI (PoolType, Memory, NoPages);\r
   }\r
 }\r