posix-cpu-timers: Fix rearm racing against process tick

Since the process wide cputime counter is started locklessly from
posix_cpu_timer_rearm(), it can be concurrently stopped by operations
on other timers from the same thread group, such as in the following
unlucky scenario:

CPU 0 CPU 1
----- -----
timer_settime(TIMER B)
posix_cpu_timer_rearm(TIMER A)
cpu_clock_sample_group()
(pct->timers_active already true)

handle_posix_cpu_timers()
check_process_timers()
stop_process_timers()
pct->timers_active = false
arm_timer(TIMER A)

tick -> run_posix_cpu_timers()
// sees !pct->timers_active, ignore
// our TIMER A

Fix this with simply locking process wide cputime counting start and
timer arm in the same block.

Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Fixes: 60f2ceaa8111 ("posix-cpu-timers: Remove unnecessary locking around cpu_clock_sample_group")
Cc: stable@vger.kernel.org
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Eric W. Biederman <ebiederm@xmission.com>

+5 -5
+5 -5
kernel/time/posix-cpu-timers.c
··· 991 991 if (!p) 992 992 goto out; 993 993 994 + /* Protect timer list r/w in arm_timer() */ 995 + sighand = lock_task_sighand(p, &flags); 996 + if (unlikely(sighand == NULL)) 997 + goto out; 998 + 994 999 /* 995 1000 * Fetch the current sample and update the timer's expiry time. 996 1001 */ ··· 1005 1000 now = cpu_clock_sample_group(clkid, p, true); 1006 1001 1007 1002 bump_cpu_timer(timer, now); 1008 - 1009 - /* Protect timer list r/w in arm_timer() */ 1010 - sighand = lock_task_sighand(p, &flags); 1011 - if (unlikely(sighand == NULL)) 1012 - goto out; 1013 1003 1014 1004 /* 1015 1005 * Now re-arm for the new expiry time.