openvmm icon indicating copy to clipboard operation
openvmm copied to clipboard

tdx: use timer virtualization for lower VTLs

Open balajimc55 opened this issue 1 month ago • 2 comments

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_state that is shared with mshv_vtl driver.
  • During entry into lower VTL, mshv_vtl driver makes the TDG.VP.WR call to set the deadline when an update is needed.

Changes

  • Added HardwareIsolatedGuestTimer trait as an abstraction for managing lower VTL timer deadlines.
  • Moved current VmTime interface as default/fallback implementation into this trait.
  • Added TdxTscDeadlineService to implement the TDX specific timer virtualization.

balajimc55 avatar Nov 23 '25 08:11 balajimc55

⚠️ 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

github-actions[bot] avatar Nov 23 '25 08:11 github-actions[bot]

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.

balajimc55 avatar Dec 05 '25 08:12 balajimc55

Backported to release/1.7.2511 in #2570

benhillis avatar Dec 17 '25 16:12 benhillis

Backported to release/1.7.2511 in #2570

benhillis avatar Dec 17 '25 16:12 benhillis