Skip to content

RFC: Component Composition - #2045

Open
makubacki wants to merge 1 commit into
OpenDevicePartnership:mainfrom
makubacki:rfc_component_composition
Open

makubacki wants to merge 1 commit into
OpenDevicePartnership:mainfrom
makubacki:rfc_component_composition

Conversation

@makubacki

Copy link
Copy Markdown
Collaborator

Description

This RFC proposes a refactor of the Patina component system to support more flexible component composition.

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

How This Was Tested

  • cargo make cspell
  • markdownlint

Integration Instructions

  • N/A

This RFC proposes a refactor of the Patina component system to support
more flexible component composition.

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
@makubacki makubacki self-assigned this Dec 1, 2026
@makubacki makubacki added the rfc A request-for-change proposal label Dec 1, 2026
@patina-automation

patina-automation Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

✅ QEMU Validation Passed

All QEMU validation jobs completed successfully.

Note: Q35 is only built on Windows hosts (QEMU boot is disabled due to a QEMU vfat issue).

Workflow run: https://github.com/OpenDevicePartnership/patina/actions/runs/46561296085

Boot Time to EFI Shell

Platform Elapsed
ArmVirt (Linux Host) 22.4s
Q35 (Linux Host) 56.4s

EFI Test App Results

Pre-compiled test apps from the v4.1.6 patina-qemu release.

Platform Target Result Apps Cases passed Cases failed Elapsed
Q35 DEBUG ❔ no result - - - -
Q35 RELEASE ✅ 16 398 0 57.6s
ArmVirt DEBUG ✅ 16 439 0 1m 15s
ArmVirt RELEASE ✅ 15 410 0 1m 37s
Per-app results
App Q35 DEBUG Q35 RELEASE ArmVirt DEBUG ArmVirt RELEASE
BaseLibUnitTestApp.efi - ✅ 22/22 ✅ 22/22 ✅ 22/22
BootAuditTestApp.efi - ✅ 6/6 ✅ 6/6 ✅ 6/6
CheckHwErrRecHeaderTestApp.efi - ✅ 19/19 ✅ 19/19 ✅ 19/19
DxeMemoryProtectionTestApp.efi - ✅ 53/53 ✅ 53/53 ✅ 53/53
DxePagingAuditTestApp.efi - ✅ 6/6 ✅ 6/6 ✅ 6/6
ExceptionPersistenceTestApp.efi - ✅ 2/2 - -
FfaPartitionTestApp.efi - - ✅ 19/19 ✅ 19/19
FmpDependencyLibUnitTestApp.efi - ✅ 16/16 ✅ 16/16 ✅ 16/16
LineParserTestApp.efi - ✅ 66/66 ✅ 66/66 ✅ 66/66
MathLibUnitTestApp.efi - ✅ 5/5 ✅ 5/5 ✅ 5/5
MemmapAndMatFunctionalTestApp.efi - ✅ 17/17 ✅ 17/17 ✅ 17/17
MfciPolicyParsingLibUnitTestApp.efi - ✅ 44/44 ✅ 44/44 ✅ 44/44
MmSupvRequestUnitTestApp.efi - ✅ 5/5 - -
MsWheaReportUnitTestApp.efi - ✅ 7/7 ✅ 7/7 ✅ 7/7
TestBaseSafeIntLibTestApp.efi - ✅ 101/101 ✅ 101/101 ✅ 101/101
VariablePolicyFuncTestApp.efi - - ✅ 29/29 -
XmlTreeLibUnitTestApp.efi - ✅ 20/20 ✅ 20/20 ✅ 20/20
XmlTreeQueryLibUnitTestApp.efi - ✅ 9/9 ✅ 9/9 ✅ 9/9
### OS Boot Results
Platform OS Bootloader DEBUG RELEASE
Q35 Ubuntu 24.04.5 LTS (x64) GRUB 1.202.5+2.12-1ubuntu7.3, shim 1.58+15.8-0ubuntu1 ✅ 3m 14s ✅ 3m 3s
Q35 Windows Validation OS (x64) — ✅ 35.7s ✅ 27.9s
ArmVirt Ubuntu 24.04.5 LTS (aarch64) GRUB 1.202.5+2.12-1ubuntu7.3, shim 1.58+15.8-0ubuntu1 ✅ 5m 12s ✅ 4m 25s
ArmVirt Windows Validation OS (aarch64) — ✅ 3m 25s ✅ 4m 15s

