From: Ahmed Abdelraoof <araoof@amazon.de>
To: Ingo Molnar <mingo@redhat.com>, Peter Zijlstra <peterz@infradead.org>
Cc: 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>,
Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Randy Dunlap <rdunlap@infradead.org>, <linux-doc@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, Anselm Busse <abusse@amazon.com>,
Ahmed Abdelraoof <araoof@amazon.com>
Subject: [PATCH 3/4] sched/core: Gate core scheduling on the isolation unit
Date: Thu, 3 Dec 2026 22:13:06 +0000 [thread overview]
Message-ID: <20261203221307.86078-4-araoof@amazon.de> (raw)
In-Reply-To: <20261203221307.86078-1-araoof@amazon.de>
From: Anselm Busse <abusse@amazon.com>
prctl(PR_SCHED_CORE) fails with -ENODEV unless sched_smt_present is set.
Once the isolation unit can be wider than the SMT siblings, core
scheduling has something to isolate on systems without SMT.
Add a separate sched_core_unit_present key, counted once per unit as its
second CPU comes up, and gate the prctl on it.
Keep sched_smt_present as it is used to report kernel suseptability to
SMT related vulnerabilities (TAA, L1TF ..etc).
No functional change intended.
Signed-off-by: Anselm Busse <abusse@amazon.com>
Co-developed-by: Ahmed Abdelraoof <araoof@amazon.com>
Signed-off-by: Ahmed Abdelraoof <araoof@amazon.com>
---
kernel/sched/core.c | 26 ++++++++++++++++++++++++++
kernel/sched/core_sched.c | 2 +-
kernel/sched/sched.h | 11 +++++++++++
3 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index b62716094445..c69f40e7b93a 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -8725,6 +8725,30 @@ static inline void sched_smt_present_dec(int cpu)
static_branch_dec_cpuslocked(&sched_smt_present);
}
+#ifdef CONFIG_SCHED_CORE
+DEFINE_STATIC_KEY_FALSE(sched_core_unit_present);
+
+/*
+ * Fire once per isolation unit, as its second CPU comes up and again as the
+ * unit shrinks back through two, which keeps the refcount balanced for any
+ * unit width. When the unit is SMT this tracks sched_smt_present exactly.
+ */
+static inline void sched_core_unit_present_inc(int cpu)
+{
+ if (cpumask_weight(sched_core_isolation_mask(cpu)) == 2)
+ static_branch_inc_cpuslocked(&sched_core_unit_present);
+}
+
+static inline void sched_core_unit_present_dec(int cpu)
+{
+ if (cpumask_weight(sched_core_isolation_mask(cpu)) == 2)
+ static_branch_dec_cpuslocked(&sched_core_unit_present);
+}
+#else
+static inline void sched_core_unit_present_inc(int cpu) { }
+static inline void sched_core_unit_present_dec(int cpu) { }
+#endif
+
int sched_cpu_activate(unsigned int cpu)
{
struct rq *rq = cpu_rq(cpu);
@@ -8739,6 +8763,7 @@ int sched_cpu_activate(unsigned int cpu)
* When going up, increment the number of cores with SMT present.
*/
sched_smt_present_inc(cpu);
+ sched_core_unit_present_inc(cpu);
set_cpu_active(cpu, true);
if (sched_smp_initialized) {
@@ -8817,6 +8842,7 @@ int sched_cpu_deactivate(unsigned int cpu)
* When going down, decrement the number of cores with SMT present.
*/
sched_smt_present_dec(cpu);
+ sched_core_unit_present_dec(cpu);
sched_core_cpu_deactivate(cpu);
diff --git a/kernel/sched/core_sched.c b/kernel/sched/core_sched.c
index d56be1c31435..ba4d608c0d80 100644
--- a/kernel/sched/core_sched.c
+++ b/kernel/sched/core_sched.c
@@ -136,7 +136,7 @@ int sched_core_share_pid(unsigned int cmd, pid_t pid, enum pid_type type,
struct pid *grp;
int err = 0;
- if (!sched_smt_active())
+ if (!sched_core_unit_active())
return -ENODEV;
BUILD_BUG_ON(PR_SCHED_CORE_SCOPE_THREAD != PIDTYPE_PID);
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 948f70af6fa6..97126c1dcb09 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1598,6 +1598,17 @@ static inline const struct cpumask *sched_core_isolation_mask(int cpu)
return cpu_smt_mask(cpu);
}
+DECLARE_STATIC_KEY_FALSE(sched_core_unit_present);
+
+/*
+ * True once some isolation unit spans more than one CPU, i.e. once core
+ * scheduling has something it can actually exclude.
+ */
+static inline bool sched_core_unit_active(void)
+{
+ return static_branch_likely(&sched_core_unit_present);
+}
+
/*
* Helpers to check if the CPU's core cookie matches with the task's cookie
* when core scheduling is enabled.
--
2.47.3
next prev parent reply other threads:[~2026-12-03 22:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 22:13 [PATCH 0/4] sched/core: Core scheduling beyond SMT siblings Ahmed Abdelraoof
2026-12-03 22:13 ` [PATCH 1/4] sched/core: Decouple the core scheduling unit from cpu_smt_mask Ahmed Abdelraoof
2026-12-03 22:13 ` [PATCH 2/4] sched/core: Nest the isolation unit rq locks under one lock for lockdep Ahmed Abdelraoof
2026-12-03 22:13 ` Ahmed Abdelraoof [this message]
2026-12-03 22:13 ` [PATCH 4/4] sched/core: Support L2 cache isolation Ahmed Abdelraoof
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=20261203221307.86078-4-araoof@amazon.de \
--to=araoof@amazon.de \
--cc=abusse@amazon.com \
--cc=araoof@amazon.com \
--cc=bsegall@google.com \
--cc=corbet@lwn.net \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rdunlap@infradead.org \
--cc=rostedt@goodmis.org \
--cc=skhan@linuxfoundation.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