Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/hyperlight_host/src/hypervisor/virtual_machine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,17 @@ pub(crate) fn hyperv_msr_reset_indices(
vm: &dyn VirtualMachine,
guest_msrs: &[u32],
) -> std::result::Result<Vec<u32>, CreateVmError> {
// MSR probing is expensive. Cache the common case with no additional guest MSRs.
// Default VMs in a process use the same partition configuration and MSR set.
static DEFAULT: OnceLock<Vec<u32>> = OnceLock::new();

// Cache hit: no guest MSRs, so the reset set is always the same.
if guest_msrs.is_empty()
&& let Some(indices) = DEFAULT.get()
{
return Ok(indices.clone());
}

validate_guest_msrs(vm, guest_msrs)?;
let mut indices = filterless_core_reset_candidates()
.filter_map(|index| match probe_resettable(vm, index) {
Expand All @@ -602,6 +613,11 @@ pub(crate) fn hyperv_msr_reset_indices(
indices.extend(guest_msrs.iter().copied());
indices.sort_unstable();
indices.dedup();
// Populate the cache for future default VMs.
if guest_msrs.is_empty() {
// An error means another thread populated the same cache (harmless).
Comment thread
ludfjig marked this conversation as resolved.
let _ = DEFAULT.set(indices.clone());
}
Ok(indices)
}

Expand Down
Loading