Skip to content

Commit

Permalink
MdeModulePkg/DxeCore: Avoid assertion in CoreLocateProtocol
Browse files Browse the repository at this point in the history
The patch uses CoreAcquireLockOrFail() instead of
CoreAcquireProtocolLock() in CoreLocateProtocol() to avoid
assertion when CoreLocateProtocol() is called with the
protocol database locked.

The issue was found when changing PcdDebugPrintErrorLevel to
enable page/pool allocation debug message.
Nt32 platform hangs immediately after DxeCore is loaded.
Investigation shows the following calling stacks:

DxeCore entry point (Install a certain protocol)
0 DxeCore::CoreInstallProtocolInterface  // Protocol DB is locked
1 DxeCore::AllocatePool
2 PeiDxeDebugLibReportStatusCode::DebugPrint
3 DxeReportStatusCodeLib::ReportStatusCodeEx // <-------------------|
4 DxeReportStatusCodeLib::InternalGetReportStatusCode               |
5 DxeCore::LocateProtocol(StatusCodeRuntimeProtocol)                |
                     // Assertion when locking Protocol DB 2nd time |
6 DxeCore::CoreAcquireProtocolLock                                  |
7 PeiDxeDebugLibReportStatusCode::DebugAssert                       |
8 DxeReportStatusCodeLib::ReportSatusCodeEx  // loop begins ---------

In frame #6 the assertion is triggered due to the protocol database
is already locked. #8 calls #4 and the loop begins.
After changing #6 to CoreAcquireLockOrFail(), the assertion is
avoided and the loop is broken.

With the fix, NT32 can boot to Shell even setting
PcdDebugPrintErrorLevel to 0xFFFFFFFF, with all error levels turned
on.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ruiyu Ni <[email protected]>
Reviewed-by: Liming Gao <[email protected]>
  • Loading branch information
niruiyu committed Apr 25, 2016
1 parent f447df5 commit ae6945b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions MdeModulePkg/Core/Dxe/Hand/Locate.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @file
Locate handle functions
Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
Expand Down Expand Up @@ -581,7 +581,10 @@ CoreLocateProtocol (
//
// Lock the protocol database
//
CoreAcquireProtocolLock ();
Status = CoreAcquireLockOrFail (&gProtocolDatabaseLock);
if (EFI_ERROR (Status)) {
return EFI_NOT_FOUND;
}

mEfiLocateHandleRequest += 1;

Expand Down

0 comments on commit ae6945b

Please sign in to comment.