Booted from an SSD. Time is QEMU power-on to guest power-off, so it includes OS shutdown.
Q35 runs with KVM acceleration and ArmVirt with TCG emulation, so times are not comparable across platforms.
USB boot is covered by the nightly OS boot test in patina-qemu.

Dependencies

Repository Ref
patina 06736b3
patina-dxe-core-qemu 9781943
patina-fw-patcher 820b0ae
patina-qemu firmware v4.1.6
patina-qemu build script 8eadf1e

Binary Size Report

Platform Commit Δ Debug Δ Release Δ Debug
(LZMA)
Δ Release
(LZMA)
Q35 (x86_64) Base:76959ab
PR:06736b3
 
1.22 MB
1.22 MB
Δ 0.00 B
978.00 KB
978.00 KB
Δ 0.00 B
470.16 KB
470.05 KB
Δ -111.00 B
384.65 KB
384.65 KB
Δ 0.00 B
ArmVirt (aarch64) Base:76959ab
PR:06736b3
 
1.11 MB
1.11 MB
Δ 0.00 B
894.00 KB
894.00 KB
Δ 0.00 B
383.77 KB
383.66 KB
Δ -107.00 B
316.04 KB
316.07 KB
Δ +28.00 B

Compressed sizes use LZMA-alone format at preset 6 (xz --format=lzma -6).

Shared QEMU integration: 9781943.

This comment was automatically generated by the Patina QEMU PR Validation Post workflow.

@github-actions github-actions Bot added impact:non-functional Does not have a functional impact type:documentation Improvements or additions to documentation labels Dec 1, 2026
@makubacki makubacki linked an issue Dec 1, 2026 that may be closed by this pull request
@codecov

codecov Bot commented Dec 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

- A simple component has one entry point and does not register other components. All existing components today are
simple components.
- A composite component is made of constituents.
- A _static_ composite component declares several `#[entry_point]` methods in an `impl` block for a given Rust type.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there can be multiple, I wonder if we should consider something other than entry_point, just to distance ourselves from the binary analogy if we are diverting from that expectation. Perhaps #[dispatch].

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

simple components.
- A composite component is made of constituents.
- A _static_ composite component declares several `#[entry_point]` methods in an `impl` block for a given Rust type.
- A _dynamic_ composite component has an entry point that registers other components using `Commands::add_component`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these mutually exclusive? Could a component implement an entry_point that adds components and also implement other entry_points? If so, is that something the core can enforce?


## Goals

1. Let one composite component represent a set of functionality regardless of how many constituents implement it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a goal to allow these dynamic components to able to be used individually? That is, is the composite a "default" setup, the only setup, or implementation defined?


