aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorRik van Riel <riel@redhat.com>2014-09-12 09:12:15 -0400
committerIngo Molnar <mingo@kernel.org>2014-09-19 06:35:17 -0400
commit9c368b5b6eccce1cbd7f68142106b3b4ddb1c5b5 (patch)
tree2d74483c5bccdf6f513a763971fe419191afffd8 /kernel
parentef8ac06359ddf95431cf6bb04ad2b36fff562328 (diff)
sched, time: Fix lock inversion in thread_group_cputime()
The sig->stats_lock nests inside the tasklist_lock and the sighand->siglock in __exit_signal and wait_task_zombie. However, both of those locks can be taken from irq context, which means we need to use the interrupt safe variant of read_seqbegin_or_lock. This blocks interrupts when the "lock" branch is taken (seq is odd), preventing the lock inversion. On the first (lockless) pass through the loop, irqs are not blocked. Reported-by: Stanislaw Gruszka <sgruszka@redhat.com> Signed-off-by: Rik van Riel <riel@redhat.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: prarit@redhat.com Cc: oleg@redhat.com Cc: Linus Torvalds <torvalds@linux-foundation.org> Link: http://lkml.kernel.org/r/1410527535-9814-3-git-send-email-riel@redhat.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/sched/cputime.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index 2b57031afc19..64492dff8a81 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -289,13 +289,14 @@ void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times)
289 cputime_t utime, stime; 289 cputime_t utime, stime;
290 struct task_struct *t; 290 struct task_struct *t;
291 unsigned int seq, nextseq; 291 unsigned int seq, nextseq;
292 unsigned long flags;
292 293
293 rcu_read_lock(); 294 rcu_read_lock();
294 /* Attempt a lockless read on the first round. */ 295 /* Attempt a lockless read on the first round. */
295 nextseq = 0; 296 nextseq = 0;
296 do { 297 do {
297 seq = nextseq; 298 seq = nextseq;
298 read_seqbegin_or_lock(&sig->stats_lock, &seq); 299 flags = read_seqbegin_or_lock_irqsave(&sig->stats_lock, &seq);
299 times->utime = sig->utime; 300 times->utime = sig->utime;
300 times->stime = sig->stime; 301 times->stime = sig->stime;
301 times->sum_exec_runtime = sig->sum_sched_runtime; 302 times->sum_exec_runtime = sig->sum_sched_runtime;
@@ -309,7 +310,7 @@ void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times)
309 /* If lockless access failed, take the lock. */ 310 /* If lockless access failed, take the lock. */
310 nextseq = 1; 311 nextseq = 1;
311 } while (need_seqretry(&sig->stats_lock, seq)); 312 } while (need_seqretry(&sig->stats_lock, seq));
312 done_seqretry(&sig->stats_lock, seq); 313 done_seqretry_irqrestore(&sig->stats_lock, seq, flags);
313 rcu_read_unlock(); 314 rcu_read_unlock();
314} 315}
315 316