Repository navigation
[DO NOT REVIEW] microVM: saturate the time ABI restore's logged phase durations - #5056
Merged
Pedro Henrique Penna (ppenna) merged 1 commit intoNov 12, 2026
Conversation
The time ABI restore logs how long each of its phases took from readings of one Instant::elapsed, subtracting the reading that ends the earlier phase from the reading that ends the later one: the "time ABI restore clock" event of time_abi_restore subtracts the end of the synchronized TSC set from the ends of the LAPIC and VM-time advances, and the synchronized TSC sets of MSHV and WHP subtract the end of the freeze or suspend from the end of the TSC writes, and WHP that from the end of the read-back. Instant::elapsed saturates when the host's monotonic clock steps back, which a faulty host can do, but a Duration subtraction panics with "overflow when subtracting durations", in release builds too. A step back between two readings, far enough that the later reading was the smaller one, so aborted the restore after the TSCs, LAPICs, and VM time were set, on any backend, at the default info log level (microsoft/nvx#1375). virt::time_abi::phase_us gives a phase's microseconds from its two readings, 0 when the later reading is the smaller one, and the three events compute with it every phase that they took as the difference of two readings. The time ABI's other logged differences of two clock readings already saturate: check_cpu_profile_with subtracts Instants, which saturates as Instant::elapsed does, and the synchronized TSC set event saturates resumed_after_anchor_ns. Tests: phase_us gives 2500 us from 1500 us to 4000 us, and 0 from 1500 us to 0 us and to 1000 us. Without the fix, its subtraction panics with "overflow when subtracting durations". Evidence: on nvx-kvm-test, an LD_PRELOAD shim stepped the host's CLOCK_MONOTONIC back by 250 ms right after the "time ABI synchronized TSC set" event of the restores of NVX's restore-processors scenario. The OpenVMM built without this commit panicked there in Duration's subtraction, called at time_abi.rs:1304 in time_abi_restore, and the restore failed; with this commit, both restores completed and logged lapic_us=0x0 vm_time_us=0x0. Without the shim, the restore-processors, snapshot-core, and time-abi-conformance scenarios pass on KVM, MSHV, and WHP, and restores with the backends' events enabled log the MSHV and WHP phases that the change computes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pedro Henrique Penna (ppenna)
requested a review
from a team
as a code owner
November 12, 2026 05:11
|
This PR modifies files containing For more on why we check whole files, instead of just diffs, check out the Rustonomicon |
Pedro Henrique Penna (ppenna)
added a commit
to microsoft/nvx
that referenced
this pull request
Nov 12, 2026
A time ABI restore logged how long its phases took by subtracting one reading of an Instant::elapsed from another, in the "time ABI restore clock" event and in the synchronized TSC sets of MSHV and WHP. Instant::elapsed saturates when the host's monotonic clock steps back, which a faulty host can do, but the Duration subtraction panics with "overflow when subtracting durations", in release builds too, so a step back between two readings, far enough that the later reading was the smaller one, aborted the restore after the TSCs, LAPICs, and VM time were set, on any backend, at OpenVMM's default info log level (#1375). Pin c2c21ddb25822e13bd1cf1b33ed693545cc7bbb5, the head of microsoft/openvmm#5056, one commit on c72fc56a3, the head of feature/microvm/dev: - c2c21ddb2 microVM: saturate the time ABI restore's logged phase durations The revision adds virt::time_abi::phase_us, which gives a phase's microseconds from its two readings, 0 when the later reading is the smaller one, and computes with it every phase that the three events took as the difference of two readings. Evidence: on nvx-kvm-test, an LD_PRELOAD shim stepped the host's CLOCK_MONOTONIC back by 250 ms right after the "time ABI synchronized TSC set" event of the restores of the restore-processors scenario. The OpenVMM built without the fix panicked in Duration's subtraction at time_abi.rs:1304, in time_abi_restore, and the scenario failed; with the fix, it passed and logged lapic_us=0x0 vm_time_us=0x0. Without the shim, the restore-processors, snapshot-core, and time-abi-conformance scenarios pass on nvx-kvm-test, nvx-mshv-test, and nvx-whp-test, and restores with the backends' events enabled log the MSHV and WHP phases that the fix computes. The new virt test panics with "overflow when subtracting durations" against the base's subtraction and passes at the pinned revision; the tests of virt, virt_whp, and openvmm_core pass on Windows, and those of virt, virt_mshv, and openvmm_core on Linux. These runs had the fix on an earlier revision of microsoft/openvmm#5055, which differs from c72fc56a3 only in the KVM backend's LAPIC timer capture and its tests; at the pinned revision, virt and openvmm_core build and the new test passes on Windows. NVX needs no coordinated change: the control-session vectors, the source excerpts, the contract versions, and the CPU profiles that nvx-rs copies from OpenVMM match the revision's. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pedro Henrique Penna (ppenna)
added a commit
to microsoft/nvx
that referenced
this pull request
Nov 12, 2026
The NVX pin moves to c2c21ddb2, position 262, 131 commits past the mapped tip. Position 262, which microsoft/openvmm#5056 proposes for feature/microvm/dev on its head, c72fc56a3, is unassigned. The Scope also says that microsoft/openvmm#5055 merged positions 259-261. It computes the phases of the time ABI restore's clock event, which position 144 adds and position 146 gives its concurrent LAPIC and VM-time phases, and of the synchronized TSC sets of the MSHV and WHP backends of positions 134 and 140, that are the difference of two readings with a helper that it adds to virt's time ABI module of position 132, which gives 0 where the host's monotonic clock stepped back past the phase's start and the subtraction panicked. It changes nothing that a mapped PR adds. Replaying it on upstream main conflicts in all four of its files, since upstream main lacks the time ABI, so it follows the time ABI series upstream. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Pedro Henrique Penna (ppenna)
merged commit Nov 12, 2026
c2c21dd
into
feature/microvm/dev
73 of 74 checks passed
Pedro Henrique Penna (ppenna)
added a commit
to microsoft/nvx
that referenced
this pull request
Nov 12, 2026
The NVX pin moves to 5d656d854, position 263, 132 commits past the mapped tip. Position 263, which microsoft/openvmm#5061 proposes for feature/microvm/dev on its head, c2c21ddb2, is unassigned. The Scope also says that microsoft/openvmm#5056 merged position 262. It makes the PIT's count writes in the low-then-high access mode take each count's low byte first, in Timer::write, code that upstream main has, and adds three tests, in a file that PR10's position 022 and position 139 also change, neither of them in the code that it changes. It changes nothing that a mapped PR adds. Replaying it on upstream main applies without conflicts, and chipset type-checks there with its tests, which pass, so it can go upstream on its own. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Keeps a faulty host clock from aborting a time ABI restore over its log, for microsoft/nvx#1375. The time ABI restore logs how long its phases took by subtracting one reading of an
Instant::elapsedfrom another.Instant::elapsedsaturates when the host's monotonic clock steps back, which a faulty host can do, but aDurationsubtraction panics with "overflow when subtracting durations", in release builds too. A step back between two readings, far enough that the later reading was the smaller one, so aborted the restore after the TSCs, LAPICs, and VM time were set, on any backend, at the defaultinfolog level.One commit on
c72fc56a3, the head offeature/microvm/dev. microsoft/nvx#1521 pins this head.Saturate the time ABI restore's logged phase durations (
c2c21ddb2)LoadedVm::time_abi_restorecomputedlapic_usandvm_time_usas(lapic_advanced - tsc_set)and(vm_time_advanced - tsc_set), each the difference of two readings ofstarted.elapsed(). The synchronized TSC sets of the MSHV and WHP backends, which onlytime_abi_restorecalls, computedwrite_us, and on WHPreadback_us, the same way.virt::time_abi::phase_us(start, end)gives a phase's microseconds from its two readings,end.saturating_sub(start), so 0 when the later reading is the smaller one, and the three events compute with it every phase that they took as the difference of two readings. Only the logged values change: no field, version, or format changes. The time ABI's other logged differences of two clock readings already saturate:check_cpu_profile_withsubtractsInstants, which saturates asInstant::elapseddoes, and the synchronized TSC set event saturatesresumed_after_anchor_ns.saturating_subat each of the five sites, as the issue's patch proposed for the two fields of the restore clock event, would fix the same class; one helper gives the class one documented and tested definition, which matters since the restore takes no clock that a test could step back.a_phase_lasts_zero_when_the_host_clock_steps_back_past_its_start:phase_usgives 2,500 µs from 1,500 µs to 4,000 µs, and 0 from 1,500 µs to 0 and to 1,000 µs. Withphase_ussubtracting as the events did,(end - start), the test fails with the issue's panic, "overflow when subtracting durations".Not in this change: VM time's stop computes the stopped VM time with the subtraction of
pal_async::timer::Instant,Instant::now() - start_time.os_time()inPrimaryKeeper::run(vm/vmcore/src/vmtime.rs), which panics on the same kind of step during a capture. On the KVM test VM, a 30 s step back ofCLOCK_MONOTONICafter the guest booted made the capture panic there, with "supplied instant ... is later than ...". It sets the stopped VM time rather than a log, in code that upstream main has, so it is a follow-up outside microsoft/nvx#1375.Validation
At this head,
c2c21ddb2, with Rust 1.97.1, on Windows:cargo check -p virt -p openvmm_coreand the new test pass.With the same change on an earlier revision of #5055's second commit, which differs from
c72fc56a3only in the KVM backend's LAPIC timer capture and its tests:cargo check,cargo clippy --all-targets,cargo doc --no-deps, andcargo nextest run --profile agentforvirt,virt_whp, andopenvmm_core: 278 passed;cargo xtask fmt --fix: clean. The new test fails against the subtraction as the Tests item says.virt,virt_mshv, andopenvmm_core: 317 passed;cargo xtask fmt --fix: clean.LD_PRELOADshim steppedCLOCK_MONOTONIC, whichInstantreads, back by 250 ms right after the "time ABI synchronized TSC set" event of the restores of NVX'srestore-processorsscenario. OpenVMM built without this change panicked inDuration::sub, called attime_abi.rs:1304intime_abi_restore, and the restore failed; with it, both restores completed and loggedlapic_us=0x0 vm_time_us=0x0.restore-processors,snapshot-core, andtime-abi-conformancescenarios pass with 1 and 2 VPs on the KVM, MSHV, and WHP test VMs, and restores with the backends'infoevents enabled log the MSHV and WHP phases that this change computes.See microsoft/nvx#1521.