Skip to content

Commit e117cb5

Browse files
jlelliIngo Molnar
authored andcommitted
sched/deadline: Fix switched_from_dl() warning
Mark noticed that syzkaller is able to reliably trigger the following warning: dl_rq->running_bw > dl_rq->this_bw WARNING: CPU: 1 PID: 153 at kernel/sched/deadline.c:124 switched_from_dl+0x454/0x608 Kernel panic - not syncing: panic_on_warn set ... CPU: 1 PID: 153 Comm: syz-executor253 Not tainted 4.18.0-rc3+ #29 Hardware name: linux,dummy-virt (DT) Call trace: dump_backtrace+0x0/0x458 show_stack+0x20/0x30 dump_stack+0x180/0x250 panic+0x2dc/0x4ec __warn_printk+0x0/0x150 report_bug+0x228/0x2d8 bug_handler+0xa0/0x1a0 brk_handler+0x2f0/0x568 do_debug_exception+0x1bc/0x5d0 el1_dbg+0x18/0x78 switched_from_dl+0x454/0x608 __sched_setscheduler+0x8cc/0x2018 sys_sched_setattr+0x340/0x758 el0_svc_naked+0x30/0x34 syzkaller reproducer runs a bunch of threads that constantly switch between DEADLINE and NORMAL classes while interacting through futexes. The splat above is caused by the fact that if a DEADLINE task is setattr back to NORMAL while in non_contending state (blocked on a futex - inactive timer armed), its contribution to running_bw is not removed before sub_rq_bw() gets called (!task_on_rq_queued() branch) and the latter sees running_bw > this_bw. Fix it by removing a task contribution from running_bw if the task is not queued and in non_contending state while switched to a different class. Reported-by: Mark Rutland <[email protected]> Signed-off-by: Juri Lelli <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Daniel Bristot de Oliveira <[email protected]> Reviewed-by: Luca Abeni <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 9fb8d5d commit e117cb5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

kernel/sched/deadline.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2290,8 +2290,17 @@ static void switched_from_dl(struct rq *rq, struct task_struct *p)
22902290
if (task_on_rq_queued(p) && p->dl.dl_runtime)
22912291
task_non_contending(p);
22922292

2293-
if (!task_on_rq_queued(p))
2293+
if (!task_on_rq_queued(p)) {
2294+
/*
2295+
* Inactive timer is armed. However, p is leaving DEADLINE and
2296+
* might migrate away from this rq while continuing to run on
2297+
* some other class. We need to remove its contribution from
2298+
* this rq running_bw now, or sub_rq_bw (below) will complain.
2299+
*/
2300+
if (p->dl.dl_non_contending)
2301+
sub_running_bw(&p->dl, &rq->dl);
22942302
sub_rq_bw(&p->dl, &rq->dl);
2303+
}
22952304

22962305
/*
22972306
* We cannot use inactive_task_timer() to invoke sub_running_bw()

0 commit comments

Comments
 (0)