Repository navigation
Description
On KVM, restoring a snapshot whose APIC page has the LVT timer unmasked in a delivery mode other than Fixed, and the timer already expired (one-shot with a current count of 0, or TSC-deadline past its deadline), makes KVM fire the re-armed timer in that mode. Depending on the mode, the restored VP then resets (INIT), latches a SIPI, wakes from halt (RemoteRead), or takes an NMI or SMI, none of which the snapshot holds. On an APICv/AVIC host this happens inside KVM_SET_LAPIC, and on any other host at the first KVM_RUN. A guest cannot set the timer's delivery mode, because KVM masks LVTT writes, so only a crafted snapshot file reaches this.
Reproduction
restore_all a KVM VP saved state whose lvt_timer is unmasked, one-shot, with delivery mode INIT (5), a nonzero initial count and a current count of 0. Expected: the restore is refused. Actual: it succeeds, with nothing visible at the restore, because KVM's APIC is not read back (can_compare is false). The INIT that KVM then latches (before restore_all returns on an APICv host) was not reproduced.
Cause
KvmVpStateAccess::set_apic (vmm_core/virt_kvm/src/arch/x86_64/vp_state.rs) passes the saved page to KVM_SET_LAPIC unchanged:
// vmm_core/virt_kvm/src/arch/x86_64/vp_state.rs
fn set_apic(&mut self, value: &vp::Apic) -> Result<(), Self::Error> {
// Set this first to set the APIC mode before updating the APIC register
// state.
self.kvm()
.set_msrs(&[(x86defs::X86X_MSR_APIC_BASE, value.apic_base)])?;
self.kvm().set_lapic(&value.registers().as_page())?;
Ok(())
}KVM re-arms the timer from the current count and delivers its expiry through kvm_apic_local_deliver with the LVT's delivery mode (arch/x86/kvm/lapic.c).
Fix
fix.patch adds check_restorable_apic_timer. set_apic calls it first, before it writes APIC_BASE or the page, and it returns KvmError::InvalidState when the LVT timer is unmasked and its mode is not Fixed. LowestPriority and ExtINT are refused too, since no save holds them. The reset APIC is unaffected, because its timer is masked. Such a restore then fails with restore_all's StateError for the APIC; every page OpenVMM saves is unchanged. The unit test restore_of_an_apic_timer_in_a_mode_other_than_fixed_is_refused covers modes 1 to 7 masked and unmasked, and the Fixed and reset values. The patch has no KVM-backed test.
A related limit, which this patch does not change: KVM also fires an expired one-shot Fixed timer once more after a restore.
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 restore's check of the APIC timer's delivery mode
doc: specify that a KVM restore rejects a non-fixed LAPIC timer