Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

um: rtc: use RTC time when calculating the alarm

The kernel realtime and the current RTC time may have a (small) offset.
Should the kernel time be slightly in the future, then the timeout is
zero. This is problematic in time-travel mode, as a zero timeout can be
correctly configured and time never advances.

Replace the kernel realtime read with a read of the actual persistent
RTC clock. Also, for time-travel, calculate the exact nanoseconds needed
for the clock to advance.

Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>
Co-developed-by: Avraham Stern <avraham.stern@intel.com>
Link: https://patch.msgid.link/20241217204906.1408011-1-benjamin@sipsolutions.net
Signed-off-by: Johannes Berg <johannes.berg@intel.com>

authored by

Benjamin Berg and committed by
Johannes Berg
579e7fd3 7ee1e43a

+5 -2
+5 -2
arch/um/drivers/rtc_kern.c
··· 51 51 52 52 static int uml_rtc_alarm_irq_enable(struct device *dev, unsigned int enable) 53 53 { 54 + struct timespec64 ts; 54 55 unsigned long long secs; 55 56 56 57 if (!enable && !uml_rtc_alarm_enabled) ··· 59 58 60 59 uml_rtc_alarm_enabled = enable; 61 60 62 - secs = uml_rtc_alarm_time - ktime_get_real_seconds(); 61 + read_persistent_clock64(&ts); 62 + secs = uml_rtc_alarm_time - ts.tv_sec; 63 63 64 64 if (time_travel_mode == TT_MODE_OFF) { 65 65 if (!enable) { ··· 75 73 76 74 if (enable) 77 75 time_travel_add_event_rel(&uml_rtc_alarm_event, 78 - secs * NSEC_PER_SEC); 76 + secs * NSEC_PER_SEC - 77 + ts.tv_nsec); 79 78 } 80 79 81 80 return 0;