Skip to content

Commit

Permalink
Fixed and cleaned up the testpoint stub for MM
Browse files Browse the repository at this point in the history
  • Loading branch information
kenlautner committed Sep 19, 2023
1 parent 7f872ca commit 09f2af5
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 165 deletions.
9 changes: 3 additions & 6 deletions MinPlatformPkg/Include/Library/TestPointLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,9 @@ typedef struct {
// On output, actual data buffer size copied.
//
UINT64 DataSize;
//PHYSICAL_ADDRESS DataBuffer;
//
// On input, data buffer offset to copy.
// On output, next time data buffer offset to copy.
//
//UINT64 DataOffset;
// Empty array that represents the start of the
// data being stored in the comm buffer we're getting
// from the MM environment.
UINT8 Data[];
} MMI_HANDLER_TEST_POINT_PARAMETER_GET_DATA_BY_OFFSET;

Expand Down
52 changes: 15 additions & 37 deletions MinPlatformPkg/Test/Library/TestPointLib/MmTestPointCommunication.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,29 +207,22 @@ MmiHandlerTestPointCopyData (
**/
VOID
MmTestPointMmiHandlerGetDataByOffset (
IN MMI_HANDLER_TEST_POINT_PARAMETER_GET_DATA_BY_OFFSET *MmiHandlerTestPointParameterGetDataByOffset
IN VOID *MmiHandlerTestPointParameterGetDataByOffset
)
{
MMI_HANDLER_TEST_POINT_PARAMETER_GET_DATA_BY_OFFSET MmiHandlerTestPointGetDataByOffset;
MMI_HANDLER_TEST_POINT_PARAMETER_GET_DATA_BY_OFFSET *MmiHandlerTestPointGetDataByOffset;
VOID *Data;
UINTN DataSize;
EFI_STATUS Status;

Data = NULL;

CopyMem (
&MmiHandlerTestPointGetDataByOffset,
MmiHandlerTestPointParameterGetDataByOffset,
MmiHandlerTestPointParameterGetDataByOffset->DataSize
);

DEBUG((DEBUG_ERROR, "Struct Buffer Address: %x\n", (UINTN)MmiHandlerTestPointParameterGetDataByOffset));
DEBUG((DEBUG_ERROR, "Struct Data Buffer Address: %x\n", (UINTN)(MmiHandlerTestPointParameterGetDataByOffset->Data)));
DEBUG((DEBUG_ERROR, "STRUCTSIZE: %x\n", sizeof(MMI_HANDLER_TEST_POINT_PARAMETER_GET_DATA_BY_OFFSET)));
MmiHandlerTestPointGetDataByOffset = (MMI_HANDLER_TEST_POINT_PARAMETER_GET_DATA_BY_OFFSET *)MmiHandlerTestPointParameterGetDataByOffset;

//
// Sanity check
//
// MU_CHANGE - Removing Sanity check as we are now completely working within the comm buffer
/*if (!IsBufferOutsideMmValid((UINTN)&MmiHandlerTestPointParameterGetDataByOffset->Data[0], (UINTN)*Size)) {
DEBUG((DEBUG_ERROR, "MmTestPointMmiHandlerGetDataByOffset: MmTestPoint get data in SMRAM or overflow!\n"));
MmiHandlerTestPointParameterGetDataByOffset->ReturnStatus = (UINT64)(INT64)(INTN)EFI_ACCESS_DENIED;
Expand All @@ -239,17 +232,17 @@ MmTestPointMmiHandlerGetDataByOffset (
DataSize = 0;
Status = GetAllMmTestPointData (&DataSize, NULL);
if (Status != EFI_BUFFER_TOO_SMALL) {
MmiHandlerTestPointParameterGetDataByOffset->Header.ReturnStatus = (UINT64)(INT64)(INTN)EFI_NOT_FOUND;
MmiHandlerTestPointGetDataByOffset->Header.ReturnStatus = (UINT64)(INT64)(INTN)EFI_NOT_FOUND;
goto Done;
}
Data = AllocatePool (DataSize);
if (Data == NULL) {
MmiHandlerTestPointParameterGetDataByOffset->Header.ReturnStatus = (UINT64)(INT64)(INTN)EFI_OUT_OF_RESOURCES;
MmiHandlerTestPointGetDataByOffset->Header.ReturnStatus = (UINT64)(INT64)(INTN)EFI_OUT_OF_RESOURCES;
goto Done;
}
Status = GetAllMmTestPointData (&DataSize, Data);
if (EFI_ERROR(Status)) {
MmiHandlerTestPointParameterGetDataByOffset->Header.ReturnStatus = (UINT64)(INT64)(INTN)Status;
MmiHandlerTestPointGetDataByOffset->Header.ReturnStatus = (UINT64)(INT64)(INTN)Status;
goto Done;
}

Expand All @@ -259,27 +252,14 @@ MmTestPointMmiHandlerGetDataByOffset (
// MmiHandlerTestPointCopyData().
//
SpeculationBarrier ();
DEBUG((DEBUG_ERROR, "InputSize: %x\n", DataSize));
/*CopyMem (
(VOID *)MmiHandlerTestPointGetDataByOffset.Data,
Data,
DataSize
);*/
/*MmiHandlerTestPointCopyData (
Data,
DataSize,
(VOID *)(UINTN)MmiHandlerTestPointGetDataByOffset.Data,
&(MmiHandlerTestPointGetDataByOffset.DataSize),
0
);*/
DEBUG((DEBUG_ERROR, "DO WE GET HERE?\n"));

CopyMem (
(VOID *)(UINTN)MmiHandlerTestPointParameterGetDataByOffset->Data,
MmiHandlerTestPointGetDataByOffset->Data,
Data,
DataSize
);

MmiHandlerTestPointParameterGetDataByOffset->Header.ReturnStatus = 0;
MmiHandlerTestPointGetDataByOffset->Header.ReturnStatus = 0;

Done:
if (Data != NULL) {
Expand Down Expand Up @@ -312,6 +292,7 @@ MmTestPointMmiHandler (
)
{
MMI_HANDLER_TEST_POINT_PARAMETER_HEADER *MmiHandlerTestPointParameterHeader;
MMI_HANDLER_TEST_POINT_PARAMETER_GET_DATA_BY_OFFSET *MmiHandlerTestPointParameterOffset;
UINTN TempCommBufferSize;

DEBUG((DEBUG_INFO, "MmTestPointMmiHandler Enter\n"));
Expand All @@ -325,10 +306,6 @@ MmTestPointMmiHandler (

TempCommBufferSize = *CommBufferSize;

DEBUG((DEBUG_ERROR, "CommBuffer Real Address: %x\n", (UINTN)CommBuffer));

DEBUG((DEBUG_ERROR, "CommBufferSize: %x, Struct size: %x\n", TempCommBufferSize, sizeof(MMI_HANDLER_TEST_POINT_PARAMETER_GET_DATA_BY_OFFSET)));

if (TempCommBufferSize < sizeof(MMI_HANDLER_TEST_POINT_PARAMETER_HEADER)) {
DEBUG((DEBUG_INFO, "MmTestPointMmiHandler: MM communication buffer size invalid!\n"));
return EFI_SUCCESS;
Expand All @@ -353,11 +330,12 @@ MmTestPointMmiHandler (
break;
case MMI_HANDLER_TEST_POINT_COMMAND_GET_DATA_BY_OFFSET:
DEBUG((DEBUG_INFO, "MmiHandlerTestPointHandlerGetDataByOffset\n"));
/*if (TempCommBufferSize != sizeof(MMI_HANDLER_TEST_POINT_PARAMETER_HEADER)) {
MmiHandlerTestPointParameterOffset = (MMI_HANDLER_TEST_POINT_PARAMETER_GET_DATA_BY_OFFSET *)CommBuffer;
if (TempCommBufferSize != (sizeof(MMI_HANDLER_TEST_POINT_PARAMETER_GET_DATA_BY_OFFSET) + MmiHandlerTestPointParameterOffset->DataSize)) {
DEBUG((DEBUG_INFO, "MmTestPointMmiHandler: MM communication buffer size invalid!\n"));
return EFI_SUCCESS;
}*/
MmTestPointMmiHandlerGetDataByOffset((MMI_HANDLER_TEST_POINT_PARAMETER_GET_DATA_BY_OFFSET *)(UINTN)CommBuffer);
}
MmTestPointMmiHandlerGetDataByOffset(CommBuffer);
break;
default:
break;
Expand Down
Loading

0 comments on commit 09f2af5

Please sign in to comment.