Skip to content

Commit

Permalink
Refactoring the MM implementation to support both Standalone MM and T…
Browse files Browse the repository at this point in the history
…raditional MM (#461)

# Preface

Please ensure you have read the [contribution
docs](https://github.com/microsoft/mu/blob/master/CONTRIBUTING.md) prior
to submitting the pull request. In particular,
[pull request
guidelines](https://github.com/microsoft/mu/blob/master/CONTRIBUTING.md#pull-request-best-practices).

## Description

Refactoring the MM implementation to support both Standalone MM and
Traditional MM

1. Add DXE_SMM_DRIVER to LIBRARY_CLASS of MmPolicyLib.inf
2. Refactor the PolicyMm module to have a common entrypoint, and both
Standalone MM and Traditional MM entrypoint call the common entrypoint.
3. Add Traditional MM description to Readme.md.

This PR resolves #460.

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, ...
- [x] 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 with the CI build

## Integration Instructions

N/A
  • Loading branch information
MarcChen46 authored and kenlautner committed Oct 20, 2023
1 parent d7b6c6d commit 0cbf215
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 15 deletions.
2 changes: 1 addition & 1 deletion PolicyServicePkg/Library/MmPolicyLib/MmPolicyLib.inf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
FILE_GUID = C2A9C781-8D58-46DA-BC39-5385AB8D5C8A
MODULE_TYPE = MM_STANDALONE
VERSION_STRING = 1.0
LIBRARY_CLASS = PolicyLib | MM_STANDALONE
LIBRARY_CLASS = PolicyLib | DXE_SMM_DRIVER MM_STANDALONE

[Sources]
../PolicyLibCommon.c
Expand Down
13 changes: 4 additions & 9 deletions PolicyServicePkg/PolicyService/DxeMm/PolicyMm.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @file
Implements the Standalone MM policy protocol, providing services to publish and
Implements the MM policy protocol, providing services to publish and
access system policy.
Copyright (c) Microsoft Corporation
Expand Down Expand Up @@ -87,20 +87,15 @@ InstallPolicyIndicatorProtocol (
}

/**
Entry to the Standalone MM policy service module.
@param[in] ImageHandle The image handle.
@param[in] SystemTable The system table.
Common Entry of the MM policy service module.
@retval Status From internal routine or boot object, should not fail
**/
EFI_STATUS
EFIAPI
PolicyStandaloneEntry (
IN EFI_HANDLE ImageHandle,
IN EFI_MM_SYSTEM_TABLE *SystemTable
PolicyMmCommonEntry (
VOID
)

{
EFI_STATUS Status;

Expand Down
3 changes: 2 additions & 1 deletion PolicyServicePkg/PolicyService/DxeMm/PolicyMm.inf
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
FILE_GUID = 9FF65AAD-5982-4609-9702-05EFD584148C
MODULE_TYPE = MM_STANDALONE
VERSION_STRING = 1.0
ENTRY_POINT = PolicyStandaloneEntry
ENTRY_POINT = PolicyStandaloneMmEntry

[Sources]
PolicyStandaloneMm.c
PolicyMm.c
PolicyCommon.c
PolicyCommon.h
Expand Down
40 changes: 40 additions & 0 deletions PolicyServicePkg/PolicyService/DxeMm/PolicyStandaloneMm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/** @file
Implements the Standalone MM policy protocol, providing services to publish and
access system policy.
Copyright (c) Microsoft Corporation
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include <Uefi.h>
#include <Library/MmServicesTableLib.h>

/**
Common Entry of the MM policy service module.
@retval Status From internal routine or boot object, should not fail
**/
EFI_STATUS
EFIAPI
PolicyMmCommonEntry (
VOID
);

/**
Entry to the Standalone MM policy service module.
@param[in] ImageHandle The image handle.
@param[in] SystemTable The system table.
@retval Status From internal routine or boot object, should not fail
**/
EFI_STATUS
EFIAPI
PolicyStandaloneMmEntry (
IN EFI_HANDLE ImageHandle,
IN EFI_MM_SYSTEM_TABLE *SystemTable
)
{
return PolicyMmCommonEntry ();
}
39 changes: 39 additions & 0 deletions PolicyServicePkg/PolicyService/DxeMm/PolicyTraditionalMm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/** @file
Implements the Traditional MM policy protocol, providing services to publish and
access system policy.
Copyright (c) Microsoft Corporation
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include <Uefi.h>

/**
Common Entry of the MM policy service module.
@retval Status From internal routine or boot object, should not fail
**/
EFI_STATUS
EFIAPI
PolicyMmCommonEntry (
VOID
);

/**
Entry to the Traditional MM policy service module.
@param[in] ImageHandle The image handle.
@param[in] SystemTable The system table.
@retval Status From internal routine or boot object, should not fail
**/
EFI_STATUS
EFIAPI
PolicyTraditionalMmEntry (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
return PolicyMmCommonEntry ();
}
47 changes: 47 additions & 0 deletions PolicyServicePkg/PolicyService/DxeMm/PolicyTraditionalMm.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
## @file
#
# This is a driver for Traditional MM policy service module.
#
# Copyright (C) Microsoft Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##

[Defines]
INF_VERSION = 0x00010017
PI_SPECIFICATION_VERSION = 0x00010032
BASE_NAME = PolicyTraditionalMm
FILE_GUID = 51084E31-393D-4D06-A867-BDE321D4E4F5
MODULE_TYPE = DXE_SMM_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = PolicyTraditionalMmEntry

[Sources]
PolicyTraditionalMm.c
PolicyMm.c
PolicyCommon.c
PolicyCommon.h

[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
PolicyServicePkg/PolicyServicePkg.dec

[LibraryClasses]
BaseLib
DebugLib
HobLib
UefiDriverEntryPoint
MmServicesTableLib
MemoryAllocationLib

[Pcd]

[Guids]
gPolicyHobGuid

[Protocols]
gMmPolicyProtocolGuid ## PRODUCES

[Depex]
TRUE
1 change: 1 addition & 0 deletions PolicyServicePkg/PolicyServicePkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@
[Protocols]
## Include/Protocol/Policy.h
gPolicyProtocolGuid = { 0xd7c9b744, 0x13a5, 0x4377, { 0x8d, 0x2a, 0x6b, 0x37, 0xad, 0x1f, 0xd8, 0x2a } }
## Include/Protocol/MmPolicy.h
gMmPolicyProtocolGuid = { 0xe55ad3a1, 0xbd34, 0x46f4, { 0xbb, 0x6e, 0x72, 0x28, 0x0b, 0xdc, 0xbf, 0xd9 } }
9 changes: 8 additions & 1 deletion PolicyServicePkg/PolicyServicePkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,24 @@
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
PolicyLib|PolicyServicePkg/Library/DxePolicyLib/DxePolicyLib.inf

[LibraryClasses.common.DXE_SMM_DRIVER]
MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemoryAllocationLib.inf
UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
MmServicesTableLib|MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf
SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServicesTableLib.inf

[LibraryClasses.common.MM_STANDALONE]
MemoryAllocationLib|StandaloneMmPkg/Library/StandaloneMmMemoryAllocationLib/StandaloneMmMemoryAllocationLib.inf
StandaloneMmDriverEntryPoint|MdePkg/Library/StandaloneMmDriverEntryPoint/StandaloneMmDriverEntryPoint.inf
HobLib|StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.inf
MmServicesTableLib|MdePkg/Library/StandaloneMmServicesTableLib/StandaloneMmServicesTableLib.inf
StandaloneMmDriverEntryPoint|MdePkg/Library/StandaloneMmDriverEntryPoint/StandaloneMmDriverEntryPoint.inf
PolicyLib|PolicyServicePkg/Library/MmPolicyLib/MmPolicyLib.inf

[Components]
PolicyServicePkg/PolicyService/DxeMm/PolicyDxe.inf
PolicyServicePkg/PolicyService/DxeMm/PolicyMm.inf
PolicyServicePkg/PolicyService/DxeMm/PolicyTraditionalMm.inf
PolicyServicePkg/PolicyService/Pei/PolicyPei.inf
PolicyServicePkg/Library/DxePolicyLib/DxePolicyLib.inf
PolicyServicePkg/Library/PeiPolicyLib/PeiPolicyLib.inf
Expand Down
6 changes: 3 additions & 3 deletions PolicyServicePkg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,19 @@ Like the PEIM, the DXE driver will install/reinstall a NULL protocol with the
given policies GUID when it is created or updated to allow for notification and
dispatch on the policy availability.

### Standalone MM
### Traditional/Standalone MM

Like the DXE phase, the MM policy service will ingest any policies from the HOB
list for architectures. The MM policy service is implemented identically to the
DXE phase module with the exception of using the MM specific protocols.

Policies in the MM service are isolated from PEI and DXE. The MM module will ingest
any policies available in the hob list from PEI where applicable but no policies
created or modified by PEI or DXE after Standalone MM has been launched will be
created or modified by PEI or DXE after Traditional/Standalone MM has been launched will be
available from the MM policy service. Similarly, no policy created or edited in
the MM policy service will be readable from the PEI or DXE policies services.

Policies are not shared with the standalone MM module after initialization. Any
Policies are not shared with the traditional/standalone MM module after initialization. Any
policy created in MM will not be readable by DXE and PEI, and any policy made after
MM initialization will not be readable from MM.

Expand Down

0 comments on commit 0cbf215

Please sign in to comment.