Skip to content

Patina: R-EFI 6.0 migration - #1480

Merged
makubacki merged 47 commits into
OpenDevicePartnership:majorfrom
vineelko:users/vineelko/patina-r-efi-6-0_0425
May 29, 2026
Merged

makubacki merged 47 commits into
OpenDevicePartnership:majorfrom
vineelko:users/vineelko/patina-r-efi-6-0_0425

Conversation

@vineelko

@vineelko vineelko commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

R-EFI 6.0 Migration

Upstream r-efi 6.0 marks all extern "efiapi" function pointers in EFI Boot
Services, Runtime Services, and other protocols as unsafe, since their safety
cannot be enforced by the Rust type system at compile time.

This PR audits almost all usage of UEFI service function pointers across the Patina
codebase for correctness and safety.

  • There are three primary areas where unsafe usage has been audited:

    1. The FFI boundary - all extern "efiapi" functions
    2. The Patina wrappers - all functions within the BootServices trait that
      eventually call into the FFI
    3. Core Patina routines that implement the FFI functions
  • Not all functions in the above categories need to be marked unsafe. For
    example, extern "efiapi" close_event is not marked unsafe because it can
    safely be called with an arbitrary event parameter without causing undefined
    behavior in the Patina implementation. The event parameter is treated as an
    opaque pointer and is never dereferenced.

    That said, any indirect caller that dereferences this Boot Services function
    pointer must still use an unsafe block, since the function pointer itself is
    defined as unsafe in r-efi 6.0. In addition, inherently unsafe Rust
    functions (such as core_free_pool()) are now explicitly marked unsafe.

  • Each inspected function or call site is documented with appropriate safety
    comments where necessary, and with explanations where unsafe is not
    required.

  • There are no functional changes.

  • Clippy flags public functions that accept raw pointer parameters and pass them
    across an FFI boundary without being marked unsafe, with the following
    warning:
    "this public function might dereference a raw pointer but is not marked unsafe"

    unsafe extern "C" {
        fn some_ffi_call(ptr: *mut i32);
    }
    
    // Triggers clippy::not_unsafe_ptr_arg_deref:
    // - public function
    // - not marked `unsafe`
    // - raw pointer parameter `ptr` is passed into an `unsafe` block
    pub fn example(ptr: *mut i32) {
        unsafe { some_ffi_call(ptr) };
    }
    

    In Patina, this pattern is common for functions that take efi::Event or
    efi::Handle parameters and call Boot Services function pointers. We
    explicitly suppress this lint for such functions because these types are
    treated as opaque pointers and are never dereferenced:
    #[allow(clippy::not_unsafe_ptr_arg_deref)]

Geiger Unsafe Stats

|             | x86_64-unknown-uefi(before) | x86_64-unknown-uefi(after) | aarch64-unknown-uefi(before) | aarch64-unknown-uefi(after) |
|-------------|-----------------------------|----------------------------|------------------------------|-----------------------------|
| overall     | 11.90% (yellow)             | 16.30% (red)               | 12.20% (yellow)              | 16.30% (red)                |
| functions   | 2.60%  (green)              | 11.40% (yellow)            | 2.80%  (green)               | 11.40% (yellow)             |
| exprs       | 12.40% (yellow)             | 17.00% (red)               | 12.60% (yellow)              | 17.00% (red)                |
| item_impls  | 12.50% (yellow)             | 13.80% (yellow)            | 13.80% (yellow)              | 13.80% (yellow)             |
| item_traits | 12.10% (yellow)             | 13.00% (yellow)            | 13.00% (yellow)              | 13.00% (yellow)             |
| methods     | 5.60%  (green)              | 6.60%  (green)             | 5.60%  (green)               | 6.60%  (green)              |

How This Was Tested

Booted to UEFI Shell Q35/SBSA

Integration Instructions

All consumers of Patina will need to pick the newer Patina version when published and also should update their r-efi version to 6.0.0.

@patina-automation

patina-automation Bot commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

QEMU Validation Failed

