Skip to content

Commit 1a3402d

Browse files
author
Frederic Weisbecker
committed
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) <[email protected]> Signed-off-by: Frederic Weisbecker <[email protected]> Fixes: 60f2cea ("posix-cpu-timers: Remove unnecessary locking around cpu_clock_sample_group") Cc: [email protected] Cc: Oleg Nesterov <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Eric W. Biederman <[email protected]>
1 parent e73f0f0 commit 1a3402d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

kernel/time/posix-cpu-timers.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,11 @@ static void posix_cpu_timer_rearm(struct k_itimer *timer)
991991
if (!p)
992992
goto out;
993993

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+
994999
/*
9951000
* Fetch the current sample and update the timer's expiry time.
9961001
*/
@@ -1001,11 +1006,6 @@ static void posix_cpu_timer_rearm(struct k_itimer *timer)
10011006

10021007
bump_cpu_timer(timer, now);
10031008

1004-
/* Protect timer list r/w in arm_timer() */
1005-
sighand = lock_task_sighand(p, &flags);
1006-
if (unlikely(sighand == NULL))
1007-
goto out;
1008-
10091009
/*
10101010
* Now re-arm for the new expiry time.
10111011
*/

0 commit comments

Comments
 (0)