Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REBASE && FF] Update Paging Audit File Collection to Defer Free/Allocate Calls, Fix SMM Parsing #450

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ extern MEMORY_PROTECTION_DEBUG_PROTOCOL *mMemoryProtectionProtocol;
- a count of each entry
- a count of each directory entry
- [optional] a flat list of each entry
- [optional] a flat list of each directory entry

@param[in, out] Pte1GCount, Pte2MCount, Pte4KCount, PdeCount
@param[in, out] Pte1GCount, Pte2MCount, Pte4KCount
On input, the number of entries that can fit in the corresponding buffer (if provided).
It is expected that this will be zero if the corresponding buffer is NULL.
On output, the number of entries that were encountered in the page table.
@param[out] Pte1GEntries, Pte2MEntries, Pte4KEntries, PdeEntries
@param[out] Pte1GEntries, Pte2MEntries, Pte4KEntries
A buffer which will be filled with the entries that are encountered in the tables.

@retval EFI_SUCCESS All requested data has been returned.
Expand All @@ -48,12 +47,10 @@ GetFlatPageTableData (
IN OUT UINTN *Pte1GCount,
IN OUT UINTN *Pte2MCount,
IN OUT UINTN *Pte4KCount,
IN OUT UINTN *PdeCount,
IN OUT UINTN *GuardCount,
OUT UINT64 *Pte1GEntries,
OUT UINT64 *Pte2MEntries,
OUT UINT64 *Pte4KEntries,
OUT UINT64 *PdeEntries,
OUT UINT64 *GuardEntries
)
{
Expand All @@ -67,7 +64,6 @@ GetFlatPageTableData (
UINT64 Index1 = 0;
UINT64 Index0 = 0;
UINTN MyGuardCount = 0;
UINTN MyPdeCount = 0;
UINTN My4KCount = 0;
UINTN My2MCount = 0;
UINTN My1GCount = 0;
Expand All @@ -78,25 +74,20 @@ GetFlatPageTableData (
UINT64 Address;

// Count parameters should be provided.
if ((Pte1GCount == NULL) || (Pte2MCount == NULL) || (Pte4KCount == NULL) || (PdeCount == NULL) || (GuardCount == NULL)) {
if ((Pte1GCount == NULL) || (Pte2MCount == NULL) || (Pte4KCount == NULL) || (GuardCount == NULL)) {
return EFI_INVALID_PARAMETER;
}

// If a count is greater than 0, the corresponding buffer pointer MUST be provided.
// It will be assumed that all buffers have space for any corresponding count.
if (((*Pte1GCount > 0) && (Pte1GEntries == NULL)) || ((*Pte2MCount > 0) && (Pte2MEntries == NULL)) ||
((*Pte4KCount > 0) && (Pte4KEntries == NULL)) || ((*PdeCount > 0) && (PdeEntries == NULL)) ||
((*GuardCount > 0) && (GuardEntries == NULL)))
((*Pte4KCount > 0) && (Pte4KEntries == NULL)) || ((*GuardCount > 0) && (GuardEntries == NULL)))
{
return EFI_INVALID_PARAMETER;
}

Pml0 = (UINT64 *)ArmGetTTBR0BaseAddress ();
RootEntryCount = ROOT_TABLE_LEN (ArmGetTCR () & TCR_T0SZ_MASK);
MyPdeCount++;
if (MyPdeCount <= *PdeCount) {
PdeEntries[MyPdeCount-1] = (UINT64)Pml0;
}

for (Index0 = 0x0; Index0 < RootEntryCount; Index0++) {
Index1 = 0;
Expand All @@ -108,11 +99,6 @@ GetFlatPageTableData (

Pte1G = (UINT64 *)(Pml0[Index0] & TT_ADDRESS_MASK);

MyPdeCount++;
if (MyPdeCount <= *PdeCount) {
PdeEntries[MyPdeCount-1] = (UINT64)Pte1G;
}

for (Index1 = 0x0; Index1 < TT_ENTRY_COUNT; Index1++ ) {
Index2 = 0;
Index3 = 0;
Expand All @@ -124,11 +110,6 @@ GetFlatPageTableData (
if (!IS_BLOCK (Pte1G[Index1], 1)) {
Pte2M = (UINT64 *)(Pte1G[Index1] & TT_ADDRESS_MASK);

MyPdeCount++;
if (MyPdeCount <= *PdeCount) {
PdeEntries[MyPdeCount-1] = (UINT64)Pte2M;
}

for (Index2 = 0x0; Index2 < TT_ENTRY_COUNT; Index2++ ) {
Index3 = 0;
if ((Pte2M[Index2] & 0x1) == 0) {
Expand All @@ -138,11 +119,6 @@ GetFlatPageTableData (

if (!IS_BLOCK (Pte2M[Index2], 2)) {
Pte4K = (UINT64 *)(Pte2M[Index2] & TT_ADDRESS_MASK);
MyPdeCount++;

if (MyPdeCount <= *PdeCount) {
PdeEntries[MyPdeCount-1] = (UINT64)Pte4K;
}

for (Index3 = 0x0; Index3 < TT_ENTRY_COUNT; Index3++ ) {
Address = IndexToAddress (Index0, Index1, Index2, Index3);
Expand Down Expand Up @@ -183,7 +159,6 @@ GetFlatPageTableData (
}
}

DEBUG ((DEBUG_ERROR, "Pages used for Page Tables = %d\n", MyPdeCount));
DEBUG ((DEBUG_ERROR, "Number of 4K Pages active = %d - NotPresent = %d\n", My4KCount - NumPage4KNotPresent, NumPage4KNotPresent));
DEBUG ((DEBUG_ERROR, "Number of 2M Pages active = %d - NotPresent = %d\n", My2MCount - NumPage2MNotPresent, NumPage2MNotPresent));
DEBUG ((DEBUG_ERROR, "Number of 1G Pages active = %d - NotPresent = %d\n", My1GCount - NumPage1GNotPresent, NumPage1GNotPresent));
Expand All @@ -194,8 +169,7 @@ GetFlatPageTableData (
// Only matters if a given buffer was provided.
//
if (((Pte1GEntries != NULL) && (*Pte1GCount < My1GCount)) || ((Pte2MEntries != NULL) && (*Pte2MCount < My2MCount)) ||
((Pte4KEntries != NULL) && (*Pte4KCount < My4KCount)) || ((PdeEntries != NULL) && (*PdeCount < MyPdeCount)) ||
((GuardEntries != NULL) && (*GuardCount < MyGuardCount)))
((Pte4KEntries != NULL) && (*Pte4KCount < My4KCount)) || ((GuardEntries != NULL) && (*GuardCount < MyGuardCount)))
{
Status = EFI_BUFFER_TOO_SMALL;
}
Expand All @@ -206,7 +180,6 @@ GetFlatPageTableData (
*Pte1GCount = My1GCount;
*Pte2MCount = My2MCount;
*Pte4KCount = My4KCount;
*PdeCount = MyPdeCount;
*GuardCount = MyGuardCount;

return Status;
Expand All @@ -229,21 +202,44 @@ CalculateMaximumSupportAddressBits (
/**
Dump platform specific handler. Created handler(s) need to be compliant with
Windows\PagingReportGenerator.py, i.e. TSEG.

@param[in] AllowAllocation If TRUE, then this function will allocate memory for the
database buffer if it is not large enough to hold the input
string. If FALSE, then this function will return an error
if the database buffer is not large enough to hold the input
string.
@param[out] StringLength The length of the string that was or would have been written
to the memory info database buffer.

@retval EFI_SUCCESS The platform specific info was successfully dumped to
the memory info database buffer.
@retval EFI_OUT_OF_RESOURCES The database buffer is not large enough to hold the
platform specific info and AllowAllocation is FALSE.
@retval EFI_NOT_STARTED The memory info database buffer has not been allocated.
@retval EFI_BUFFER_TOO_SMALL The database buffer is not large enough to hold the
platform specific info and AllowAllocation is FALSE.
@retval EFI_INVALID_PARAMETER StringLength is NULL.
**/
VOID
EFI_STATUS
EFIAPI
DumpProcessorSpecificHandlers (
VOID
IN BOOLEAN AllowAllocation,
OUT UINTN *StringLength
)
{
return;
return EFI_SUCCESS;
}

/**
Dumps platform info required to correctly parse the pages (architecture,
execution level, etc.)

@retval EFI_SUCCESS The platform info was successfully dumped to the associated
data file.
@retval EFI_ABORTED An error occurred while opening the SFS volume.
@retval Others The return value of CreateAndWriteFileSFS()
**/
VOID
EFI_STATUS
EFIAPI
DumpPlatforminfo (
VOID
Expand Down Expand Up @@ -281,5 +277,5 @@ DumpPlatforminfo (
(MemoryAttributeProtocol == NULL) ? "FALSE" : "TRUE"
);

WriteBufferToFile (L"PlatformInfo", TempString, StringIndex);
return WriteBufferToFile (L"PlatformInfo", TempString, StringIndex);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
// Aligns the input address down to the nearest page boundary
#define ALIGN_ADDRESS(Address) ((Address / EFI_PAGE_SIZE) * EFI_PAGE_SIZE)

// Globals required to create the memory info database
CHAR8 *mMemoryInfoDatabaseBuffer = NULL;
UINTN mMemoryInfoDatabaseSize = 0;
UINTN mMemoryInfoDatabaseAllocSize = 0;

// Globals for memory protection special regions
MEMORY_PROTECTION_SPECIAL_REGION *mSpecialRegions = NULL;
UINTN mSpecialRegionCount = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent

#include "../../PagingAuditCommon.h"

CHAR8 *mMemoryInfoDatabaseBuffer = NULL;
UINTN mMemoryInfoDatabaseSize = 0;
UINTN mMemoryInfoDatabaseAllocSize = 0;

/**
Event notification handler. Will dump paging information to disk.

Expand Down
Loading
Loading