Skip to content

Add handlers for OP-TEE TA request and execution result#564

Closed
sangho2 wants to merge 52 commits intosanghle/lvbs/optee_msg_handler_1from
sanghle/lvbs/optee_msg_handler_2
Closed

Add handlers for OP-TEE TA request and execution result#564
sangho2 wants to merge 52 commits intosanghle/lvbs/optee_msg_handler_1from
sanghle/lvbs/optee_msg_handler_2

Conversation

@sangho2
Copy link
Contributor

@sangho2 sangho2 commented Dec 17, 2025

This PR adds handlers for OP-TEE TA request and its execution result. It also has a runner-side
controller that leverages all OP-TEE SMC/messages handlers to deal with OP-TEE calls from
the normal world. Currently, this controller is no-op because it should be invoked via
an upcall from the platform and it relies on run_thread, both are in different PRs.

@sangho2 sangho2 changed the title Add decoder and handler for OP-TEE TA request and execution result Add handlers for OP-TEE TA request and execution result Dec 18, 2025
@sangho2 sangho2 marked this pull request as ready for review December 18, 2025 23:12
@sangho2 sangho2 force-pushed the sanghle/lvbs/optee_msg_handler_2 branch from bd37e2f to 9c7a30d Compare December 23, 2025 05:44
@sangho2 sangho2 force-pushed the sanghle/lvbs/optee_msg_handler_2 branch from 9c7a30d to 0f0c934 Compare December 23, 2025 15:57
@sangho2 sangho2 force-pushed the sanghle/lvbs/optee_msg_handler_2 branch from 2cd83ef to 5b4fcf9 Compare January 9, 2026 04:01
@sangho2 sangho2 force-pushed the sanghle/lvbs/optee_msg_handler_2 branch from 8b2b117 to a91950e Compare January 9, 2026 19:03
@sangho2 sangho2 force-pushed the sanghle/lvbs/optee_msg_handler_2 branch from a91950e to 8700931 Compare January 9, 2026 19:56
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.

I left some comments below.

/// # Panics
///
/// Panics if XSAVE areas are not allocated or if an invalid VTL value is provided.
pub fn save_extended_states(&self, vtl: u8) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: save_extended_state?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Intel calls it Extended States

vtl_switch_loop_entry(platform)
}

// Tentative OP-TEE message handler upcall implementation.
Copy link
Member

Choose a reason for hiding this comment

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

Nit: should we move this comment down to be right next to the implementation?

) -> Result<i64, litebox_common_linux::errno::Errno> {
let smc_args_addr: usize = smc_args_addr.truncate();
match optee_msg_handler(smc_args_addr) {
Ok(smc_arg) => {
Copy link
Member

Choose a reason for hiding this comment

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

optee_msg_handler returns an smc_arg? I would expect a handler to return a result.

Copy link
Member

Choose a reason for hiding this comment

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

optee_smc_handler?


#[inline]
fn page_align_down(address: u64) -> u64 {
fn page_align_down_u64(address: u64) -> u64 {
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 we need to change the function name?

data[1] = (msg_arg.get_param_value(0)?.b).truncate();
data[2] = (msg_arg.get_param_value(1)?.a).truncate();
data[3] = (msg_arg.get_param_value(1)?.b).truncate();
(Some(TeeUuid::from_u32_array(data)), 2)
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 we skip 2?

read_data_from_shm(&shm_info, &mut data)?;
UteeParamOwned::MemrefInput { data: data.into() }
}
OpteeMsgAttrType::TmemOutput | OpteeMsgAttrType::RmemOutput => {
Copy link
Member

Choose a reason for hiding this comment

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

Minot: It doesn't save much by first handling Tmem and Rmem together and then handling them separately. It might be easier to just handle each case one by one.

/// Note that we use this function for handing TA requests and in this context
/// `OpteeMsgParamTmem` and `OpteeMsgParamRmem` are equivalent because every shared memory
/// reference accessible by TAs must be registered in advance.
/// `OpteeMsgParamTmem` is matter for the registration of shared memory regions.
Copy link
Member

Choose a reason for hiding this comment

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

Nit: "is matter for"?

///
/// `rmem.offs` must be an offset within the shared memory region registered with `rmem.shm_ref` before
/// and `rmem.offs + rmem.size` must not exceed the size of the registered shared memory region.
/// All addresses this function returns are page aligned and virtually contiguous within the normal world but
Copy link
Member

Choose a reason for hiding this comment

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

If we don't trust the normal world, why does it matter if the memory is virtually contiguous in the normal world?

@sangho2 sangho2 force-pushed the sanghle/lvbs/optee_msg_handler_1 branch from 20a424a to 42500bb Compare January 23, 2026 00:36
@sangho2
Copy link
Contributor Author

sangho2 commented Jan 23, 2026

Note. This PR cannot be easily merged because #555 has been changed a lot. I'll cherry pick it once approved.

@sangho2 sangho2 force-pushed the sanghle/lvbs/optee_msg_handler_1 branch from 4cecf50 to 4d0df5e Compare January 24, 2026 00:29
@sangho2
Copy link
Contributor Author

sangho2 commented Jan 24, 2026

Since this PR's base branch has been heavily changed, I'll close it and create a new PR.

@sangho2 sangho2 closed this Jan 24, 2026
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