Skip to content

Commit db06e78

Browse files
Ben SegallIngo Molnar
authored andcommitted
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 <[email protected]> Signed-off-by: Peter Zijlstra <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/20131016181617.22647.73829.stgit@sword-of-the-dawn.mtv.corp.google.com Signed-off-by: Ingo Molnar <[email protected]>
1 parent 1ee14e6 commit db06e78

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

kernel/sched/fair.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3285,7 +3285,13 @@ static const u64 min_bandwidth_expiration = 2 * NSEC_PER_MSEC;
32853285
/* how long we wait to gather additional slack before distributing */
32863286
static const u64 cfs_bandwidth_slack_period = 5 * NSEC_PER_MSEC;
32873287

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+
*/
32893295
static int runtime_refresh_within(struct cfs_bandwidth *cfs_b, u64 min_expire)
32903296
{
32913297
struct hrtimer *refresh_timer = &cfs_b->period_timer;
@@ -3361,10 +3367,12 @@ static void do_sched_cfs_slack_timer(struct cfs_bandwidth *cfs_b)
33613367
u64 expires;
33623368

33633369
/* 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);
33653373
return;
3374+
}
33663375

3367-
raw_spin_lock(&cfs_b->lock);
33683376
if (cfs_b->quota != RUNTIME_INF && cfs_b->runtime > slice) {
33693377
runtime = cfs_b->runtime;
33703378
cfs_b->runtime = 0;

0 commit comments

Comments
 (0)