From: "Nhi Pham via groups.io" <nhi=os.amperecomputing.com@groups.io>
To: devel@edk2.groups.io, huangming@linux.alibaba.com, ardb@kernel.org
Cc: Sami Mujawar <sami.mujawar@arm.com>,
Ard Biesheuvel <ardb+tianocore@kernel.org>,
Jiewen Yao <jiewen.yao@intel.com>,
Supreeth Venkatesh <supreeth.venkatesh@arm.com>,
ming.huang-@outlook.com
Subject: Re: [edk2-devel] [PATCH v1 2/2] StandaloneMmPkg: Fix HOB space and heap space conflicted issue
Date: Wed, 16 Aug 2023 15:55:52 +0700 [thread overview]
Message-ID: <0e0bc14c-88a1-21a8-0be7-34ed023e1127@amperemail.onmicrosoft.com> (raw)
In-Reply-To: <14f25a95-7153-4eec-8804-a3da768ccb11@linux.alibaba.com>
Hi Ard and Ming,
I have been seeing an issue with StandaloneMM HobLib that can be fixed
by this patch as well.
The function CreateHob() in the HobLib instance
StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCoreHobLib.inf
does not work at all. The HobList is early created by the
StandaloneMmCoreEntryPoint then it is relocated on the heap memory by
StandaloneMmCore. But the FreeMemoryTop and FreeMemoryBottom are not
updated accordingly and the HOB free memory top is overlapped with the
heap space. This causes the CreateHob() function to not work as
expected. Introducing the PcdMemoryHobSize is reasonable to fix this issue.
I tested this patch in my end.
Tested-by: Nhi Pham <nhi@os.amperecomputing.com>
Thanks,
-Nhi
On 5/12/2022 5:09 PM, Ming Huang via groups.io wrote:
>
> 在 5/3/22 5:10 PM, Ard Biesheuvel 写道:
>> On Wed, 9 Feb 2022 at 13:26, Ming Huang <huangming@linux.alibaba.com> wrote:
>>> The heap space will be rewrote if a StandloneMmPkg module create HOB
>>> by BuildGuidHob() interface and write data to HOB space.
>> Can you elaborate? What is supposed to happen and why, and what is
>> happening instead?
> I tried my best to explain the issue:
>
> -----------------------------<--HandOffHob->EfiFreeMemoryTop
> | |
> | |
> | |
> | |
> | |
> | |
> | mMmMemoryMap |
> |---------------------------|<--HandOffHob->EfiFreeMemoryBottom
> | HobEnd |
> |---------------------------|<--HandOffHob->EfiEndOfHobList
> | |
> | Hob #1 |
> -----------------------------<--MmHobStart
> 1 The mMmMemoryMap which use for free page is on above the HobEnd.
> 2 Create a hob by BuildGuidHob(), the HobEnd will move up and cover
> the structure or list using by free page.
>
> After this patch, there is a pre-allocation space for creating hob.
>
> -----------------------------<--HandOffHob->EfiFreeMemoryTop
> | |
> | |
> | |
> | |
> | mMmMemoryMap |
> |---------------------------|<--HandOffHob->EfiFreeMemoryBottom
> | Hob free space | by PcdMemoryHobSize
> |---------------------------|
> | HobEnd |
> |---------------------------|<--HandOffHob->EfiEndOfHobList
> | |
> | Hob #1 |
> -----------------------------<--MmHobStart
>
>>> 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/Core/StandaloneMmCore.c | 17 ++++++++++++++++-
>>> StandaloneMmPkg/Core/StandaloneMmCore.inf | 3 +++
>>> StandaloneMmPkg/StandaloneMmPkg.dec | 2 ++
>>> 3 files changed, 21 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.c b/StandaloneMmPkg/Core/StandaloneMmCore.c
>>> index d221f1d111..1cf259d946 100644
>>> --- a/StandaloneMmPkg/Core/StandaloneMmCore.c
>>> +++ b/StandaloneMmPkg/Core/StandaloneMmCore.c
>>> @@ -512,6 +512,9 @@ StandaloneMmMain (
>>> EFI_MMRAM_DESCRIPTOR *MmramRanges;
>>> UINTN MmramRangeCount;
>>> EFI_HOB_FIRMWARE_VOLUME *BfvHob;
>>> + EFI_HOB_HANDOFF_INFO_TABLE *HandOffHobNew;
>>> + EFI_HOB_HANDOFF_INFO_TABLE *HandOffHobOrg;
>>> + UINT64 MaxHobSize = PcdGet64 (PcdMemoryHobSize);
>>>
>>> ProcessLibraryConstructorList (HobStart, &gMmCoreMmst);
>>>
>>> @@ -619,10 +622,22 @@ StandaloneMmMain (
>>> //
>>> HobSize = GetHobListSize (HobStart);
>>> DEBUG ((DEBUG_INFO, "HobSize - 0x%x\n", HobSize));
>>> - MmHobStart = AllocatePool (HobSize);
>>> + ASSERT (HobSize <= MaxHobSize);
>>> + MmHobStart = AllocatePool (MaxHobSize);
>>> DEBUG ((DEBUG_INFO, "MmHobStart - 0x%x\n", MmHobStart));
>>> ASSERT (MmHobStart != NULL);
>>> CopyMem (MmHobStart, HobStart, HobSize);
>>> + //
>>> + // Initlialize the new HOB table
>>> + //
>>> + HandOffHobOrg = (EFI_HOB_HANDOFF_INFO_TABLE *)HobStart;
>>> + HandOffHobNew = (EFI_HOB_HANDOFF_INFO_TABLE *)MmHobStart;
>>> + HandOffHobNew->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS)MmHobStart +
>>> + (HandOffHobOrg->EfiEndOfHobList - (EFI_PHYSICAL_ADDRESS)HobStart);
>>> + HandOffHobNew->EfiFreeMemoryBottom = HandOffHobNew->EfiEndOfHobList +
>>> + sizeof (EFI_HOB_GENERIC_HEADER);
>>> + HandOffHobNew->EfiFreeMemoryTop = (EFI_PHYSICAL_ADDRESS)MmHobStart + MaxHobSize;
>>> +
>>> Status = MmInstallConfigurationTable (&gMmCoreMmst, &gEfiHobListGuid, MmHobStart, HobSize);
>>> ASSERT_EFI_ERROR (Status);
>>>
>>> diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.inf b/StandaloneMmPkg/Core/StandaloneMmCore.inf
>>> index c44b9ff333..37e6135d73 100644
>>> --- a/StandaloneMmPkg/Core/StandaloneMmCore.inf
>>> +++ b/StandaloneMmPkg/Core/StandaloneMmCore.inf
>>> @@ -76,6 +76,9 @@
>>> gEfiEventExitBootServicesGuid
>>> gEfiEventReadyToBootGuid
>>>
>>> +[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 (#107793): https://edk2.groups.io/g/devel/message/107793
Mute This Topic: https://groups.io/mt/89020085/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
next prev parent reply other threads:[~2023-08-16 8:56 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-09 12:25 [PATCH v1 0/2] Fix StandaloneMmPkg HOB issue Ming Huang
2022-02-09 12:25 ` [PATCH v1 1/2] StandaloneMmPkg/Hob: Assert or return NULL for create hob failed Ming Huang
2022-02-09 12:25 ` [PATCH v1 2/2] StandaloneMmPkg: Fix HOB space and heap space conflicted issue Ming Huang
2022-05-03 9:10 ` Ard Biesheuvel
2022-05-12 10:09 ` [edk2-devel] " Ming Huang
2023-08-16 8:55 ` Nhi Pham via groups.io [this message]
2023-08-30 13:10 ` Ard Biesheuvel
2023-08-31 8:20 ` Nhi Pham via groups.io
2023-09-01 20:43 ` Oliver Smith-Denny
2023-09-05 2:20 ` Nhi Pham via groups.io
2023-09-05 21:29 ` Oliver Smith-Denny
2023-09-06 6:33 ` Ni, Ray
2023-09-06 6:56 ` Ard Biesheuvel
2023-09-06 7:55 ` Nhi Pham via groups.io
2023-09-06 8:50 ` Ard Biesheuvel
2023-09-06 16:22 ` Oliver Smith-Denny
2023-09-07 15:38 ` Nhi Pham via groups.io
2023-11-30 13:59 ` Nhi Pham via groups.io
2023-12-01 5:29 ` Ni, Ray
2023-09-06 7:35 ` Nhi Pham via groups.io
[not found] ` <177BD141FD103BE4.8497@groups.io>
2023-08-29 2:48 ` Nhi Pham via groups.io
2022-03-30 9:35 ` [PATCH v1 0/2] Fix StandaloneMmPkg HOB issue Ming Huang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0e0bc14c-88a1-21a8-0be7-34ed023e1127@amperemail.onmicrosoft.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox