StandaloneMmPkg/Core: Shadow Standalone BFV into MMRAM

BFV is outside the MMRAM. Currently, StandaloneMmIplPei uses the API
MmUnblockMemoryRequest() to unblock the access for the BFV. However,
the BFV's memory might be gone after ExitBootService event. If any
access to the memory, unexpected error would happen.
To fix the above issue, StandaloneMmCore should shadow standalone BFV
into MMRAM before processing it, then free the shadowed BFV after MM
driver dispatch is done.

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Signed-off-by: Wei6 Xu <wei6.xu@intel.com>
This commit is contained in:
Wei6 Xu 2024-10-21 10:13:54 +08:00 committed by mergify[bot]
parent 11d4edc7c6
commit 56dfab9a8a
4 changed files with 28 additions and 17 deletions

View File

@ -766,6 +766,13 @@ MmDriverDispatchHandler (
MmiHandlerUnRegister (DispatchHandle);
//
// Free shadowed standalone BFV
//
if (mBfv != NULL) {
FreePool (mBfv);
}
return EFI_SUCCESS;
}

View File

@ -83,9 +83,10 @@ MM_CORE_MMI_HANDLERS mMmCoreMmiHandlers[] = {
{ NULL, NULL, NULL, FALSE },
};
BOOLEAN mMmEntryPointRegistered = FALSE;
MM_COMM_BUFFER *mMmCommunicationBuffer;
VOID *mInternalCommBufferCopy;
BOOLEAN mMmEntryPointRegistered = FALSE;
MM_COMM_BUFFER *mMmCommunicationBuffer;
VOID *mInternalCommBufferCopy;
EFI_FIRMWARE_VOLUME_HEADER *mBfv = NULL;
/**
Place holder function until all the MM System Table Service are available.
@ -844,9 +845,19 @@ StandaloneMmMain (
// Dispatch standalone BFV
//
if (BfvHob->BaseAddress != 0) {
DEBUG ((DEBUG_INFO, "Mm Dispatch StandaloneBfvAddress - 0x%08x\n", BfvHob->BaseAddress));
MmCoreFfsFindMmDriver ((EFI_FIRMWARE_VOLUME_HEADER *)(UINTN)BfvHob->BaseAddress, 0);
MmDispatcher ();
//
// Shadow standalone BFV into MMRAM
//
mBfv = AllocatePool (BfvHob->Length);
if (mBfv != NULL) {
CopyMem ((VOID *)mBfv, (VOID *)(UINTN)BfvHob->BaseAddress, BfvHob->Length);
DEBUG ((DEBUG_INFO, "Mm Dispatch StandaloneBfvAddress - 0x%08x\n", mBfv));
MmCoreFfsFindMmDriver (mBfv, 0);
MmDispatcher ();
if (!FeaturePcdGet (PcdRestartMmDispatcherOnceMmEntryRegistered)) {
FreePool (mBfv);
}
}
}
}

View File

@ -178,9 +178,10 @@ typedef struct {
//
// MM Core Global Variables
//
extern EFI_MM_SYSTEM_TABLE gMmCoreMmst;
extern LIST_ENTRY gHandleList;
extern BOOLEAN mMmEntryPointRegistered;
extern EFI_MM_SYSTEM_TABLE gMmCoreMmst;
extern LIST_ENTRY gHandleList;
extern BOOLEAN mMmEntryPointRegistered;
extern EFI_FIRMWARE_VOLUME_HEADER *mBfv;
/**
Called to initialize the memory service.

View File

@ -513,14 +513,6 @@ ExecuteMmCoreFromMmram (
Status = LocateMmCoreFv (&MmFvBase, &MmFvSize, &MmCoreFileName, &ImageContext.Handle);
ASSERT_EFI_ERROR (Status);
//
// Unblock the MM FV range to be accessible from inside MM
//
if ((MmFvBase != 0) && (MmFvSize != 0)) {
Status = MmUnblockMemoryRequest (MmFvBase, EFI_SIZE_TO_PAGES (MmFvSize));
ASSERT_EFI_ERROR (Status);
}
//
// Initialize ImageContext
//