Skip to content

Commit 579e7fd

Browse files
benzeajmberg-intel
authored andcommitted
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>
1 parent 7ee1e43 commit 579e7fd

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

arch/um/drivers/rtc_kern.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,16 @@ static int uml_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
5151

5252
static int uml_rtc_alarm_irq_enable(struct device *dev, unsigned int enable)
5353
{
54+
struct timespec64 ts;
5455
unsigned long long secs;
5556

5657
if (!enable && !uml_rtc_alarm_enabled)
5758
return 0;
5859

5960
uml_rtc_alarm_enabled = enable;
6061

61-
secs = uml_rtc_alarm_time - ktime_get_real_seconds();
62+
read_persistent_clock64(&ts);
63+
secs = uml_rtc_alarm_time - ts.tv_sec;
6264

6365
if (time_travel_mode == TT_MODE_OFF) {
6466
if (!enable) {
@@ -73,7 +75,8 @@ static int uml_rtc_alarm_irq_enable(struct device *dev, unsigned int enable)
7375

7476
if (enable)
7577
time_travel_add_event_rel(&uml_rtc_alarm_event,
76-
secs * NSEC_PER_SEC);
78+
secs * NSEC_PER_SEC -
79+
ts.tv_nsec);
7780
}
7881

7982
return 0;

0 commit comments

Comments
 (0)