public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Juri Lelli <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: juri.lelli@arm.com, hpa@zytor.com, peterz@infradead.org,
	tglx@linutronix.de, michael@amarulasolutions.com,
	daniel.wagner@bmw-carit.de, mingo@kernel.org,
	linux-kernel@vger.kernel.org, torvalds@linux-foundation.org,
	raistlin@linux.it, fchecconi@gmail.com
Subject: [tip:sched/core] sched/deadline: Fix races between rt_mutex_setprio() and dl_task_timer()
Date: Tue, 28 Oct 2014 04:02:07 -0700	[thread overview]
Message-ID: <tip-aee38ea95419c818dfdde52b115aeffe9cbb259b@git.kernel.org> (raw)
In-Reply-To: <1414142198-18552-5-git-send-email-juri.lelli@arm.com>

Commit-ID:  aee38ea95419c818dfdde52b115aeffe9cbb259b
Gitweb:     http://git.kernel.org/tip/aee38ea95419c818dfdde52b115aeffe9cbb259b
Author:     Juri Lelli <juri.lelli@arm.com>
AuthorDate: Fri, 24 Oct 2014 10:16:38 +0100
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Tue, 28 Oct 2014 10:46:01 +0100

sched/deadline: Fix races between rt_mutex_setprio() and dl_task_timer()

dl_task_timer() is racy against several paths. Daniel noticed that
the replenishment timer may experience a race condition against an
enqueue_dl_entity() called from rt_mutex_setprio(). With his own
words:

 rt_mutex_setprio() resets p->dl.dl_throttled. So the pattern is:
 start_dl_timer() throttled = 1, rt_mutex_setprio() throlled = 0,
 sched_switch() -> enqueue_task(), dl_task_timer-> enqueue_task()
 throttled is 0

=> BUG_ON(on_dl_rq(dl_se)) fires as the scheduling entity is already
enqueued on the -deadline runqueue.

As we do for the other races, we just bail out in the replenishment
timer code.

Reported-by: Daniel Wagner <daniel.wagner@bmw-carit.de>
Tested-by: Daniel Wagner <daniel.wagner@bmw-carit.de>
Signed-off-by: Juri Lelli <juri.lelli@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: vincent@legout.info
Cc: Dario Faggioli <raistlin@linux.it>
Cc: Michael Trimarchi <michael@amarulasolutions.com>
Cc: Fabio Checconi <fchecconi@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: http://lkml.kernel.org/r/1414142198-18552-5-git-send-email-juri.lelli@arm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/sched/deadline.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 92279ea..4616789 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -518,12 +518,20 @@ again:
 	}
 
 	/*
-	 * We need to take care of a possible races here. In fact, the
-	 * task might have changed its scheduling policy to something
-	 * different from SCHED_DEADLINE or changed its reservation
-	 * parameters (through sched_setattr()).
+	 * We need to take care of several possible races here:
+	 *
+	 *   - the task might have changed its scheduling policy
+	 *     to something different than SCHED_DEADLINE
+	 *   - the task might have changed its reservation parameters
+	 *     (through sched_setattr())
+	 *   - the task might have been boosted by someone else and
+	 *     might be in the boosting/deboosting path
+	 *
+	 * In all this cases we bail out, as the task is already
+	 * in the runqueue or is going to be enqueued back anyway.
 	 */
-	if (!dl_task(p) || dl_se->dl_new)
+	if (!dl_task(p) || dl_se->dl_new ||
+	    dl_se->dl_boosted || !dl_se->dl_throttled)
 		goto unlock;
 
 	sched_clock_tick();

  reply	other threads:[~2014-10-28 11:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-24  9:16 [PATCH 0/4] Fix various bits of AC and PI for SCHED_DEADLINE Juri Lelli
2014-10-24  9:16 ` [PATCH 1/4] sched/deadline: fix bandwidth check/update when migrating tasks between exclusive cpusets Juri Lelli
2014-10-24  9:16 ` [PATCH 2/4] sched/deadline: ensure that updates to exclusive cpusets don't break AC Juri Lelli
2014-10-24  9:16 ` [PATCH 3/4] sched/deadline: don't replenish from a !SCHED_DEADLINE entity Juri Lelli
2014-10-28 11:01   ` [tip:sched/core] sched/deadline: Don' t " tip-bot for Juri Lelli
2014-10-24  9:16 ` [PATCH 4/4] sched/deadline: fix races between rt_mutex_setprio and dl_task_timer Juri Lelli
2014-10-28 11:02   ` tip-bot for Juri Lelli [this message]
2014-10-24 11:34 ` [PATCH 0/4] Fix various bits of AC and PI for SCHED_DEADLINE Daniel Wagner
2014-10-24 13:21   ` Juri Lelli
2014-10-24 13:39     ` Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-aee38ea95419c818dfdde52b115aeffe9cbb259b@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=daniel.wagner@bmw-carit.de \
    --cc=fchecconi@gmail.com \
    --cc=hpa@zytor.com \
    --cc=juri.lelli@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=michael@amarulasolutions.com \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=raistlin@linux.it \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox