Skip to content

Add preemption timer to bound TA execution#907

Open
sangho2 wants to merge 7 commits into
mainfrom
sanghle/lvbs/timebomb
Open

Add preemption timer to bound TA execution#907
sangho2 wants to merge 7 commits into
mainfrom
sanghle/lvbs/timebomb

Conversation

@sangho2

@sangho2 sangho2 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

This PR adds a timer-based mechanism for preempting TAs on the LVBS platform. In OP-TEE, TA execution is unbounded because there is no secure-world scheduler: if a TA spins in an infinite loop, it can hold the (V)CPU indefinitely. On Arm TrustZone, the normal world can eventually regain control by interrupting the secure world. However, in Hyper-V, VTL0 is not allowed to interrupt VTL1.
To overcome this problem, this PR implements a VTL1-local one-shot preemption timer based on the Hyper-V synthetic timer to limit the execution time of each TA command invocation (which could span multiple syscalls). If it fires, the VTL1 kernel kills the TA and returns back to VTL0.

@sangho2 sangho2 changed the title Add local APIC timebomb for TA preemption Add timebomb for TA preemption Jun 10, 2026
@sangho2 sangho2 changed the title Add timebomb for TA preemption Add LVBS timer for TA preemption Jun 10, 2026
@sangho2 sangho2 changed the title Add LVBS timer for TA preemption Preemption timer to bound TA execution Jun 10, 2026
@sangho2 sangho2 changed the title Preemption timer to bound TA execution Add preemption timer to bound TA execution Jun 10, 2026
@sangho2 sangho2 force-pushed the sanghle/lvbs/timebomb branch 3 times, most recently from 7bea3f7 to e5adb24 Compare June 10, 2026 18:10
@sangho2 sangho2 marked this pull request as ready for review June 10, 2026 18:15
@sangho2 sangho2 force-pushed the sanghle/lvbs/timebomb branch from 4ac37cb to d795648 Compare June 10, 2026 19:53

@sangho2 sangho2 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

.

@sangho2 sangho2 force-pushed the sanghle/lvbs/timebomb branch from d795648 to f4be5b2 Compare June 10, 2026 23:57
@sangho2 sangho2 force-pushed the sanghle/lvbs/timebomb branch from f4be5b2 to e4329fc Compare June 11, 2026 03:48
@sangho2 sangho2 force-pushed the sanghle/lvbs/timebomb branch from d2d638b to d7f79ae Compare June 12, 2026 17:03
@sangho2 sangho2 added the must-not-merge:blocked-on-other-changes Other changes/PRs to be handled first. Label not needed for non-main changes. label Jun 15, 2026
@sangho2

sangho2 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

Potential conflict with PR #865. Merge it first and then this one.

@wdcui wdcui left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thanks!

linux_syscall = []
devbox = []
# Tighten the preemption timer quantum so runaway-TA preemption can be tested
# without waiting out the production budget. Test builds only.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's the production budget?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This PR for now uses 8 seconds, which is slightly below Linux kernel's hard CPU lockup timeout (10 seconds).

Comment thread litebox_platform_lvbs/src/lib.rs Outdated
// member variable offset calculation in assembly code).
unsafe { run_thread_arch(&mut thread_ctx, ctx_ptr, u8::from(reenter)) };
//
// Arm the preemption timer for this TA entry; disarmed at the VTL0-return

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: "bracket the entry" is a little confusing.

Comment on lines +11 to +12
//! expiry it fires `STIMER_VECTOR` and the shim terminates the offending
//! thread.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Where does the shim terminate the thread?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

A user-mode STIMER interrupt will be delivered to the OP-TEE shim, and it'll terminate the thread. No extra code in this PR for this because the OP-TEE has no notion of interrupt such that its shim currently just terminates the thread if there is an interrupt.

@github-actions

Copy link
Copy Markdown

🤖 SemverChecks 🤖 No breaking API changes detected

Note: this does not mean API is unchanged, or even that there are no breaking changes; simply, none of the detections triggered.

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

Labels

must-not-merge:blocked-on-other-changes Other changes/PRs to be handled first. Label not needed for non-main changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants