[PATCH 0/3] timers: Report disarmed alarm timerfds and SIGEV_NONE timers as disarmed
From: Shashank Mohan Jain
Date: Sun Oct 11 2026 - 01:21:44 EST
Two interfaces keep reporting the remaining time of the previous
setting after a timer was disarmed with a zero it_value, until the old
expiry time has passed:
- timerfd_gettime() for timerfds on CLOCK_REALTIME_ALARM and
CLOCK_BOOTTIME_ALARM (patch 1). The timerfds on the hrtimer based
clocks report zero.
- timer_gettime() for SIGEV_NONE timers on CLOCK_MONOTONIC,
CLOCK_BOOTTIME, CLOCK_REALTIME and the alarm clocks (patch 2).
Timers with signal delivery and the CPU time clocks report zero.
In both cases the stale expiry time of a timer which is not queued is
used to compute the remaining time. Patch 1 resets it in alarm_init(),
patch 2 moves it into the past when a SIGEV_NONE timer is disarmed.
Patch 3 adds a test for the second case to the posix_timers selftest.
The first problem was found by reading fs/timerfd.c, the second one
when the test program for the first was extended to POSIX timers.
Both are old: the first exists since timerfd got alarm clock support,
the second is also there in a v6.8 based distribution kernel.
Patch 2 uses the timer_arm() callback with an expiry time of 0 to
reset the stored expiry time, because that needs no new callback. If
a dedicated callback or a different place is preferred, I can redo it
that way.
Tested in qemu (x86_64) on top of mainline a5ebb76233b7 (v7.3-rc6+)
with a program which runs the arm/disarm/gettime sequence on all five
clocks for timerfd and for POSIX timers with SIGEV_SIGNAL and
SIGEV_NONE: 9 wrong results without the series, none with it. The
posix_timers selftest with patch 3 fails the new CLOCK_MONOTONIC test
without patch 2 and passes all 21 tests with it. The patches also
apply to next-20261009.
Shashank Mohan Jain (3):
alarmtimer: Reset the expiry time in alarm_init()
posix-timers: Report a disarmed SIGEV_NONE timer as disarmed
selftests/timers: Test timer_gettime() on a disarmed SIGEV_NONE timer
kernel/time/alarmtimer.c | 1 +
kernel/time/posix-timers.c | 12 +++++-
tools/testing/selftests/timers/posix_timers.c | 38 ++++++++++++++++++-
3 files changed, 48 insertions(+), 3 deletions(-)
base-commit: a5ebb76233b79db01e82e061173cb73c6d2b5c6b
--
2.43.0