Patina: R-EFI 6.0 migration#1480
Conversation
⌛ QEMU Validation PendingQEMU validation is pending on successful CI completion.
This comment was automatically generated by the Patina QEMU PR Validation workflow. |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
I haven't looked at the PR changes yet, but it should target the |
102fbd3 to
ede86cc
Compare
Michael, The branch is now updated to target major instead of main. |
ede86cc to
3e6fd6c
Compare
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>
3e6fd6c to
cc656fc
Compare
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
Signed-off-by: Vineel Kovvuri[MSFT] <vineelko@microsoft.com>
cc656fc to
6114c86
Compare
| /// ``` | ||
| /// | ||
| pub unsafe fn core_disconnect_controller( | ||
| pub fn core_disconnect_controller( |
There was a problem hiding this comment.
I notice that you changed core_disconnect_controller() from unsafe to safe, and I understand the reasoning, given the platform/environment uncertainties during disconnect versus conditions controlled by the caller for connect. While the nuance is fine, at the function level, the asymmetry is more apparent by the fact that core_connect_controller() remains unsafe.
Can you please add a brief clarifying comment about this in the core_disconnect_controller() doc comment?
There was a problem hiding this comment.
This one feel bit odd to me, because marking the core_connect_controller() as unsafe for its undefined behavior not caused by the current inputs(but purely based on spec assumptions). This cannot be guaranteed by the caller. So, even though we have a safety comment explaining the scenario it feels like that function is marked unsafe incorrectly. In any case, we should have marked both unsafe or both safe. For now, I am marking the core_disconnect_controller() also as unsafe as similar undefined behavior can happen in disconnect call. I am open to change both of them otherwise.
There was a problem hiding this comment.
Yeah, my comment here is specifically about clearly explaining the decision made regardless of the decision itself.
Regarding the decision, my take is:
Handles are disjoint from the type system but should be able to be safely verified by the protocol database implementation. Since core_disconnect_controller() exclusively takes three handles, I thought it was reasonable to be safe. Implementation-aware safety invariants can be considered separately from UEFI-specification environmental dangers.
Because core_connect_controller() takes handles + a raw pointer (optional, to a protocol), I thought it was reasonable to be unsafe. The pointer can be checked for being non-null simple enough, but there is a lifetime aspect to its protocol interface buffer being valid throughout the execution of core_connect_controller() that is, at least partially, the caller's responsibility and cannot be verified otherwise than the safety contract.
There was a problem hiding this comment.
Updated the function comments to explain why they are being marked unsafe. The lifetime aspect of the protocol interface also seems to apply for the core_disconnect_controller() because it internally calls DriverBinding->Stop(). Hence keeping both of them as unsafe(Even though the inputs are exclusively handles which can be validated against the ProtocolDB).
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>
82949ad to
90b03b5
Compare
Description
R-EFI 6.0 Migration
Upstream r-efi 6.0 marks all
extern "efiapi"function pointers in EFI BootServices, Runtime Services, and other protocols as
unsafe, since their safetycannot 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
unsafeusage has been audited:extern "efiapi"functionsBootServicestrait thateventually call into the FFI
Not all functions in the above categories need to be marked
unsafe. Forexample,
extern "efiapi" close_eventis not markedunsafebecause it cansafely be called with an arbitrary event parameter without causing undefined
behavior in the Patina implementation. The
eventparameter is treated as anopaque pointer and is never dereferenced.
That said, any indirect caller that dereferences this Boot Services function
pointer must still use an
unsafeblock, since the function pointer itself isdefined as
unsafein r-efi 6.0. In addition, inherently unsafe Rustfunctions (such as
core_free_pool()) are now explicitly markedunsafe.Each inspected function or call site is documented with appropriate safety
comments where necessary, and with explanations where
unsafeis notrequired.
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 followingwarning:
"this public function might dereference a raw pointer but is not marked
unsafe"In Patina, this pattern is common for functions that take
efi::Eventorefi::Handleparameters and call Boot Services function pointers. Weexplicitly 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
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.