Revision: 18499
http://sourceforge.net/p/edk2/code/18499
Author: lzeng14
Date: 2015-09-17 08:32:14 +0000 (Thu, 17 Sep 2015)
Log Message:
-----------
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 <[email protected]>
Cc: Liming Gao <[email protected]>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <[email protected]>
Reviewed-by: Jiewen Yao <[email protected]>
Modified Paths:
--------------
trunk/edk2/MdeModulePkg/Core/Dxe/Gcd/Gcd.c
Modified: trunk/edk2/MdeModulePkg/Core/Dxe/Gcd/Gcd.c
===================================================================
--- trunk/edk2/MdeModulePkg/Core/Dxe/Gcd/Gcd.c 2015-09-17 07:37:44 UTC (rev
18498)
+++ trunk/edk2/MdeModulePkg/Core/Dxe/Gcd/Gcd.c 2015-09-17 08:32:14 UTC (rev
18499)
@@ -2311,6 +2311,7 @@
UINTN Index;
UINT64 Capabilities;
EFI_HOB_CPU * CpuHob;
+ EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMapHobList;
//
// Cache the PHIT HOB for later use
@@ -2494,23 +2495,12 @@
}
//
- // 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 @@
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 @@
}
}
}
+
+ //
+ // 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;
------------------------------------------------------------------------------
Monitor Your Dynamic Infrastructure at Any Scale With Datadog!
Get real-time metrics from all of your servers, apps and tools
in one place.
SourceForge users - Click here to start your Free Trial of Datadog now!
http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits