mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sched_ext: idle: Respect task affinity in restricted CPU selection
@ 2026-10-11  2:52 Hui Su
  2026-10-11  7:02 ` Andrea Righi
  0 siblings, 1 reply; 6+ messages in thread
From: Hui Su @ 2026-10-11  2:52 UTC (permalink / raw)
  To: tj
  Cc: void, arighi, changwoo, mingo, peterz, juri.lelli,
	vincent.guittot, dietmar.eggemann, rostedt, bsegall, mgorman,
	vschneid, kprateek.nayak, sched-ext, linux-kernel, bpf, Hui Su,
	stable

The restricted select_cpu kfunc path handles single-CPU and
migration-disabled tasks without going through scx_select_cpu_dfl().

When a caller supplies @allowed, the path currently checks prev_cpu only
against that mask. It can therefore return an idle prev_cpu which isn't
in p->cpus_ptr.

Require prev_cpu to belong to both p->cpus_ptr and the caller-provided
mask before consuming its idle state.

Fixes: 683d2d0faba1 ("sched_ext: idle: Introduce scx_bpf_select_cpu_and()")
Cc: stable@vger.kernel.org
Signed-off-by: Hui Su <sh_def@163.com>
---
Testing:
- x86_64 KVM/QEMU.
- A private regression harness pinned the task to CPU 0 and called
  scx_bpf_select_cpu_and() with an idle CPU 1 outside the task affinity
  but inside the caller-provided mask.
- On the baseline kernel, the helper returned CPU 1.
- With this fix, the helper rejected the out-of-affinity CPU.
- The existing allowed_cpus selftest passed with the fix.

 kernel/sched/ext/idle.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/ext/idle.c b/kernel/sched/ext/idle.c
index aa9fb6de0ad6..20efa463cafa 100644
--- a/kernel/sched/ext/idle.c
+++ b/kernel/sched/ext/idle.c
@@ -999,7 +999,8 @@ static s32 select_cpu_from_kfunc(struct scx_sched *sch, struct task_struct *p,
 	 * used CPU is idle and within the allowed cpumask.
 	 */
 	if (p->nr_cpus_allowed == 1 || is_bpf_migration_disabled(p)) {
-		if (cpumask_test_cpu(prev_cpu, allowed ?: p->cpus_ptr) &&
+		if (cpumask_test_cpu(prev_cpu, p->cpus_ptr) &&
+		    (!allowed || cpumask_test_cpu(prev_cpu, allowed)) &&
 		    scx_idle_test_and_clear_cpu(prev_cpu))
 			cpu = prev_cpu;
 		else

base-commit: 7b63ef2d55f24519e7e9e5f4d15dbea03f126e40


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-10-11 17:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-11  2:52 [PATCH] sched_ext: idle: Respect task affinity in restricted CPU selection Hui Su
2026-10-11  7:02 ` Andrea Righi
2026-10-11  9:10   ` Hui Su
2026-10-11 13:17   ` [PATCH v2] " Hui Su
2026-10-11 14:39     ` Andrea Righi
2026-10-11 17:09       ` Hui Su

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®