diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index 7ca4a1bb30..9272da89a9 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -100,6 +100,7 @@ SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf DisplayUpdateProgressLib|MdeModulePkg/Library/DisplayUpdateProgressLibGraphics/DisplayUpdateProgressLibGraphics.inf VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/VariablePolicyHelperLib.inf + MmUnblockMemoryLib|MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibNull.inf [LibraryClasses.EBC.PEIM] IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c index c47e614d81..a166d284df 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c @@ -35,6 +35,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include #include #include @@ -165,6 +166,7 @@ InitVariableCache ( ) { VARIABLE_STORE_HEADER *VariableCacheStorePtr; + EFI_STATUS Status; if (TotalVariableCacheSize == NULL) { return EFI_INVALID_PARAMETER; @@ -186,6 +188,18 @@ InitVariableCache ( if (*VariableCacheBuffer == NULL) { return EFI_OUT_OF_RESOURCES; } + + // + // Request to unblock the newly allocated cache region to be accessible from inside MM + // + Status = MmUnblockMemoryRequest ( + (EFI_PHYSICAL_ADDRESS) (UINTN) *VariableCacheBuffer, + EFI_SIZE_TO_PAGES (*TotalVariableCacheSize) + ); + if (Status != EFI_UNSUPPORTED && EFI_ERROR (Status)) { + return Status; + } + VariableCacheStorePtr = *VariableCacheBuffer; SetMem32 ((VOID *) VariableCacheStorePtr, *TotalVariableCacheSize, (UINT32) 0xFFFFFFFF); @@ -1536,6 +1550,34 @@ SendRuntimeVariableCacheContextToSmm ( SmmRuntimeVarCacheContext->ReadLock = &mVariableRuntimeCacheReadLock; SmmRuntimeVarCacheContext->HobFlushComplete = &mHobFlushComplete; + // + // Request to unblock this region to be accessible from inside MM environment + // These fields "should" be all on the same page, but just to be on the safe side... + // + Status = MmUnblockMemoryRequest ( + (EFI_PHYSICAL_ADDRESS) ALIGN_VALUE ((UINTN) SmmRuntimeVarCacheContext->PendingUpdate - EFI_PAGE_SIZE + 1, EFI_PAGE_SIZE), + EFI_SIZE_TO_PAGES (sizeof(mVariableRuntimeCachePendingUpdate)) + ); + if (Status != EFI_UNSUPPORTED && EFI_ERROR (Status)) { + goto Done; + } + + Status = MmUnblockMemoryRequest ( + (EFI_PHYSICAL_ADDRESS) ALIGN_VALUE ((UINTN) SmmRuntimeVarCacheContext->ReadLock - EFI_PAGE_SIZE + 1, EFI_PAGE_SIZE), + EFI_SIZE_TO_PAGES (sizeof(mVariableRuntimeCacheReadLock)) + ); + if (Status != EFI_UNSUPPORTED && EFI_ERROR (Status)) { + goto Done; + } + + Status = MmUnblockMemoryRequest ( + (EFI_PHYSICAL_ADDRESS) ALIGN_VALUE ((UINTN) SmmRuntimeVarCacheContext->HobFlushComplete - EFI_PAGE_SIZE + 1, EFI_PAGE_SIZE), + EFI_SIZE_TO_PAGES (sizeof(mHobFlushComplete)) + ); + if (Status != EFI_UNSUPPORTED && EFI_ERROR (Status)) { + goto Done; + } + // // Send data to SMM. // diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf index b6dbc839e0..a0d8b2267e 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf @@ -60,6 +60,7 @@ TpmMeasurementLib SafeIntLib PcdLib + MmUnblockMemoryLib [Protocols] gEfiVariableWriteArchProtocolGuid ## PRODUCES