Virtualization

KVM guests' clocks jump forward minutes after host suspend/resume when host uses TSC as RTC and guests use kvmclock

aliceadmin
1mo ago
Environment

Environment

KVM/QEMU hosts running Debian 12, Linux kernel 6.1, guests are CentOS 8 and Ubuntu 20.04 with virtio drivers. Host suspend/resume used nightly for power savings. Guests configured with kvmclock and no NTP daemon in some minimal images.

Symptoms

Symptoms

After host resumes from suspend, guests show clock advanced by several minutes to hours; time-sensitive jobs (cron, cert renewals) misfire. Guest dmesg shows kvmclock sync messages. Problem intermittent across hosts; guests sometimes correct after ntp/chrony restart.

Observations

Observations

Host dmesg shows 'PM: suspend exit' with TSC rebase; host hardware uses invariant TSC and hosts resume quickly. Guests without running chronyd experience larger jumps. Enabling guest NTP immediately corrects time. qemu commandline lacks -rtc options forcing kvmclock behavior.

Already attempted

Already attempted

Installed chrony in guests — mitigates but some services still see missed real-time deadlines until chrony slews. Added -rtc base=localtime to qemu for one test VM — inconsistent. Upgraded host kernel to minor release — no change.

Question

Question

Why do KVM guests' clocks jump forward after host suspend and how to make guest time resilient without relying on guest NTP daemons alone?

COMMUNITY RESPONSES

Verified community troubleshooting

0 replies

No answers yet..

Showing 0 of 0 community responses
AI DIAGNOSTICS

Incident analysis

Updated 1mo ago• Trouble ID

Most likely causes

Host TSC rebase on resume causes kvmclock guests to advance wallclock because guest kvmclock relies on host monotonic counters 85%
Guest lacks a time synchronization daemon (chrony/ntpd) configured to handle large steps smoothly 60%
QEMU/KVM not receiving or not propagating proper suspend/resume notifications to guests due to qemu args or outdated libvirt hooks 35%

Summary

Host suspend/resume can rebase TSC/clocksource. Guests using kvmclock can inherit an advanced host monotonic reference, causing guest wallclock to jump if not adjusted. If guest has no NTP/chrony to correct smoothly, time jumps. qemu's rtc options and kernel clocksource selection influence behavior. Also, kvmclock paravirtual timers require host/guest coordination on suspend path.

Suggested Fixes

Diagnostic step 1
Install and configure chrony in every guest with 'makestep' options to handle big jumps and ensure realtime drift correction.
Diagnostic step 2
Enable qemu guest-agent and ensure libvirt hooks propagate suspend/resume events so guests can pause kvmclock and resync.
Diagnostic step 3
Set qemu -rtc parameters (e.g., -rtc base=utc,clock=host) cautiously and test on non-critical VMs.

Continue troubleshooting

Matched from the title, description and tags