* [PATCH] fs/timerfd: fix stale remaining time after disarming an alarm timerfd
@ 2026-11-18 9:46 zhangjiao2
2026-12-04 21:08 ` Thomas Gleixner
0 siblings, 1 reply; 2+ messages in thread
From: zhangjiao2 @ 2026-11-18 9:46 UTC (permalink / raw)
To: tglx
Cc: frederic, brauner, john.stultz, toddpoynor, stable, linux-kernel,
trivial, zhang jiao
From: zhang jiao <zhangjiao2@cmss.chinamobile.com>
timerfd_setup() reinitializes the timer on every timerfd_settime()
invocation. For the hrtimer based clockids this goes through
hrtimer_setup(), which zeroes the whole hrtimer including the expiry
time which is stored in the embedded timerqueue node.
For the alarm based clockids (CLOCK_REALTIME_ALARM and
CLOCK_BOOTTIME_ALARM) timerfd_setup() uses alarm_init(), which only
reinitializes the timerqueue node linkage and the alarm state. The
expiry time, which alarm_start_timer() stores in alarm->node.expires,
survives that reinitialization.
As a consequence, disarming an alarm timerfd with timerfd_settime()
and an all zero it_value leaves the expiry time of the previous
arming in place. The remaining time of a timerfd is reported by
timerfd_gettime(), by the old_value copyout of a subsequent
timerfd_settime() and by the fdinfo file. A disarmed alarm timerfd
therefore keeps reporting a non-zero it_value until the stale expiry
time has passed, while the hrtimer based clockids correctly report
zero as required by POSIX.
Reset the expiry time when disarming an alarm based timerfd, which
matches what the memset() in hrtimer_setup() establishes for the
hrtimer based clockids.
Fixes: 11ffa9d6065f ("timerfd: Add alarm timers")
Cc: Todd Poynor <toddpoynor@google.com>
Cc: Thomas Gleixner <tglx@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
---
fs/timerfd.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fs/timerfd.c b/fs/timerfd.c
index fe845af0b74e..d7cc704e4afa 100644
--- a/fs/timerfd.c
+++ b/fs/timerfd.c
@@ -247,6 +247,8 @@ static int timerfd_setup(struct timerfd_ctx *ctx, int flags,
ctx->clockid == CLOCK_REALTIME_ALARM ?
ALARM_REALTIME : ALARM_BOOTTIME,
timerfd_alarmproc);
+ if (!texp)
+ ctx->t.alarm.node.expires = 0;
} else {
hrtimer_setup(&ctx->t.tmr, timerfd_tmrproc, clockid, htmode);
}
--
2.33.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] fs/timerfd: fix stale remaining time after disarming an alarm timerfd
2026-11-18 9:46 [PATCH] fs/timerfd: fix stale remaining time after disarming an alarm timerfd zhangjiao2
@ 2026-12-04 21:08 ` Thomas Gleixner
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Gleixner @ 2026-12-04 21:08 UTC (permalink / raw)
To: zhangjiao2
Cc: frederic, brauner, john.stultz, toddpoynor, linux-kernel,
zhang jiao
On Wed, Nov 18 2026 at 17:46, zhangjiao2@cmss.chinamobile.com wrote:
> @@ -247,6 +247,8 @@ static int timerfd_setup(struct timerfd_ctx *ctx, int flags,
> ctx->clockid == CLOCK_REALTIME_ALARM ?
> ALARM_REALTIME : ALARM_BOOTTIME,
> timerfd_alarmproc);
> + if (!texp)
> + ctx->t.alarm.node.expires = 0;
What's this conditional for?
Aside of that this is just a hack to cure a symptom.
Clearly timerqueue_init() should set node.expires to 0 unconditionally
as that's what an init function is supposed to do, no?
Thanks,
tglx
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-04 21:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 9:46 [PATCH] fs/timerfd: fix stale remaining time after disarming an alarm timerfd zhangjiao2
2026-12-04 21:08 ` Thomas Gleixner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox