Skip to content

Conversation

@makubacki
Copy link
Collaborator

@makubacki makubacki commented Sep 16, 2025

Description

Closes #444

Refactors performance code interacting with MM to be more ergonomic and use the MM Communication service (instead of the MM Communication protocol). Use zerocopy in some places to reduce overhead from scroll. General other improvements for error handling and adding more testing.


perf: Update dependencies for MM communication support

Add patina_mm dependency to workspace and performance component to
enable MM communication. Replace scroll with zerocopy for improved
serialization performance and reduced dependency weight.

  • Add patina_mm dependency to workspace Cargo.toml
  • Add patina_mm and zerocopy dependencies to performance component
  • Remove scroll dependency in favor of zerocopy for serialization
  • Add zerocopy with derive features to SDK

This establishes the foundation for modernizing MM communication in the
performance component by replacing HOB-based communication with a
service-based approach.


patina_performance: Add MM module

Add a dedicated MM communication module for performance related
MM definitions and functionality such as record fetching.

  • SmmCommHeader is zerocopy wire format compatible
  • Adds GetRecordSize for querying total performance record size
  • Adds GetRecordDataByOffset for chunked record retrieval wit
    configurable buffer sizes

patina_sdk/performance: Improve perf record serialization infra

  • Adds the PerformanceRecordHeader struct to represent and manage
    performance record headers.
  • Replaces scroll::Error with Error::Serialization so scroll errror
    types are not leaking into performance code.
  • Implement direct little-endian serialization helpers for certain
    primitives
  • Favors zerocopy instead of scroll in relevant places.
  • Adds improved bounds checking for serialization operations.

patina_performance: Update configuration with explicit defaults

Enhance PerfConfig with explicit default values and improved
documentation to provide clearer configuration semantics.

  • Add explicit DEFAULT_ENABLE_COMPONENT and
    DEFAULT_ENABLED_MEASUREMENTS constants
  • Implement custom Default trait instead of derive to better
    control defaults
  • Improve documentation
  • Improve PerfConfig usage ergonomics

patina_performance: Use the MM Communication service

Drop HOB-based MM comm buffers and the Communicate protocol being
used in the performance component to instead use the Communicate
service.

Implements more robust error handling, general code cleanup, and
additional tests.

  • Uses the MmCommunication service

  • Adds better error handling using the MmPerformanceError enum

  • Implements chunked MM record fetching with configurable buffer
    sizes

  • Adds PerformanceRecordIterator for more memory-efficient perf
    record processing

  • Adds unit tests covering different scenarios such as zero records,
    single record, and multi-chunk scenarios

  • Mocks the MmCommunication service implementations to better
    isolate testing


patina_sdk: Refactor perf measurement module to drop MM comm protocol

Remove protocol-based MM communication in the patina_sdk perf code
and clean up the event_callback namespace.

  • Remove Vec import as it's no longer needed for temporary buffers
  • Remove fetch_and_add_mm_performance_records from event_callback
    module
  • Clean up unused imports and simplify module dependencies

patina_sdk/performance: Remove temp SMM module

Remove the temporary _smm module that provided scroll-based MM
communication.

The new MM communication approach in the mm.rs module provides
the same functionality with improved error handling, better
resource management, and integration with the Patina service
architecture.


patina_performance: Add records module

Adds structures that represent performance records so they can
be parsed and printed in debug messages.


patina_mm: Add MM communication buffer update protocol

