* [LTP] [PATCH] leapsec01: Keep STA_UNSYNC set to avoid corrupting the RTC
@ 2026-11-16 6:42 Wake Liu via ltp
0 siblings, 0 replies; only message in thread
From: Wake Liu via ltp @ 2026-11-16 6:42 UTC (permalink / raw)
To: ltp; +Cc: Wake Liu
The test sets CLOCK_REALTIME to two seconds before the next UTC midnight
and then calls adjtimex(ADJ_STATUS) with STA_PLL, 0 and STA_INS. None of
these include STA_UNSYNC, so the kernel treats the clock as synchronized
by NTP and its "11 minute mode" (sync_hw_clock(), CONFIG_RTC_SYSTOHC=y
by default) copies the system time into the RTC shortly afterwards. The
RTC thus ends up with the fake time around 23:59:59.
The test restores CLOCK_REALTIME at the end, but nothing restores the
RTC, which is left up to a day ahead of the system time. Tests that run
later and compare the RTC with the system time, such as sys_rtc01, fail,
and the machine boots with a wrong time until the clock is synced again.
Set STA_UNSYNC in every ADJ_STATUS call. The kernel inserts the leap
second regardless of STA_UNSYNC, as second_overflow() only checks
STA_INS, so the test still exercises the hrtimer bug. adjtimex() now
returns TIME_ERROR instead of the leap second state, which only changes
the informational messages printed by the test.
Signed-off-by: Wake Liu <wakel@google.com>
---
Tested on QEMU (x86_64, 6.12 kernel with CONFIG_RTC_SYSTOHC=y) by
running leapsec01 followed by sys_rtc01:
without the patch: rtc0 - system time = 75612s, sys_rtc01 TFAIL
with the patch: rtc0 - system time = 2s, sys_rtc01 TPASS, and the
kernel still logs "Clock: inserting leap second
23:59:60 UTC"
The remaining 2s come from the existing CLOCK_REALTIME restore in
run_leapsec(), which accounts neither for the time spent before the
clock is set nor for the inserted leap second.
We hit this on Android devices, where leapsec01 runs about ten minutes
before sys_rtc01.
testcases/kernel/syscalls/clock_gettime/leapsec01.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/testcases/kernel/syscalls/clock_gettime/leapsec01.c b/testcases/kernel/syscalls/clock_gettime/leapsec01.c
index a71e2adc6..2d175468b 100644
--- a/testcases/kernel/syscalls/clock_gettime/leapsec01.c
+++ b/testcases/kernel/syscalls/clock_gettime/leapsec01.c
@@ -79,6 +79,15 @@ static void adjtimex_status(struct timex *tx, int status)
int ret;
struct timespec now;
+ /*
+ * Keep STA_UNSYNC set, otherwise the kernel considers the clock
+ * synchronized and copies the system time, i.e. the fake time set by
+ * this test, into the RTC (CONFIG_RTC_SYSTOHC). Nothing restores the
+ * RTC afterwards. The leap second is inserted regardless of
+ * STA_UNSYNC.
+ */
+ status |= STA_UNSYNC;
+
tx->modes = ADJ_STATUS;
tx->status = status;
ret = adjtimex(tx);
--
2.56.0.611.g1030f0b940-goog
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-16 6:42 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 6:42 [LTP] [PATCH] leapsec01: Keep STA_UNSYNC set to avoid corrupting the RTC Wake Liu via ltp
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.