]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.14/posix-cpu-timers-unbreak-timer-rearming.patch
Linux 4.9.154
[thirdparty/kernel/stable-queue.git] / queue-4.14 / posix-cpu-timers-unbreak-timer-rearming.patch
1 From 93ad0fc088c5b4631f796c995bdd27a082ef33a6 Mon Sep 17 00:00:00 2001
2 From: Thomas Gleixner <tglx@linutronix.de>
3 Date: Fri, 11 Jan 2019 14:33:16 +0100
4 Subject: posix-cpu-timers: Unbreak timer rearming
5
6 From: Thomas Gleixner <tglx@linutronix.de>
7
8 commit 93ad0fc088c5b4631f796c995bdd27a082ef33a6 upstream.
9
10 The recent commit which prevented a division by 0 issue in the alarm timer
11 code broke posix CPU timers as an unwanted side effect.
12
13 The reason is that the common rearm code checks for timer->it_interval
14 being 0 now. What went unnoticed is that the posix cpu timer setup does not
15 initialize timer->it_interval as it stores the interval in CPU timer
16 specific storage. The reason for the separate storage is historical as the
17 posix CPU timers always had a 64bit nanoseconds representation internally
18 while timer->it_interval is type ktime_t which used to be a modified
19 timespec representation on 32bit machines.
20
21 Instead of reverting the offending commit and fixing the alarmtimer issue
22 in the alarmtimer code, store the interval in timer->it_interval at CPU
23 timer setup time so the common code check works. This also repairs the
24 existing inconistency of the posix CPU timer code which kept a single shot
25 timer armed despite of the interval being 0.
26
27 The separate storage can be removed in mainline, but that needs to be a
28 separate commit as the current one has to be backported to stable kernels.
29
30 Fixes: 0e334db6bb4b ("posix-timers: Fix division by zero bug")
31 Reported-by: H.J. Lu <hjl.tools@gmail.com>
32 Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
33 Cc: John Stultz <john.stultz@linaro.org>
34 Cc: Peter Zijlstra <peterz@infradead.org>
35 Cc: stable@vger.kernel.org
36 Link: https://lkml.kernel.org/r/20190111133500.840117406@linutronix.de
37 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
38
39 ---
40 kernel/time/posix-cpu-timers.c | 1 +
41 1 file changed, 1 insertion(+)
42
43 --- a/kernel/time/posix-cpu-timers.c
44 +++ b/kernel/time/posix-cpu-timers.c
45 @@ -685,6 +685,7 @@ static int posix_cpu_timer_set(struct k_
46 * set up the signal and overrun bookkeeping.
47 */
48 timer->it.cpu.incr = timespec64_to_ns(&new->it_interval);
49 + timer->it_interval = ns_to_ktime(timer->it.cpu.incr);
50
51 /*
52 * This acts as a modification timestamp for the timer,