Skip to content

Commit

Permalink
Add PeiCore method to find AdvancedLogger log buffer if LoggerInfo is… (
Browse files Browse the repository at this point in the history
#389)

## Description

This was discovered in a platform that uses AdvancedLogger Starting in
Pei, but without permanent memory until after MRC runs.
(i.e. AdvancedLoggerLib PeiCore instance allocates CAR heap for the log
buffer)

The platform makes uses of EFI_PEI_TEMPORARY_RAM_DONE_PPI, where is
tears down all variable range MTRRs.

When PeiCore is reentered after memory has become available, it will
relocate Hobs to system memory, then it will go through the Hobs and fix
up the memory allocation pointers to point to the system memory
addresses instead of the Heap addresses.

During this transition, the PlatformBlob pointer will become invalid,
after CAR is torn down.

During the PeiCore's `PeiServicesInstallPpi (&mMemoryDiscoveredPpi);`, a
debug message will attempt to be output about the `Install PPI: ` of the
Memory Discovered Ppi, and the current logic will attempt to use the
PlatformBlob, which results in a memory exception (the pointer is all
Fs).

This PR updates the logic in `AdvancedLoggerGetLoggerInfo` to verify the
PlatformBlob pointer contains the correct signature before returning it,
and if that fails, it then will go through Memory Allocation Hobs to try
to find a memory allocation that corresponds to the AdvancedLogger
buffer. If it fails, it will fall through to the existing functionality
of creating a new allocation hob.

For each item, place an "x" in between `[` and `]` if true. Example:
`[x]`.
_(you can also check items in the GitHub UI)_

- [x] Impacts functionality?
- **Functionality** - Does the change ultimately impact how firmware
functions?
- Examples: Add a new library, publish a new PPI, update an algorithm,
...
- [ ] Impacts security?
- **Security** - Does the change have a direct security impact on an
application,
    flow, or firmware?
  - Examples: Crypto algorithm change, buffer overflow fix, parameter
    validation improvement, ...
- [ ] Breaking change?
- **Breaking change** - Will anyone consuming this change experience a
break
    in build or boot behavior?
- Examples: Add a new library class, move a module to a different repo,
call
    a function in a new library class in a pre-existing module, ...
- [ ] Includes tests?
  - **Tests** - Does the change include any explicit test code?
  - Examples: Unit tests, integration tests, robot tests, ...
- [ ] Includes documentation?
- **Documentation** - Does the change contain explicit documentation
additions
    outside direct code modifications (and comments)?
- Examples: Update readme file, add feature readme file, link to
documentation
    on an a separate Web page, ...

## How This Was Tested

Verified that the system that was triggering an exception was able to
function correctly after this change was incorporated.

## Integration Instructions

N/A
  • Loading branch information
apop5 authored Dec 21, 2023
1 parent 066c9b8 commit 710c922
Showing 1 changed file with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,38 @@ UpdateSecLoggerInfo (
}
}

/**
RecoverLogBufferFromHobs
Search the HOBs for a memory allocation with a valid logger
signature, and return it if found.
**/
STATIC
ADVANCED_LOGGER_INFO *
RecoverLogBufferFromHobs (
VOID
)
{
ADVANCED_LOGGER_INFO *LoggerInfo;
EFI_PEI_HOB_POINTERS Hob;

Hob.Raw = GetHobList ();

while ((Hob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, Hob.Raw)) != NULL) {
// Go through Allocation Hobs, attempting to find an allocation that matches
// the expected Advanced Logger Signature
LoggerInfo = ALI_FROM_PA (Hob.MemoryAllocation->AllocDescriptor.MemoryBaseAddress);
if (LoggerInfo->Signature == ADVANCED_LOGGER_SIGNATURE) {
return LoggerInfo;
}

Hob.Raw = GET_NEXT_HOB (Hob);
}

return NULL;
}

/**
Get the Logger Information block
Expand Down Expand Up @@ -436,11 +468,27 @@ AdvancedLoggerGetLoggerInfo (

PeiCoreInstance = PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices);
LoggerInfo = ALI_FROM_PA (PeiCoreInstance->PlatformBlob);
if (LoggerInfo != NULL) {
if ((LoggerInfo != NULL) && (LoggerInfo->Signature == ADVANCED_LOGGER_SIGNATURE)) {
// Logger Info was saved from an earlier call - Return LoggerInfo.
return LoggerInfo;
}

// If the fast methods of locating logger info have failed, check the
// Hob list to see if a allocation hob exists with valid logger info.
// This is specific to the PeiCore being the start of advanced logger support
GuidHob = GetFirstGuidHob (&gAdvancedLoggerHobGuid);
if (GuidHob != NULL) {
LoggerInfo = RecoverLogBufferFromHobs ();
if (LoggerInfo != NULL) {
LogPtr = (ADVANCED_LOGGER_PTR *)GET_GUID_HOB_DATA (GuidHob);
(PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices))->PlatformBlob = PA_FROM_PTR (LoggerInfo);
LogPtr->LogBuffer = PA_FROM_PTR (LoggerInfo);

// return the pointer
return LoggerInfo;
}
}

//
// No Logger Info - this must be the time to allocate a new LoggerInfo and save
// the pointer in the PeiCoreInstance.
Expand Down

0 comments on commit 710c922

Please sign in to comment.