* [PATCH] MdeModulePkg/Core: fix guard page missing issue
@ 2018-01-29 4:52 Jian J Wang
2018-02-01 5:39 ` Ni, Ruiyu
0 siblings, 1 reply; 2+ messages in thread
From: Jian J Wang @ 2018-01-29 4:52 UTC (permalink / raw)
To: edk2-devel; +Cc: Ruiyu Ni, Star Zeng, Eric Dong
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: Ruiyu Ni <ruiyu.ni@intel.com>
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>
---
MdeModulePkg/Core/Dxe/Mem/HeapGuard.c | 7 +++----
MdeModulePkg/Core/Dxe/Mem/Pool.c | 16 ++++++++--------
2 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c
index 92753c7269..392aeb8a02 100644
--- a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c
+++ b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c
@@ -1135,10 +1135,6 @@ CoreConvertPagesWithGuard (
OldPages = NumberOfPages;
AdjustMemoryF (&Start, &NumberOfPages);
- if (NumberOfPages == 0) {
- return EFI_SUCCESS;
- }
-
//
// It's safe to unset Guard page inside memory lock because there should
// be no memory allocation occurred in updating memory page attribute at
@@ -1147,6 +1143,9 @@ CoreConvertPagesWithGuard (
// marking it usable (from non-present to present).
//
UnsetGuardForMemory (OldStart, OldPages);
+ if (NumberOfPages == 0) {
+ return EFI_SUCCESS;
+ }
} else {
AdjustMemoryA (&Start, &NumberOfPages);
}
diff --git a/MdeModulePkg/Core/Dxe/Mem/Pool.c b/MdeModulePkg/Core/Dxe/Mem/Pool.c
index df9a1d28df..1ff2061f7f 100644
--- a/MdeModulePkg/Core/Dxe/Mem/Pool.c
+++ b/MdeModulePkg/Core/Dxe/Mem/Pool.c
@@ -642,15 +642,15 @@ CoreFreePoolPagesWithGuard (
NoPagesGuarded = NoPages;
AdjustMemoryF (&Memory, &NoPages);
+ //
+ // It's safe to unset Guard page inside memory lock because there should
+ // be no memory allocation occurred in updating memory page attribute at
+ // this point. And unsetting Guard page before free will prevent Guard
+ // page just freed back to pool from being allocated right away before
+ // marking it usable (from non-present to present).
+ //
+ UnsetGuardForMemory (MemoryGuarded, NoPagesGuarded);
if (NoPages > 0) {
- //
- // It's safe to unset Guard page inside memory lock because there should
- // be no memory allocation occurred in updating memory page attribute at
- // this point. And unsetting Guard page before free will prevent Guard
- // page just freed back to pool from being allocated right away before
- // marking it usable (from non-present to present).
- //
- UnsetGuardForMemory (MemoryGuarded, NoPagesGuarded);
CoreFreePoolPagesI (PoolType, Memory, NoPages);
}
}
--
2.14.1.windows.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] MdeModulePkg/Core: fix guard page missing issue
2018-01-29 4:52 [PATCH] MdeModulePkg/Core: fix guard page missing issue Jian J Wang
@ 2018-02-01 5:39 ` Ni, Ruiyu
0 siblings, 0 replies; 2+ messages in thread
From: Ni, Ruiyu @ 2018-02-01 5:39 UTC (permalink / raw)
To: Jian J Wang, edk2-devel; +Cc: Star Zeng, Eric Dong
On 1/29/2018 12:52 PM, Jian J Wang wrote:
> 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: Ruiyu Ni <ruiyu.ni@intel.com>
> 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>
> ---
> MdeModulePkg/Core/Dxe/Mem/HeapGuard.c | 7 +++----
> MdeModulePkg/Core/Dxe/Mem/Pool.c | 16 ++++++++--------
> 2 files changed, 11 insertions(+), 12 deletions(-)
>
> diff --git a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c
> index 92753c7269..392aeb8a02 100644
> --- a/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c
> +++ b/MdeModulePkg/Core/Dxe/Mem/HeapGuard.c
> @@ -1135,10 +1135,6 @@ CoreConvertPagesWithGuard (
> OldPages = NumberOfPages;
>
> AdjustMemoryF (&Start, &NumberOfPages);
> - if (NumberOfPages == 0) {
> - return EFI_SUCCESS;
> - }
> -
> //
> // It's safe to unset Guard page inside memory lock because there should
> // be no memory allocation occurred in updating memory page attribute at
> @@ -1147,6 +1143,9 @@ CoreConvertPagesWithGuard (
> // marking it usable (from non-present to present).
> //
> UnsetGuardForMemory (OldStart, OldPages);
> + if (NumberOfPages == 0) {
> + return EFI_SUCCESS;
> + }
> } else {
> AdjustMemoryA (&Start, &NumberOfPages);
> }
> diff --git a/MdeModulePkg/Core/Dxe/Mem/Pool.c b/MdeModulePkg/Core/Dxe/Mem/Pool.c
> index df9a1d28df..1ff2061f7f 100644
> --- a/MdeModulePkg/Core/Dxe/Mem/Pool.c
> +++ b/MdeModulePkg/Core/Dxe/Mem/Pool.c
> @@ -642,15 +642,15 @@ CoreFreePoolPagesWithGuard (
> NoPagesGuarded = NoPages;
>
> AdjustMemoryF (&Memory, &NoPages);
> + //
> + // It's safe to unset Guard page inside memory lock because there should
> + // be no memory allocation occurred in updating memory page attribute at
> + // this point. And unsetting Guard page before free will prevent Guard
> + // page just freed back to pool from being allocated right away before
> + // marking it usable (from non-present to present).
> + //
> + UnsetGuardForMemory (MemoryGuarded, NoPagesGuarded);
> if (NoPages > 0) {
> - //
> - // It's safe to unset Guard page inside memory lock because there should
> - // be no memory allocation occurred in updating memory page attribute at
> - // this point. And unsetting Guard page before free will prevent Guard
> - // page just freed back to pool from being allocated right away before
> - // marking it usable (from non-present to present).
> - //
> - UnsetGuardForMemory (MemoryGuarded, NoPagesGuarded);
> CoreFreePoolPagesI (PoolType, Memory, NoPages);
> }
> }
>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
--
Thanks,
Ray
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-02-01 5:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-29 4:52 [PATCH] MdeModulePkg/Core: fix guard page missing issue Jian J Wang
2018-02-01 5:39 ` Ni, Ruiyu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox