tdx: use timer virtualization for lower VTLs
Implements https://github.com/microsoft/openvmm/issues/2028
This PR implements hardware timer virtualization for lower VTLs on TDX CVM usingL2-VM TSC deadline timer, an architectural capability provided by TDX module. This improves the CVM performance by eliminating guest exits to hypervisor for timer arming and expiry notifications for lower VTL's timer requirements.
The related changes in OHCL-kernel is implemented by https://github.com/microsoft/OHCL-Linux-Kernel/pull/107
Background - TDX L2-VM TSC Deadline Timer
This allows VTL2 to set an execution deadline for lower VTLs. If the lower VTL is running when the deadline time arrives, it exits to VTL2 with exit reason VmxExitBasic::TIMER_EXPIRED.
If the TSC deadline is in the past during entry into lower VTL (i.e., TSC deadline value is lower than the current virtual TSC value), it will immediately exit back to VTL2 with exit reason VmxExitBasic::TIMER_EXPIRED.
The TSC deadline is set using TDG.VP.WR for TDVPS.TSC_DEADLINE[L2-VM Index].
Implementation
- With these changes, openvmm evaluates earliest deadline across all lower VTLs and sets it in a
tdx_vp_context ->tdx_l2_tsc_deadline_statethat is shared withmshv_vtldriver. - During entry into lower VTL,
mshv_vtldriver makes theTDG.VP.WRcall to set the deadline when an update is needed.
Changes
- Added
HardwareIsolatedGuestTimertrait as an abstraction for managing lower VTL timer deadlines. - Moved current
VmTimeinterface as default/fallback implementation into this trait. - Added
TdxTscDeadlineServiceto implement the TDX specific timer virtualization.
⚠️ Unsafe Code Detected
This PR modifies files containing unsafe Rust code. Extra scrutiny is required during review.
For more on why we check whole files, instead of just diffs, check out the Rustonomicon
looks reasonable but i want to also have @smalis-msft review. We also use this timer for VTL1 - have you tested that?
@chris-oo Yes, we validated with VTL1 enabled on Windows guest and we don't see any issues. Performance improvements are consistent with expectation.
Backported to release/1.7.2511 in #2570
Backported to release/1.7.2511 in #2570