]> xenbits.xensource.com Git - people/aperard/ovmf.git/commitdiff
MdeModulePkg/DxeCapsuleLibFmp: Check BootService Status to Use ESRT Cache
authorJason1 Lin <jason1.lin@intel.com>
Wed, 28 Aug 2024 09:36:11 +0000 (17:36 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 11 Sep 2024 20:26:20 +0000 (20:26 +0000)
- In c36414b131dfd0a1ca51f10f87a18955bc110ff2 change, it was introduced
  the ReadyToBoot event check to prevent the boot service got called
  in runtime to cause the issue.

- In this patch introduced the ExitBootService event to replace it.
  It would be better to base on the BootService status to decide
  the source of ESRT table.

- Based on the BootService availability to decide,
  - Exit    : Use cache ESRT table in IF-condition
  - Not Exit: Use boot service to locate protocol in ELSE-condition

Co-authored-by: Dakota Chiang <dakota.chiang@intel.com>
Signed-off-by: Jason1 Lin <jason1.lin@intel.com>
MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleRuntime.c
MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf

index 8befbae1de076ddbf34a448f215f8dbad2701ecb..edf927649ff1a94949923367bb8df42d7712aaad 100644 (file)
@@ -10,7 +10,7 @@
   ValidateFmpCapsule(), and DisplayCapsuleImage() receives untrusted input and\r
   performs basic validation.\r
 \r
-  Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2016 - 2024, Intel Corporation. All rights reserved.<BR>\r
   Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR>\r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
@@ -49,7 +49,7 @@ EFI_EVENT  mDxeCapsuleLibEndOfDxeEvent = NULL;
 \r
 EDKII_FIRMWARE_MANAGEMENT_PROGRESS_PROTOCOL  *mFmpProgress = NULL;\r
 \r
-BOOLEAN  mDxeCapsuleLibReadyToBootEvent = FALSE;\r
+BOOLEAN  mDxeCapsuleLibIsExitBootService = FALSE;\r
 \r
 /**\r
   Initialize capsule related variables.\r
@@ -1396,25 +1396,17 @@ IsNestedFmpCapsule (
   EFI_SYSTEM_RESOURCE_ENTRY  Entry;\r
 \r
   EsrtGuidFound = FALSE;\r
-  if (mEsrtTable != NULL) {\r
-    EsrtEntry = (EFI_SYSTEM_RESOURCE_ENTRY *)(mEsrtTable + 1);\r
-    for (Index = 0; Index < mEsrtTable->FwResourceCount; Index++, EsrtEntry++) {\r
-      if (CompareGuid (&EsrtEntry->FwClass, &CapsuleHeader->CapsuleGuid)) {\r
-        EsrtGuidFound = TRUE;\r
-        break;\r
+  if (mDxeCapsuleLibIsExitBootService) {\r
+    if (mEsrtTable != NULL) {\r
+      EsrtEntry = (EFI_SYSTEM_RESOURCE_ENTRY *)(mEsrtTable + 1);\r
+      for (Index = 0; Index < mEsrtTable->FwResourceCount; Index++, EsrtEntry++) {\r
+        if (CompareGuid (&EsrtEntry->FwClass, &CapsuleHeader->CapsuleGuid)) {\r
+          EsrtGuidFound = TRUE;\r
+          break;\r
+        }\r
       }\r
     }\r
   } else {\r
-    if (mDxeCapsuleLibReadyToBootEvent) {\r
-      //\r
-      // The ESRT table (mEsrtTable) in the Configuration Table would be located\r
-      // at the ReadyToBoot event if it exists. Hence, it should return here to\r
-      // avoid a crash due to calling gBS->LocateProtocol () at runtime in case\r
-      // there is no ERST table installed.\r
-      //\r
-      return FALSE;\r
-    }\r
-\r
     //\r
     // Check ESRT protocol\r
     //\r
index 9bea682bee4c7e34e3395f060f91ff7c79e1ec95..34dc595dc8a47cc808523e6863822c23bf470024 100644 (file)
 #include <Library/MemoryAllocationLib.h>\r
 \r
 extern EFI_SYSTEM_RESOURCE_TABLE  *mEsrtTable;\r
+extern BOOLEAN                    mDxeCapsuleLibIsExitBootService;\r
 EFI_EVENT                         mDxeRuntimeCapsuleLibVirtualAddressChangeEvent = NULL;\r
 EFI_EVENT                         mDxeRuntimeCapsuleLibSystemResourceTableEvent  = NULL;\r
-EFI_EVENT                         mDxeRuntimeCapsuleLibReadyToBootEvent          = NULL;\r
-extern BOOLEAN                    mDxeCapsuleLibReadyToBootEvent;\r
+EFI_EVENT                         mDxeRuntimeCapsuleLibExitBootServiceEvent      = NULL;\r
 \r
 /**\r
   Convert EsrtTable physical address to virtual address.\r
@@ -107,7 +107,7 @@ DxeCapsuleLibSystemResourceTableInstallEventNotify (
 }\r
 \r
 /**\r
-  Notify function for event group EFI_EVENT_GROUP_READY_TO_BOOT.\r
+  Notify function for event of exit boot service.\r
 \r
   @param[in]  Event    The Event that is being processed.\r
   @param[in]  Context  The Event Context.\r
@@ -116,12 +116,12 @@ DxeCapsuleLibSystemResourceTableInstallEventNotify (
 STATIC\r
 VOID\r
 EFIAPI\r
-DxeCapsuleLibReadyToBootEventNotify (\r
+DxeCapsuleLibExitBootServiceEventNotify (\r
   IN EFI_EVENT  Event,\r
   IN VOID       *Context\r
   )\r
 {\r
-  mDxeCapsuleLibReadyToBootEvent = TRUE;\r
+  mDxeCapsuleLibIsExitBootService = TRUE;\r
 }\r
 \r
 /**\r
@@ -168,15 +168,15 @@ DxeRuntimeCapsuleLibConstructor (
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
-  // Register notify function to indicate the event is signaled at ReadyToBoot.\r
+  // Register notify function to indicate the event is signaled at ExitBootService.\r
   //\r
   Status = gBS->CreateEventEx (\r
                   EVT_NOTIFY_SIGNAL,\r
                   TPL_CALLBACK,\r
-                  DxeCapsuleLibReadyToBootEventNotify,\r
+                  DxeCapsuleLibExitBootServiceEventNotify,\r
                   NULL,\r
-                  &gEfiEventReadyToBootGuid,\r
-                  &mDxeRuntimeCapsuleLibReadyToBootEvent\r
+                  &gEfiEventExitBootServicesGuid,\r
+                  &mDxeRuntimeCapsuleLibExitBootServiceEvent\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
@@ -213,9 +213,9 @@ DxeRuntimeCapsuleLibDestructor (
   ASSERT_EFI_ERROR (Status);\r
 \r
   //\r
-  // Close the ReadyToBoot event.\r
+  // Close the ExitBootService event.\r
   //\r
-  Status = gBS->CloseEvent (mDxeRuntimeCapsuleLibReadyToBootEvent);\r
+  Status = gBS->CloseEvent (mDxeRuntimeCapsuleLibExitBootServiceEvent);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   return EFI_SUCCESS;\r
index bf56f4623f80f3a2895a2f894df6843f38170d13..ef1fa57c518226b4a7ece5486e139813562ce293 100644 (file)
@@ -3,7 +3,7 @@
 #\r
 #  Capsule library instance for DXE_RUNTIME_DRIVER module types.\r
 #\r
-#  Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2016 - 2024, Intel Corporation. All rights reserved.<BR>\r
 #  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
 ##\r
@@ -66,7 +66,7 @@
   gEfiCapsuleReportGuid\r
   gEfiCapsuleVendorGuid                   ## SOMETIMES_CONSUMES ## Variable:L"CapsuleUpdateData"\r
   gEfiEndOfDxeEventGroupGuid              ## CONSUMES ## Event\r
-  gEfiEventReadyToBootGuid                ## CONSUMES ## Event\r
+  gEfiEventExitBootServicesGuid           ## CONSUMES ## Event\r
   gEfiEventVirtualAddressChangeGuid       ## CONSUMES ## Event\r
   gEdkiiCapsuleOnDiskNameGuid             ## SOMETIMES_CONSUMES ## GUID\r
 \r