* [PATCH] timers/itimer: Preserve nonzero remaining time for active timers
@ 2026-11-02 7:01 Avi Weiss
2026-11-02 22:15 ` Frederic Weisbecker
0 siblings, 1 reply; 2+ messages in thread
From: Avi Weiss @ 2026-11-02 7:01 UTC (permalink / raw)
To: Anna-Maria Behnsen; +Cc: Frederic Weisbecker, Thomas Gleixner, linux-kernel
itimer_get_remtime() preserves positive remainders below one
microsecond, but struct timeval only stores whole microseconds.
So, for example, the conversion to tv_usec truncates a 500 ns
remainder to zero, causing getitimer(ITIMER_REAL) to report an
active timer as disarmed.
Clamp active remainders below one microsecond to one microsecond
so they remain nonzero after conversion.
Fixes: 2ff678b8da64 ("[PATCH] hrtimer: switch itimers to hrtimer")
Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
---
kernel/time/itimer.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/time/itimer.c b/kernel/time/itimer.c
index 03a32dffc56c..a472a4f8babb 100644
--- a/kernel/time/itimer.c
+++ b/kernel/time/itimer.c
@@ -36,7 +36,7 @@ static struct timespec64 itimer_get_remtime(struct hrtimer *timer)
* then we return 0 - which is correct.
*/
if (hrtimer_active(timer)) {
- if (rem <= 0)
+ if (rem < NSEC_PER_USEC)
rem = NSEC_PER_USEC;
} else
rem = 0;
base-commit: d135ab453a7400a34930bdda1ef4bdc8acfac80e
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] timers/itimer: Preserve nonzero remaining time for active timers
2026-11-02 7:01 [PATCH] timers/itimer: Preserve nonzero remaining time for active timers Avi Weiss
@ 2026-11-02 22:15 ` Frederic Weisbecker
0 siblings, 0 replies; 2+ messages in thread
From: Frederic Weisbecker @ 2026-11-02 22:15 UTC (permalink / raw)
To: Avi Weiss; +Cc: Anna-Maria Behnsen, Thomas Gleixner, linux-kernel
Le Mon, Nov 02, 2026 at 09:01:49AM +0200, Avi Weiss a écrit :
> itimer_get_remtime() preserves positive remainders below one
> microsecond, but struct timeval only stores whole microseconds.
> So, for example, the conversion to tv_usec truncates a 500 ns
> remainder to zero, causing getitimer(ITIMER_REAL) to report an
> active timer as disarmed.
>
> Clamp active remainders below one microsecond to one microsecond
> so they remain nonzero after conversion.
>
> Fixes: 2ff678b8da64 ("[PATCH] hrtimer: switch itimers to hrtimer")
> Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
> ---
> kernel/time/itimer.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/time/itimer.c b/kernel/time/itimer.c
> index 03a32dffc56c..a472a4f8babb 100644
> --- a/kernel/time/itimer.c
> +++ b/kernel/time/itimer.c
> @@ -36,7 +36,7 @@ static struct timespec64 itimer_get_remtime(struct hrtimer *timer)
> * then we return 0 - which is correct.
> */
> if (hrtimer_active(timer)) {
> - if (rem <= 0)
> + if (rem < NSEC_PER_USEC)
> rem = NSEC_PER_USEC;
Right, though at this point it can race with the hrtimer at any point.
But it makes sense to have.
Thanks.
> } else
> rem = 0;
>
> base-commit: d135ab453a7400a34930bdda1ef4bdc8acfac80e
> --
> 2.43.0
>
--
Frederic Weisbecker
SUSE Labs
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-02 22:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-02 7:01 [PATCH] timers/itimer: Preserve nonzero remaining time for active timers Avi Weiss
2026-11-02 22:15 ` Frederic Weisbecker
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®