RTC synchronization (11-minute mode) doesn't work on KVM
Environment
- Red Hat Enterprise Linux 8
- KVM virtual machines
Issue
- The kernel does not synchronize the RTC to the system clock. It should set the RTC about every 11 minutes.
- Chrony continues to synchronize time correctly, however, RTC does not get in sync even after 11 minutes as expected.
Resolution
- Update the kernel to version 4.18.0-477.10.1.el8_8 or later.
For information on the advisory, and where to find the updated files, follow the link below:
https://access.redhat.com/errata/RHSA-2023:2951
- As a workaround, kvmclock can be disabled by adding "no-kvmclock" to the kernel parameters, which enables the original x86 set_wallclock() used by sync_cmos_clock().
Root Cause
- The KVM module performed the real-time clock (RTC) synchronization less frequently than intended. As a consequence, the system time in VMs hosted on RHEL 8 sometimes did not correctly reflect the system time on the host. This update fixes the RTC scheduling in KVM, which prevents the described problem from occurring.
- The kvmclock driver overrides the x86-specific set_wallclock() function with a stub returning ENODEV, which causes sync_cmos_clock() to fail, but sync_rtc_clock() doesn't do anything due to missing CONFIG_RTC_SYSTOHC.
Diagnostic Steps
- To test the workaround, add the "no-kvmclock" to the kernel parameters.
[root@rhel8 ~]# cat /proc/cmdline
BOOT_IMAGE=(hd0,msdos1)/vmlinuz-4.18.0-372.26.1.el8_6.x86_64 root=/dev/mapper/rhel-root ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet no-kvmclock
- Manually modify the RTC clock:
[root@rhel8 ~]# timedatectl
Local time: Thu 2022-10-27 20:46:42 IDT
Universal time: Thu 2022-10-27 17:46:42 UTC
RTC time: Thu 2022-10-27 17:46:42
[...]
[root@rhel8 ~]# hwclock --set --date '10 sec'
[root@rhel8 ~]# timedatectl
Local time: Thu 2022-10-27 20:46:59 IDT
Universal time: Thu 2022-10-27 17:46:59 UTC
RTC time: Thu 2022-10-27 17:47:09
[...]
- Wait at least 11 minutes:
[root@rhel8 ~]# sleep 11m
- The RTC time was corrected:
[root@rhel8 ~]# timedatectl
Local time: Thu 2022-10-27 21:02:37 IDT
Universal time: Thu 2022-10-27 18:02:37 UTC
RTC time: Thu 2022-10-27 18:02:37
[...]
Product(s)
Components
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.