Skip to content

Refactor OP-TEE message types and add RPC args support#664

Open
sangho2 wants to merge 7 commits intomainfrom
sanghle/optee/msgs_v2
Open

Refactor OP-TEE message types and add RPC args support#664
sangho2 wants to merge 7 commits intomainfrom
sanghle/optee/msgs_v2

Conversation

@sangho2
Copy link
Contributor

@sangho2 sangho2 commented Feb 13, 2026

This PR refactors the OP-TEE message types and related functions to handle variable-length parameters. It also supports OP-TEE RPC message types to enable future RPC implementation. In addition, it leverages zerocopy to remove some unsafe operations.

#641

@sangho2 sangho2 marked this pull request as ready for review February 13, 2026 03:32
@sangho2 sangho2 force-pushed the sanghle/optee/msgs_v2 branch from 275c28f to e2e91e2 Compare February 13, 2026 05:07
Copy link
Member

@wdcui wdcui left a comment

Choose a reason for hiding this comment

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

Overall the code looks good to me. I left some minor comments below.

}
}
pub use workaround_identity_op_suppression::UteeParamsTypes;
/// Number of RPC parameters that LiteBox defined and reported to the normal-world
Copy link
Member

Choose a reason for hiding this comment

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

Nit: LiteBox -> the OPTEE shim?


/// `OPTEE_MSG_RPC_CMD_*` from `optee_os/core/include/optee_msg.h`
///
/// These are the command IDs used in the `cmd` field of the RPC `optee_msg_arg`.
Copy link
Member

Choose a reason for hiding this comment

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

The comment here overlaps quite a bit with the comment above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let me merge them

