From 65d4fe780a1dee0ebbb8fe49f71c1f5ff335917f Mon Sep 17 00:00:00 2001 From: Yu Liao Date: Sat, 2 Sep 2023 14:26:58 +0800 Subject: [PATCH] sched/smt: fix unbalance sched_smt_present dec/inc hulk inclusion category: bugfix bugzilla: 189013 CVE: NA -------------------------------- If cpuset_cpu_inactive() fails in sched_cpu_deactivate(), the cpu offline failed, but sched_smt_present is decreased before calling sched_cpu_deactivate, it leads unbalance dec/inc, so fix it by increasing sched_smt_present in the error path. Signed-off-by: Yang Yingliang Signed-off-by: Yu Liao --- kernel/sched/core.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 67bda877bfa8..7825ceaae0c4 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -5897,6 +5897,10 @@ int sched_cpu_deactivate(unsigned int cpu) ret = cpuset_cpu_inactive(cpu); if (ret) { +#ifdef CONFIG_SCHED_SMT + if (cpumask_weight(cpu_smt_mask(cpu)) == 2) + static_branch_inc_cpuslocked(&sched_smt_present); +#endif set_cpu_active(cpu, true); return ret; } -- Gitee