Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Theory and Operation

Patina implements Standalone MM as two Rust cores separated by privilege. The MM Supervisor (patina_mm_supervisor) runs in Ring 0 inside MMRAM. It takes over the page table MM Init built and is then the only code that changes it, and it owns MMRAM allocation, the processors and the security policy. The MM User Core (patina_mm_user_core) runs in Ring 3 together with every MM driver and provides the MM System Table, the protocol and MMI handler databases and driver dispatch. The split keeps driver code away from MMRAM, MSRs, I/O ports and the page table: Ring 3 reaches them only through syscalls that the supervisor checks against the firmware security policy.

Both cores are library crates, not images. A platform builds each one into an image with its own small binary crate: the binary crate links the library, supplies the platform configuration and the function the library's entry shim calls, and is built for x86_64-unknown-uefi. The result is two PE/COFF images, typically named mm_supervisor.efi and mm_user_core.efi, which MM Init loads into MMRAM. The crate READMEs show the binary crate for each.

Construction

Each binary crate holds one static instance of its core and exports the function the library's efi_main shim calls. The platform chooses its supervisor MMI handlers through PlatformInfo and its user core components through MmComponentInfo; everything else comes from the library.

// mm_supervisor.efi
static SUPERVISOR: MmSupervisorCore<Platform> = MmSupervisorCore::new();

fn rust_main(cpu_index, hob_list) {
    SUPERVISOR.entry_point(cpu_index, hob_list)
}

// mm_user_core.efi
static USER_CORE: MmUserCore = MmUserCore::new();

fn user_core_main(op_code, arg1, arg2) -> status {
    USER_CORE.entry_point_worker::<Platform>(op_code, arg1, arg2)
}

Neither library installs a logger or a panic handler; each binary crate provides its own. The user core's logger runs in Ring 3, where every port access faults, so a logger that writes a serial port must use the IoWrite syscall, and the security policy must allow those ports.

Actors

ActorRuns inRole
MM InitPEI phase, started by the PEI MM IPLLoads the supervisor, user core and MM driver images into MMRAM and prepares the HOB list, page table and per-core MMI entry
SupervisorRing 0, MMRAMValidates what MM Init left behind, serves every MMI on every core, and performs privileged operations for Ring 3
User core and MM driversRing 3, MMRAMRuns the MM System Table services, Patina components, MM driver entry points and MMI handlers

MM Init today is MmSupervisorInit.efi from mu_feature_mm_supv. The supervisor does not depend on that image, only on the state it leaves behind, which the requirements describe.

MM actors

MM Init does not stay in control. It raises the first MMI, and from then on the MMI entry code calls MmSupervisorCore::entry_point on every core. The supervisor is the only code that enters Ring 3, and Ring 3 comes back only through a syscall or the call gate at the end of a demoted routine.

Cores and Privilege Rings

Every core runs in Ring 0 unless the supervisor demotes it. The BSP and an AP are never in Ring 3 at the same time: while an AP runs a procedure in Ring 3, the BSP waits in Ring 0 inside the StartApProc syscall.

CoreRing 0Ring 3
BSP- One-time initialization on the first MMI
- The rendezvous on every later MMI
- Every supervisor request
- Every syscall it makes from Ring 3
- Waiting on an AP procedure
- The exit barrier
- StartUserCore, once on the first MMI
- Every user request and asynchronous MMI (UserRequest)
AP- Its first entry
- The holding pen
- Every syscall it makes from Ring 3
- The exit barrier
- Only while running a procedure the BSP sent with StartApProc (UserApProcedure)

Initialization covers the first MMI and MMI Handling covers later MMIs.

Memory Map

A typical physical address map, top to bottom. Rows are not to scale; the dimension lines mark the window and stack sizes. The order of the regions inside MMRAM varies by platform; only the offsets within each core's SMBASE window are fixed. Outside MMRAM, a page is present only where a HOB names it.

Typical MM physical address map

Each core's SMBASE window is 64 KiB, but MM Init places the SMBASEs one tile apart, typically 8 KiB, so the windows overlap, as the shaded rectangles show. Inside its window a core uses only its MMI entry code at SMBASE + 0x8000 and its PSD and save state map from SMBASE + 0xFB00 to the end of the window. Other cores' pieces sit between them, and the lower 32 KiB of the window holds nothing for that core. The processor writes the save state map on every SMI, so no two cores' entry code, PSD or save state may overlap. Memory Management and Initialization Validation describe how each region is mapped and checked.

Trust Model

