Skip to content

Commit feffe5b

Browse files
schspaPeter Zijlstra
authored andcommitted
sched/rt: Fix bad task migration for rt tasks
Commit 95158a8 ("sched,rt: Use the full cpumask for balancing") allows find_lock_lowest_rq() to pick a task with migration disabled. The purpose of the commit is to push the current running task on the CPU that has the migrate_disable() task away. However, there is a race which allows a migrate_disable() task to be migrated. Consider: CPU0 CPU1 push_rt_task check is_migration_disabled(next_task) task not running and migration_disabled == 0 find_lock_lowest_rq(next_task, rq); _double_lock_balance(this_rq, busiest); raw_spin_rq_unlock(this_rq); double_rq_lock(this_rq, busiest); <<wait for busiest rq>> <wakeup> task become running migrate_disable(); <context out> deactivate_task(rq, next_task, 0); set_task_cpu(next_task, lowest_rq->cpu); WARN_ON_ONCE(is_migration_disabled(p)); Fixes: 95158a8 ("sched,rt: Use the full cpumask for balancing") Signed-off-by: Schspa Shi <schspa@gmail.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org> Reviewed-by: Dietmar Eggemann <dietmar.eggemann@arm.com> Reviewed-by: Valentin Schneider <vschneid@redhat.com> Tested-by: Dwaine Gonyier <dgonyier@redhat.com>
1 parent 223baf9 commit feffe5b

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

kernel/sched/deadline.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,6 +2246,7 @@ static struct rq *find_lock_later_rq(struct task_struct *task, struct rq *rq)
22462246
!cpumask_test_cpu(later_rq->cpu, &task->cpus_mask) ||
22472247
task_on_cpu(rq, task) ||
22482248
!dl_task(task) ||
2249+
is_migration_disabled(task) ||
22492250
!task_on_rq_queued(task))) {
22502251
double_unlock_balance(rq, later_rq);
22512252
later_rq = NULL;

kernel/sched/rt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,11 +2000,15 @@ static struct rq *find_lock_lowest_rq(struct task_struct *task, struct rq *rq)
20002000
* the mean time, task could have
20012001
* migrated already or had its affinity changed.
20022002
* Also make sure that it wasn't scheduled on its rq.
2003+
* It is possible the task was scheduled, set
2004+
* "migrate_disabled" and then got preempted, so we must
2005+
* check the task migration disable flag here too.
20032006
*/
20042007
if (unlikely(task_rq(task) != rq ||
20052008
!cpumask_test_cpu(lowest_rq->cpu, &task->cpus_mask) ||
20062009
task_on_cpu(rq, task) ||
20072010
!rt_task(task) ||
2011+
is_migration_disabled(task) ||
20082012
!task_on_rq_queued(task))) {
20092013

20102014
double_unlock_balance(rq, lowest_rq);

0 commit comments

Comments
 (0)