-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
StandaloneMM fixes for x86 #5814
Changes from all commits
15624ed
1d23ede
900b69e
2e35918
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -9,6 +9,20 @@ | |||||
|
||||||
#include "StandaloneMmCore.h" | ||||||
|
||||||
#if defined (__GNUC__) | ||||||
#define ALIGN_EFI_PAGE __attribute__((aligned(EFI_PAGE_SIZE))) | ||||||
#elif defined (_MSC_VER) | ||||||
#define ALIGN_EFI_PAGE __declspec(align(EFI_PAGE_SIZE)) | ||||||
#elif defined (__SUNPRO_C) | ||||||
#define ALIGN_EFI_PAGE | ||||||
#pragma align EFI_PAGE_SIZE(one,two80) | ||||||
#else | ||||||
/* not fatal, might waste a bit of memory */ | ||||||
#define ALIGN_EFI_PAGE | ||||||
#endif | ||||||
|
||||||
ALIGN_EFI_PAGE STATIC UINT8 FreePoolOnHeap[FixedPcdGet32 (PcdRuntimeMemoryOnHeapSize)]; | ||||||
|
||||||
LIST_ENTRY mMmPoolLists[MAX_POOL_INDEX]; | ||||||
// | ||||||
// To cache the MMRAM base since when Loading modules At fixed address feature is enabled, | ||||||
|
@@ -63,6 +77,15 @@ MmInitializeMemoryServices ( | |||||
MmramRanges[Index].RegionState | ||||||
); | ||||||
} | ||||||
|
||||||
if (FixedPcdGetBool (PcdRuntimeMemoryOnHeap)) { | ||||||
MmAddMemoryRegion ( | ||||||
(UINTN)FreePoolOnHeap, | ||||||
sizeof (FreePoolOnHeap), | ||||||
EfiConventionalMemory, | ||||||
EFI_CACHEABLE | ||||||
); | ||||||
} | ||||||
Comment on lines
+80
to
+88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the ARM standalone MM binary is loaded by some other module and that module allocates enough memory for the FreePoolOnHeap. MmCore can just use the FreePoolOnHeap as the free memory. Can you move the logic to StandaloneMmPkg/Library/StandaloneMmCoreEntryPoint/Arm/CreateHobList.c? So that the MmCore still finds the MMRAM from the HOB while the HOB is produced by CreateHobList.c and points to FreePoolOnHeap defined in that library. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. StanaloneMm is a HOB consumer and not a HOB producer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's okay that the Standalone MM core modifies some of the HOB contents. The HOB read-only restriction applies to all MM drivers. See edk2/StandaloneMmPkg/Core/StandaloneMmCore.c Line 656 in 0f9dbb4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But, modification should be done after StandaloneMmCore call InitializeMmHobList (See edk2/StandaloneMmPkg/Core/StandaloneMmCore.c Line 856 in 0f9dbb4
Becuase StandaloneMmEntryPoint's Hob list passed in #6116., Could be readonly memory from firmware. So, I think it's reasonable to modify contents in here. However, I'm not sure which platform whether there is the case of Since when StandaloneMm loaded, the Heap memory space is specified by manifest file and delivered always to StandaloneMm, I don't know it's useful for Arm. |
||||||
} | ||||||
|
||||||
/** | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,6 +117,7 @@ CheckBufferAddr ( | |
@retval EFI_UNSUPPORTED Operation not supported. | ||
**/ | ||
EFI_STATUS | ||
EFIAPI | ||
PiMmStandaloneMmCpuDriverEntry ( | ||
IN UINTN EventId, | ||
IN UINTN CpuNumber, | ||
|
@@ -147,24 +148,35 @@ PiMmStandaloneMmCpuDriverEntry ( | |
NsCommBufferSize = ((EFI_MM_COMMUNICATE_HEADER *)NsCommBufferAddr)->MessageLength + | ||
sizeof (EFI_MM_COMMUNICATE_HEADER); | ||
|
||
GuidedEventContext = NULL; | ||
// Now that the secure world can see the normal world buffer, allocate | ||
// memory to copy the communication buffer to the secure world. | ||
Status = mMmst->MmAllocatePool ( | ||
EfiRuntimeServicesData, | ||
NsCommBufferSize, | ||
(VOID **)&GuidedEventContext | ||
); | ||
|
||
if (Status != EFI_SUCCESS) { | ||
DEBUG ((DEBUG_ERROR, "Mem alloc failed - 0x%x\n", EventId)); | ||
return EFI_OUT_OF_RESOURCES; | ||
if (FixedPcdGetBool (PcdRuntimeMemoryOnHeap)) { | ||
// | ||
// When runtime memory is allocated on the heap the buffer allocated by | ||
// MmAllocatePool is within the MM 'secure world'. The MMI handler will | ||
// assert as it checks again if the passed buffer is outside the 'secure world'. | ||
// Thus drop the separate allocation and directly pass the NS buffer to | ||
// the MMI handler. | ||
// | ||
Comment on lines
+153
to
+158
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. old logic is to always allocate MMRAM and copy Non-Secure comm buffer into MMRAM. |
||
GuidedEventContext = (VOID *)NsCommBufferAddr; | ||
} else { | ||
GuidedEventContext = NULL; | ||
// Now that the secure world can see the normal world buffer, allocate | ||
// memory to copy the communication buffer to the secure world. | ||
Status = mMmst->MmAllocatePool ( | ||
EfiRuntimeServicesData, | ||
NsCommBufferSize, | ||
(VOID **)&GuidedEventContext | ||
); | ||
|
||
if (Status != EFI_SUCCESS) { | ||
DEBUG ((DEBUG_ERROR, "Mem alloc failed - 0x%x\n", EventId)); | ||
return EFI_OUT_OF_RESOURCES; | ||
} | ||
|
||
// X1 contains the VA of the normal world memory accessible from | ||
// secure world. | ||
CopyMem (GuidedEventContext, (CONST VOID *)NsCommBufferAddr, NsCommBufferSize); | ||
} | ||
|
||
// X1 contains the VA of the normal world memory accessible from | ||
// secure world. | ||
CopyMem (GuidedEventContext, (CONST VOID *)NsCommBufferAddr, NsCommBufferSize); | ||
|
||
// Stash the pointer to the allocated Event Context for this CPU | ||
PerCpuGuidedEventContext[CpuNumber] = GuidedEventContext; | ||
|
||
|
@@ -188,11 +200,14 @@ PiMmStandaloneMmCpuDriverEntry ( | |
|
||
// Free the memory allocation done earlier and reset the per-cpu context | ||
ASSERT (GuidedEventContext); | ||
CopyMem ((VOID *)NsCommBufferAddr, (CONST VOID *)GuidedEventContext, NsCommBufferSize); | ||
|
||
Status = mMmst->MmFreePool ((VOID *)GuidedEventContext); | ||
if (Status != EFI_SUCCESS) { | ||
return EFI_OUT_OF_RESOURCES; | ||
if (!FixedPcdGetBool (PcdRuntimeMemoryOnHeap)) { | ||
CopyMem ((VOID *)NsCommBufferAddr, (CONST VOID *)GuidedEventContext, NsCommBufferSize); | ||
|
||
Status = mMmst->MmFreePool ((VOID *)GuidedEventContext); | ||
if (Status != EFI_SUCCESS) { | ||
return EFI_OUT_OF_RESOURCES; | ||
} | ||
} | ||
|
||
PerCpuGuidedEventContext[CpuNumber] = NULL; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use the same code maximum for XIP and non-XIP images?
Similar code flow is in MdeModulePkg/Core/Pei/Image/Image.c: LoadAndRelocatePeCoffImage().