#[entry_point]
fn communicator(
self,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the self makes sense as a copy, I suspect it may be an easy logical mistake for people to make with the introduction of multiple entry points. That is having one entry do self.setting = value and not realizing that doesn't persist to the other entries.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes this is a good call. These entry points will share the same "self" which is actually a nice side-effect beneifit of this. But because of this, they will need to be &self or &mut self.

With the current implementation of a StructComponent, the "self" is an Option<Self>. When we dispatch a component with &self and &mut self, we do a Option::borrow() or Option::borrow_mut() respectively. But for self, we do an Option::take(), which means when we go to dispatch the second entry point, we will panic.

- The final public names for the new APIs, including `Commands::add_component`, the attribute that marks multiple entry
points in one `impl` block, and whether `IntoComponent` and the `Component` trait are renamed. The `Component` trait
is the dispatchable form of an entry point, and `IntoComponent` can now produce several of them.
- Whether multiple entry points that share `&self` or `&mut self` (rather than `self` by value) are worth supporting,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mentioned later, I think the self is a pitfall with multiple entry points. This could be solved with private config types to pass config between entry points, but it seems like a logic thing to store data between entries in self.

But that also does mean that there is some ordering assumptions potentially..

`add.component` calls but not the limitation that the composition of a set of functionality is always public and always
static.

## Rust Code Design

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the general direction. My main concern is just the all the different ways it could be implemented. My hope from the "bundle" concept we had discussed was a simple prescribed method that the average consumer could use across every crate to create a well-prescribed and relatively standard was of including functionality. Perhaps one public composite component is that, but it seems we leave a lot of room for creativity still.

Perhaps this is a coding standard instead of a mechanism one.

entry points require an interior mutability design. Some general guidance on storing state in a component is provided in
[Storing State for Later Use](../../component/storing_state.md).

### Dynamic composition

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps I'm missed it, but does this RFC cover why both dynamic and static are required? Would it be possible to solve all problems with just one of these mechanisms? It would be nice to keep crate design relatively consistent so the more high-level options we provide may cause design divergence.

`Commands::add_component` (described below) both iterate the returned collection, so a registration call takes the same
path regardless of whether the component is simple or composite.

Each declared entry point receives a copy of `self`, so a type with more than one `#[entry_point]` method must implement

@Javagedes Javagedes Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I agree with this. I actually think it would be way more beneficial to component writers to have &self and &mut self shared between the independently dispatchable portions of a component. I think either removing self to support this type of usage, or at least restrict self usage to components with only one dispatchable component.

I can think of multiple benefits of sharing mutable state between different dispatchable pieces of a statically composed component.


### Dynamic composition

Dynamic composition applies when a constituent's existence depends on information that is available only during

@Javagedes Javagedes Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think dynamic composition is necessary; but I don't like enabling that by adding functionality that allows components to register other components at runtime. I understand that there is a similar precedence in PI spec to allow drivers to dispatch other drivers themselves, but I would much rather enable this differently, in a way that gets all dispatchable pieces of code registered before beginning the runtime dispatch process.

I think a better approach is to define an entirely new component type - e.g. an alternative to StructComponent defined in struct_component.rs whose Component trait implementation has a registration-only interface that executes during the intialize() phase of the component registration and can only register (1) other components, (2) services, (3) configs. It specifically has no ability to retrieve anything, only add things.

A lightweight mockup could look something like this:

// All of this goes somewhere in patina crate

pub struct Add<'a> {
    storage: &'a mut Storage,
    components: &'a mut ComponentRegistry,
}

impl Add<'_> {
    pub fn component<C: IntoComponent>(&mut self, component: C) {
        // Register component
    }

    pub fn config<C: Default + 'static>(&mut self, config: C) {
        self.storage.add_config(config);
    }

    pub fn service<S: IntoService + 'static>(&mut self, service: S) {
        self.storage.add_service(service);
    }
}

// A Component type that allows registration of components, services, and configs during its initialization before component dispatch begins.
pub struct DynamicComponent<F> {
    initialize: Option<F>,
    metadata: MetaData,
}

impl<F> Component for DynamicComponent<F>
where
    F: FnOnce(Add<'_>) -> bool,
{
    unsafe fn run_unsafe(
        &mut self,
        _storage: UnsafeStorageCell<'_>,
    ) -> Result<bool> {
        Ok(true)
    }

    fn initialize(&mut self, storage: &mut Storage) -> bool {
        let Some(initialize) = self.initialize.take() else {
            return false;
        };

        let add = Add::new(
            storage,
            /* component registration sink */
        );

        initialize(add)
    }

    fn metadata(&self) -> &MetaData {
        &self.metadata
    }
}
/// Now in the component writer crate, it goes somewhere like this
#[component]
fn my_dynamic_component(add: &mut Add) -> bool {
    add.config(MyConfig(u32));
    add.service(MyService::new());
    
    for test in STATIC_TEST_LIST {
        add.component(test)
    }

    true
}

impl ComponentInfo for MyPlatform {
    fn components(mut add: Add) {
        add.component(my_dynamic_component);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact:non-functional Does not have a functional impact rfc A request-for-change proposal type:documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tracking Issue: Patina component "bundling"

3 participants