summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei6 Xu <wei6.xu@intel.com>2024-10-21 10:13:54 +0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2024-10-30 02:16:14 +0000
commit56dfab9a8a143aa486d07eafc3d5a78bff540228 (patch)
treea79d836d9cb36d68064eb24e003fc945d7c982e1
parent11d4edc7c6dadd4992cb75e4581de5867590e694 (diff)
downloadedk2-56dfab9a8a143aa486d07eafc3d5a78bff540228.tar.gz
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>
-rw-r--r--StandaloneMmPkg/Core/Dispatcher.c7
-rw-r--r--StandaloneMmPkg/Core/StandaloneMmCore.c23
-rw-r--r--StandaloneMmPkg/Core/StandaloneMmCore.h7
-rw-r--r--StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c8
4 files changed, 28 insertions, 17 deletions
diff --git a/StandaloneMmPkg/Core/Dispatcher.c b/StandaloneMmPkg/Core/Dispatcher.c
index e55fdbabf2..8e6b85caee 100644
--- a/StandaloneMmPkg/Core/Dispatcher.c
+++ b/StandaloneMmPkg/Core/Dispatcher.c
@@ -766,6 +766,13 @@ MmDriverDispatchHandler (
MmiHandlerUnRegister (DispatchHandle);
+ //
+ // Free shadowed standalone BFV
+ //
+ if (mBfv != NULL) {
+ FreePool (mBfv);
+ }
+
return EFI_SUCCESS;
}
diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.c b/StandaloneMmPkg/Core/StandaloneMmCore.c
index 970a06045b..127248afab 100644
--- a/StandaloneMmPkg/Core/StandaloneMmCore.c
+++ b/StandaloneMmPkg/Core/StandaloneMmCore.c
@@ -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);
+ }
+ }
}
}
diff --git a/StandaloneMmPkg/Core/StandaloneMmCore.h b/StandaloneMmPkg/Core/StandaloneMmCore.h
index 093a35fb56..7bff1cde14 100644
--- a/StandaloneMmPkg/Core/StandaloneMmCore.h
+++ b/StandaloneMmPkg/Core/StandaloneMmCore.h
@@ -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.
diff --git a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c
index b1cd3c1d81..1a01d7a465 100644
--- a/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c
+++ b/StandaloneMmPkg/Drivers/StandaloneMmIplPei/StandaloneMmIplPei.c
@@ -514,14 +514,6 @@ ExecuteMmCoreFromMmram (
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
//
ImageContext.ImageRead = PeCoffLoaderImageReadFromMemory;