impl OpteeMsgAttr {
/// Returns the attribute type (bits 0–7).
#[allow(clippy::cast_possible_truncation)]
pub fn typ(&self) -> u8 {
Copy link
Member

Choose a reason for hiding this comment

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

OPTEE calls this typ instead of type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OP-TEE calls it type but type is a reserved keyword in Rust.

Copy link
Member

Choose a reason for hiding this comment

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

Can we use a longer name like "xxx_type"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

attr_type?

/// Maximum number of parameters that `OpteeMsgArgs` can hold.
///
/// This is `TEE_NUM_PARAMS + 2` = 6, matching the Linux driver's `MAX_ARG_PARAM_COUNT`.
pub const MAX_PARAMS: usize = TEE_NUM_PARAMS + 2;
Copy link
Member

Choose a reason for hiding this comment

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

NIT: MAX_PARAMS is public and sounds very general. Maybe TEE_MAX_NUMBER_PARAME`?

Copy link
Contributor Author

@sangho2 sangho2 Feb 13, 2026

Choose a reason for hiding this comment

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

This is a member constant of OpteeMsgArgs. Can rename it if it looks too general.

Copy link
Member

Choose a reason for hiding this comment

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

It may help to make the name more specific.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

MAX_ARG_PARAM_COUNT? This is what OP-TEE driver is using.

/// Maximum number of RPC parameters this struct can hold.
///
/// This is [`NUM_RPC_PARAMS`], the count negotiated during `EXCHANGE_CAPABILITIES`.
pub const MAX_PARAMS: usize = NUM_RPC_PARAMS;
Copy link
Member

Choose a reason for hiding this comment

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

Another MAX_PARAMS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same. this is a member constant of OpteeRpcArgs.

if num > Self::MAX_PARAMS {
return Err(OpteeSmcReturnCode::EBadCmd);
}
let needed = num * size_of::<OpteeMsgParam>();
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to include the header size here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This variable checks whether the length of new_params is enough to store parameters. Let me rename the variable name.

// Compute copy size from known-good upper bounds — no untrusted data involved.
let main_max = optee_msg_arg_total_size(OpteeMsgArgs::MAX_PARAMS.truncate());
let copy_size = if has_rpc_arg {
main_max + optee_msg_arg_total_size(NUM_RPC_PARAMS.truncate())
Copy link
Member

Choose a reason for hiding this comment

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

why do use NUM_RPC_PARAMS here instead of MAX_PARAMS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me use OpteeRpcArgs::MAX_PARAMS instead of NUM_RPC_PARAMS.

@sangho2 sangho2 force-pushed the sanghle/optee/msgs_v2 branch from 002a576 to 28d0a36 Compare February 13, 2026 23:17
@github-actions
Copy link

🤖 SemverChecks 🤖 ⚠️ Potential breaking API changes detected ⚠️

Click for details
--- failure enum_struct_variant_field_added: pub enum struct variant field added ---

Description:
An enum's exhaustive struct variant has a new field, which has to be included when constructing or matching on this variant.
        ref: https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.46.0/src/lints/enum_struct_variant_field_added.ron

Failed in:
  field rpc_args of variant OpteeSmcResult::CallWithArg in /home/runner/work/litebox/litebox/litebox_common_optee/src/lib.rs:2060

--- failure inherent_method_missing: pub method removed or renamed ---

Description:
A publicly-visible method or associated fn is no longer available under its prior name. It may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.46.0/src/lints/inherent_method_missing.ron

Failed in:
  UteeParamsTypes::new, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:415
  UteeParamsTypes::into_bytes, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:415
  UteeParamsTypes::from_bytes, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:415
  UteeParamsTypes::type_0_or_err, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:418
  UteeParamsTypes::with_type_0, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:418
  UteeParamsTypes::with_type_0_checked, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:418
  UteeParamsTypes::set_type_0_checked, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:418
  UteeParamsTypes::type_1_or_err, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:419
  UteeParamsTypes::with_type_1, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:419
  UteeParamsTypes::with_type_1_checked, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:419
  UteeParamsTypes::set_type_1_checked, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:419
  UteeParamsTypes::type_2_or_err, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:420
  UteeParamsTypes::with_type_2, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:420
  UteeParamsTypes::with_type_2_checked, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:420
  UteeParamsTypes::set_type_2_checked, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:420
  UteeParamsTypes::type_3_or_err, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:421
  UteeParamsTypes::with_type_3, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:421
  UteeParamsTypes::with_type_3_checked, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:421
  UteeParamsTypes::set_type_3_checked, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:421
  OpteeMsgAttr::new, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:1348
  OpteeMsgAttr::into_bytes, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:1348
  OpteeMsgAttr::from_bytes, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:1348
  OpteeMsgAttr::typ, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:1353
  OpteeMsgAttr::typ_or_err, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:1353
  OpteeMsgAttr::with_typ, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:1353
  OpteeMsgAttr::with_typ_checked, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:1353
  OpteeMsgAttr::set_typ, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:1353
  OpteeMsgAttr::set_typ_checked, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:1353
  OpteeMsgAttr::meta_or_err, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:1354
  OpteeMsgAttr::with_meta, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:1354
  OpteeMsgAttr::with_meta_checked, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:1354
  OpteeMsgAttr::set_meta, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:1354
  OpteeMsgAttr::set_meta_checked, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:1354
  OpteeMsgAttr::noncontig_or_err, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:1355
  OpteeMsgAttr::with_noncontig, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:1355
  OpteeMsgAttr::with_noncontig_checked, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:1355
  OpteeMsgAttr::set_noncontig, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:1355
  OpteeMsgAttr::set_noncontig_checked, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:1355

--- failure repr_c_removed: repr(C) removed ---

Description:
repr(C) was removed from a type. This can cause its memory layout to change, breaking FFI use cases.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#repr-c-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.46.0/src/lints/repr_c_removed.ron

Failed in:
  struct UteeParamsTypes in /home/runner/work/litebox/litebox/litebox_common_optee/src/lib.rs:422
  struct OpteeMsgAttr in /home/runner/work/litebox/litebox/litebox_common_optee/src/lib.rs:1429

--- failure union_missing: pub union removed or renamed ---

Description:
A publicly-visible union cannot be imported by its prior path. A `pub use` may have been removed, or the union itself may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.46.0/src/lints/union_missing.ron

Failed in:
  union litebox_common_optee::OpteeMsgParamUnion, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/aa028baa08c98942826f673ebeb18e6d6f5baf6d/litebox_common_optee/src/lib.rs:1311

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants