public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v1 1/1] StandaloneMmPkg: Fix HOB space and heap space conflicted issue
@ 2022-02-08  2:43 Ming Huang
  2022-02-09 12:13 ` Ming Huang
  0 siblings, 1 reply; 2+ messages in thread
From: Ming Huang @ 2022-02-08  2:43 UTC (permalink / raw)
  To: devel, sami.mujawar, ardb+tianocore, jiewen.yao,
	supreeth.venkatesh
  Cc: ming.huang-, Ming Huang

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 <huangming@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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v1 1/1] StandaloneMmPkg: Fix HOB space and heap space conflicted issue
  2022-02-08  2:43 [PATCH v1 1/1] StandaloneMmPkg: Fix HOB space and heap space conflicted issue Ming Huang
@ 2022-02-09 12:13 ` Ming Huang
  0 siblings, 0 replies; 2+ messages in thread
From: Ming Huang @ 2022-02-09 12:13 UTC (permalink / raw)
  To: devel, sami.mujawar, ardb+tianocore, jiewen.yao,
	supreeth.venkatesh
  Cc: ming.huang-

Abandon this patch, send a new one for fixing this issue.

在 2/8/22 10:43 AM, Ming Huang 写道:
> 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 <huangming@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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-02-09 12:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-08  2:43 [PATCH v1 1/1] StandaloneMmPkg: Fix HOB space and heap space conflicted issue Ming Huang
2022-02-09 12:13 ` Ming Huang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox