diff options
author | Roman Gushchin <klamm@yandex-team.ru> | 2014-05-19 07:10:09 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2014-06-05 05:51:34 -0400 |
commit | 09dc4ab03936df5c5aa711d27c81283c6d09f495 (patch) | |
tree | 58266dad582dcf05a46036b2a75a5b9de57872ca /kernel/sched/core.c | |
parent | 0f397f2c90ce68821ee864c2c53baafe78de765d (diff) |
sched/fair: Fix tg_set_cfs_bandwidth() deadlock on rq->lock
tg_set_cfs_bandwidth() sets cfs_b->timer_active to 0 to
force the period timer restart. It's not safe, because
can lead to deadlock, described in commit 927b54fccbf0:
"__start_cfs_bandwidth calls hrtimer_cancel while holding rq->lock,
waiting for the hrtimer to finish. However, if sched_cfs_period_timer
runs for another loop iteration, the hrtimer can attempt to take
rq->lock, resulting in deadlock."
Three CPUs must be involved:
CPU0 CPU1 CPU2
take rq->lock period timer fired
... take cfs_b lock
... ... tg_set_cfs_bandwidth()
throttle_cfs_rq() release cfs_b lock take cfs_b lock
... distribute_cfs_runtime() timer_active = 0
take cfs_b->lock wait for rq->lock ...
__start_cfs_bandwidth()
{wait for timer callback
break if timer_active == 1}
So, CPU0 and CPU1 are deadlocked.
Instead of resetting cfs_b->timer_active, tg_set_cfs_bandwidth can
wait for period timer callbacks (ignoring cfs_b->timer_active) and
restart the timer explicitly.
Signed-off-by: Roman Gushchin <klamm@yandex-team.ru>
Reviewed-by: Ben Segall <bsegall@google.com>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/87wqdi9g8e.wl\%klamm@yandex-team.ru
Cc: pjt@google.com
Cc: chris.j.arges@canonical.com
Cc: gregkh@linuxfoundation.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel/sched/core.c')
-rw-r--r-- | kernel/sched/core.c | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 540542b93f9f..f3f48e7a2dda 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c | |||
@@ -7751,8 +7751,7 @@ static int tg_set_cfs_bandwidth(struct task_group *tg, u64 period, u64 quota) | |||
7751 | /* restart the period timer (if active) to handle new period expiry */ | 7751 | /* restart the period timer (if active) to handle new period expiry */ |
7752 | if (runtime_enabled && cfs_b->timer_active) { | 7752 | if (runtime_enabled && cfs_b->timer_active) { |
7753 | /* force a reprogram */ | 7753 | /* force a reprogram */ |
7754 | cfs_b->timer_active = 0; | 7754 | __start_cfs_bandwidth(cfs_b, true); |
7755 | __start_cfs_bandwidth(cfs_b); | ||
7756 | } | 7755 | } |
7757 | raw_spin_unlock_irq(&cfs_b->lock); | 7756 | raw_spin_unlock_irq(&cfs_b->lock); |
7758 | 7757 | ||