[edk2-devel] [PATCH v5 22/38] MdeModulePkg/PcdPeim: Permit unshadowed execution

Ard Biesheuvel posted 38 patches 1 year, 3 months ago
[edk2-devel] [PATCH v5 22/38] MdeModulePkg/PcdPeim: Permit unshadowed execution
Posted by Ard Biesheuvel 1 year, 3 months ago
PEIM shadowing is optional, but the PCD PEIM does so explicitly,
seemingly without a functional need. So make this behavior dependent on
the existing PCD, which is generally (and by default) set to TRUE,
whereas some systems (such as ARM virtual machines) may prefer to
disable shadowing.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 MdeModulePkg/Universal/PCD/Pei/Pcd.c   | 112 ++++++++++----------
 MdeModulePkg/Universal/PCD/Pei/Pcd.inf |   1 +
 2 files changed, 58 insertions(+), 55 deletions(-)

diff --git a/MdeModulePkg/Universal/PCD/Pei/Pcd.c b/MdeModulePkg/Universal/PCD/Pei/Pcd.c
index c51ac96a32e3..632254f1c5fa 100644
--- a/MdeModulePkg/Universal/PCD/Pei/Pcd.c
+++ b/MdeModulePkg/Universal/PCD/Pei/Pcd.c
@@ -346,73 +346,75 @@ PcdPeimInit (
 {
   EFI_STATUS  Status;
 
-  Status = PeiServicesRegisterForShadow (FileHandle);
-  if (Status == EFI_ALREADY_STARTED) {
-    //
-    // This is now starting in memory, the second time starting.
-    //
-    EFI_PEI_PPI_DESCRIPTOR  *OldPpiList;
-    EFI_PEI_PPI_DESCRIPTOR  *OldPpiList2;
-    VOID                    *Ppi;
-    VOID                    *Ppi2;
+  if (PcdGetBool (PcdShadowPeimOnBoot)) {
+    Status = PeiServicesRegisterForShadow (FileHandle);
+    if (Status == EFI_ALREADY_STARTED) {
+      //
+      // This is now starting in memory, the second time starting.
+      //
+      EFI_PEI_PPI_DESCRIPTOR  *OldPpiList;
+      EFI_PEI_PPI_DESCRIPTOR  *OldPpiList2;
+      VOID                    *Ppi;
+      VOID                    *Ppi2;
 
-    OldPpiList = NULL;
-    Status     = PeiServicesLocatePpi (
-                   &gPcdPpiGuid,
-                   0,
-                   &OldPpiList,
-                   &Ppi
-                   );
-    ASSERT_EFI_ERROR (Status);
-
-    if (OldPpiList != NULL) {
-      Status = PeiServicesReInstallPpi (OldPpiList, &mPpiList[0]);
+      OldPpiList = NULL;
+      Status     = PeiServicesLocatePpi (
+                     &gPcdPpiGuid,
+                     0,
+                     &OldPpiList,
+                     &Ppi
+                     );
       ASSERT_EFI_ERROR (Status);
-    }
 
-    OldPpiList2 = NULL;
-    Status      = PeiServicesLocatePpi (
-                    &gGetPcdInfoPpiGuid,
-                    0,
-                    &OldPpiList2,
-                    &Ppi2
-                    );
-    ASSERT_EFI_ERROR (Status);
+      if (OldPpiList != NULL) {
+        Status = PeiServicesReInstallPpi (OldPpiList, &mPpiList[0]);
+        ASSERT_EFI_ERROR (Status);
+      }
 
-    if (OldPpiList2 != NULL) {
-      Status = PeiServicesReInstallPpi (OldPpiList2, &mPpiList2[0]);
+      OldPpiList2 = NULL;
+      Status      = PeiServicesLocatePpi (
+                      &gGetPcdInfoPpiGuid,
+                      0,
+                      &OldPpiList2,
+                      &Ppi2
+                      );
       ASSERT_EFI_ERROR (Status);
-    }
 
-    OldPpiList = NULL;
-    Status     = PeiServicesLocatePpi (
-                   &gEfiPeiPcdPpiGuid,
-                   0,
-                   &OldPpiList,
-                   &Ppi
-                   );
-    ASSERT_EFI_ERROR (Status);
+      if (OldPpiList2 != NULL) {
+        Status = PeiServicesReInstallPpi (OldPpiList2, &mPpiList2[0]);
+        ASSERT_EFI_ERROR (Status);
+      }
 
-    if (OldPpiList != NULL) {
-      Status = PeiServicesReInstallPpi (OldPpiList, &mPpiList[1]);
+      OldPpiList = NULL;
+      Status     = PeiServicesLocatePpi (
+                     &gEfiPeiPcdPpiGuid,
+                     0,
+                     &OldPpiList,
+                     &Ppi
+                     );
       ASSERT_EFI_ERROR (Status);
-    }
 
-    OldPpiList2 = NULL;
-    Status      = PeiServicesLocatePpi (
-                    &gEfiGetPcdInfoPpiGuid,
-                    0,
-                    &OldPpiList2,
-                    &Ppi2
-                    );
-    ASSERT_EFI_ERROR (Status);
+      if (OldPpiList != NULL) {
+        Status = PeiServicesReInstallPpi (OldPpiList, &mPpiList[1]);
+        ASSERT_EFI_ERROR (Status);
+      }
 
-    if (OldPpiList2 != NULL) {
-      Status = PeiServicesReInstallPpi (OldPpiList2, &mPpiList2[1]);
+      OldPpiList2 = NULL;
+      Status      = PeiServicesLocatePpi (
+                      &gEfiGetPcdInfoPpiGuid,
+                      0,
+                      &OldPpiList2,
+                      &Ppi2
+                      );
       ASSERT_EFI_ERROR (Status);
-    }
 
-    return Status;
+      if (OldPpiList2 != NULL) {
+        Status = PeiServicesReInstallPpi (OldPpiList2, &mPpiList2[1]);
+        ASSERT_EFI_ERROR (Status);
+      }
+
+      return Status;
+    }
   }
 
   BuildPcdDatabase (FileHandle);
diff --git a/MdeModulePkg/Universal/PCD/Pei/Pcd.inf b/MdeModulePkg/Universal/PCD/Pei/Pcd.inf
index 7152a7d53b7d..a820ace70ec2 100644
--- a/MdeModulePkg/Universal/PCD/Pei/Pcd.inf
+++ b/MdeModulePkg/Universal/PCD/Pei/Pcd.inf
@@ -343,6 +343,7 @@ [Pcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdMaxPeiPcdCallBackNumberPerPcdEntry ## SOMETIMES_CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdNvStoreDefaultValueBuffer ## SOMETIMES_CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdSetNvStoreDefaultId       ## CONSUMES
+  gEfiMdeModulePkgTokenSpaceGuid.PcdShadowPeimOnBoot          ## CONSUMES
 
 [Depex]
   TRUE
-- 
2.39.2



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#101126): https://edk2.groups.io/g/devel/message/101126
Mute This Topic: https://groups.io/mt/97586027/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-