[edk2-devel] [PATCH v4] MdeModulePkg/Universal/StatusCodeHandler: Fix a bug about log lost

Tan, Ming posted 1 patch 3 years, 4 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/edk2 tags/patchew/20201217062043.1358-1-ming.tan@intel.com
There is a newer version of this series
.../RuntimeDxe/SerialStatusCodeWorker.c          | 16 ++++++++++++++++
.../RuntimeDxe/StatusCodeHandlerRuntimeDxe.c     | 16 +---------------
2 files changed, 17 insertions(+), 15 deletions(-)
[edk2-devel] [PATCH v4] MdeModulePkg/Universal/StatusCodeHandler: Fix a bug about log lost
Posted by Tan, Ming 3 years, 4 months ago
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3126

1. If use PeiDxeDebugLibReportStatusCode as DebugLib, then some logs
after ExitBootService() will be lost.
2. The root cause:
2.1 The original code will register an unregister function
of gEfiEventExitBootServicesGuid, this unregister function will call
EFI_RSC_HANDLER_PROTOCOL->Unregister and does not support log through
serial port.
2.2 And some other drivers also register call back funtions of
gEfiEventExitBootServicesGuid.
2.3 Then after the unregister function is called, other call back
functions can't out log if them use RSC as DebugLib.
3. The DxeMain will report status code EFI_SW_BS_PC_EXIT_BOOT_SERVICES
after notify all the call back functions of
gEfiEventExitBootServicesGuid.
4. Solution: the StatusCodeHandlerRuntimeDxe.c will not register an
unregister function of gEfiEventExitBootServicesGuid, but unregister it
after receive the status code of EFI_SW_BS_PC_EXIT_BOOT_SERVICES.

Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Ming Tan <ming.tan@intel.com>
---
V4: Fix a spell bug in code comment, change 'a' to 'an' before 'unregister'.
V3: Fix a spell bug in commit message, change 'a' to 'an' before 'unregister'.
V2: Add the REF link in commit message.

 .../RuntimeDxe/SerialStatusCodeWorker.c          | 16 ++++++++++++++++
 .../RuntimeDxe/StatusCodeHandlerRuntimeDxe.c     | 16 +---------------
 2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/SerialStatusCodeWorker.c b/MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/SerialStatusCodeWorker.c
index 0b98e7ec63..4816cf047f 100644
--- a/MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/SerialStatusCodeWorker.c
+++ b/MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/SerialStatusCodeWorker.c
@@ -8,6 +8,12 @@
 
 #include "StatusCodeHandlerRuntimeDxe.h"
 
+VOID
+EFIAPI
+UnregisterBootTimeHandlers (
+  VOID
+  );
+
 /**
   Convert status code value and extended data to readable ASCII string, send string to serial I/O device.
 
@@ -151,6 +157,16 @@ SerialStatusCodeReportWorker (
   //
   SerialPortWrite ((UINT8 *) Buffer, CharCount);
 
+  //
+  // If register an unregister function of gEfiEventExitBootServicesGuid,
+  // then some log called in ExitBootServices() will be lost,
+  // so unregister the handler after receive the value of exit boot service.
+  //
+  if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE &&
+      Value == (EFI_SOFTWARE_EFI_BOOT_SERVICE | EFI_SW_BS_PC_EXIT_BOOT_SERVICES)) {
+    UnregisterBootTimeHandlers();
+  }
+
   return EFI_SUCCESS;
 }
 
diff --git a/MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.c b/MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.c
index a8c0fe5b71..011d03f01b 100644
--- a/MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.c
+++ b/MdeModulePkg/Universal/StatusCodeHandler/RuntimeDxe/StatusCodeHandlerRuntimeDxe.c
@@ -17,16 +17,11 @@ EFI_RSC_HANDLER_PROTOCOL  *mRscHandlerProtocol       = NULL;
   Unregister status code callback functions only available at boot time from
   report status code router when exiting boot services.
 
-  @param  Event         Event whose notification function is being invoked.
-  @param  Context       Pointer to the notification function's context, which is
-                        always zero in current implementation.
-
 **/
 VOID
 EFIAPI
 UnregisterBootTimeHandlers (
-  IN EFI_EVENT        Event,
-  IN VOID             *Context
+  VOID
   )
 {
   if (PcdGetBool (PcdStatusCodeUseSerial)) {
@@ -178,15 +173,6 @@ StatusCodeHandlerRuntimeDxeEntry (
     mRscHandlerProtocol->Register (RtMemoryStatusCodeReportWorker, TPL_HIGH_LEVEL);
   }
 
-  Status = gBS->CreateEventEx (
-                  EVT_NOTIFY_SIGNAL,
-                  TPL_NOTIFY,
-                  UnregisterBootTimeHandlers,
-                  NULL,
-                  &gEfiEventExitBootServicesGuid,
-                  &mExitBootServicesEvent
-                  );
-
   Status = gBS->CreateEventEx (
                   EVT_NOTIFY_SIGNAL,
                   TPL_NOTIFY,
-- 
2.24.0.windows.2



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