From 9d1a51d1b98f5a0526d84dd6bea78e817e27e7d5 Mon Sep 17 00:00:00 2001 From: Stephen Dickey Date: Mon, 22 Feb 2021 09:34:21 -0800 Subject: [PATCH] ANDROID: sched/pause: migrate_tasks crash With DEQUEUE_SAVE and ENQUEUE_RESTORE set when calling deactivate_task and activate_task, the rt class scheduler will not dequeue/enqueue the task respectively - move_entity() returns false. This results in the same task being picked multiple times by __pick_migrate_task, which results in the same task getting a second initialization of next->percpu_kthread_node, corrupting the list and causing a crash with __list_add_valid. Remove DEQUEUE_SAVE and ENQUEUE_RESTORE when holding back kthreads from being migrated, for the calls to activate/deactivate task, preventing the crash. Bug: 180893027 Change-Id: I3171c26a4f9415287feb5acfe933b4442ca05937 Signed-off-by: Stephen Dickey --- kernel/sched/core.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 9671f3f08ba3..70682a97194c 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -6940,8 +6940,10 @@ static void migrate_tasks(struct rq *dead_rq, struct rq_flags *rf, bool force) if (!force && is_per_cpu_kthread(next)) { INIT_LIST_HEAD(&next->percpu_kthread_node); list_add(&next->percpu_kthread_node, &percpu_kthreads); + + /* DEQUEUE_SAVE not used due to move_entity in rt */ deactivate_task(rq, next, - DEQUEUE_NOCLOCK | DEQUEUE_SAVE); + DEQUEUE_NOCLOCK); continue; } @@ -6989,7 +6991,9 @@ static void migrate_tasks(struct rq *dead_rq, struct rq_flags *rf, bool force) list_for_each_entry_safe(next, tmp, &percpu_kthreads, percpu_kthread_node) { - activate_task(rq, next, ENQUEUE_NOCLOCK | ENQUEUE_RESTORE); + + /* ENQUEUE_RESTORE not used due to move_entity in rt */ + activate_task(rq, next, ENQUEUE_NOCLOCK); list_del(&next->percpu_kthread_node); }