From 92edb0ce6ab89399f3a976edddd03a2267ddfe8d Mon Sep 17 00:00:00 2001 From: Stephen Dickey Date: Wed, 11 Jan 2023 12:14:21 -0800 Subject: [PATCH] sched/walt: Prevent cpu rejection if only unhalted cpus are online In certain chipsets, there will be no constraint on which cpus are allowed to be offlined. In an extreme case where the last online cpu is a halted cpu, the requested cpu will still be rejected. This causes an unacceptable case to the upstream fallback cpu selection, and the system will crash. Avoid this by ensuring that if there are no online unhalted cpus the requested cpu will always be allowed. Change-Id: I7bf59bf5490a024fb1a28fc60f4acc38285d05e2 Signed-off-by: Stephen Dickey --- kernel/sched/walt/walt_halt.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/kernel/sched/walt/walt_halt.c b/kernel/sched/walt/walt_halt.c index 833e879eb277..2b79de9e1737 100644 --- a/kernel/sched/walt/walt_halt.c +++ b/kernel/sched/walt/walt_halt.c @@ -1,7 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2021-2021 Qualcomm Innovation Center, Inc. All rights reserved. - * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. + * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved. */ #include #include @@ -562,6 +561,20 @@ static void android_rvh_is_cpu_allowed(void *unused, struct task_struct *p, int * the context is execve. allow this cpu. */ *allowed = true; + } else { + cpumask_t active_unhalted_cpus; + + /* make sure there is a cpu to handle this task */ + cpumask_andnot(&active_unhalted_cpus, cpu_active_mask, cpu_halt_mask); + + if (cpumask_weight(&active_unhalted_cpus) == 0) { + /* + * there must be at least one active unhalted cpu in the system + * if not, blanket allow this cpu, regardless of halt status + */ + *allowed = true; + return; + } } } }