FAILED: patch "[PATCH] sched_ext: Fix inverted ops.core_sched_before() invocation" failed to apply to 6.18-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x f7b6d128dd49a6eec09066ecfd29095f12588786
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026090359-grew-grab-d96a@gregkh' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From f7b6d128dd49a6eec09066ecfd29095f12588786 Mon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
Date: Sat, 15 Aug 2026 13:08:28 -1000
Subject: [PATCH] sched_ext: Fix inverted ops.core_sched_before() invocation
scx_prio_less() implements prio_less() semantics - %true means that @a is the lower priority and should run after @b. ops.core_sched_before() is documented to return %true when @a should run before @b. scx_prio_less() returns the op's value as-is, inverting the documented semantics at runtime.
Call the op with the arguments swapped.
scx_qmap followed the wiring instead of the documentation and returned %true for the younger task, so the two inversions canceled out and it behaved as intended. Flip its comparison to match. scx_qmap is likely the only current user in or out of the kernel tree. Any scheduler written the same way needs the same flip, while schedulers following the documentation are fixed by this change.
kernel/sched/ext/ext.c +8 -2
@@ -3528,6 +3528,8 @@ void ext_server_init(struct rq *rq)* * When ops.core_sched_before() is enabled, @p->scx.core_sched_at is used to * implement FIFO ordering within each local DSQ. See pick_task_scx(). +* +* Return: %true if @a should run after @b. */ bool scx_prio_less (const struct task_struct *a,const struct task_struct *b,bool in_fi)
@@ -3536,6 +3538,10 @@ bool scx_prio_less(const struct task_struct *a, const struct task_struct *b,struct scx_sched *sch_b =scx_task_sched (b);/* +* scx_prio_less() returns whether @a should run after @b while +* ops.core_sched_before() returns whether its first argument should run +* before the second. Swap the arguments. +* * The const qualifiers are dropped from task_struct pointers when * calling ops.core_sched_before(). Accesses are controlled by the * verifier.
@@ -3544,8 +3550,8 @@ bool scx_prio_less(const struct task_struct *a, const struct task_struct *b, !scx_bypassing(sch_a, task_cpu(a)))return SCX_CALL_OP_2TASKS_RET (sch_a, core_sched_before,task_rq (a), - (struct task_struct *)a, - (struct task_struct *)b); + (struct task_struct *)b, + (struct task_struct *)a); else return time_after64(a->scx.core_sched_at, b->scx.core_sched_at); }
tools/sched_ext/scx_qmap.bpf.c +1 -1
@@ -900,7 +900,7 @@ static s64 task_qdist(struct task_struct *p)bool BPF_STRUCT_OPS (qmap_core_sched_before ,struct task_struct *a,struct task_struct *b) { -return task_qdist (a) >task_qdist (b); +return task_qdist (a) <task_qdist (b); }/*
Sasha Levin
maintainerPATCH 1/1 sched_ext: Fix inverted ops.core_sched_before() invocation
From: Tejun Heo <[email protected]>
[ Upstream commit f7b6d128dd49a6eec09066ecfd29095f12588786 ]
scx_prio_less() implements prio_less() semantics - %true means that @a is the lower priority and should run after @b. ops.core_sched_before() is documented to return %true when @a should run before @b. scx_prio_less() returns the op's value as-is, inverting the documented semantics at runtime.
Call the op with the arguments swapped.
scx_qmap followed the wiring instead of the documentation and returned %true for the younger task, so the two inversions canceled out and it behaved as intended. Flip its comparison to match. scx_qmap is likely the only current user in or out of the kernel tree. Any scheduler written the same way needs the same flip, while schedulers following the documentation are fixed by this change.
--- kernel/sched/ext.c | 10 ++++++++-- tools/sched_ext/scx_qmap.bpf.c | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-)
kernel/sched/ext.c +8 -2
@@ -2513,6 +2513,8 @@ static struct task_struct *pick_task_scx(struct rq *rq)* * When ops.core_sched_before() is enabled, @p->scx.core_sched_at is used to * implement FIFO ordering within each local DSQ. See pick_task_scx(). +* +* Return: %true if @a should run after @b. */ bool scx_prio_less (const struct task_struct *a,const struct task_struct *b,bool in_fi)
@@ -2520,6 +2522,10 @@ bool scx_prio_less(const struct task_struct *a, const struct task_struct *b,struct scx_sched *sch = scx_root;/* +* scx_prio_less() returns whether @a should run after @b while +* ops.core_sched_before() returns whether its first argument should run +* before the second. Swap the arguments. +* * The const qualifiers are dropped from task_struct pointers when * calling ops.core_sched_before(). Accesses are controlled by the * verifier.
@@ -2528,8 +2534,8 @@ bool scx_prio_less(const struct task_struct *a, const struct task_struct *b, !scx_rq_bypassing(task_rq(a)))return SCX_CALL_OP_2TASKS_RET (sch,SCX_KF_REST , core_sched_before,task_rq (a), - (struct task_struct *)a, - (struct task_struct *)b); + (struct task_struct *)b, + (struct task_struct *)a); else return time_after64(a->scx.core_sched_at, b->scx.core_sched_at); }
tools/sched_ext/scx_qmap.bpf.c +1 -1
@@ -530,7 +530,7 @@ static s64 task_qdist(struct task_struct *p)bool BPF_STRUCT_OPS (qmap_core_sched_before ,struct task_struct *a,struct task_struct *b) { -return task_qdist (a) >task_qdist (b); +return task_qdist (a) <task_qdist (b); }void BPF_STRUCT_OPS (qmap_cpu_release ,s32 cpu,struct scx_cpu_release_args *args)
Signature · 1 line
2.53.0