From: Keisuke Nishimura <keisuke.nishimura@inria.fr>
To: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
K Prateek Nayak <kprateek.nayak@amd.com>,
linux-kernel@vger.kernel.org
Cc: julia.lawall@inria.fr, jean-pierre.lozi@inria.fr,
Keisuke Nishimura <keisuke.nishimura@inria.fr>
Subject: [PATCH] sched/fair: Don't pick recent_used_cpu if target has no LLC domain
Date: Tue, 24 Nov 2026 16:51:06 +0100 [thread overview]
Message-ID: <20261124155107.358643-1-keisuke.nishimura@inria.fr> (raw)
select_idle_sibling() can return prev or recent_used_cpu if they are idle
and share the LLC with target. However, cpus_share_cache() returns true
for any two isolated CPUs because their sd_llc_id is never set and keeps
the initial value.
As a result, the original implementation can move a task between
isolated CPUs. Consider the following situation:
* isolcpus=1,2
* recent_used_cpu=1
* target=prev=2
* affinity=1,2
When CPU 1 is idle but CPU 2 is busy, select_idle_sibling() returns
recent_used_cpu (CPU 1).
To prevent the scheduler from moving the task among isolated CPUs, add a
check whether target has an LLC domain.
The path for prev is not impacted, because target == prev if target is
isolated. Add the same check there for consistency.
This bug was found with the help of verification using Frama-C.
Fixes: 32e839dda3ba ("sched/fair: Use a recently used CPU as an idle candidate and the basis for SIS")
Signed-off-by: Keisuke Nishimura <keisuke.nishimura@inria.fr>
---
kernel/sched/fair.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index da0d9e19c457..6314ff4c2f99 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -9151,7 +9151,7 @@ static inline bool asym_fits_cpu(unsigned long util,
static int select_idle_sibling(struct task_struct *p, int prev, int target)
{
bool has_idle_core = false;
- struct sched_domain *sd;
+ struct sched_domain *sd, *sd_asym;
unsigned long task_util, util_min, util_max;
int i, recent_used_cpu, prev_aff = -1;
@@ -9175,10 +9175,13 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)
asym_fits_cpu(task_util, util_min, util_max, target))
goto select_smt_priority;
+ /* NULL if target has no LLC domain, e.g. isolcpus */
+ sd = rcu_dereference_all(per_cpu(sd_llc, target));
+
/*
* If the previous CPU is cache affine and idle, don't be stupid:
*/
- if (prev != target && cpus_share_cache(prev, target) &&
+ if (prev != target && sd && cpus_share_cache(prev, target) &&
choose_idle_cpu(prev, p) &&
asym_fits_cpu(task_util, util_min, util_max, prev)) {
@@ -9213,7 +9216,7 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)
p->recent_used_cpu = prev;
if (recent_used_cpu != prev &&
recent_used_cpu != target &&
- cpus_share_cache(recent_used_cpu, target) &&
+ sd && cpus_share_cache(recent_used_cpu, target) &&
choose_idle_cpu(recent_used_cpu, p) &&
cpumask_test_cpu(recent_used_cpu, p->cpus_ptr) &&
asym_fits_cpu(task_util, util_min, util_max, recent_used_cpu)) {
@@ -9233,7 +9236,7 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)
* sd_asym_cpucapacity rather than sd_llc.
*/
if (sched_asym_cpucap_active()) {
- sd = rcu_dereference_all(per_cpu(sd_asym_cpucapacity, target));
+ sd_asym = rcu_dereference_all(per_cpu(sd_asym_cpucapacity, target));
/*
* On an asymmetric CPU capacity system where an exclusive
* cpuset defines a symmetric island (i.e. one unique
@@ -9242,8 +9245,8 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)
* SD_ASYM_CPUCAPACITY. These should follow the usual symmetric
* capacity path.
*/
- if (sd) {
- i = select_idle_capacity(p, sd, target);
+ if (sd_asym) {
+ i = select_idle_capacity(p, sd_asym, target);
if ((unsigned int)i < nr_cpumask_bits) {
target = i;
goto select_smt_priority;
@@ -9252,7 +9255,6 @@ static int select_idle_sibling(struct task_struct *p, int prev, int target)
}
}
- sd = rcu_dereference_all(per_cpu(sd_llc, target));
if (!sd)
return target;
--
2.34.1
next reply other threads:[~2026-11-24 16:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 15:51 Keisuke Nishimura [this message]
2026-11-24 16:36 ` Vincent Guittot
2026-11-24 18:13 ` Keisuke Nishimura
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261124155107.358643-1-keisuke.nishimura@inria.fr \
--to=keisuke.nishimura@inria.fr \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=jean-pierre.lozi@inria.fr \
--cc=julia.lawall@inria.fr \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®