Skip to content

Commit 76f16f0

Browse files
committed
fix(kvmclock): don't pass KVM_CLOCK_REALTIME to KVM_SET_CLOCK
When we pass KVM_CLOCK_REALTIME to KVM_SET_CLOCK, the kernel steps the monotonic clock by the elapsed wallclock time. This is ok for live migration, but in the case of snapshots that were take long ago it might cause issues to guest userspace. Change the snapshot restore logic to not clear the KVM_CLOCK_REALTIME bit when restoring kvmclock. Wallclock time will then be handled by userspace (chronyd or otherwise). Signed-off-by: Babis Chalios <babis.chalios@e2b.dev>
1 parent af9c995 commit 76f16f0

File tree

1 file changed

+7
-3
lines changed
  • src/vmm/src/arch/x86_64

1 file changed

+7
-3
lines changed

src/vmm/src/arch/x86_64/vm.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ use std::fmt;
55
use std::sync::{Arc, Mutex};
66

77
use kvm_bindings::{
8-
KVM_CLOCK_TSC_STABLE, KVM_IRQCHIP_IOAPIC, KVM_IRQCHIP_PIC_MASTER, KVM_IRQCHIP_PIC_SLAVE,
9-
KVM_PIT_SPEAKER_DUMMY, MsrList, kvm_clock_data, kvm_irqchip, kvm_pit_config, kvm_pit_state2,
8+
KVM_CLOCK_REALTIME, KVM_CLOCK_TSC_STABLE, KVM_IRQCHIP_IOAPIC, KVM_IRQCHIP_PIC_MASTER, KVM_IRQCHIP_PIC_SLAVE, KVM_PIT_SPEAKER_DUMMY, MsrList, kvm_clock_data, kvm_irqchip, kvm_pit_config, kvm_pit_state2
109
};
1110
use kvm_ioctls::Cap;
1211
use serde::{Deserialize, Serialize};
@@ -131,8 +130,13 @@ impl ArchVm {
131130
self.fd()
132131
.set_pit2(&state.pitstate)
133132
.map_err(ArchVmError::SetPit2)?;
133+
134+
// Do not pass KVM_CLOCK_REALTIME to the ioctl(). This causes the kernel to
135+
// adjust the MONOTONIC clock which might cause issues for the guest userspace.
136+
let mut clock = state.clock;
137+
clock.flags &= !KVM_CLOCK_REALTIME;
134138
self.fd()
135-
.set_clock(&state.clock)
139+
.set_clock(&clock)
136140
.map_err(ArchVmError::SetClock)?;
137141
self.fd()
138142
.set_irqchip(&state.pic_master)

0 commit comments

Comments
 (0)