]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/3.14.7/sched-dl-fix-race-in-dl_task_timer.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.14.7 / sched-dl-fix-race-in-dl_task_timer.patch
CommitLineData
cc6b8f45
GKH
1From 0f397f2c90ce68821ee864c2c53baafe78de765d Mon Sep 17 00:00:00 2001
2From: Kirill Tkhai <tkhai@yandex.ru>
3Date: Tue, 20 May 2014 13:33:42 +0400
4Subject: sched/dl: Fix race in dl_task_timer()
5
6From: Kirill Tkhai <tkhai@yandex.ru>
7
8commit 0f397f2c90ce68821ee864c2c53baafe78de765d upstream.
9
10Throttled task is still on rq, and it may be moved to other cpu
11if user is playing with sched_setaffinity(). Therefore, unlocked
12task_rq() access makes the race.
13
14Juri Lelli reports he got this race when dl_bandwidth_enabled()
15was not set.
16
17Other thing, pointed by Peter Zijlstra:
18
19 "Now I suppose the problem can still actually happen when
20 you change the root domain and trigger a effective affinity
21 change that way".
22
23To fix that we do the same as made in __task_rq_lock(). We do not
24use __task_rq_lock() itself, because it has a useful lockdep check,
25which is not correct in case of dl_task_timer(). We do not need
26pi_lock locked here. This case is an exception (PeterZ):
27
28 "The only reason we don't strictly need ->pi_lock now is because
29 we're guaranteed to have p->state == TASK_RUNNING here and are
30 thus free of ttwu races".
31
32Signed-off-by: Kirill Tkhai <tkhai@yandex.ru>
33Signed-off-by: Peter Zijlstra <peterz@infradead.org>
34Cc: Linus Torvalds <torvalds@linux-foundation.org>
35Link: http://lkml.kernel.org/r/3056991400578422@web14g.yandex.ru
36Signed-off-by: Ingo Molnar <mingo@kernel.org>
37Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
38
39---
40 kernel/sched/deadline.c | 10 +++++++++-
41 1 file changed, 9 insertions(+), 1 deletion(-)
42
43--- a/kernel/sched/deadline.c
44+++ b/kernel/sched/deadline.c
45@@ -490,9 +490,17 @@ static enum hrtimer_restart dl_task_time
46 struct sched_dl_entity,
47 dl_timer);
48 struct task_struct *p = dl_task_of(dl_se);
49- struct rq *rq = task_rq(p);
50+ struct rq *rq;
51+again:
52+ rq = task_rq(p);
53 raw_spin_lock(&rq->lock);
54
55+ if (rq != task_rq(p)) {
56+ /* Task was moved, retrying. */
57+ raw_spin_unlock(&rq->lock);
58+ goto again;
59+ }
60+
61 /*
62 * We need to take care of a possible races here. In fact, the
63 * task might have changed its scheduling policy to something