Repository navigation
Conversation
✅ QEMU Validation PassedAll QEMU validation jobs completed successfully.
Workflow run: https://github.com/OpenDevicePartnership/patina/actions/runs/44638544883 Boot Time to EFI Shell
Dependencies
Binary Size Report
Compressed sizes use LZMA-alone format at preset 6 ( Shared QEMU integration: This comment was automatically generated by the Patina QEMU PR Validation Post workflow. |
|
@vineelko, could we get some patina book docs for this PR? We will need it eventually anyways, and it would be good to get an understanding of the architecture before reviewing edit: noticed the README.md files after posting, but would still be good to get this for the patina book. |
Sure Chris, will include it. |
515c48e to
6bb3601
Compare
|
Renaming this PR as draft until some more dust is settled. Please hold off on reviewing it. |
os-d
left a comment
There was a problem hiding this comment.
Leaving current set of comments in response to the comment to wait for the dust to settle :)
59d1a2a to
36656d1
Compare
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
Addressed most of the previous comments, fixed the alloc feature build failure, and consolidated the changes into above 7 commits. I did look into Stacked PRs, but the workflow seemed a bit more complicated, so I decided to continue in the current PR :-). I haven't gotten to the documentation yet, but I'll add it next. Overall, the PR is now up for review. |
36656d1 to
b42ed51
Compare
b42ed51 to
c92f2c0
Compare
b39911c to
577872b
Compare
0466373 to
5e85591
Compare
cfernald
left a comment
There was a problem hiding this comment.
Because I'm late to the party, I've avoiding leaving any non-blocking or stylistic comments. Looks good!
|
@vineelko, before merging, could you consider the following simple changes to address some final coverage gaps?
|
766afbc to
07cc6ff
Compare
07cc6ff to
57fde8a
Compare
This is the patch release before merging the Rust MM Supervisor changes. #1875 Co-authored-by: patina-automation[bot] <patina@microsoft.com>
Add the MmServices trait to the patina SDK. The trait is the safe Rust interface to the PI EFI_MM_SYSTEM_TABLE services. It covers pool and page allocation, MMI handler registration, protocol install notifications, and handle lookup. Every method returns a Result instead of a raw status. A core such as patina_mm_user_core implements MmServices and registers that implementation with StandardMmServices. The EfiMmSystemTable function pointers then forward each C call into the registered implementation. Rust callers use the trait directly and never dispatch through the shared table. Components reach the same implementation through MmServiceProvider, which resolves during parameter setup. Also add the management_mode::supervisor module. It holds what the two halves of the MM core must agree on before either one exists: the module GUIDs for the supervisor core, the user core and the init module, the UserCommandType values the supervisor passes when it calls into Ring 3, the SyscallIndex values Ring 3 passes back, and raw_syscall. Neither half can own this, so it lives in the SDK. Signed-off-by: Kun Qin <kun.qin@microsoft.com> Co-authored-by: Kun Qin <kun.qin@microsoft.com> Co-authored-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
…for supv Add a save_state module to patina_internal_cpu. It defines the MmSaveStateRegister values from the PI specification and the vendor register maps that give the offset and width of each register inside the SMRAM save state area. The MM supervisor needs these offsets to serve save state reads on behalf of Ring 3 code. The layout differs between Intel and AMD, so each vendor map lives in its own file, intel.rs and amd.rs. Both maps are always compiled so each one is type checked and unit tested in every build, including the --all-features build that CI uses for clippy, coverage, and docs. The active map is chosen by the save_state_intel and save_state_amd features. Intel is the default when both features or neither feature is enabled. Signed-off-by: Kun Qin <kun.qin@microsoft.com> Co-authored-by: Kun Qin <kun.qin@microsoft.com> Co-authored-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Add MemoryRange to the base module and export it, with MemoryRangeError, from the crate root. A MemoryRange is a [base, base + size) range whose size is never zero and whose end always fits in a u64. The constructors (new, from_inclusive, from_pages and TryFrom for Rust ranges) return an error instead of building a range that breaks these rules. Code that handles address ranges as (base, size) pairs repeats the same overflow, overlap and containment checks, often with checked_add at each call site. With these rules held by the type, a range that wraps the address space or has no size cannot reach that code. The type provides containment, overlap, intersection, union, alignment checks, extension and iteration by step. collapse returns the range that covers a list of ranges, and coalesce does the same but fails when the ranges leave a gap. find_overlap returns the first overlapping pair in a list, and coverage reports whether a list covers a range fully, partly, or not at all. MemoryRangeError converts to EfiError::InvalidParameter. Signed-off-by: Kun Qin <kun.qin@microsoft.com> Co-authored-by: Kun Qin <kun.qin@microsoft.com> Co-authored-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Add patina_mm_supervisor, the Ring 0 half of the standalone MM core. It runs on x86-64 and replaces the C MM supervisor in MmSupervisorPkg. The entry shim starts at efi_main and jumps to rust_main, which the platform binary supplies. The BSP performs the one time initialization and then serves incoming MMI requests. It arms the syscall entry path and the call gate, builds the page tables and the memory policy, programs the SMRRs to protect MMRAM from accesses outside MM, and demotes execution to Ring 3 before it calls the user core. APs wait in a holding pen and poll a mailbox for work from the BSP. The crate does not allocate from a heap. Signed-off-by: Kun Qin <kun.qin@microsoft.com> Co-authored-by: Kun Qin <kun.qin@microsoft.com> Co-authored-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Add unit tests that run on the host for most modules in the crate: HOB validation, the page and paging allocators, the policy gate, the syscall dispatcher, the call gate, the supervisor request handlers, save state, SMRR, the mailbox and the semaphore. A new test_support module holds the shared fixtures, and mm_policy gains a builder for synthetic policy buffers. Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com> Co-authored-by: Kun Qin <kun.qin@microsoft.com> Co-authored-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Add patina_mm_user_core, the Ring 3 half of the standalone MM core. It performs the same work as the C StandaloneMmCore. It walks the HOB list to find MM drivers, evaluates their dependency expressions, dispatches them, and routes MMI requests to the registered handlers. The supervisor calls the entry point with one of three commands. StartUserCore runs the one time setup and the first dispatch pass. UserRequest parses a communication buffer and invokes the matching MMI handler. UserApProcedure runs a procedure on behalf of an AP. The crate implements the MmServices trait from the SDK and publishes an EfiMmSystemTable for C drivers. It keeps its own protocol database and configuration table, and serves small allocations from a pool that requests pages from the supervisor by syscall. Ring 3 has no direct access to supervisor resources, so every privileged operation goes through the syscall interface. A component dispatcher lets a platform register native Patina components next to the C drivers. Signed-off-by: Kun Qin <kun.qin@microsoft.com> Co-authored-by: Kun Qin <kun.qin@microsoft.com> Co-authored-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
``` | Filename | Function Coverage | Line Coverage | Region Coverage | | --------------------------------------------------------------------------- | ----------------- | ----------------- | ----------------- | | patina_mm_user_core\src\component_dispatcher.rs | 100.00% (19/19) | 100.00% (83/83) | 95.80% (137/143) | | patina_mm_user_core\src\config_table.rs | 100.00% (7/7) | 100.00% (69/69) | 98.72% (77/78) | | patina_mm_user_core\src\core_handlers.rs | 100.00% (10/10) | 94.74% (90/95) | 92.04% (104/113) | | patina_mm_user_core\src\lib.rs | 100.00% (19/19) | 86.18% (187/217) | 85.25% (289/339) | | patina_mm_user_core\src\mm_dispatcher.rs | 100.00% (9/9) | 93.33% (140/150) | 89.26% (216/242) | | patina_mm_user_core\src\mm_mem.rs | 100.00% (8/8) | 100.00% (45/45) | 100.00% (68/68) | | patina_mm_user_core\src\mm_services.rs | 100.00% (34/34) | 99.47% (378/380) | 98.85% (431/436) | | patina_mm_user_core\src\mmi.rs | 100.00% (17/17) | 99.41% (169/170) | 96.40% (214/222) | | patina_mm_user_core\src\pool_allocator.rs | 100.00% (9/9) | 100.00% (90/90) | 99.38% (160/161) | | patina_mm_user_core\src\protocol_db.rs | 100.00% (29/29) | 100.00% (153/153) | 100.00% (248/248) | ``` Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com> Co-authored-by: Kun Qin <kun.qin@microsoft.com> Co-authored-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
…evel Add patina_mm_cpu, a component that produces the PI EFI_MM_CPU_PROTOCOL inside the MM user core. The protocol lets MM drivers read the architecture standard registers of a CPU save state, including the fields that describe the I/O instruction that caused a software MMI. The save state lives in SMRAM that only the supervisor can read, so Ring 3 cannot reach it. ReadSaveState forwards each read to the supervisor through the save state syscall, and the supervisor applies the save state policy before it returns a value. This replaces the C MmSupervisedCpu driver in MmSupervisorPkg. A platform registers the component through its MmComponentInfo implementation. Signed-off-by: Kun Qin <kun.qin@microsoft.com> Co-authored-by: Kun Qin <kun.qin@microsoft.com> Co-authored-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Add a Patina MM Subsystems part to the book. It explains how patina_mm_supervisor and patina_mm_user_core work, from the first MMI to the services that MM drivers call, so a reader can follow the design without reading the code first. The part has eight pages: - Theory and Operation: actors, cores and rings, the MMRAM map, the trust model, the crate map and the global state of each core - Initialization and Initialization Validation: the first MMI on the BSP and the APs, and every check made on what MM Init hands over - Privilege Boundary: demotion to Ring 3, the call gate, the syscalls, failure handling and Ring 0 access to user pages - MMI Handling: the rendezvous, the communication buffers, supervisor and user requests, and AP procedures - Memory Management: MMRAM and the SMRRs, the page allocator, the page table, page ownership and unblocked memory - Security Policy: the policy blob, the runtime gate, the memory policy and the boundary audit - User Core: the MM System Table, the protocol and MMI handler databases, component and driver dispatch, and the save state A new integration page, Patina MM Supervisor Requirements, lists what a platform must provide: processor support, MMRAM layout, MM Init state, HOBs, the security policy file, MM driver rules and the requests from outside MM, followed by the known limitations. The figures are SVG files in docs/src/media, drawn in one style with numbered steps. Every statement was checked against the code. Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com> Co-authored-by: Kun Qin <kun.qin@microsoft.com> Co-authored-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
57fde8a to
641ec14
Compare
Description
[feature/supv] patina: sdk: Add MM services and the supervisor ABI
[feature/supv] patina: core: patina_internal_cpu: save state support for supv
patina: Add MemoryRange for checked address ranges
[feature/supv] patina_mm_supervisor: Add the MM supervisor core
[feature/supv] patina_mm_supervisor: Add unit tests across the crate
[feature/supv] patina_mm_user_core: Add the MM user core
[feature/supv] patina_mm_user_core: Improve unit test coverage
[feature/supv] patina: component: Add a MM CPU component at mm user level
[feature/supv] docs: Add the MM supervisor and user core documentation
RFC: https://github.com/OpenDevicePartnership/patina/blob/main/docs/src/rfc/text/0026-mm-supv.md
[feature/supv] patina: sdk: Add MM services and the supervisor ABI
Add the MmServices trait to the patina SDK. The trait is the safe Rust
interface to the PI EFI_MM_SYSTEM_TABLE services. It covers pool and
page allocation, MMI handler registration, protocol install
notifications, and handle lookup. Every method returns a Result instead
of a raw status.
A core such as patina_mm_user_core implements MmServices and registers
that implementation with StandardMmServices. The EfiMmSystemTable
function pointers then forward each C call into the registered
implementation. Rust callers use the trait directly and never dispatch
through the shared table. Components reach the same implementation
through MmServiceProvider, which resolves during parameter setup.
Also add the management_mode::supervisor module. It holds what the two
halves of the MM core must agree on before either one exists: the
module GUIDs for the supervisor core, the user core and the init
module, the UserCommandType values the supervisor passes when it calls
into Ring 3, the SyscallIndex values Ring 3 passes back, and
raw_syscall. Neither half can own this, so it lives in the SDK.
[feature/supv] patina: core: patina_internal_cpu: save state support for supv
Add a save_state module to patina_internal_cpu. It defines the
MmSaveStateRegister values from the PI specification and the vendor
register maps that give the offset and width of each register inside the
SMRAM save state area.
The MM supervisor needs these offsets to serve save state reads on behalf
of Ring 3 code. The layout differs between Intel and AMD, so each vendor
map lives in its own file, intel.rs and amd.rs.
Both maps are always compiled so each one is type checked and unit tested
in every build, including the --all-features build that CI uses for
clippy, coverage, and docs. The active map is chosen by the
save_state_intel and save_state_amd features. Intel is the default when
both features or neither feature is enabled.
patina: Add MemoryRange for checked address ranges
Add MemoryRange to the base module and export it, with MemoryRangeError,
from the crate root. A MemoryRange is a [base, base + size) range whose
size is never zero and whose end always fits in a u64. The constructors
(new, from_inclusive, from_pages and TryFrom for Rust ranges) return an
error instead of building a range that breaks these rules.
Code that handles address ranges as (base, size) pairs repeats the same
overflow, overlap and containment checks, often with checked_add at each
call site. With these rules held by the type, a range that wraps the
address space or has no size cannot reach that code.
The type provides containment, overlap, intersection, union, alignment
checks, extension and iteration by step. collapse returns the range that
covers a list of ranges, and coalesce does the same but fails when the
ranges leave a gap. find_overlap returns the first overlapping pair in a
list, and coverage reports whether a list covers a range fully, partly,
or not at all. MemoryRangeError converts to EfiError::InvalidParameter.
[feature/supv] patina_mm_supervisor: Add the MM supervisor core
Add patina_mm_supervisor, the Ring 0 half of the standalone MM core. It
runs on x86-64 and replaces the C MM supervisor in MmSupervisorPkg. The
entry shim starts at efi_main and jumps to rust_main, which the
platform binary supplies.
The BSP performs the one time initialization and then serves incoming
MMI requests. It arms the syscall entry path and the call gate, builds
the page tables and the memory policy, programs the SMRRs to protect
MMRAM from accesses outside MM, and demotes execution to Ring 3 before
it calls the user core. APs wait in a holding pen and poll a mailbox
for work from the BSP.
The crate does not allocate from a heap.
[feature/supv] patina_mm_supervisor: Add unit tests across the crate
Add unit tests that run on the host for most modules in the crate: HOB
validation, the page and paging allocators, the policy gate, the
syscall dispatcher, the call gate, the supervisor request handlers,
save state, SMRR, the mailbox and the semaphore. A new test_support
module holds the shared fixtures, and mm_policy gains a builder for
synthetic policy buffers.
[feature/supv] patina_mm_user_core: Add the MM user core
Add patina_mm_user_core, the Ring 3 half of the standalone MM core. It
performs the same work as the C StandaloneMmCore. It walks the HOB list
to find MM drivers, evaluates their dependency expressions, dispatches
them, and routes MMI requests to the registered handlers.
The supervisor calls the entry point with one of three commands.
StartUserCore runs the one time setup and the first dispatch pass.
UserRequest parses a communication buffer and invokes the matching MMI
handler. UserApProcedure runs a procedure on behalf of an AP.
The crate implements the MmServices trait from the SDK and publishes an
EfiMmSystemTable for C drivers. It keeps its own protocol database and
configuration table, and serves small allocations from a pool that
requests pages from the supervisor by syscall. Ring 3 has no direct
access to supervisor resources, so every privileged operation goes
through the syscall interface. A component dispatcher lets a platform
register native Patina components next to the C drivers.
[feature/supv] patina_mm_user_core: Improve unit test coverage
[feature/supv] patina: component: Add a MM CPU component at mm user level
Add patina_mm_cpu, a component that produces the PI EFI_MM_CPU_PROTOCOL
inside the MM user core. The protocol lets MM drivers read the
architecture standard registers of a CPU save state, including the fields
that describe the I/O instruction that caused a software MMI.
The save state lives in SMRAM that only the supervisor can read, so Ring
3 cannot reach it. ReadSaveState forwards each read to the supervisor
through the save state syscall, and the supervisor applies the save state
policy before it returns a value.
This replaces the C MmSupervisedCpu driver in MmSupervisorPkg. A platform
registers the component through its MmComponentInfo implementation.
[feature/supv] docs: Add the MM supervisor and user core documentation
Add a Patina MM Subsystems part to the book. It explains how
patina_mm_supervisor and patina_mm_user_core work, from the first MMI to
the services that MM drivers call, so a reader can follow the design
without reading the code first.
The part has eight pages:
trust model, the crate map and the global state of each core
BSP and the APs, and every check made on what MM Init hands over
failure handling and Ring 0 access to user pages
and user requests, and AP procedures
table, page ownership and unblocked memory
and the boundary audit
databases, component and driver dispatch, and the save state
A new integration page, Patina MM Supervisor Requirements, lists what a
platform must provide: processor support, MMRAM layout, MM Init state,
HOBs, the security policy file, MM driver rules and the requests from
outside MM, followed by the known limitations. The figures are SVG files
in docs/src/media, drawn in one style with numbered steps. Every
statement was checked against the code.
Coauthored-off-by: Kun Qin kun.qin@microsoft.com
Coauthored-off-by: Vineel Kovvuri[MSFT] vineelko@microsoft.com
How This Was Tested
Validated on internal hardware platforms.
Integration Instructions
Consumed in SEA repository to produce Supervisor, User Core, SEA rule sets and related binaries.
Note: Patina v24.4.1 is the last release before merging this PR.