From: Wake Liu via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Cc: Wake Liu <wakel@google.com>
Subject: [LTP] [PATCH] leapsec01: Keep STA_UNSYNC set to avoid corrupting the RTC
Date: Mon, 16 Nov 2026 06:42:05 +0000 [thread overview]
Message-ID: <20261116064205.2360040-1-wakel@google.com> (raw)
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
reply other threads:[~2026-11-16 6:42 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261116064205.2360040-1-wakel@google.com \
--to=ltp@lists.linux.it \
--cc=wakel@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.