Implements the MM communication buffer update protocol to support`
dynamic updates to MM communication buffers during boot. This is
an option that can be enabled in the MM Comm buffer config. The
protocol is currently published the Mu MM Supervisor Standalone MM
implementation.

High-level changes:

  • Add support for the MmCommBufferUpdate protocol
  • Update the patina_mm component to support MM Comm buffer updates
  • Update patina_mm config to support MM Comm buffer updates
  • Integration with SW MMI manager for buffer update handling
  • Component integration tests for buffer update functionality

An example of a pending MM Communication buffer being applied when
the perf component triggers a SW MMI:

DEBUG - Starting MM communication: buffer_id=1, data_size=40, recipient=C095791A-3001-47B2-80C9-EAC7319F2FA4
INFO - Pending buffer update detected, applying now
INFO - Adding new comm buffer 1: addr=0x7ddd9000, size=0x10000
INFO - Successfully applied pending comm buffer 1 update
TRACE - patina_mm\src\component\communicator.rs:466: Buffer validation: buffer_len=65536, required_len=64
TRACE - patina_mm\src\component\communicator.rs:473: Resetting the comm buffer and internal tracking state
TRACE - patina_mm\src\component\communicator.rs:476: Setting up communication buffer for MM request
TRACE - patina_mm\src\config.rs:569: Setting message info for buffer 1: recipient=C095791A-3001-47B2-80C9-EAC7319F2FA4
TRACE - patina_mm\src\config.rs:540: Validating capacity for buffer 1: buffer_size=65536, message_size=0
TRACE - patina_mm\src\config.rs:558: Buffer 1 capacity validation passed
TRACE - patina_mm\src\config.rs:527: Buffer 1 state consistency was verified successfully
TRACE - patina_mm\src\config.rs:586: Message info set successfully for buffer 1
TRACE - patina_mm\src\config.rs:598: Setting message for buffer 1: message_size=40
TRACE - patina_mm\src\config.rs:540: Validating capacity for buffer 1: buffer_size=65536, message_size=40
TRACE - patina_mm\src\config.rs:558: Buffer 1 capacity validation passed
TRACE - patina_mm\src\config.rs:610: Buffer 1: writing header and message data
TRACE - patina_mm\src\config.rs:527: Buffer 1 state consistency was verified successfully
DEBUG - Buffer 1 message set successfully: header_size=24, message_size=40
DEBUG - Outgoing MM communication request: buffer_id=1, data_size=40, recipient=C095791A-3001-47B2-80C9-EAC7319F2FA4
DEBUG - Request Data (hex): [01, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00]
TRACE - patina_mm\src\component\communicator.rs:488: Comm buffer before request: CommunicateBuffer(id: 0x1. len: 0x10000)
. . .

Add additional MM Communicator unit tests

Coverage for:

  • Debug output
  • Default trait implementation
  • Using an MM executor

Improve MM perf record debuggability

Prints additional information about MM performance records retrieved,
including record-specific information. That allows better visibility
into the records themselves and MM communication between the Patina
Performance component the MM performance code.

An example of two MM performance records received from the MM UEFI
variable driver:

DEBUG - MM communication response received: size=156
INFO - Performance: Processing 116 bytes of MM performance data
DEBUG - Performance: MM record #1 - type: 0x1011 (Dynamic String Event), length: 58, revision: 1, data_len: 54
DEBUG -   Record #1: progress_id: 0x0030, apic_id: 0, timestamp: 4105960673, guid: 7EE2C0C1-C21A-4113-A53A-66824A95696F
DEBUG -     String: "MmVariableServiceInitia"
DEBUG - Performance: MM record #2 - type: 0x1011 (Dynamic String Event), length: 58, revision: 1, data_len: 54
DEBUG -   Record #2: progress_id: 0x0031, apic_id: 0, timestamp: 4157443753, guid: 7EE2C0C1-C21A-4113-A53A-66824A95696F
DEBUG -     String: "MmVariableServiceInitia"
INFO - Performance: MM record summary - total: 2, added: 2, failed: 0

  • Impacts functionality?
  • Impacts security?
  • Breaking change?
  • Includes tests?
  • Includes documentation?

How This Was Tested

  • cargo make all
  • Boot on QEMU Q35 with default Q35 build and run settings
  • Boot on QEMU Q35 with PERF_TRACE_ENABLE
  • Add two MM perf records for testing and verify they are found using MM communication
  • Verify the MM communicate buffer can be updated successfully when the MM Communication Buffer update protocol is published and the following performance configuration is used:
  enable_comm_buffer_updates: true,
  updatable_buffer_id: Some(1),

Integration Instructions

Update performance configuration to include the following fields:

  enable_comm_buffer_updates: false,
  updatable_buffer_id: None,

If the MM Communication Buffer Update protocol is installed on the platform (protocol with GUID 2a22e38f-9d1c-49d0-bdce-7ddac16da45d), then use the following configration:

  enable_comm_buffer_updates: true,
  updatable_buffer_id: Some(1),

Where updatable_buffer_id is the ID of the comm buffer that should be updated with the information in the protocol.

@makubacki makubacki self-assigned this Sep 16, 2025
@github-actions github-actions bot added impact:breaking-change Requires integration attention impact:testing Affects testing type:documentation Improvements or additions to documentation labels Sep 16, 2025
@makubacki makubacki force-pushed the personal/mikuback/use_mm_in_perf_component_3 branch from 016d9b8 to ed1f66c Compare September 17, 2025 00:04
@makubacki makubacki force-pushed the personal/mikuback/use_mm_in_perf_component_3 branch 4 times, most recently from 8929318 to 71fd25d Compare September 17, 2025 22:50
@makubacki makubacki force-pushed the personal/mikuback/use_mm_in_perf_component_3 branch from 71fd25d to ad64aa1 Compare September 23, 2025 21:16
@makubacki
Copy link
Collaborator Author

makubacki commented Sep 29, 2025

I'm holding merging of this PR until a few others go in that this one will build on top of.

Currently blocked on microsoft/mu_feature_mm_supv#541 for compat with MM Supervisor Standalone MM.

@makubacki
Copy link
Collaborator Author

I'm holding merging of this PR until a few others go in that this one will build on top of.

Currently blocked on microsoft/mu_feature_mm_supv#541 for compat with MM Supervisor Standalone MM.

Marking the PR as draft until that is done. Then, I'll rebase and update the PR as needed.

@makubacki makubacki marked this pull request as draft October 3, 2025 15:35
@makubacki makubacki force-pushed the personal/mikuback/use_mm_in_perf_component_3 branch from ad64aa1 to 56da443 Compare November 4, 2025 16:03
@makubacki makubacki force-pushed the personal/mikuback/use_mm_in_perf_component_3 branch from 56da443 to 2876f01 Compare November 17, 2025 15:36
@makubacki makubacki marked this pull request as ready for review November 17, 2025 15:37
@makubacki makubacki force-pushed the personal/mikuback/use_mm_in_perf_component_3 branch from 2876f01 to e8d8285 Compare November 17, 2025 18:44
@makubacki makubacki force-pushed the personal/mikuback/use_mm_in_perf_component_3 branch from e8d8285 to c22a615 Compare November 17, 2025 18:45
@makubacki
Copy link
Collaborator Author

@joschock, @Javagedes, @os-d, @magravel, @berlin-with0ut-return, this PR is now updated to work with the MM Supervisor, taking advantage of a new protocol that updates the comm buffer protocol during boot. That change in particular is made in ef054ea.

The new commits since the last review period are:

@makubacki
Copy link
Collaborator Author

Can you please take a look through the current PR? I'll complete the PR after getting two approvals on the latest changes.

@makubacki makubacki force-pushed the personal/mikuback/use_mm_in_perf_component_3 branch from c22a615 to a784dd4 Compare November 17, 2025 19:27
@makubacki
Copy link
Collaborator Author

If anyone would like to review, please comment in the next hour or so, otherwise I'll rebase and merge it.

@makubacki
Copy link
Collaborator Author

If anyone would like to review, please comment in the next hour or so, otherwise I'll rebase and merge it.

@os-d reached out about taking a look. The PR will stay open.

`zerocopy_dervice` does not need to be explicitly used. Duplicate
symbols are now being reported with the latest build using nightly.

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Add patina_mm dependency to workspace and performance component to
enable MM communication. Replace scroll with zerocopy for improved
serialization performance and reduced dependency weight.

Key changes:
- Add patina_mm dependency to workspace Cargo.toml
- Add patina_mm and zerocopy dependencies to performance component
- Remove scroll dependency in favor of zerocopy for serialization
- Add zerocopy with derive features to SDK

This establishes the foundation for modernizing MM communication in the
performance component by replacing HOB-based communication with a
service-based approach.

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Add a dedicated MM communication module for performance related
MM definitions and functionality such as record fetching.

- SmmCommHeader is zerocopy wire format compatible
- Adds GetRecordSize for querying total performance record size
- Adds GetRecordDataByOffset for chunked record retrieval wit
  configurable buffer sizes

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
- Adds the PerformanceRecordHeader struct to represent and manage
  performance record headers.
- Replaces scroll::Error with Error::Serialization so scroll errror
  types are not leaking into performance code.
- Implement direct little-endian serialization helpers for certain
  primitives
- Favors zerocopy instead of scroll in relevant places.
- Adds improved bounds checking for serialization operations.

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Enhance `PerfConfig` with explicit default values and improved
documentation to provide clearer configuration semantics.

- Add explicit `DEFAULT_ENABLE_COMPONENT` and
  `DEFAULT_ENABLED_MEASUREMENTS` constants
- Implement custom `Default` trait instead of derive to better
  control defaults
- Improve documentation
- Improve `PerfConfig` usage ergonomics

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Drop HOB-based MM comm buffers and the Communicate protocol being
used in the performance component to instead use the Communicate
service.

Implements more robust error handling, general code cleanup, and
additional tests.

- Uses the `MmCommunication` service
- Adds better error handling using the `MmPerformanceError` enum
- Implements chunked MM record fetching with configurable buffer
  sizes
- Adds `PerformanceRecordIterator` for more memory-efficient perf
  record processing

- Adds unit tests covering different scenarios such as zero records,
  single record, and multi-chunk scenarios
- Mocks the `MmCommunication` service implementations to better
  isolate testing

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Remove protocol-based MM communication in the patina_sdk perf code
and clean up the `event_callback` namespace.

- Remove Vec import as it's no longer needed for temporary buffers
- Remove fetch_and_add_mm_performance_records from event_callback
  module
- Clean up unused imports and simplify module dependencies

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Remove the temporary _smm module that provided scroll-based MM
communication.

The new MM communication approach in the mm.rs module provides
the same functionality with improved error handling, better
resource management, and integration with the Patina service
architecture.

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Adds structures that represent performance records so they can
be parsed and printed in debug messages.

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Implements the MM communication buffer update protocol to support`
dynamic updates to MM communication buffers during boot. This is
an option that can be enabled in the MM Comm buffer config. The
protocol is currently published the Mu MM Supervisor Standalone MM
implementation.

