From 32db2ec6033183d6f702531d9fad911c2ae53527 Mon Sep 17 00:00:00 2001 From: Stephen Dickey Date: Thu, 27 Jan 2022 15:46:16 -0800 Subject: [PATCH] sched/walt: catch any set_task_cpu to unaffined cpus When a task's cpu affinity is changed, do_set_cpus_allowed() dequeues the task, updates the task's cpus_mask with new affinity but enqueues the task back on the current cpu, even if the current_cpu is not in the updated mask. This causes the affinity check in enqueue path to fail. Instead add this affinity check to set_task_cpu, this will catch any selection of an cpu outside allowed cpus. Change-Id: I6c1eaf77951f20aea961da463c1e8de0189d36e1 Signed-off-by: Stephen Dickey --- kernel/sched/walt/walt.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kernel/sched/walt/walt.c b/kernel/sched/walt/walt.c index b4c09317d2a1..e81198c54f61 100644 --- a/kernel/sched/walt/walt.c +++ b/kernel/sched/walt/walt.c @@ -3885,6 +3885,10 @@ static void android_rvh_set_task_cpu(void *unused, struct task_struct *p, unsign if (unlikely(walt_disabled)) return; fixup_busy_time(p, (int) new_cpu); + + if (!cpumask_test_cpu(new_cpu, p->cpus_ptr)) + WALT_BUG(WALT_BUG_WALT, p, "selecting unaffined cpu=%d comm=%s(%d) affinity=0x%x", + new_cpu, p->comm, p->pid, (*(cpumask_bits(p->cpus_ptr)))); } static void android_rvh_new_task_stats(void *unused, struct task_struct *p) @@ -3938,9 +3942,6 @@ static void android_rvh_enqueue_task(void *unused, struct rq *rq, struct task_st double_enqueue = true; } - if (!cpumask_test_cpu(cpu_of(rq), p->cpus_ptr)) - WALT_BUG(WALT_BUG_NONCRITICAL, p, "enqueueing on rq=%d comm=%s(%d) affinity=0x%x", - cpu_of(rq), p->comm, p->pid, (*(cpumask_bits(p->cpus_ptr)))); if (cpu_halted(cpu_of(rq)) && !(p->flags & PF_KTHREAD) && !walt_halt_check_last(cpu_of(rq))) WALT_BUG(WALT_BUG_NONCRITICAL, p,