diff options
| author | Oliver Smith-Denny <osde@microsoft.com> | 2026-09-02 12:44:21 -0700 |
|---|---|---|
| committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2026-09-03 09:00:37 +0000 |
| commit | ee655c4d815231bd0916fbdde7a59f4dfdf0ee9f (patch) | |
| tree | ad942937e7bd7c905d0de18fefd5165db70a30c3 | |
| parent | 143032958ea9f97cfbab17a4fe7ada2e51c87d18 (diff) | |
| download | edk2-ee655c4d815231bd0916fbdde7a59f4dfdf0ee9f.tar.gz edk2-ee655c4d815231bd0916fbdde7a59f4dfdf0ee9f.zip | |
MdeModulePkg: DxeIpl: Don't Duplicate Mem Alloc Hob for Stack
Currently, DxeIpl will allocate memory for the new DXE stack,
which creates a memory allocation HOB for that region. It will
then call UpdateStackHob() to find the stack HOB with the old
stack info and update the memory address/length to correspond
to the new stack. It then creates a new memory allocation HOB
for the old stack region as it needs to remain mapped.
This ends up creating two memory allocation HOBs for the new
stack: a regular memory allocation HOB for the AllocatePages()
call and then the stack HOB (which is a memory allocation HOB
with a special name).
When DXE Core ingests these, it will ignore one of the two HOBs
when it goes to allocate memory. However, this is incorrectly
describing handoff state. There never should be overlapping
memory allocation HOBs.
This commit updates DxeIpl behavior to instead find the old
stack HOB, convert it to a regular memory allocation HOB,
then find the memory allocation HOB for the new stack range
and convert it into the stack HOB.
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
| -rw-r--r-- | MdeModulePkg/Core/DxeIplPeim/DxeLoad.c | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c b/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c index 67d3983522..15f4951eed 100644 --- a/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c +++ b/MdeModulePkg/Core/DxeIplPeim/DxeLoad.c @@ -830,23 +830,18 @@ UpdateStackHob ( Hob.Raw = GetHobList ();
while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)) != NULL) {
- if (CompareGuid (&gEfiHobMemoryAllocStackGuid, &(Hob.MemoryAllocationStack->AllocDescriptor.Name))) {
+ if (CompareGuid (&gEfiHobMemoryAllocStackGuid, &(Hob.MemoryAllocationStack->AllocDescriptor.Name)) &&
+ (Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress != BaseAddress))
+ {
//
- // Build a new memory allocation HOB with old stack info with EfiBootServicesData type. Need to
- // avoid this region be reclaimed by DXE core as the IDT built in SEC might be on stack, and some
- // PEIMs may also keep key information on stack
+ // Convert this stack HOB with the old stack info into a regular memory allocation HOB. We need to
+ // avoid this region being reclaimed by DXE core as the IDT built in SEC might be on the stack, and some
+ // PEIMs may also keep key information on the stack.
//
- BuildMemoryAllocationHob (
- Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress,
- Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength,
- EfiBootServicesData
- );
- //
- // Update the BSP Stack Hob to reflect the new stack info.
- //
- Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress = BaseAddress;
- Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength = Length;
- break;
+ ZeroMem (&(Hob.MemoryAllocationStack->AllocDescriptor.Name), sizeof (EFI_GUID));
+ } else if ((Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress == BaseAddress) && (Hob.MemoryAllocation->AllocDescriptor.MemoryLength == Length)) {
+ // Find the memory allocation HOB that matches the new stack location and mark it as the stack HOB.
+ CopyGuid (&(Hob.MemoryAllocation->AllocDescriptor.Name), &gEfiHobMemoryAllocStackGuid);
}
Hob.Raw = GET_NEXT_HOB (Hob);
|
