From 68461c2c37afe11c7dda2769efc10bf20d2a7b23 Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny Date: Sat, 9 Mar 2024 11:06:03 -0800 Subject: MdeModulePkg: DxeCore: Correct Runtime Granularity Memory Type Per the UEFI spec 2.10, section 2.3.6 (for the AARCH64 arch, other architectures in section two confirm the same) the memory types that need runtime page allocation granularity are EfiReservedMemoryType, EfiACPIMemoryNVS, EfiRuntimeServicesCode, and EfiRuntimeServicesData. However, legacy code was setting runtime page allocation granularity for EfiACPIReclaimMemory and not EfiReservedMemoryType. This patch fixes that error. Cc: Leif Lindholm Cc: Ard Biesheuvel Cc: Sami Mujawar Cc: Liming Gao Signed-off-by: Oliver Smith-Denny Suggested-by: Ard Biesheuvel Reviewed-by: Liming Gao --- MdeModulePkg/Core/Dxe/Mem/Page.c | 4 ++-- MdeModulePkg/Core/Dxe/Mem/Pool.c | 4 ++-- MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c | 4 ++-- MdeModulePkg/Core/Pei/Memory/MemoryServices.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Mem/Page.c b/MdeModulePkg/Core/Dxe/Mem/Page.c index dd558696ba..cd201d36a3 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Page.c +++ b/MdeModulePkg/Core/Dxe/Mem/Page.c @@ -1403,7 +1403,7 @@ CoreInternalAllocatePages ( Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY; - if ((MemoryType == EfiACPIReclaimMemory) || + if ((MemoryType == EfiReservedMemoryType) || (MemoryType == EfiACPIMemoryNVS) || (MemoryType == EfiRuntimeServicesCode) || (MemoryType == EfiRuntimeServicesData)) @@ -1666,7 +1666,7 @@ CoreInternalFreePages ( Alignment = DEFAULT_PAGE_ALLOCATION_GRANULARITY; - if ((Entry->Type == EfiACPIReclaimMemory) || + if ((Entry->Type == EfiReservedMemoryType) || (Entry->Type == EfiACPIMemoryNVS) || (Entry->Type == EfiRuntimeServicesCode) || (Entry->Type == EfiRuntimeServicesData)) diff --git a/MdeModulePkg/Core/Dxe/Mem/Pool.c b/MdeModulePkg/Core/Dxe/Mem/Pool.c index 716dd045f9..ccfce8c5f9 100644 --- a/MdeModulePkg/Core/Dxe/Mem/Pool.c +++ b/MdeModulePkg/Core/Dxe/Mem/Pool.c @@ -370,7 +370,7 @@ CoreAllocatePoolI ( ASSERT_LOCKED (&mPoolMemoryLock); - if ((PoolType == EfiACPIReclaimMemory) || + if ((PoolType == EfiReservedMemoryType) || (PoolType == EfiACPIMemoryNVS) || (PoolType == EfiRuntimeServicesCode) || (PoolType == EfiRuntimeServicesData)) @@ -753,7 +753,7 @@ CoreFreePoolI ( Pool->Used -= Size; DEBUG ((DEBUG_POOL, "FreePool: %p (len %lx) %,ld\n", Head->Data, (UINT64)(Head->Size - POOL_OVERHEAD), (UINT64)Pool->Used)); - if ((Head->Type == EfiACPIReclaimMemory) || + if ((Head->Type == EfiReservedMemoryType) || (Head->Type == EfiACPIMemoryNVS) || (Head->Type == EfiRuntimeServicesCode) || (Head->Type == EfiRuntimeServicesData)) diff --git a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c index 977239d08a..eb243a0137 100644 --- a/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c +++ b/MdeModulePkg/Core/Dxe/Misc/MemoryProtection.c @@ -300,18 +300,18 @@ IsMemoryProtectionSectionAligned ( switch (MemoryType) { case EfiRuntimeServicesCode: case EfiACPIMemoryNVS: + case EfiReservedMemoryType: PageAlignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY; break; case EfiRuntimeServicesData: - case EfiACPIReclaimMemory: ASSERT (FALSE); PageAlignment = RUNTIME_PAGE_ALLOCATION_GRANULARITY; break; case EfiBootServicesCode: case EfiLoaderCode: - case EfiReservedMemoryType: PageAlignment = EFI_PAGE_SIZE; break; + case EfiACPIReclaimMemory: default: ASSERT (FALSE); PageAlignment = EFI_PAGE_SIZE; diff --git a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c index a30925da39..52f37c960e 100644 --- a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c +++ b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c @@ -584,7 +584,7 @@ PeiAllocatePages ( } if ((RUNTIME_PAGE_ALLOCATION_GRANULARITY > DEFAULT_PAGE_ALLOCATION_GRANULARITY) && - ((MemoryType == EfiACPIReclaimMemory) || + ((MemoryType == EfiReservedMemoryType) || (MemoryType == EfiACPIMemoryNVS) || (MemoryType == EfiRuntimeServicesCode) || (MemoryType == EfiRuntimeServicesData))) -- cgit