mirror of https://github.com/acidanthera/audk.git
MdeModulePkg DxeCore: Relocate HOB List after other tested memory resources added
The HOB List relocation should be at after all the tested memory resources added (except the memory space that covers HOB List) to the memory services, because the memory resource found in CoreInitializeMemoryServices() may have not enough remaining resource for HOB List. And the memory space that covers HOB List should be processed after HOB List relocation to avoid the resources allocated by others to corrupt HOB List before its relocation. Cc: Jiewen Yao <jiewen.yao@intel.com> Cc: Liming Gao <liming.gao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18499 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
2d3e4cd167
commit
a46bbdd379
|
@ -2311,6 +2311,7 @@ CoreInitializeGcdServices (
|
|||
UINTN Index;
|
||||
UINT64 Capabilities;
|
||||
EFI_HOB_CPU * CpuHob;
|
||||
EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMapHobList;
|
||||
|
||||
//
|
||||
// Cache the PHIT HOB for later use
|
||||
|
@ -2493,24 +2494,13 @@ CoreInitializeGcdServices (
|
|||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Relocate HOB List to an allocated pool buffer.
|
||||
//
|
||||
NewHobList = AllocateCopyPool (
|
||||
(UINTN)PhitHob->EfiFreeMemoryBottom - (UINTN)(*HobStart),
|
||||
*HobStart
|
||||
);
|
||||
ASSERT (NewHobList != NULL);
|
||||
|
||||
*HobStart = NewHobList;
|
||||
gHobList = NewHobList;
|
||||
|
||||
//
|
||||
// Add and allocate the remaining unallocated system memory to the memory services.
|
||||
//
|
||||
Status = CoreGetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);
|
||||
ASSERT (Status == EFI_SUCCESS);
|
||||
|
||||
MemorySpaceMapHobList = NULL;
|
||||
for (Index = 0; Index < NumberOfDescriptors; Index++) {
|
||||
if ((MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeSystemMemory) ||
|
||||
(MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeMoreReliable)) {
|
||||
|
@ -2520,6 +2510,16 @@ CoreInitializeGcdServices (
|
|||
if (Length == 0 || MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length < BaseAddress) {
|
||||
continue;
|
||||
}
|
||||
if (((UINTN) MemorySpaceMap[Index].BaseAddress <= (UINTN) (*HobStart)) &&
|
||||
((UINTN) (MemorySpaceMap[Index].BaseAddress + MemorySpaceMap[Index].Length) >= (UINTN) PhitHob->EfiFreeMemoryBottom)) {
|
||||
//
|
||||
// Skip the memory space that covers HOB List, it should be processed
|
||||
// after HOB List relocation to avoid the resources allocated by others
|
||||
// to corrupt HOB List before its relocation.
|
||||
//
|
||||
MemorySpaceMapHobList = &MemorySpaceMap[Index];
|
||||
continue;
|
||||
}
|
||||
CoreAddMemoryDescriptor (
|
||||
EfiConventionalMemory,
|
||||
BaseAddress,
|
||||
|
@ -2538,6 +2538,47 @@ CoreInitializeGcdServices (
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Relocate HOB List to an allocated pool buffer.
|
||||
// The relocation should be at after all the tested memory resources added
|
||||
// (except the memory space that covers HOB List) to the memory services,
|
||||
// because the memory resource found in CoreInitializeMemoryServices()
|
||||
// may have not enough remaining resource for HOB List.
|
||||
//
|
||||
NewHobList = AllocateCopyPool (
|
||||
(UINTN) PhitHob->EfiFreeMemoryBottom - (UINTN) (*HobStart),
|
||||
*HobStart
|
||||
);
|
||||
ASSERT (NewHobList != NULL);
|
||||
|
||||
*HobStart = NewHobList;
|
||||
gHobList = NewHobList;
|
||||
|
||||
if (MemorySpaceMapHobList != NULL) {
|
||||
//
|
||||
// Add and allocate the memory space that covers HOB List to the memory services
|
||||
// after HOB List relocation.
|
||||
//
|
||||
BaseAddress = PageAlignAddress (MemorySpaceMapHobList->BaseAddress);
|
||||
Length = PageAlignLength (MemorySpaceMapHobList->BaseAddress + MemorySpaceMapHobList->Length - BaseAddress);
|
||||
CoreAddMemoryDescriptor (
|
||||
EfiConventionalMemory,
|
||||
BaseAddress,
|
||||
RShiftU64 (Length, EFI_PAGE_SHIFT),
|
||||
MemorySpaceMapHobList->Capabilities & (~EFI_MEMORY_RUNTIME)
|
||||
);
|
||||
Status = CoreAllocateMemorySpace (
|
||||
EfiGcdAllocateAddress,
|
||||
MemorySpaceMapHobList->GcdMemoryType,
|
||||
0,
|
||||
Length,
|
||||
&BaseAddress,
|
||||
gDxeCoreImageHandle,
|
||||
NULL
|
||||
);
|
||||
}
|
||||
|
||||
CoreFreePool (MemorySpaceMap);
|
||||
|
||||
return EFI_SUCCESS;
|
||||
|
|
Loading…
Reference in New Issue