Skip to content

Conversation

@balajimc55
Copy link
Collaborator

@balajimc55 balajimc55 commented Dec 16, 2025

Cherry-pick of PR #2483 to support timer virtualization for lower VTLs.
Issue - #2028

Implements microsoft#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
microsoft/OHCL-Linux-Kernel#107

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]`.

- 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.

- 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.
@github-actions github-actions bot added release_1.7.2511 Targets the release/1.7.2511 branch. unsafe Related to unsafe code labels Dec 16, 2025
@github-actions
Copy link

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

@balajimc55 balajimc55 marked this pull request as ready for review December 16, 2025 18:32
@balajimc55 balajimc55 requested a review from a team as a code owner December 16, 2025 18:32
Copilot AI review requested due to automatic review settings December 16, 2025 18:32
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enables timer virtualization for lower VTLs in TDX environments, implementing hardware-accelerated timer management through TDX's L2-VM TSC Deadline Timer capability.

Key Changes:

  • Adds TDX L2-VM TSC deadline timer service for hardware-accelerated timer virtualization
  • Introduces new HCL capability flag (HCL_CAP_LOWER_VTL_TIMER_VIRT) to detect kernel support
  • Adds configuration option to disable timer virtualization via OPENHCL_DISABLE_LOWER_VTL_TIMER_VIRT

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
vm/x86/x86defs/src/vmx.rs Adds TIMER_EXPIRED exit reason constant for TDX timer expiration events
openhcl/virt_mshv_vtl/src/processor/tdx/mod.rs Implements TdxTscDeadlineService for hardware timer virtualization and integrates it with TDX backing
openhcl/virt_mshv_vtl/src/processor/snp/mod.rs Updates SNP backing to use VmTimeGuestTimer for timer management
openhcl/virt_mshv_vtl/src/processor/mod.rs Adds lower_vtl_timer_virt_available parameter and timer deadline methods to HardwareIsolatedBacking trait
openhcl/virt_mshv_vtl/src/processor/hardware_cvm/mod.rs Introduces HardwareIsolatedGuestTimer trait and VmTimeGuestTimer implementation as fallback
openhcl/virt_mshv_vtl/src/lib.rs Adds logic to detect and enable lower VTL timer virtualization based on HCL capabilities
openhcl/underhill_core/src/worker.rs Passes disable_lower_vtl_timer_virt configuration to partition parameters
openhcl/underhill_core/src/options.rs Adds command-line option for disabling lower VTL timer virtualization
openhcl/underhill_core/src/lib.rs Threads disable_lower_vtl_timer_virt configuration through to worker
openhcl/hcl/src/protocol.rs Defines tdx_l2_tsc_deadline_state structure and adds it to TDX VP context
openhcl/hcl/src/ioctl/tdx.rs Adds accessors for TDX L2 TSC deadline state in processor runner
openhcl/hcl/src/ioctl.rs Adds HCL capability check for lower VTL timer virtualization support
tmk/tmk_vmm/src/paravisor_vmm.rs Disables lower VTL timer virtualization for TMK VMM (with TODO to match OpenHCL defaults)
flowey/flowey_lib_hvlite/src/_jobs/cfg_versions.rs Updates OpenHCL kernel stable version to 6.12.52.4

@smalis-msft smalis-msft enabled auto-merge (squash) December 16, 2025 18:34
@smalis-msft smalis-msft merged commit df47f67 into microsoft:release/1.7.2511 Dec 16, 2025
101 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release_1.7.2511 Targets the release/1.7.2511 branch. unsafe Related to unsafe code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants