The recent commit which prevented a division by 0 issue in the alarm timer
code broke posix CPU timers as an unwanted side effect.
The reason is that the common rearm code checks for timer->it_interval
being 0 now. What went unnoticed is that the posix cpu timer setup does not
initialize timer->it_interval as it stores the interval in CPU timer
specific storage. The reason for the separate storage is historical as the
posix CPU timers always had a 64bit nanoseconds representation internally
while timer->it_interval is type ktime_t which used to be a modified
timespec representation on 32bit machines.
Instead of reverting the offending commit and fixing the alarmtimer issue
in the alarmtimer code, store the interval in timer->it_interval at CPU
timer setup time so the common code check works. This also repairs the
existing inconistency of the posix CPU timer code which kept a single shot
timer armed despite of the interval being 0.
The separate storage can be removed in mainline, but that needs to be a
separate commit as the current one has to be backported to stable kernels.
Fixes: 0e334db6bb4b ("posix-timers: Fix division by zero bug")
Reported-by: H.J. Lu <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Cc: [email protected]
Cc: Peter Zijlstra <[email protected]>
Cc: John Stultz <[email protected]>
---
kernel/time/posix-cpu-timers.c | 1 +
1 file changed, 1 insertion(+)
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -685,6 +685,7 @@ static int posix_cpu_timer_set(struct k_
* set up the signal and overrun bookkeeping.
*/
timer->it.cpu.incr = timespec64_to_ns(&new->it_interval);
+ timer->it_interval = ns_to_ktime(timer->it.cpu.incr);
/*
* This acts as a modification timestamp for the timer,
On Fri, Jan 11, 2019 at 5:36 AM Thomas Gleixner <[email protected]> wrote:
>
> The recent commit which prevented a division by 0 issue in the alarm timer
> code broke posix CPU timers as an unwanted side effect.
>
> The reason is that the common rearm code checks for timer->it_interval
> being 0 now. What went unnoticed is that the posix cpu timer setup does not
> initialize timer->it_interval as it stores the interval in CPU timer
> specific storage. The reason for the separate storage is historical as the
> posix CPU timers always had a 64bit nanoseconds representation internally
> while timer->it_interval is type ktime_t which used to be a modified
> timespec representation on 32bit machines.
>
> Instead of reverting the offending commit and fixing the alarmtimer issue
> in the alarmtimer code, store the interval in timer->it_interval at CPU
> timer setup time so the common code check works. This also repairs the
> existing inconistency of the posix CPU timer code which kept a single shot
> timer armed despite of the interval being 0.
>
> The separate storage can be removed in mainline, but that needs to be a
> separate commit as the current one has to be backported to stable kernels.
>
> Fixes: 0e334db6bb4b ("posix-timers: Fix division by zero bug")
> Reported-by: H.J. Lu <[email protected]>
> Signed-off-by: Thomas Gleixner <[email protected]>
> Cc: [email protected]
> Cc: Peter Zijlstra <[email protected]>
> Cc: John Stultz <[email protected]>
> ---
> kernel/time/posix-cpu-timers.c | 1 +
> 1 file changed, 1 insertion(+)
>
> --- a/kernel/time/posix-cpu-timers.c
> +++ b/kernel/time/posix-cpu-timers.c
> @@ -685,6 +685,7 @@ static int posix_cpu_timer_set(struct k_
> * set up the signal and overrun bookkeeping.
> */
> timer->it.cpu.incr = timespec64_to_ns(&new->it_interval);
> + timer->it_interval = ns_to_ktime(timer->it.cpu.incr);
>
> /*
> * This acts as a modification timestamp for the timer,
>
>
I verified that this patch works on 4.19.14 kernel.
Thanks.
--
H.J.
Commit-ID: 93ad0fc088c5b4631f796c995bdd27a082ef33a6
Gitweb: https://git.kernel.org/tip/93ad0fc088c5b4631f796c995bdd27a082ef33a6
Author: Thomas Gleixner <[email protected]>
AuthorDate: Fri, 11 Jan 2019 14:33:16 +0100
Committer: Thomas Gleixner <[email protected]>
CommitDate: Tue, 15 Jan 2019 16:34:37 +0100
posix-cpu-timers: Unbreak timer rearming
The recent commit which prevented a division by 0 issue in the alarm timer
code broke posix CPU timers as an unwanted side effect.
The reason is that the common rearm code checks for timer->it_interval
being 0 now. What went unnoticed is that the posix cpu timer setup does not
initialize timer->it_interval as it stores the interval in CPU timer
specific storage. The reason for the separate storage is historical as the
posix CPU timers always had a 64bit nanoseconds representation internally
while timer->it_interval is type ktime_t which used to be a modified
timespec representation on 32bit machines.
Instead of reverting the offending commit and fixing the alarmtimer issue
in the alarmtimer code, store the interval in timer->it_interval at CPU
timer setup time so the common code check works. This also repairs the
existing inconistency of the posix CPU timer code which kept a single shot
timer armed despite of the interval being 0.
The separate storage can be removed in mainline, but that needs to be a
separate commit as the current one has to be backported to stable kernels.
Fixes: 0e334db6bb4b ("posix-timers: Fix division by zero bug")
Reported-by: H.J. Lu <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Cc: John Stultz <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: [email protected]
Link: https://lkml.kernel.org/r/[email protected]
---
kernel/time/posix-cpu-timers.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index 8f0644af40be..80f955210861 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -685,6 +685,7 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags,
* set up the signal and overrun bookkeeping.
*/
timer->it.cpu.incr = timespec64_to_ns(&new->it_interval);
+ timer->it_interval = ns_to_ktime(timer->it.cpu.incr);
/*
* This acts as a modification timestamp for the timer,