QEMU validation did not complete successfully or did not shutdown as expected.

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

⚠️ Build Failure Detected

The Setup and Build patina-dxe-core-qemu step failed in the following job(s):

  • Run Patina QEMU Validation / Validate QEMU - SBSA (Linux)
  • Run Patina QEMU Validation / Validate QEMU - Q35 (Linux)
  • Run Patina QEMU Validation / Validate QEMU Q35 (Windows)

Build logs are available in the workflow run artifacts:

Download the log artifacts from the workflow run to review the build output and
determine whether the error is expected.

Is this expected? If the PR introduces breaking changes to patina that
require a corresponding update to patina-dxe-core-qemu,
the build failure is expected.

Contact a repo admin or PR reviewer to override the Patina QEMU PR Validation status check.

Job Results

Job Result
Gather Incoming PR Metadata ✅
Run Patina QEMU Validation / Preflight Checks ✅
Run Patina QEMU Validation / Post In-Progress Notification ✅
Run Patina QEMU Validation / Get Constants / Get Repository Constants ✅
Run Patina QEMU Validation / Validate QEMU - SBSA (Linux) ❌
Run Patina QEMU Validation / Validate QEMU - Q35 (Linux) ❌
Run Patina QEMU Validation / Validate QEMU Q35 (Windows) ❌
Run Patina QEMU Validation / Emit PR Metadata ✅

Error Details

qemu-validation-logs-Linux-SBSA/sbsa-linux.log (15 error/warning sections)
… (truncated)


error[E0308]: mismatched types
   --> src/q35/component/service/smbios_platform.rs:125:30
    |
125 |             security_status: 0x02,
    |                              ^^^^ expected `SecurityStatus`, found integer


error[E0308]: mismatched types
   --> src/q35/component/service/smbios_platform.rs:155:28
    |
155 |             feature_flags: 0x01, // Board is a hosting board
    |                            ^^^^ expected `FeatureFlags`, found integer
    |
help: call `Into::into` on this expression to convert `{integer}` into `FeatureFlags`
    |
155 |             feature_flags: 0x01.into(), // Board is a hosting board
    |                                +++++++


error[E0308]: mismatched types
   --> src/q35/component/service/smbios_platform.rs:158:25
    |
158 |             board_type: 0x0A, // Motherboard
    |                         ^^^^ expected `BoardType`, found integer


