Skip to content

[Draft] optee: share TA binaries through a global UUID map - #1142

Open
Praveen K Paladugu (praveen-pk) wants to merge 1 commit into
microsoft:mainfrom
praveen-pk:global_ta_uuid
Open

[Draft] optee: share TA binaries through a global UUID map#1142
Praveen K Paladugu (praveen-pk) wants to merge 1 commit into
microsoft:mainfrom
praveen-pk:global_ta_uuid

Conversation

@praveen-pk

Copy link
Copy Markdown
Contributor

Move the TA UUID-to-binary map out of individual shim instances so TA binaries can be registered once and reused across instances. This global map is required to support Dyanamically Loading TAs and using them across sessions.

Protect the map with a spin-based RwLock and expose shim methods for storing and retrieving TA binaries.

Register the LVBS runner's embedded TA during BSP initialization and resolve new TA instances through the shared map.

Move the TA UUID-to-binary map out of individual shim instances
so TA binaries can be registered once and reused across instances.
This global map is required to support Dyanamically Loading TAs and
using them across sessions.

Protect the map with a spin-based RwLock and expose shim methods for
storing and retrieving TA binaries.

Register the LVBS runner's embedded TA during BSP initialization and
resolve new TA instances through the shared map.

Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
@praveen-pk Praveen K Paladugu (praveen-pk) changed the title optee: share TA binaries through a global UUID map [Draft] optee: share TA binaries through a global UUID map Aug 6, 2026

@sangho2 Sangho Lee (sangho2) left a comment

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.

Thanks for your effort! Yes, we should differentiate shim-global from runner-global. I left some comments/suggestions.

Comment on lines +227 to +230
if is_bsp {
let shim = litebox_shim_optee::OpteeShimBuilder::new().build();
register_embedded_tas(&shim);
}

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.

It is a bit unclear whether this is a good place to register TA binaries. a bit early. Probably fine because this is a temporary solution.


/// Register all TA binaries embedded in the runner image.
fn register_embedded_tas(shim: &litebox_shim_optee::OpteeShim) {
static REGISTERED: spin::Once<()> = spin::Once::new();

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.

Do we need this static REGISTERED? ta_uuid_map itself should be able to reject redundant registration.

fn register_embedded_tas(shim: &litebox_shim_optee::OpteeShim) {
static REGISTERED: spin::Once<()> = spin::Once::new();
REGISTERED.call_once(|| {
assert!(register_embedded_ta(

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.

It registers only a single TA, regression. We could keep using const TA_BINARIES.

Comment on lines -172 to -173
/// The TA UUID to binary map for TA loading.
ta_uuid_map: TaUuidMap,

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.

Dropping ta_uuid_map is here is a bit concerning because we can no longer use shim's self. Instead, we could store &'static TaUuidMap here. This is an outstanding PR's direction (#1127).


/// Get the global TA UUID map.
fn ta_uuid_map() -> Arc<TaUuidMap> {
static TA_UUID_MAP: once_cell::race::OnceBox<Arc<TaUuidMap>> = once_cell::race::OnceBox::new();

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.

Using Arc in general a good idea, but using it against TaUuidMap itself is not a good call IMO. This map is already protected by a lock and reference counting it less meaningful because we would not drop this map anyhow. Instead, we can Arc each TA binary which might be helpful to deal with future TA binary update as well.

/// Entry in the TA UUID map containing binary data and parsed flags.
struct TaInfo {
/// The raw TA binary
binary: alloc::boxed::Box<[u8]>,

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.

As noted, we could do binary: Arc<[u8]> here.

}

/// Get the TA binary associated with the given TA UUID.
pub(crate) fn get_ta_bin(&self, ta_uuid: &TeeUuid) -> Option<alloc::boxed::Box<[u8]>> {

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.

once we do use Arc<[u8]>, functions like this one can return Arc, avoiding deep heap copy.

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