Skip to content

Commit 653e31e

Browse files
authored
MdeModulePkg/Variable: Init var policy after SMM variable is ready (#1269)
## Description On a MM system, the main UEFI variable logic resides in MMRAM. In that case, the variable policy logic in `VarCheckPolicyLib`, such as `VarCheckPolicyLibStandaloneMm` is linked against the MM driver also in that case `VariableStandaloneMm`. The MM variable driver indicates its presence to the RT DXE driver via `gEfiSmmVariableProtocolGuid` to indicate variable read support is available from MM. This triggers installation of the variable architectural protocol in DXE. Today, variable policy is initialized by calling `VariablePolicySmmDxeMain()` in `VariableSmmRuntimeInitialize()`. In turn, this installs `gEdkiiVariablePolicyProtocolGuid`. Functions in `gEdkiiVariablePolicyProtocolGuid` may trigger MMIs. However, it is possible that the MM variable driver which is linked against the code with the variable policy MMI handlers (i.e. `VarCheckPolicyLib`) is not loaded yet. Therefore, this change moves invocation of `VariablePolicySmmDxeMain()` to `SmmVariableReady()` which is called on installation of `gEfiSmmVariableProtocolGuid` indicating variable MM services are ready. `gEdkiiVariablePolicyProtocolGuid` is still installed prior to the variable architectural protocol being installed. - [x] Impacts functionality? - [ ] Impacts security? - [ ] Breaking change? - [ ] Includes tests? - [ ] Includes documentation? - [ ] Backport to release branch? ## How This Was Tested - Verify variable policy is initialized as expected on QEMU Q35/SBSA and a physical Intel system. - Check that the variable image handle passed to `VariablePolicySmmDxeMain()` is correct. ## Integration Instructions N/A - Some drivers may dispatch differently if they depend on `gEdkiiVariablePolicyProtocolGuid`. However, this is not considered breaking as that is an inherent expectation in dispatch based on dependency expressions. Signed-off-by: Michael Kubacki <[email protected]>
1 parent c75e4c8 commit 653e31e

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

MdeModulePkg/Universal/Variable/RuntimeDxe/VariablePolicySmmDxe.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ VariablePolicyVirtualAddressCallback (
813813
The driver's entry point.
814814
815815
@param[in] ImageHandle The firmware allocated handle for the EFI image.
816-
@param[in] SystemTable A pointer to the EFI System Table.
816+
// @param[in] SystemTable A pointer to the EFI System Table. // MU_CHANGE - Initialize var policy after SMM Variable is ready
817817
818818
@retval EFI_SUCCESS The entry point executed successfully.
819819
@retval other Some error occured when executing this entry point.
@@ -822,8 +822,8 @@ VariablePolicyVirtualAddressCallback (
822822
EFI_STATUS
823823
EFIAPI
824824
VariablePolicySmmDxeMain (
825-
IN EFI_HANDLE ImageHandle,
826-
IN EFI_SYSTEM_TABLE *SystemTable
825+
IN EFI_HANDLE ImageHandle // MU_CHANGE - Initialize var policy after SMM Variable is ready
826+
// IN EFI_SYSTEM_TABLE *SystemTable // MU_CHANGE - Initialize var policy after SMM Variable is ready
827827
)
828828
{
829829
EFI_STATUS Status;

MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ EDKII_VAR_CHECK_PROTOCOL mVarCheck;
7373
EFI_STATUS
7474
EFIAPI
7575
VariablePolicySmmDxeMain (
76-
IN EFI_HANDLE ImageHandle,
77-
IN EFI_SYSTEM_TABLE *SystemTable
76+
IN EFI_HANDLE ImageHandle // MU_CHANGE - Initialize var policy after SMM Variable is ready
77+
// IN EFI_SYSTEM_TABLE *SystemTable // MU_CHANGE - Initialize var policy after SMM Variable is ready
7878
);
7979

8080
/**
@@ -1692,6 +1692,7 @@ SmmVariableReady (
16921692
)
16931693
{
16941694
EFI_STATUS Status;
1695+
EFI_HANDLE VariablePolicyHandle; // MU_CHANGE - Initialize var policy after SMM Variable is ready
16951696

16961697
Status = gBS->LocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOID **)&mSmmVariable);
16971698
if (EFI_ERROR (Status)) {
@@ -1758,6 +1759,16 @@ SmmVariableReady (
17581759
gRT->SetVariable = RuntimeServiceSetVariable;
17591760
gRT->QueryVariableInfo = RuntimeServiceQueryVariableInfo;
17601761

1762+
// MU_CHANGE [BEGIN] - Initialize var policy after SMM Variable is ready
1763+
VariablePolicyHandle = (Context != NULL) ? Context : mHandle;
1764+
if (Context == NULL) {
1765+
DEBUG ((DEBUG_ERROR, "Variable policy was installed on a handle other than the variable image handle.\n"));
1766+
}
1767+
1768+
// Initialize the VariablePolicy protocol and engine.
1769+
VariablePolicySmmDxeMain (VariablePolicyHandle);
1770+
// MU_CHANGE [END] - Initialize var policy after SMM Variable is ready
1771+
17611772
//
17621773
// Install the Variable Architectural Protocol on a new handle.
17631774
//
@@ -1868,7 +1879,7 @@ VariableSmmRuntimeInitialize (
18681879
&gEfiSmmVariableProtocolGuid,
18691880
TPL_CALLBACK,
18701881
SmmVariableReady,
1871-
NULL,
1882+
ImageHandle, // MU_CHANGE - Initialize var policy after SMM Variable is ready
18721883
&SmmVariableRegistration
18731884
);
18741885

@@ -1930,8 +1941,10 @@ VariableSmmRuntimeInitialize (
19301941
&mVirtualAddressChangeEvent
19311942
);
19321943

1933-
// Initialize the VariablePolicy protocol and engine.
1934-
VariablePolicySmmDxeMain (ImageHandle, SystemTable);
1944+
// MU_CHANGE [BEGIN] - Initialize var policy after SMM Variable is ready
1945+
// // Initialize the VariablePolicy protocol and engine.
1946+
// VariablePolicySmmDxeMain (ImageHandle, SystemTable);
1947+
// MU_CHANGE [END] - Initialize var policy after SMM Variable is ready
19351948

19361949
return EFI_SUCCESS;
19371950
}

0 commit comments

Comments
 (0)