Stop KVM guests from leaking clock drift into your logs
By Saket Jain Published Linux/Unix
Stop KVM guests from leaking clock drift into your logs
Technical Briefing | 12/6/2026
You spend all morning chasing an application error, checking logs, tweaking config files, and questioning your sanity. Everything looks clean, but the timestamps between your host and your virtual machine are drifting apart by seconds every hour. It is a subtle form of madness that breaks Kerberos tokens, invalidates TLS handshakes, and makes log correlation impossible. You expect the hypervisor to handle this, but the guest kernel has its own ideas about what time it is.
Why your VM ignores the hardware clock
Most of the time, we rely on kvm-clock, which is supposed to sync guest time to the host’s TSC. But when the host is under heavy load or suffers from interrupt latency, the guest can start skipping ticks. If you are not using a paravirtualized clock or if your guest kernel is fighting between PIT, ACPI, or HPET timers, the drift becomes inevitable. I have seen this silently ruin database replication clusters because the secondary server drifted just enough to trigger a panic.
virsh edit your-vm-name
<clock offset='utc'>
<timer name='rtc' tickpolicy='catchup'/>
<timer name='pit' tickpolicy='delay'/>
<timer name='hpet' present='no'/>
<timer name='kvmclock' present='yes'/>
</clock>
- Disable HPET in the libvirt config if you are running modern Linux kernels as it often causes more overhead than it saves.
- Set the RTC tickpolicy to catchup so the guest attempts to sync up when it misses cycles under host load.
- Verify your guest is actually using kvm-clock by checking dmesg for kvm-clock as the clocksource.
Once you have updated the XML, you will need to restart the guest for these timer changes to actually stick. Don’t assume a warm reboot of the OS is enough, because libvirt needs to reinitialize the QEMU process arguments. After the reboot, check your clocksource status to ensure it is sitting on kvm-clock. If you are still seeing drift, you probably have a host CPU pinning issue or excessive interrupt steering that the guest can’t recover from.
Getting time sync right isn’t just about cron jobs and ntp; it is about infrastructure honesty. If you fix the virtualization layer, you stop treating the symptom in the guest OS and solve the problem at the hardware abstraction level. Next time you see a weird log gap, check the hypervisor timers before you start refactoring your application code.
