• Z
    sched/rt.c: pick and check task if double_lock_balance() unlock the rq · f253eed2
    Zhou Chengming 提交于
    euler inclusion
    category: bugfix
    bugzilla: 2535
    CVE: N/A
    
    -------------------------------------------------
    
    push_rt_task() pick the first pushable task and find an eligible
    lowest_rq, then double_lock_balance(rq, lowest_rq). So if
    double_lock_balance() unlock the rq (when double_lock_balance() return 1),
    we have to check if this task is still on the rq.
    
    The problem is that the check conditions are not sufficient:
    
    if (unlikely(task_rq(task) != rq ||
    	     !cpumask_test_cpu(lowest_rq->cpu, &task->cpus_allowed) ||
    	     task_running(rq, task) ||
    	     !rt_task(task) ||
    	     !task_on_rq_queued(task))) {
    
    cpu2				cpu1			cpu0
    push_rt_task(rq1)
      pick task_A on rq1
      find rq0
        double_lock_balance(rq1, rq0)
          unlock(rq1)
    				rq1 __schedule
    				  pick task_A run
    				task_A sleep (dequeued)
          lock(rq0)
          lock(rq1)
        do_above_check(task_A)
          task_rq(task_A) == rq1
          cpus_allowed unchanged
          task_running == false
          rt_task(task_A) == true
    							try_to_wake_up(task_A)
    							  select_cpu = cpu3
    							  enqueue(rq3, task_A)
    							  task_A->on_rq = 1
          task_on_rq_queued(task_A)
        above_check passed, return rq0
        ...
        migrate task_A from rq1 to rq0
    
    So we can't rely on these checks of task_A to make sure the task_A is
    still on the rq1, even though we hold the rq1->lock. This patch will
    repick the first pushable task to be sure the task is still on the rq.
    Signed-off-by: NZhou Chengming <zhouchengming1@huawei.com>
    Signed-off-by: NKefeng Wang <wangkefeng.wang@huawei.com>
    Signed-off-by: NHui Wang <john.wanghui@huawei.com>
    Signed-off-by: NZhang Xiaoxu <zhangxiaoxu5@huawei.com>
    
    Conflicts: kernel/sched/rt.c
    Signed-off-by: NXuefeng Wang <wxf.wang@hisilicon.com>
    Reviewed-by: NXie XiuQi <xiexiuqi@huawei.com>
    Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
    f253eed2
rt.c 63.4 KB