[PATCH 3/4] sched/core: Gate core scheduling on the isolation unit
From: Ahmed Abdelraoof
Date: Thu Dec 03 2026 - 17:14:32 EST
From: Anselm Busse <abusse@xxxxxxxxxx>
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@xxxxxxxxxx>
Co-developed-by: Ahmed Abdelraoof <araoof@xxxxxxxxxx>
Signed-off-by: Ahmed Abdelraoof <araoof@xxxxxxxxxx>
---
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