* [edk2-devel] [PATCH v1 0/1] Fix Memory Bin Range Calculation to Account for Guard Page
@ 2023-08-10 18:06 Taylor Beebe
2023-08-10 18:06 ` [edk2-devel] [PATCH v1 1/1] MdeModulePkg: Memory Bin Range Update Accounts " Taylor Beebe
0 siblings, 1 reply; 4+ messages in thread
From: Taylor Beebe @ 2023-08-10 18:06 UTC (permalink / raw)
To: devel; +Cc: Jian J Wang, Liming Gao, Dandan Bi
From: Taylor Beebe <taylor.d.beebe@gmail.com>
The following flow will produce an issue:
If page guards are active for EfiReservedMemoryType and SMM NULL pointer
protection is active with nonstop mode enabled, then a large (600 page)
allocation of EfiReservedMemoryType will be made for profiling.
0. InitSmmProfile() will be called to allocate a large range of memory for
profiling.
1. gBS->AllocatePages() will be called with Type = EfiReservedMemoryType and
Pages = 600.
2. gBS->AllocatePages() will call FindFreePages() to find a range of 600 pages
in the memory map.
3. FindFreePages() will find a range and the binned address range will need to
be updated.
4. The binned address range start will be updated to include the start of the
range found by FindFreePages() but will NOT include the guard page.
5. CoreConvertPagesWithGuard() will be called to change the range type to
EfiReservedMemoryType. The function will increase the conversion range
to include the guard pages.
6. After converting the range, the CoreConvertRangeEx() logic will check
if the range is in the binned address bounds to see if it should updated
the memory type statistics.
7. The range will be outside of the binned address bounds by one page because
the guard page was not included in the binned address range causing the
large allocation to be unnacounted for in the of memory type statistics.
8. When the original bins are compared with the current bins to see if the
system should reset with a larger original bin size, the large allocation
will not be accounted for and the system will not reset with a larger bin
size which is incorrect behavior.
Cc: Taylor Beebe <t@taylorbeebe.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Dandan Bi <dandan.bi@intel.com>
Taylor Beebe (1):
MdeModulePkg: Memory Bin Range Update Accounts for Guard Page
MdeModulePkg/Core/Dxe/Mem/Page.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--
2.41.0.windows.3
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107697): https://edk2.groups.io/g/devel/message/107697
Mute This Topic: https://groups.io/mt/100668861/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply [flat|nested] 4+ messages in thread
* [edk2-devel] [PATCH v1 1/1] MdeModulePkg: Memory Bin Range Update Accounts for Guard Page
2023-08-10 18:06 [edk2-devel] [PATCH v1 0/1] Fix Memory Bin Range Calculation to Account for Guard Page Taylor Beebe
@ 2023-08-10 18:06 ` Taylor Beebe
2023-08-16 1:01 ` [edk2-devel] 回复: " gaoliming via groups.io
2023-09-18 21:25 ` [edk2-devel] " Michael Kubacki
0 siblings, 2 replies; 4+ messages in thread
From: Taylor Beebe @ 2023-08-10 18:06 UTC (permalink / raw)
To: devel; +Cc: Jian J Wang, Liming Gao, Dandan Bi
From: Taylor Beebe <taylor.d.beebe@gmail.com>
When finding a free page range for allocation, if the found range
starts below the tracked memory bin address range, the lowest
memory bin address is updated which will not include the guard page if
present. When CoreConvertPagesWithGuard() is called on the range
being allocated, the memory range is adjusted to include guard
pages which can push it out of the memory bin address range and
cause the memory type statistics to be unaltered.
This patch updates the lowest memory bin address range to account for
the guard page if NeedGuard is TRUE so the memory type statistics
are updated correctly.
Signed-off-by: Taylor Beebe <t@taylorbeebe.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Dandan Bi <dandan.bi@intel.com>
---
MdeModulePkg/Core/Dxe/Mem/Page.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c
index 41af50b3d5ab..6497af573353 100644
--- a/MdeModulePkg/Core/Dxe/Mem/Page.c
+++ b/MdeModulePkg/Core/Dxe/Mem/Page.c
@@ -1210,7 +1210,7 @@ FindFreePages (
);
if (Start != 0) {
if (Start < mDefaultBaseAddress) {
- mDefaultBaseAddress = Start;
+ mDefaultBaseAddress = NeedGuard ? Start - EFI_PAGE_SIZE : Start;
}
return Start;
--
2.41.0.windows.3
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107698): https://edk2.groups.io/g/devel/message/107698
Mute This Topic: https://groups.io/mt/100668862/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [edk2-devel] 回复: [PATCH v1 1/1] MdeModulePkg: Memory Bin Range Update Accounts for Guard Page
2023-08-10 18:06 ` [edk2-devel] [PATCH v1 1/1] MdeModulePkg: Memory Bin Range Update Accounts " Taylor Beebe
@ 2023-08-16 1:01 ` gaoliming via groups.io
2023-09-18 21:25 ` [edk2-devel] " Michael Kubacki
1 sibling, 0 replies; 4+ messages in thread
From: gaoliming via groups.io @ 2023-08-16 1:01 UTC (permalink / raw)
To: 'Taylor Beebe', devel; +Cc: 'Jian J Wang', 'Dandan Bi'
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
> -----邮件原件-----
> 发件人: Taylor Beebe <t@taylorbeebe.com>
> 发送时间: 2023年8月11日 2:07
> 收件人: devel@edk2.groups.io
> 抄送: Jian J Wang <jian.j.wang@intel.com>; Liming Gao
> <gaoliming@byosoft.com.cn>; Dandan Bi <dandan.bi@intel.com>
> 主题: [PATCH v1 1/1] MdeModulePkg: Memory Bin Range Update Accounts
> for Guard Page
>
> From: Taylor Beebe <taylor.d.beebe@gmail.com>
>
> When finding a free page range for allocation, if the found range
> starts below the tracked memory bin address range, the lowest
> memory bin address is updated which will not include the guard page if
> present. When CoreConvertPagesWithGuard() is called on the range
> being allocated, the memory range is adjusted to include guard
> pages which can push it out of the memory bin address range and
> cause the memory type statistics to be unaltered.
>
> This patch updates the lowest memory bin address range to account for
> the guard page if NeedGuard is TRUE so the memory type statistics
> are updated correctly.
>
> Signed-off-by: Taylor Beebe <t@taylorbeebe.com>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Dandan Bi <dandan.bi@intel.com>
> ---
> MdeModulePkg/Core/Dxe/Mem/Page.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c
> b/MdeModulePkg/Core/Dxe/Mem/Page.c
> index 41af50b3d5ab..6497af573353 100644
> --- a/MdeModulePkg/Core/Dxe/Mem/Page.c
> +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c
> @@ -1210,7 +1210,7 @@ FindFreePages (
> );
> if (Start != 0) {
> if (Start < mDefaultBaseAddress) {
> - mDefaultBaseAddress = Start;
> + mDefaultBaseAddress = NeedGuard ? Start - EFI_PAGE_SIZE :
> Start;
> }
>
> return Start;
> --
> 2.41.0.windows.3
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#107774): https://edk2.groups.io/g/devel/message/107774
Mute This Topic: https://groups.io/mt/100771119/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [edk2-devel] [PATCH v1 1/1] MdeModulePkg: Memory Bin Range Update Accounts for Guard Page
2023-08-10 18:06 ` [edk2-devel] [PATCH v1 1/1] MdeModulePkg: Memory Bin Range Update Accounts " Taylor Beebe
2023-08-16 1:01 ` [edk2-devel] 回复: " gaoliming via groups.io
@ 2023-09-18 21:25 ` Michael Kubacki
1 sibling, 0 replies; 4+ messages in thread
From: Michael Kubacki @ 2023-09-18 21:25 UTC (permalink / raw)
To: devel, t; +Cc: Jian J Wang, Liming Gao, Dandan Bi
Merged -
https://github.com/tianocore/edk2/commit/408e4631359d3e67633b36f6adf9a13a7cc573d3
On 8/10/2023 2:06 PM, Taylor Beebe wrote:
> From: Taylor Beebe <taylor.d.beebe@gmail.com>
>
> When finding a free page range for allocation, if the found range
> starts below the tracked memory bin address range, the lowest
> memory bin address is updated which will not include the guard page if
> present. When CoreConvertPagesWithGuard() is called on the range
> being allocated, the memory range is adjusted to include guard
> pages which can push it out of the memory bin address range and
> cause the memory type statistics to be unaltered.
>
> This patch updates the lowest memory bin address range to account for
> the guard page if NeedGuard is TRUE so the memory type statistics
> are updated correctly.
>
> Signed-off-by: Taylor Beebe <t@taylorbeebe.com>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Dandan Bi <dandan.bi@intel.com>
> ---
> MdeModulePkg/Core/Dxe/Mem/Page.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c
> index 41af50b3d5ab..6497af573353 100644
> --- a/MdeModulePkg/Core/Dxe/Mem/Page.c
> +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c
> @@ -1210,7 +1210,7 @@ FindFreePages (
> );
> if (Start != 0) {
> if (Start < mDefaultBaseAddress) {
> - mDefaultBaseAddress = Start;
> + mDefaultBaseAddress = NeedGuard ? Start - EFI_PAGE_SIZE : Start;
> }
>
> return Start;
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108807): https://edk2.groups.io/g/devel/message/108807
Mute This Topic: https://groups.io/mt/100668862/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-09-18 21:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-10 18:06 [edk2-devel] [PATCH v1 0/1] Fix Memory Bin Range Calculation to Account for Guard Page Taylor Beebe
2023-08-10 18:06 ` [edk2-devel] [PATCH v1 1/1] MdeModulePkg: Memory Bin Range Update Accounts " Taylor Beebe
2023-08-16 1:01 ` [edk2-devel] 回复: " gaoliming via groups.io
2023-09-18 21:25 ` [edk2-devel] " Michael Kubacki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox