You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
openvmm: time-ABI restore panics in a log line if the host clock steps back #1375
LoadedVm::time_abi_restore logs each phase's duration by subtracting one Duration from another. If the host's monotonic clock steps back between the reading at the end of the TSC set and the reading at the end of the LAPIC or VM-time phase, the subtraction panics with "overflow when subtracting durations", in release builds too. The microVM restore then aborts, after the TSCs, LAPICs and VM time were already set. This happens on any backend, at OpenVMM's default info log level. Only a faulty host clock triggers it: std::time::Instant assumes a monotonic clock, which some hosts and VMs do not provide.
Reproduction
Not reproduced: it needs a host clock that steps backwards. The panic happens when lapic_advanced or vm_time_advanced (each started.elapsed(), read at the end of its phase) is smaller than tsc_set.
Cause
The "time ABI restore clock" event subtracts the started.elapsed() readings from each other:
Instant::elapsed saturates, but subtracting one Duration from another does not.
Fix
fix.patch computes both values with saturating_sub before the event, so a backwards step logs 0 and the restore completes. Only these two log fields change. The patch adds no test, since Instant cannot be injected here.
Patch against OpenVMM 3cf58a5234ed824435825c9f87187f5129219724. Save the contents below as fix.patch and run git apply fix.patch.
fix.patch
diff --git a/openvmm/openvmm_core/src/worker/dispatch/time_abi.rs b/openvmm/openvmm_core/src/worker/dispatch/time_abi.rs
index c2cdeeb..db8c651 100644
--- a/openvmm/openvmm_core/src/worker/dispatch/time_abi.rs+++ b/openvmm/openvmm_core/src/worker/dispatch/time_abi.rs@@ -1201,11 +1201,14 @@ pub(super) async fn time_abi_restore(&mut self, input: RestoreTimeInput) -> anyh
let finished = started.elapsed();
// Per-phase durations attribute the restore.time_abi_clock profile
// phase. The LAPIC and VM time phases overlap; each is measured from
- // the end of the TSC set.+ // the end of the TSC set. A faulty host monotonic clock may step+ // backwards; clamp the logged phase duration instead of panicking.+ let lapic_us = lapic_advanced.saturating_sub(tsc_set).as_micros() as u64;+ let vm_time_us = vm_time_advanced.saturating_sub(tsc_set).as_micros() as u64;
tracing::info!(
tsc_set_us = tsc_set.as_micros() as u64,
- lapic_us = (lapic_advanced - tsc_set).as_micros() as u64,- vm_time_us = (vm_time_advanced - tsc_set).as_micros() as u64,+ lapic_us,+ vm_time_us,
total_us = finished.as_micros() as u64,
"time ABI restore clock"
);
Activity
tangruize commentedon Nov 8, 2026
Proposed patch
Patch against OpenVMM 3cf58a5234ed824435825c9f87187f5129219724. Save the contents below as
fix.patchand rungit apply fix.patch.fix.patchopenvmm: pin the saturated time ABI restore phase logs
microVM: saturate the time ABI restore's logged phase durations
microVM: saturate the time ABI restore's logged phase durations