High-level changes:

- Add support for the MmCommBufferUpdate protocol
- Update the patina_mm component to support MM Comm buffer updates
- Update patina_mm config to support MM Comm buffer updates
- Integration with SW MMI manager for buffer update handling
- Component integration tests for buffer update functionality

An example of a pending MM Communication buffer being applied when
the perf component triggers a SW MMI:

```
DEBUG - Starting MM communication: buffer_id=1, data_size=40, recipient=C095791A-3001-47B2-80C9-EAC7319F2FA4
INFO - Pending buffer update detected, applying now
INFO - Adding new comm buffer 1: addr=0x7ddd9000, size=0x10000
INFO - Successfully applied pending comm buffer 1 update
TRACE - patina_mm\src\component\communicator.rs:466: Buffer validation: buffer_len=65536, required_len=64
TRACE - patina_mm\src\component\communicator.rs:473: Resetting the comm buffer and internal tracking state
TRACE - patina_mm\src\component\communicator.rs:476: Setting up communication buffer for MM request
TRACE - patina_mm\src\config.rs:569: Setting message info for buffer 1: recipient=C095791A-3001-47B2-80C9-EAC7319F2FA4
TRACE - patina_mm\src\config.rs:540: Validating capacity for buffer 1: buffer_size=65536, message_size=0
TRACE - patina_mm\src\config.rs:558: Buffer 1 capacity validation passed
TRACE - patina_mm\src\config.rs:527: Buffer 1 state consistency was verified successfully
TRACE - patina_mm\src\config.rs:586: Message info set successfully for buffer 1
TRACE - patina_mm\src\config.rs:598: Setting message for buffer 1: message_size=40
TRACE - patina_mm\src\config.rs:540: Validating capacity for buffer 1: buffer_size=65536, message_size=40
TRACE - patina_mm\src\config.rs:558: Buffer 1 capacity validation passed
TRACE - patina_mm\src\config.rs:610: Buffer 1: writing header and message data
TRACE - patina_mm\src\config.rs:527: Buffer 1 state consistency was verified successfully
DEBUG - Buffer 1 message set successfully: header_size=24, message_size=40
DEBUG - Outgoing MM communication request: buffer_id=1, data_size=40, recipient=C095791A-3001-47B2-80C9-EAC7319F2FA4
DEBUG - Request Data (hex): [01, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00]
TRACE - patina_mm\src\component\communicator.rs:488: Comm buffer before request: CommunicateBuffer(id: 0x1. len: 0x10000)
. . .
```

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Coverage for:

