aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorBenjamin Berg <benjamin.berg@intel.com>2024-12-17 21:49:06 +0100
committerJohannes Berg <johannes.berg@intel.com>2025-01-10 13:50:00 +0100
commit579e7fd383ff3f7a4f685489f8fe18cfd8659074 (patch)
treefeef61e31fb2de558cd7eb0427f20efacd31652e
parentum: Remove unused user_context function (diff)
downloadwireguard-linux-579e7fd383ff3f7a4f685489f8fe18cfd8659074.tar.xz
wireguard-linux-579e7fd383ff3f7a4f685489f8fe18cfd8659074.zip
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>
Diffstat (limited to '')
-rw-r--r--arch/um/drivers/rtc_kern.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/arch/um/drivers/rtc_kern.c b/arch/um/drivers/rtc_kern.c
index 134a58f93c85..9158c936c128 100644
--- a/arch/um/drivers/rtc_kern.c
+++ b/arch/um/drivers/rtc_kern.c
@@ -51,6 +51,7 @@ static int uml_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
static int uml_rtc_alarm_irq_enable(struct device *dev, unsigned int enable)
{
+ struct timespec64 ts;
unsigned long long secs;
if (!enable && !uml_rtc_alarm_enabled)
@@ -58,7 +59,8 @@ static int uml_rtc_alarm_irq_enable(struct device *dev, unsigned int enable)
uml_rtc_alarm_enabled = enable;
- secs = uml_rtc_alarm_time - ktime_get_real_seconds();
+ read_persistent_clock64(&ts);
+ secs = uml_rtc_alarm_time - ts.tv_sec;
if (time_travel_mode == TT_MODE_OFF) {
if (!enable) {
@@ -73,7 +75,8 @@ static int uml_rtc_alarm_irq_enable(struct device *dev, unsigned int enable)
if (enable)
time_travel_add_event_rel(&uml_rtc_alarm_event,
- secs * NSEC_PER_SEC);
+ secs * NSEC_PER_SEC -
+ ts.tv_nsec);
}
return 0;