This is a note to let you know that I've just added the patch titled sched/fair: Fixes for capacity inversion detection to the 5.15-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: sched-fair-fixes-for-capacity-inversion-detection.patch and it can be found in the queue-5.15 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From stable-owner@xxxxxxxxxxxxxxx Tue Apr 18 16:06:11 2023 From: Qais Yousef <qyousef@xxxxxxxxxxx> Date: Tue, 18 Apr 2023 15:05:47 +0100 Subject: sched/fair: Fixes for capacity inversion detection To: stable@xxxxxxxxxxxxxxx, Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>, Vincent Guittot <vincent.guittot@xxxxxxxxxx>, Dietmar Eggemann <dietmar.eggemann@xxxxxxx>, Qais Yousef <qyousef@xxxxxxxxxxx> Message-ID: <20230418140547.88035-8-qyousef@xxxxxxxxxxx> From: Qais Yousef <qyousef@xxxxxxxxxxx> commit da07d2f9c153e457e845d4dcfdd13568d71d18a4 upstream. Traversing the Perf Domains requires rcu_read_lock() to be held and is conditional on sched_energy_enabled(). Ensure right protections applied. Also skip capacity inversion detection for our own pd; which was an error. Fixes: 44c7b80bffc3 ("sched/fair: Detect capacity inversion") Reported-by: Dietmar Eggemann <dietmar.eggemann@xxxxxxx> Signed-off-by: Qais Yousef (Google) <qyousef@xxxxxxxxxxx> Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx> Reviewed-by: Vincent Guittot <vincent.guittot@xxxxxxxxxx> Link: https://lore.kernel.org/r/20230112122708.330667-3-qyousef@xxxxxxxxxxx (cherry picked from commit da07d2f9c153e457e845d4dcfdd13568d71d18a4) Signed-off-by: Qais Yousef (Google) <qyousef@xxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- kernel/sched/fair.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -8649,16 +8649,23 @@ static void update_cpu_capacity(struct s * * Thermal pressure will impact all cpus in this perf domain * equally. */ - if (static_branch_unlikely(&sched_asym_cpucapacity)) { + if (sched_energy_enabled()) { unsigned long inv_cap = capacity_orig - thermal_load_avg(rq); - struct perf_domain *pd = rcu_dereference(rq->rd->pd); + struct perf_domain *pd; + rcu_read_lock(); + + pd = rcu_dereference(rq->rd->pd); rq->cpu_capacity_inverted = 0; for (; pd; pd = pd->next) { struct cpumask *pd_span = perf_domain_span(pd); unsigned long pd_cap_orig, pd_cap; + /* We can't be inverted against our own pd */ + if (cpumask_test_cpu(cpu_of(rq), pd_span)) + continue; + cpu = cpumask_any(pd_span); pd_cap_orig = arch_scale_cpu_capacity(cpu); @@ -8683,6 +8690,8 @@ static void update_cpu_capacity(struct s break; } } + + rcu_read_unlock(); } trace_sched_cpu_capacity_tp(rq); Patches currently in stable-queue which might be from stable-owner@xxxxxxxxxxxxxxx are queue-5.15/sched-fair-detect-capacity-inversion.patch queue-5.15/sched-uclamp-make-cpu_overutilized-use-util_fits_cpu.patch queue-5.15/sched-uclamp-fix-fits_capacity-check-in-feec.patch queue-5.15/sched-fair-consider-capacity-inversion-in-util_fits_cpu.patch queue-5.15/sched-fair-fixes-for-capacity-inversion-detection.patch queue-5.15/sched-uclamp-fix-a-uninitialized-variable-warnings.patch queue-5.15/sched-uclamp-cater-for-uclamp-in-find_energy_efficient_cpu-s-early-exit-condition.patch