aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorBen Segall <bsegall@google.com>2013-10-16 14:16:17 -0400
committerIngo Molnar <mingo@kernel.org>2013-10-29 07:02:20 -0400
commitdb06e78cc13d70f10877e0557becc88ab3ad2be8 (patch)
tree867b99d17a5df49fc4c413940a99e6209e81e7a7 /kernel
parent1ee14e6c8cddeeb8a490d7b54cd9016e4bb900b4 (diff)
sched: Fix cfs_bandwidth misuse of hrtimer_expires_remaining
hrtimer_expires_remaining does not take internal hrtimer locks and thus must be guarded against concurrent __hrtimer_start_range_ns (but returning HRTIMER_RESTART is safe). Use cfs_b->lock to make it safe. Signed-off-by: Ben Segall <bsegall@google.com> Signed-off-by: Peter Zijlstra <peterz@infradead.org> Cc: pjt@google.com Link: http://lkml.kernel.org/r/20131016181617.22647.73829.stgit@sword-of-the-dawn.mtv.corp.google.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/sched/fair.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index ebd187f50339..897d97762d8a 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -3285,7 +3285,13 @@ static const u64 min_bandwidth_expiration = 2 * NSEC_PER_MSEC;
3285/* how long we wait to gather additional slack before distributing */ 3285/* how long we wait to gather additional slack before distributing */
3286static const u64 cfs_bandwidth_slack_period = 5 * NSEC_PER_MSEC; 3286static const u64 cfs_bandwidth_slack_period = 5 * NSEC_PER_MSEC;
3287 3287
3288/* are we near the end of the current quota period? */ 3288/*
3289 * Are we near the end of the current quota period?
3290 *
3291 * Requires cfs_b->lock for hrtimer_expires_remaining to be safe against the
3292 * hrtimer base being cleared by __hrtimer_start_range_ns. In the case of
3293 * migrate_hrtimers, base is never cleared, so we are fine.
3294 */
3289static int runtime_refresh_within(struct cfs_bandwidth *cfs_b, u64 min_expire) 3295static int runtime_refresh_within(struct cfs_bandwidth *cfs_b, u64 min_expire)
3290{ 3296{
3291 struct hrtimer *refresh_timer = &cfs_b->period_timer; 3297 struct hrtimer *refresh_timer = &cfs_b->period_timer;
@@ -3361,10 +3367,12 @@ static void do_sched_cfs_slack_timer(struct cfs_bandwidth *cfs_b)
3361 u64 expires; 3367 u64 expires;
3362 3368
3363 /* confirm we're still not at a refresh boundary */ 3369 /* confirm we're still not at a refresh boundary */
3364 if (runtime_refresh_within(cfs_b, min_bandwidth_expiration)) 3370 raw_spin_lock(&cfs_b->lock);
3371 if (runtime_refresh_within(cfs_b, min_bandwidth_expiration)) {
3372 raw_spin_unlock(&cfs_b->lock);
3365 return; 3373 return;
3374 }
3366 3375
3367 raw_spin_lock(&cfs_b->lock);
3368 if (cfs_b->quota != RUNTIME_INF && cfs_b->runtime > slice) { 3376 if (cfs_b->quota != RUNTIME_INF && cfs_b->runtime > slice) {
3369 runtime = cfs_b->runtime; 3377 runtime = cfs_b->runtime;
3370 cfs_b->runtime = 0; 3378 cfs_b->runtime = 0;