SideTrustsValidates
SupervisorThe core, and the address of its own code as proof of where MMRAM isEverything MM Init hands over, once on the first MMI; every request from outside MM, after copying it into MMRAM; every syscall's index, arguments and policy grant
User coreThe supervisor, and the read-only HOB list copy the supervisor hands overThe raw arguments of every MM System Table service, and each MMI message against its communication buffer
MM driversThe user core and the supervisorPointers from callers, through MmIsCommBuffer and MmMemoryUnblocked

MM Init is checked, not trusted. Initialization Validation lists every check, and the requirements page lists what MM Init must provide for them to pass.

Crate Map

patina_mm_supervisor:

ModuleOwns
mmcoreThe per-core lifecycle: first entry, initialization, runtime, cores and AP mailboxes
hobHOB list validation and the MM Supervisor PassDown HOB
memoryThe MMRAM bound, page allocation, the paging pool and page table checks
policyFirmware policy validation, the PolicyGate and the memory policy
privilege_mgmtDemotion to Ring 3, the call gate return, syscall dispatch and save state access
handlersBuilt-in supervisor MMI handlers and the SupervisorMmiHandler type for platforms
comm_bufferThe supervisor and user communication channels
stateThe supervisor's global state
errorMmSupervisorError, the crate's error type
intrinsicsWrappers for privileged instructions
user_access_guardScoped Ring 0 access to Ring 3 memory
versionThe version the supervisor reports

patina_mm_user_core:

ModuleOwns
libMmUserCore and the entry protocol from the supervisor
mm_servicesThe MM System Table services
protocol_dbThe handle and protocol database
mmiThe MMI handler database
mm_dispatcherMM driver discovery and dispatch in dependency order
component_dispatcherThe platform's Patina components, from MmComponentInfo
core_handlersThe lifecycle MMI handlers the user core registers for itself
config_tableThe MM configuration table
pool_allocatorThe global heap allocator
mm_memPage allocation through syscalls
image_nameDriver names for dispatch logs

Global State

The supervisor keeps its global state in two stores, InitState and SecurityState. Most of it is written once, by the BSP during initialization, and only read afterwards. One-time values are Once cells that ignore later writes; counters and flags are atomics; the page table and the save state handoff are behind spin locks. The arrows show who writes, reads, or does both.

MM supervisor global state

The platform's MmSupervisorCore static holds the per-core data (core slots, AP mailboxes, Ring 3 stacks and the core count), and InitState records its address so code without a reference can reach it. The allocators, the unblocked memory tracker and the policy gate are described in Memory Management and Security Policy.

Design Rules

No heap in the supervisor. MmSupervisorCore::new is a const fn, so the platform declares the supervisor as a static, and the crate has no global allocator. Run-time memory such as the per-core arrays and the HOB list copy comes from the MMRAM page allocator. The user core has a heap, whose pages come from the supervisor through syscalls.

Per-core arrays are sized from the MP Information HOB. The HOB must lie inside MMRAM and report at least one core. The Ring 3 stacks, the SMBASE array and the per-core initialized slots from the PassDown HOB are checked against the same count. There is no compile-time core limit; a core index outside the arrays is an initialization error.

Validate before use. The HOB list headers are checked before anything walks the list, and the MMRAM descriptors must cover the supervisor's own code before anything in MMRAM is written. Requests from outside MM are copied into MMRAM before a handler reads them. A Ring 3 pointer is checked for user ownership before Ring 0 touches it, and then only inside a scoped user access window. The firmware policy is accepted before the first syscall can run.

Fail secure. Every fallible step returns a Result. The supervisor panics on purpose where continuing would mean running on state it has not validated, or with part of the system outside its control:

Panic siteTriggerReason
Entry pointAny error on a core's first entry, in initialization or MMI entry validationThe supervisor cannot run on state it could not validate
RendezvousAn AP misses the arrival or exit windowNo request is served, and MM is not left, with cores missing
Syscall dispatchA refused or failed syscall, or an unknown syscall indexThe policy or page ownership forbids the request
Ready to lockThe memory policy snapshot failsReady to lock must not complete without a locked memory policy
MM Init image releaseThe image is outside MMRAM, no page table is installed, or its pages cannot be freedThe image must not stay mapped after MM Init is done
Per-core initializationThe core does not report SMM Code Access CheckThere is no fallback without it
MMRAM range checkA buffer crosses the MMRAM boundaryA range must be wholly inside or wholly outside MMRAM
Exception handlerAny CPU exception, in Ring 0 or Ring 3MM has no recovery path for a fault

Note

Save state read syscalls are the exception to the syscall rule: their failures return a status that ReadSaveState passes to its caller. Privilege Boundary lists each syscall's failure behavior.

Where to Go Next