- Debug output
- Default trait implementation
- Using an MM executor

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Prints additional information about MM performance records retrieved,
including record-specific information. That allows better visibility
into the records themselves and MM communication between the Patina
Performance component the MM performance code.

An example of two MM performance records received from the MM UEFI
variable driver:

```
DEBUG - MM communication response received: size=156
INFO - Performance: Processing 116 bytes of MM performance data
DEBUG - Performance: MM record #1 - type: 0x1011 (Dynamic String Event), length: 58, revision: 1, data_len: 54
DEBUG -   Record #1: progress_id: 0x0030, apic_id: 0, timestamp: 4105960673, guid: 7EE2C0C1-C21A-4113-A53A-66824A95696F
DEBUG -     String: "MmVariableServiceInitia"
DEBUG - Performance: MM record #2 - type: 0x1011 (Dynamic String Event), length: 58, revision: 1, data_len: 54
DEBUG -   Record #2: progress_id: 0x0031, apic_id: 0, timestamp: 4157443753, guid: 7EE2C0C1-C21A-4113-A53A-66824A95696F
DEBUG -     String: "MmVariableServiceInitia"
INFO - Performance: MM record summary - total: 2, added: 2, failed: 0
```

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
@makubacki makubacki force-pushed the personal/mikuback/use_mm_in_perf_component_3 branch from a784dd4 to 2f0c6ea Compare November 18, 2025 01:20
@makubacki makubacki enabled auto-merge (rebase) November 18, 2025 01:27
@makubacki makubacki merged commit f7410f3 into main Nov 18, 2025
7 checks passed
@makubacki makubacki deleted the personal/mikuback/use_mm_in_perf_component_3 branch November 18, 2025 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact:breaking-change Requires integration attention impact:testing Affects testing type:documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task]: Update the patina_performance component to use the MM Communication service

5 participants