The heap space will be rewrote if a StandloneMmPkg module create HOB by BuildGuidHob() interface and write data to HOB space. Add a PCD PcdMemoryHobSize for pre-allocation a space to create HOB to fix this issue.
Signed-off-by: Ming Huang <huangm...@linux.alibaba.com> --- StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c | 11 ++++++----- StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf | 4 ++++ StandaloneMmPkg/StandaloneMmPkg.dec | 2 ++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c index eb0c1f82db..c9fb46c532 100644 --- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c @@ -68,13 +68,14 @@ CreateHobListFromBootInfo ( EFI_PROCESSOR_INFORMATION *ProcInfoBuffer; EFI_SECURE_PARTITION_CPU_INFO *CpuInfo; ARM_TF_CPU_DRIVER_EP_DESCRIPTOR *CpuDriverEntryPointDesc; + UINT64 MaxHobSize = PcdGet64 (PcdMemoryHobSize); // Create a hoblist with a PHIT and EOH HobStart = HobConstructor ( (VOID *)(UINTN)PayloadBootInfo->SpMemBase, (UINTN)PayloadBootInfo->SpMemLimit - PayloadBootInfo->SpMemBase, (VOID *)(UINTN)PayloadBootInfo->SpHeapBase, - (VOID *)(UINTN)(PayloadBootInfo->SpHeapBase + PayloadBootInfo->SpHeapSize) + (VOID *)(UINTN)(PayloadBootInfo->SpHeapBase +MaxHobSize) ); // Check that the Hoblist starts at the bottom of the Heap @@ -192,13 +193,13 @@ CreateHobListFromBootInfo ( // Base and size of heap memory shared by all cpus MmramRanges[4].PhysicalStart = (EFI_PHYSICAL_ADDRESS)(UINTN)HobStart; MmramRanges[4].CpuStart = (EFI_PHYSICAL_ADDRESS)(UINTN)HobStart; - MmramRanges[4].PhysicalSize = HobStart->EfiFreeMemoryBottom - (EFI_PHYSICAL_ADDRESS)(UINTN)HobStart; + MmramRanges[4].PhysicalSize = MaxHobSize; MmramRanges[4].RegionState = EFI_CACHEABLE | EFI_ALLOCATED; // Base and size of heap memory shared by all cpus - MmramRanges[5].PhysicalStart = HobStart->EfiFreeMemoryBottom; - MmramRanges[5].CpuStart = HobStart->EfiFreeMemoryBottom; - MmramRanges[5].PhysicalSize = HobStart->EfiFreeMemoryTop - HobStart->EfiFreeMemoryBottom; + MmramRanges[5].PhysicalStart = HobStart->EfiFreeMemoryTop; + MmramRanges[5].CpuStart = HobStart->EfiFreeMemoryTop; + MmramRanges[5].PhysicalSize = PayloadBootInfo->SpHeapSize - MaxHobSize; MmramRanges[5].RegionState = EFI_CACHEABLE; return HobStart; diff --git a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf index 75cfb98c0e..c469ac2cca 100644 --- a/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf +++ b/StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/StandaloneMmCoreEntryPoint.inf @@ -40,6 +40,7 @@ [LibraryClasses] BaseLib DebugLib + PcdLib [LibraryClasses.ARM, LibraryClasses.AARCH64] StandaloneMmMmuLib @@ -54,6 +55,9 @@ [FeaturePcd.ARM, FeaturePcd.AARCH64] gArmTokenSpaceGuid.PcdFfaEnable +[FixedPcd] + gStandaloneMmPkgTokenSpaceGuid.PcdMemoryHobSize + # # This configuration fails for CLANGPDB, which does not support PIE in the GCC # sense. Such however is required for ARM family StandaloneMmCore diff --git a/StandaloneMmPkg/StandaloneMmPkg.dec b/StandaloneMmPkg/StandaloneMmPkg.dec index 46784d94e4..cf554676e2 100644 --- a/StandaloneMmPkg/StandaloneMmPkg.dec +++ b/StandaloneMmPkg/StandaloneMmPkg.dec @@ -48,3 +48,5 @@ gEfiStandaloneMmNonSecureBufferGuid = { 0xf00497e3, 0xbfa2, 0x41a1, { 0x9d, 0x29, 0x54, 0xc2, 0xe9, 0x37, 0x21, 0xc5 }} gEfiArmTfCpuDriverEpDescriptorGuid = { 0x6ecbd5a1, 0xc0f8, 0x4702, { 0x83, 0x01, 0x4f, 0xc2, 0xc5, 0x47, 0x0a, 0x51 }} +[PcdsFixedAtBuild] + gStandaloneMmPkgTokenSpaceGuid.PcdMemoryHobSize|0x00000000|UINT64|0x00000004 -- 2.17.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#86438): https://edk2.groups.io/g/devel/message/86438 Mute This Topic: https://groups.io/mt/88988964/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-