public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Kun Qin" <kun.q@outlook.com>
To: devel@edk2.groups.io
Cc: Jian J Wang <jian.j.wang@intel.com>,
	Hao A Wu <hao.a.wu@intel.com>,
	Liming Gao <gaoliming@byosoft.com.cn>
Subject: [PATCH v2 2/6] MdeModulePkg: VariableSmmRuntimeDxe: Added request unblock memory interface
Date: Tue,  9 Feb 2021 17:24:53 -0800	[thread overview]
Message-ID: <MWHPR06MB31027D3FF11ED164088E810FF38D9@MWHPR06MB3102.namprd06.prod.outlook.com> (raw)
In-Reply-To: <20210210012457.315-1-kun.q@outlook.com>

This changes added usage of DxeMmUnblockMemoryLib to explicitly request
runtime cache regions(and its indicators) to be accessible from MM
environment when PcdEnableVariableRuntimeCache is enabled. It will bring
in compatibility with architectures that supports full memory blockage
inside MM.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>

Signed-off-by: Kun Qin <kun.q@outlook.com>
---

Notes:
    v2:
    - Newly added in v2.

 MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c   | 42 ++++++++++++++++++++
 MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf |  1 +
 2 files changed, 43 insertions(+)

diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c
index c47e614d81f4..b96ca4b89ee4 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 <Library/DebugLib.h>
 #include <Library/UefiLib.h>
 #include <Library/BaseLib.h>
+#include <Library/DxeMmUnblockMemoryLib.h>
 
 #include <Guid/EventGroup.h>
 #include <Guid/SmmVariableCommon.h>
@@ -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 = DxeMmUnblockMemoryRequest (
+            (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 = DxeMmUnblockMemoryRequest (
+            (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 = DxeMmUnblockMemoryRequest (
+            (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 = DxeMmUnblockMemoryRequest (
+            (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 b6dbc839e023..b84a407833c2 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf
@@ -60,6 +60,7 @@ [LibraryClasses]
   TpmMeasurementLib
   SafeIntLib
   PcdLib
+  DxeMmUnblockMemoryLib
 
 [Protocols]
   gEfiVariableWriteArchProtocolGuid             ## PRODUCES
-- 
2.30.0.windows.1


  parent reply	other threads:[~2021-02-10  1:25 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20210210012457.315-1-kun.q@outlook.com>
2021-02-10  1:24 ` [PATCH v2 1/6] MdeModulePkg: DxeMmUnblockMemoryLib: Added definition and null instance Kun Qin
2021-02-22 22:15   ` Kun Qin
2021-02-23  1:42     ` Wu, Hao A
2021-02-23 19:29       ` [edk2-devel] " Kun Qin
2021-02-24  1:27         ` Wu, Hao A
2021-02-24  1:33           ` Yao, Jiewen
2021-02-24  1:48             ` Kun Qin
2021-02-25 14:03               ` 回复: " gaoliming
2021-02-25 18:57                 ` Kun Qin
     [not found]             ` <16668BE524C457EA.19172@groups.io>
2021-02-25  1:53               ` Kun Qin
2021-02-25  2:06                 ` Yao, Jiewen
2021-02-25  2:20                   ` Kun Qin
2021-02-10  1:24 ` Kun Qin [this message]
2021-02-10  1:24 ` [PATCH v2 3/6] SecurityPkg: Tcg2Smm: Switching from gSmst to gMmst Kun Qin
2021-02-24  1:20   ` Yao, Jiewen
2021-02-10  1:24 ` [PATCH v2 4/6] SecurityPkg: Tcg2Smm: Separate Tcg2Smm into 2 modules Kun Qin
2021-02-22 22:33   ` Kun Qin
2021-02-24  1:20   ` Yao, Jiewen
2021-02-10  1:24 ` [PATCH v2 5/6] SecurityPkg: Tcg2Smm: Added support for Standalone Mm Kun Qin
2021-02-24  1:26   ` Yao, Jiewen
2021-02-24  1:40     ` [edk2-devel] " Kun Qin
     [not found]     ` <16668B740798D6CC.26818@groups.io>
2021-02-25  2:26       ` Kun Qin
2021-03-01  8:28         ` Yao, Jiewen
2021-03-01  8:57           ` Kun Qin
2021-03-01  9:27             ` Yao, Jiewen
2021-03-01  9:45               ` Kun Qin
2021-02-10  1:24 ` [PATCH v2 6/6] SecurityPkg: Tcg2Acpi: Added unblock memory interface for NVS region Kun Qin
2021-02-24  1:24   ` Yao, Jiewen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=MWHPR06MB31027D3FF11ED164088E810FF38D9@MWHPR06MB3102.namprd06.prod.outlook.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox