diff options
author | Frederic Weisbecker <fweisbec@gmail.com> | 2013-10-11 11:41:11 -0400 |
---|---|---|
committer | Frederic Weisbecker <fweisbec@gmail.com> | 2013-12-09 10:53:51 -0500 |
commit | 50875788a1d4a3f662a27ed13cd05282d835939a (patch) | |
tree | 254cb6e105b576170aac22c195289de7b1998749 /kernel | |
parent | 33ab0fec33527e8b5ab124cff6aefd4746508e04 (diff) |
posix-timers: Use sighand lock instead of tasklist_lock for task clock sample
There is no need for the tasklist_lock just to take a process
wide clock sample.
All we need is to get a coherent sample that doesn't race with
exit() and exec():
* exit() may be concurrently reaping a task and flushing its time
* sighand is unstable under exit() and exec(), and the latter also
result in group leader that can change
To protect against these, locking the target's sighand is enough.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Kosaki Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/posix-cpu-timers.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c index 03c5d6c3e614..71a07699a36b 100644 --- a/kernel/posix-cpu-timers.c +++ b/kernel/posix-cpu-timers.c | |||
@@ -271,12 +271,22 @@ static int posix_cpu_clock_get_task(struct task_struct *tsk, | |||
271 | if (same_thread_group(tsk, current)) | 271 | if (same_thread_group(tsk, current)) |
272 | err = cpu_clock_sample(which_clock, tsk, &rtn); | 272 | err = cpu_clock_sample(which_clock, tsk, &rtn); |
273 | } else { | 273 | } else { |
274 | read_lock(&tasklist_lock); | 274 | unsigned long flags; |
275 | struct sighand_struct *sighand; | ||
275 | 276 | ||
276 | if (tsk->sighand && (tsk == current || thread_group_leader(tsk))) | 277 | /* |
278 | * while_each_thread() is not yet entirely RCU safe, | ||
279 | * keep locking the group while sampling process | ||
280 | * clock for now. | ||
281 | */ | ||
282 | sighand = lock_task_sighand(tsk, &flags); | ||
283 | if (!sighand) | ||
284 | return err; | ||
285 | |||
286 | if (tsk == current || thread_group_leader(tsk)) | ||
277 | err = cpu_clock_sample_group(which_clock, tsk, &rtn); | 287 | err = cpu_clock_sample_group(which_clock, tsk, &rtn); |
278 | 288 | ||
279 | read_unlock(&tasklist_lock); | 289 | unlock_task_sighand(tsk, &flags); |
280 | } | 290 | } |
281 | 291 | ||
282 | if (!err) | 292 | if (!err) |