error[E0308]: mismatched types
   --> src/q35/component/service/smbios_test.rs:45:49
    |
 45 |         boot_services.locate_protocol_unchecked(&SMBIOS_PROTOCOL_GUID, core::ptr::null_mut()).map_err(|e| {
    |                       ------------------------- ^^^^^^^^^^^^^^^^^^^^^ expected `r_efi::base::Guid`, found a different `r_efi::base::Guid`
    |                       |
    |                       arguments to this method are incorrect
    |
note: there are multiple different versions of crate `r_efi` in the dependency graph
   --> /.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/r-efi-6.0.0/src/base.rs:392:1
    |
392 | pub struct Guid {
    | ^^^^^^^^^^^^^^^ this is the expected type
    |
   ::: /.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/r-efi-5.3.0/src/base.rs:392:1
    |
392 | pub struct Guid {
    | --------------- this is the found type
    = help: you can use `cargo tree` to explore your dependency tree
note: method defined here
   --> /__w/patina/patina/sdk/patina/src/boot_services.rs:826:15
    |
826 |     unsafe fn locate_protocol_unchecked(
    |               ^^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0308`.

error: could not compile `qemu_dxe_core` (lib) due to 12 previous errors

warning: build failed, waiting for other jobs to finish...

[cargo-make] ERROR - Error while running duckscript: Source: Unknown Line: 113 - Error while executing command, exit code: 101
qemu-validation-logs-Linux-Q35/q35-linux.log (15 error/warning sections)
… (truncated)


error[E0308]: mismatched types
   --> src/q35/component/service/smbios_platform.rs:125:30
    |
125 |             security_status: 0x02,
    |                              ^^^^ expected `SecurityStatus`, found integer


error[E0308]: mismatched types
   --> src/q35/component/service/smbios_platform.rs:155:28
    |
155 |             feature_flags: 0x01, // Board is a hosting board
    |                            ^^^^ expected `FeatureFlags`, found integer
    |
help: call `Into::into` on this expression to convert `{integer}` into `FeatureFlags`
    |
155 |             feature_flags: 0x01.into(), // Board is a hosting board
    |                                +++++++


error[E0308]: mismatched types
   --> src/q35/component/service/smbios_platform.rs:158:25
    |
158 |             board_type: 0x0A, // Motherboard
    |                         ^^^^ expected `BoardType`, found integer


error[E0308]: mismatched types
   --> src/q35/component/service/smbios_test.rs:45:49
    |
 45 |         boot_services.locate_protocol_unchecked(&SMBIOS_PROTOCOL_GUID, core::ptr::null_mut()).map_err(|e| {
    |                       ------------------------- ^^^^^^^^^^^^^^^^^^^^^ expected `r_efi::base::Guid`, found a different `r_efi::base::Guid`
    |                       |
    |                       arguments to this method are incorrect
    |
note: there are multiple different versions of crate `r_efi` in the dependency graph
   --> /.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/r-efi-6.0.0/src/base.rs:392:1
    |
392 | pub struct Guid {
    | ^^^^^^^^^^^^^^^ this is the expected type
    |
   ::: /.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/r-efi-5.3.0/src/base.rs:392:1
    |
392 | pub struct Guid {
    | --------------- this is the found type
    = help: you can use `cargo tree` to explore your dependency tree
note: method defined here
   --> /__w/patina/patina/sdk/patina/src/boot_services.rs:826:15
    |
826 |     unsafe fn locate_protocol_unchecked(
    |               ^^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0308`.

error: could not compile `qemu_dxe_core` (lib) due to 12 previous errors

warning: build failed, waiting for other jobs to finish...

[cargo-make] ERROR - Error while running duckscript: Source: Unknown Line: 113 - Error while executing command, exit code: 101
qemu-validation-logs-Windows-Q35/q35-windows.log (15 error/warning sections)
… (truncated)


error[E0308]: mismatched types
   --> src\q35\component\service\smbios_platform.rs:125:30
    |
125 |             security_status: 0x02,
    |                              ^^^^ expected `SecurityStatus`, found integer


error[E0308]: mismatched types
   --> src\q35\component\service\smbios_platform.rs:155:28
    |
155 |             feature_flags: 0x01, // Board is a hosting board
    |                            ^^^^ expected `FeatureFlags`, found integer
    |
help: call `Into::into` on this expression to convert `{integer}` into `FeatureFlags`
    |
155 |             feature_flags: 0x01.into(), // Board is a hosting board
    |                                +++++++


error[E0308]: mismatched types
   --> src\q35\component\service\smbios_platform.rs:158:25
    |
158 |             board_type: 0x0A, // Motherboard
    |                         ^^^^ expected `BoardType`, found integer


error[E0308]: mismatched types
   --> src\q35\component\service\smbios_test.rs:45:49
    |
 45 |         boot_services.locate_protocol_unchecked(&SMBIOS_PROTOCOL_GUID, core::ptr::null_mut()).map_err(|e| {
    |                       ------------------------- ^^^^^^^^^^^^^^^^^^^^^ expected `r_efi::base::Guid`, found a different `r_efi::base::Guid`
    |                       |
    |                       arguments to this method are incorrect
    |
note: there are multiple different versions of crate `r_efi` in the dependency graph
   --> C:\Users\runneradmin\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\r-efi-6.0.0\src\base.rs:392:1
    |
392 | pub struct Guid {
    | ^^^^^^^^^^^^^^^ this is the expected type
    |
   ::: C:\Users\runneradmin\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\r-efi-5.3.0\src\base.rs:392:1
    |
392 | pub struct Guid {
    | --------------- this is the found type
    = help: you can use `cargo tree` to explore your dependency tree
note: method defined here
   --> D:\a\patina\patina\sdk\patina\src\boot_services.rs:826:15
    |
826 |     unsafe fn locate_protocol_unchecked(
    |               ^^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0308`.

error: could not compile `qemu_dxe_core` (lib) due to 12 previous errors

warning: build failed, waiting for other jobs to finish...

[cargo-make] ERROR - Error while running duckscript: Source: Unknown Line: 113 - Error while executing command, exit code: 101

Dependencies

Repository Ref
patina f5857cb
patina-dxe-core-qemu 5b470dd
patina-fw-patcher 3ea3802
patina-qemu firmware v3.0.0
patina-qemu build script 05e6c57

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

@codecov

codecov Bot commented Apr 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.92946% with 63 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
patina_dxe_core/src/protocols.rs 32.65% 33 Missing ⚠️
sdk/patina/src/boot_services.rs 93.64% 14 Missing ⚠️
patina_dxe_core/src/driver_services.rs 85.42% 7 Missing ⚠️
patina_dxe_core/src/pi_dispatcher/image.rs 88.24% 6 Missing ⚠️
patina_dxe_core/src/allocator.rs 91.67% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

Comment thread sdk/patina/src/boot_services.rs Resolved
Comment thread sdk/patina/src/boot_services.rs Resolved
Comment thread sdk/patina/src/boot_services.rs Resolved
Comment thread sdk/patina/src/boot_services.rs Resolved
Comment thread sdk/patina/src/boot_services.rs Resolved
@makubacki

Copy link
Copy Markdown
Collaborator

I haven't looked at the PR changes yet, but it should target the major branch due to the severity of breaking changes.

@vineelko
vineelko changed the base branch from main to major April 29, 2026 17:47
@vineelko
vineelko force-pushed the users/vineelko/patina-r-efi-6-0_0425 branch from 102fbd3 to ede86cc Compare April 29, 2026 17:48
@vineelko

Copy link
Copy Markdown
Contributor Author

I haven't looked at the PR changes yet, but it should target the major branch due to the severity of breaking changes.

Michael, The branch is now updated to target major instead of main.

@vineelko
vineelko force-pushed the users/vineelko/patina-r-efi-6-0_0425 branch from ede86cc to 3e6fd6c Compare May 1, 2026 18:07
Comment thread patina_dxe_core/src/allocator.rs Resolved
Comment thread patina_dxe_core/src/allocator.rs Resolved
Comment thread patina_dxe_core/src/allocator.rs Resolved
Comment thread patina_dxe_core/src/driver_services.rs Resolved
Comment thread patina_dxe_core/src/memory_manager.rs Resolved
@joschock joschock mentioned this pull request May 15, 2026
1 of 5 tasks
@vineelko
vineelko force-pushed the users/vineelko/patina-r-efi-6-0_0425 branch 2 times, most recently from cc656fc to 6114c86 Compare May 21, 2026 21:47
Comment thread sdk/patina/src/device_path/ptr.rs Resolved
Comment thread patina_dxe_core/src/allocator.rs Resolved
Comment thread patina_dxe_core/src/driver_services.rs Resolved
Comment thread sdk/patina/src/device_path/ptr.rs Resolved
Comment thread patina_dxe_core/src/allocator.rs Resolved
Comment thread patina_dxe_core/src/protocols.rs Resolved
Comment thread patina_dxe_core/src/protocols.rs Resolved
Comment thread sdk/patina/src/boot_services.rs Resolved
Comment thread sdk/patina/src/boot_services.rs Resolved
Comment thread sdk/patina/src/boot_services.rs Resolved
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
vineelko added 27 commits May 28, 2026 13:59
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
@vineelko
vineelko force-pushed the users/vineelko/patina-r-efi-6-0_0425 branch from 90b03b5 to f5857cb Compare May 28, 2026 21:34
@makubacki
makubacki merged commit e396ec8 into OpenDevicePartnership:major May 29, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants