Skip to content

Commit 89f2ff1

Browse files
authored
MdeModulePkg: Refactor MM Services Tables linked in MM Core Perf Lib (#1369)
## Description The code used a `MmServicesTableLib` dependency for both the Standalone MM and Traditional MM instances and shared code between those. There is not a readily available `MmServicesTable` lib instance for Traditional SMM (that can link to `PiSmmCore`). To ease integration and prevent creating an instance just for this case, this change uses `SmmServicesTableLib` in the Traditional SMM instance and `MmServicesTableLib` in the Standalone MM instance and moves code as necessary to accommodate this. - [x] Impacts functionality? - [ ] Impacts security? - [ ] Breaking change? - [ ] Includes tests? - [ ] Includes documentation? - [x] Backport to release branch? ## How This Was Tested - Tested Standalone MM on Qemu Q35 and Traditional MM on OvmfPkg X64. ## Integration Instructions N/A Signed-off-by: Michael Kubacki <[email protected]>
1 parent 0ef6116 commit 89f2ff1

File tree

5 files changed

+236
-65
lines changed

5 files changed

+236
-65
lines changed

MdeModulePkg/Library/SmmCorePerformanceLib/MmCorePerformanceLib.c

Lines changed: 65 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ UINT32 mCachedLength = 0;
4242
UINT32 mBootRecordSize = 0;
4343
BOOLEAN mPerformanceMeasurementEnabled;
4444

45-
//
46-
// Interfaces for SMM PerformanceMeasurement Protocol.
47-
//
48-
EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL mPerformanceMeasurementInterface = {
49-
CreatePerformanceMeasurement,
50-
};
45+
// MU_CHANGE [BEGIN] - Split MM Services Table dependencies
46+
// //
47+
// // Interfaces for SMM PerformanceMeasurement Protocol.
48+
// //
49+
// EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL mPerformanceMeasurementInterface = {
50+
// CreatePerformanceMeasurement,
51+
// };
52+
// MU_CHANGE [END] - Split MM Services Table dependencies
5153

5254
/**
5355
Return the module name and optionally module GUID for a given handle.
@@ -932,61 +934,63 @@ SmmCorePerformanceLibExitBootServicesCallback (
932934
return EFI_SUCCESS;
933935
}
934936

935-
/**
936-
Common initialization code for the MM Core Performance Library.
937-
938-
@param[in] ExitBootServicesProtocolGuid The GUID of the ExitBootServices protocol.
939-
940-
@retval EFI_SUCCESS The MM Core Performance Library was initialized successfully.
941-
@retval Others The MM Core Performance Library was not initialized successfully.
942-
**/
943-
EFI_STATUS
944-
InitializeMmCorePerformanceLibCommon (
945-
IN CONST EFI_GUID *ExitBootServicesProtocolGuid
946-
)
947-
{
948-
EFI_STATUS Status;
949-
EFI_HANDLE Handle;
950-
EFI_HANDLE MmiHandle;
951-
VOID *Registration;
952-
953-
//
954-
// Initialize spin lock
955-
//
956-
InitializeSpinLock (&mSmmFpdtLock);
957-
958-
//
959-
// Install the protocol interfaces for MM performance library instance.
960-
//
961-
Handle = NULL;
962-
Status = gMmst->MmInstallProtocolInterface (
963-
&Handle,
964-
&gEdkiiSmmPerformanceMeasurementProtocolGuid,
965-
EFI_NATIVE_INTERFACE,
966-
&mPerformanceMeasurementInterface
967-
);
968-
ASSERT_EFI_ERROR (Status);
969-
970-
//
971-
// Register MMI handler.
972-
//
973-
MmiHandle = NULL;
974-
Status = gMmst->MmiHandlerRegister (FpdtSmiHandler, &gEfiFirmwarePerformanceGuid, &MmiHandle);
975-
if (EFI_ERROR (Status)) {
976-
return Status;
977-
}
978-
979-
//
980-
// Register callback function for ExitBootServices event.
981-
//
982-
Status = gMmst->MmRegisterProtocolNotify (
983-
ExitBootServicesProtocolGuid,
984-
SmmCorePerformanceLibExitBootServicesCallback,
985-
&Registration
986-
);
987-
988-
return Status;
989-
}
937+
// MU_CHANGE [BEGIN] - Split MM Services Table dependencies
938+
// /**
939+
// Common initialization code for the MM Core Performance Library.
940+
941+
// @param[in] ExitBootServicesProtocolGuid The GUID of the ExitBootServices protocol.
942+
943+
// @retval EFI_SUCCESS The MM Core Performance Library was initialized successfully.
944+
// @retval Others The MM Core Performance Library was not initialized successfully.
945+
// **/
946+
// EFI_STATUS
947+
// InitializeMmCorePerformanceLibCommon (
948+
// IN CONST EFI_GUID *ExitBootServicesProtocolGuid
949+
// )
950+
// {
951+
// EFI_STATUS Status;
952+
// EFI_HANDLE Handle;
953+
// EFI_HANDLE MmiHandle;
954+
// VOID *Registration;
955+
956+
// //
957+
// // Initialize spin lock
958+
// //
959+
// InitializeSpinLock (&mSmmFpdtLock);
960+
961+
// //
962+
// // Install the protocol interfaces for MM performance library instance.
963+
// //
964+
// Handle = NULL;
965+
// Status = gMmst->MmInstallProtocolInterface (
966+
// &Handle,
967+
// &gEdkiiSmmPerformanceMeasurementProtocolGuid,
968+
// EFI_NATIVE_INTERFACE,
969+
// &mPerformanceMeasurementInterface
970+
// );
971+
// ASSERT_EFI_ERROR (Status);
972+
973+
// //
974+
// // Register MMI handler.
975+
// //
976+
// MmiHandle = NULL;
977+
// Status = gMmst->MmiHandlerRegister (FpdtSmiHandler, &gEfiFirmwarePerformanceGuid, &MmiHandle);
978+
// if (EFI_ERROR (Status)) {
979+
// return Status;
980+
// }
981+
982+
// //
983+
// // Register callback function for ExitBootServices event.
984+
// //
985+
// Status = gMmst->MmRegisterProtocolNotify (
986+
// ExitBootServicesProtocolGuid,
987+
// SmmCorePerformanceLibExitBootServicesCallback,
988+
// &Registration
989+
// );
990+
991+
// return Status;
992+
// }
993+
// MU_CHANGE [END] - Split MM Services Table dependencies
990994

991995
/**
992996
Create performance record with event description and a timestamp.

MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.c

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,22 @@ MU_CHANGE [WHOLE FILE] - Standalone MM Perf Support
2828

2929
#include <Library/DxeServicesLib.h>
3030
#include <Library/SmmMemLib.h>
31+
#include <Library/SmmServicesTableLib.h> // MU_CHANGE - Split MM Services Table dependencies
3132
#include <Library/UefiBootServicesTableLib.h>
3233
#include <Library/UefiLib.h>
3334
#include <Protocol/SmmBase2.h>
3435
#include <Protocol/SmmExitBootServices.h>
3536

3637
PERFORMANCE_PROPERTY mPerformanceProperty;
3738

39+
// MU_CHANGE [BEGIN] - Split MM Services Table dependencies
40+
extern SPIN_LOCK mSmmFpdtLock;
41+
42+
EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL mPerformanceMeasurementInterface = {
43+
CreatePerformanceMeasurement,
44+
};
45+
// MU_CHANGE [END] - Split MM Services Table dependencies
46+
3847
/**
3948
A library internal MM-instance specific implementation to check if a buffer outside MM is valid.
4049
@@ -194,10 +203,45 @@ InitializeSmmCorePerformanceLib (
194203
{
195204
EFI_STATUS Status;
196205
PERFORMANCE_PROPERTY *PerformanceProperty;
206+
// MU_CHANGE [BEGIN] - Split MM Services Table dependencies
207+
EFI_HANDLE Handle;
208+
EFI_HANDLE MmiHandle;
209+
VOID *Registration;
197210

198-
Status = InitializeMmCorePerformanceLibCommon (&gEdkiiSmmExitBootServicesProtocolGuid);
211+
//
212+
// Initialize spin lock
213+
//
214+
InitializeSpinLock (&mSmmFpdtLock);
215+
216+
//
217+
// Install the protocol interfaces for MM performance library instance.
218+
//
219+
Handle = NULL;
220+
Status = gSmst->SmmInstallProtocolInterface (
221+
&Handle,
222+
&gEdkiiSmmPerformanceMeasurementProtocolGuid,
223+
EFI_NATIVE_INTERFACE,
224+
&mPerformanceMeasurementInterface
225+
);
199226
ASSERT_EFI_ERROR (Status);
200227

228+
//
229+
// Register MMI handler.
230+
//
231+
MmiHandle = NULL;
232+
Status = gSmst->SmiHandlerRegister (FpdtSmiHandler, &gEfiFirmwarePerformanceGuid, &MmiHandle);
233+
ASSERT_EFI_ERROR (Status);
234+
235+
//
236+
// Register callback function for ExitBootServices event.
237+
//
238+
Status = gSmst->SmmRegisterProtocolNotify (
239+
&gEdkiiSmmExitBootServicesProtocolGuid,
240+
SmmCorePerformanceLibExitBootServicesCallback,
241+
&Registration
242+
);
243+
// MU_CHANGE [END] - Split MM Services Table dependencies
244+
201245
Status = EfiGetSystemConfigurationTable (&gPerformanceProtocolGuid, (VOID **)&PerformanceProperty);
202246
if (EFI_ERROR (Status)) {
203247
//

MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.inf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@
4646
DebugLib
4747
DxeServicesLib
4848
MemoryAllocationLib
49-
MmServicesTableLib
49+
# MmServicesTableLib # MU_CHANGE - Split SMM Services Table libs
5050
PcdLib
5151
PeCoffGetEntryPointLib
5252
SmmMemLib
53+
SmmServicesTableLib # MU_CHANGE - Split SMM Services Table libs
5354
SynchronizationLib
5455
TimerLib
5556
UefiBootServicesTableLib

MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLibInternal.h

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
2424
#include <Library/BaseMemoryLib.h>
2525
#include <Library/DebugLib.h>
2626
#include <Library/MemoryAllocationLib.h>
27-
#include <Library/MmServicesTableLib.h>
27+
// include <Library/MmServicesTableLib.h> // MU_CHANGE - Split MM Services Table dependencies
2828
#include <Library/PcdLib.h>
2929
#include <Library/PeCoffGetEntryPointLib.h>
3030
#include <Library/PerformanceLib.h>
@@ -45,6 +45,61 @@ extern BOOLEAN mPerformanceMeasurementEnabled;
4545
// Library internal function declarations
4646
//
4747

48+
// MU_CHANGE [BEGIN] - Split MM Services Table dependencies
49+
50+
/**
51+
Communication service SMI Handler entry.
52+
53+
This SMI handler provides services for report MM boot records.
54+
55+
Caution: This function may receive untrusted input.
56+
Communicate buffer and buffer size are external input, so this function will do basic validation.
57+
58+
@param[in] DispatchHandle The unique handle assigned to this handler by SmiHandlerRegister().
59+
@param[in] RegisterContext Points to an optional handler context which was specified when the
60+
handler was registered.
61+
@param[in, out] CommBuffer A pointer to a collection of data in memory that will
62+
be conveyed from a non-MM environment into an MM environment.
63+
@param[in, out] CommBufferSize The size of the CommBuffer.
64+
65+
@retval EFI_SUCCESS The interrupt was handled and quiesced. No other handlers
66+
should still be called.
67+
@retval EFI_WARN_INTERRUPT_SOURCE_QUIESCED The interrupt has been quiesced but other handlers should
68+
still be called.
69+
@retval EFI_WARN_INTERRUPT_SOURCE_PENDING The interrupt is still pending and other handlers should still
70+
be called.
71+
@retval EFI_INTERRUPT_PENDING The interrupt could not be quiesced.
72+
73+
**/
74+
EFI_STATUS
75+
EFIAPI
76+
FpdtSmiHandler (
77+
IN EFI_HANDLE DispatchHandle,
78+
IN CONST VOID *RegisterContext,
79+
IN OUT VOID *CommBuffer,
80+
IN OUT UINTN *CommBufferSize
81+
);
82+
83+
/**
84+
This is the Event call back function is triggered in SMM to notify the Library
85+
the system is entering runtime phase.
86+
87+
@param[in] Protocol Points to the protocol's unique identifier
88+
@param[in] Interface Points to the interface instance
89+
@param[in] Handle The handle on which the interface was installed
90+
91+
@retval EFI_SUCCESS SmmAtRuntimeCallBack runs successfully
92+
**/
93+
EFI_STATUS
94+
EFIAPI
95+
SmmCorePerformanceLibExitBootServicesCallback (
96+
IN CONST EFI_GUID *Protocol,
97+
IN VOID *Interface,
98+
IN EFI_HANDLE Handle
99+
);
100+
101+
// MU_CHANGE [END] - Split MM Services Table dependencies
102+
48103
/**
49104
Return a pointer to the loaded image protocol for the given handle.
50105

MdeModulePkg/Library/SmmCorePerformanceLib/StandaloneMmCorePerformanceLib.c

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,17 @@
1717
#include "SmmCorePerformanceLibInternal.h"
1818

1919
#include <Guid/EventGroup.h>
20+
#include <Library/MmServicesTableLib.h> // MU_CHANGE - Split MM Services Table dependencies
2021
#include <Library/StandaloneMmMemLib.h>
2122

23+
// MU_CHANGE [BEGIN] - Split MM Services Table dependencies
24+
extern SPIN_LOCK mSmmFpdtLock;
25+
26+
EDKII_PERFORMANCE_MEASUREMENT_PROTOCOL mPerformanceMeasurementInterface = {
27+
CreatePerformanceMeasurement,
28+
};
29+
// MU_CHANGE [END] - Split MM Services Table dependencies
30+
2231
/**
2332
A library internal MM-instance specific implementation to check if a buffer outside MM is valid.
2433
@@ -109,6 +118,64 @@ GetNameFromUiSection (
109118
return EFI_NOT_FOUND;
110119
}
111120

121+
// MU_CHANGE [BEGIN] - Split MM Services Table dependencies
122+
123+
/**
124+
Initializes the MM Core Performance library.
125+
126+
@retval EFI_SUCCESS The performance library was initialized successfully.
127+
@retval Other An error occurred during initialization.
128+
**/
129+
EFI_STATUS
130+
EFIAPI
131+
InitializeStandaloneMmCorePerformanceLib (
132+
VOID
133+
)
134+
{
135+
EFI_STATUS Status;
136+
EFI_HANDLE Handle;
137+
EFI_HANDLE MmiHandle;
138+
VOID *Registration;
139+
140+
//
141+
// Initialize spin lock
142+
//
143+
InitializeSpinLock (&mSmmFpdtLock);
144+
//
145+
// Install the protocol interfaces for MM performance library instance.
146+
//
147+
Handle = NULL;
148+
Status = gMmst->MmInstallProtocolInterface (
149+
&Handle,
150+
&gEdkiiSmmPerformanceMeasurementProtocolGuid,
151+
EFI_NATIVE_INTERFACE,
152+
&mPerformanceMeasurementInterface
153+
);
154+
ASSERT_EFI_ERROR (Status);
155+
156+
//
157+
// Register MMI handler.
158+
//
159+
MmiHandle = NULL;
160+
Status = gMmst->MmiHandlerRegister (FpdtSmiHandler, &gEfiFirmwarePerformanceGuid, &MmiHandle);
161+
if (EFI_ERROR (Status)) {
162+
return Status;
163+
}
164+
165+
//
166+
// Register callback function for ExitBootServices event.
167+
//
168+
Status = gMmst->MmRegisterProtocolNotify (
169+
&gEfiEventExitBootServicesGuid,
170+
SmmCorePerformanceLibExitBootServicesCallback,
171+
&Registration
172+
);
173+
174+
return Status;
175+
}
176+
177+
// MU_CHANGE [END] - Split MM Services Table dependencies
178+
112179
/**
113180
The constructor function initializes the Standalone MM Core performance library.
114181
@@ -140,7 +207,7 @@ StandaloneMmCorePerformanceLibConstructor (
140207
return EFI_SUCCESS;
141208
}
142209

143-
Status = InitializeMmCorePerformanceLibCommon (&gEfiEventExitBootServicesGuid);
210+
Status = InitializeStandaloneMmCorePerformanceLib (); // MU_CHANGE - Split MM Services Table dependencies
144211
ASSERT_EFI_ERROR (Status);
145212

146213
return EFI_SUCCESS;

0 commit comments

Comments
 (0)