* [PATCH sched_ext/for-7.1-fixes] tools/sched_ext: scx_qmap: Silence task_ctx lookup miss
@ 2026-04-21 6:13 Tejun Heo
2026-04-21 6:47 ` Andrea Righi
2026-04-21 7:17 ` [PATCH v2 " Tejun Heo
0 siblings, 2 replies; 5+ messages in thread
From: Tejun Heo @ 2026-04-21 6:13 UTC (permalink / raw)
To: David Vernet, Andrea Righi, Changwoo Min
Cc: sched-ext, Emil Tsalapatis, linux-kernel
scx_fork() dispatches ops.init_task to exactly one scheduler - the one
owning the forking task's cgroup. A task forked inside a sub-scheduler's
cgroup is init'd into the sub only; the root scheduler has no task_ctx
entry for it. When that task later appears as @prev in the root's
qmap_dispatch() (or flows through core-sched comparison via task_qdist),
the bpf_task_storage_get() legitimately misses.
qmap treated those misses as fatal via scx_bpf_error("task_ctx lookup
failed") and aborted the scheduler as soon as the first cross-sched
task hit the root. Drop the error in the three sites where the miss is
legitimate: lookup_task_ctx() (helper; callers already check for NULL),
qmap_dispatch()'s @prev branch (bookkeeping-only), and task_qdist()
(returns 0 which makes the comparison a no-op). The existing scx_error
was a paranoid guard from the pre-sub-sched world where every task was
owned by the one and only scheduler.
Fixes: 4f8b122848db ("sched_ext: Add basic building blocks for nested sub-scheduler dispatching")
Signed-off-by: Tejun Heo <tj@kernel.org>
---
tools/sched_ext/scx_qmap.bpf.c | 22 +++++-----------------
1 file changed, 5 insertions(+), 17 deletions(-)
diff --git a/tools/sched_ext/scx_qmap.bpf.c b/tools/sched_ext/scx_qmap.bpf.c
index b68abb9e760b..0330ba15210d 100644
--- a/tools/sched_ext/scx_qmap.bpf.c
+++ b/tools/sched_ext/scx_qmap.bpf.c
@@ -159,13 +159,7 @@ static s32 pick_direct_dispatch_cpu(struct task_struct *p, s32 prev_cpu)
static struct task_ctx *lookup_task_ctx(struct task_struct *p)
{
- struct task_ctx *tctx;
-
- if (!(tctx = bpf_task_storage_get(&task_ctx_stor, p, 0, 0))) {
- scx_bpf_error("task_ctx lookup failed");
- return NULL;
- }
- return tctx;
+ return bpf_task_storage_get(&task_ctx_stor, p, 0, 0);
}
s32 BPF_STRUCT_OPS(qmap_select_cpu, struct task_struct *p,
@@ -540,13 +534,9 @@ void BPF_STRUCT_OPS(qmap_dispatch, s32 cpu, struct task_struct *prev)
*/
if (prev) {
tctx = bpf_task_storage_get(&task_ctx_stor, prev, 0, 0);
- if (!tctx) {
- scx_bpf_error("task_ctx lookup failed");
- return;
- }
-
- tctx->core_sched_seq =
- core_sched_tail_seqs[weight_to_idx(prev->scx.weight)]++;
+ if (tctx)
+ tctx->core_sched_seq =
+ core_sched_tail_seqs[weight_to_idx(prev->scx.weight)]++;
}
}
@@ -584,10 +574,8 @@ static s64 task_qdist(struct task_struct *p)
s64 qdist;
tctx = bpf_task_storage_get(&task_ctx_stor, p, 0, 0);
- if (!tctx) {
- scx_bpf_error("task_ctx lookup failed");
+ if (!tctx)
return 0;
- }
qdist = tctx->core_sched_seq - core_sched_head_seqs[idx];
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH sched_ext/for-7.1-fixes] tools/sched_ext: scx_qmap: Silence task_ctx lookup miss
2026-04-21 6:13 [PATCH sched_ext/for-7.1-fixes] tools/sched_ext: scx_qmap: Silence task_ctx lookup miss Tejun Heo
@ 2026-04-21 6:47 ` Andrea Righi
2026-04-21 7:17 ` [PATCH v2 " Tejun Heo
1 sibling, 0 replies; 5+ messages in thread
From: Andrea Righi @ 2026-04-21 6:47 UTC (permalink / raw)
To: Tejun Heo
Cc: David Vernet, Changwoo Min, sched-ext, Emil Tsalapatis,
linux-kernel
Hi Tejun,
On Mon, Apr 20, 2026 at 08:13:09PM -1000, Tejun Heo wrote:
> scx_fork() dispatches ops.init_task to exactly one scheduler - the one
> owning the forking task's cgroup. A task forked inside a sub-scheduler's
> cgroup is init'd into the sub only; the root scheduler has no task_ctx
> entry for it. When that task later appears as @prev in the root's
> qmap_dispatch() (or flows through core-sched comparison via task_qdist),
> the bpf_task_storage_get() legitimately misses.
>
> qmap treated those misses as fatal via scx_bpf_error("task_ctx lookup
> failed") and aborted the scheduler as soon as the first cross-sched
> task hit the root. Drop the error in the three sites where the miss is
> legitimate: lookup_task_ctx() (helper; callers already check for NULL),
> qmap_dispatch()'s @prev branch (bookkeeping-only), and task_qdist()
> (returns 0 which makes the comparison a no-op). The existing scx_error
> was a paranoid guard from the pre-sub-sched world where every task was
> owned by the one and only scheduler.
>
> Fixes: 4f8b122848db ("sched_ext: Add basic building blocks for nested sub-scheduler dispatching")
> Signed-off-by: Tejun Heo <tj@kernel.org>
Should we return prev_cpu in qmap_select_cpu() instead of -ESRCH when
lookup_task_ctx() returns NULL? Otherwise the scheduler would error.
Apart than that looks good to me.
Reviewed-by: Andrea Righi <arighi@nvidia.com>
Thanks,
-Andrea
> ---
> tools/sched_ext/scx_qmap.bpf.c | 22 +++++-----------------
> 1 file changed, 5 insertions(+), 17 deletions(-)
>
> diff --git a/tools/sched_ext/scx_qmap.bpf.c b/tools/sched_ext/scx_qmap.bpf.c
> index b68abb9e760b..0330ba15210d 100644
> --- a/tools/sched_ext/scx_qmap.bpf.c
> +++ b/tools/sched_ext/scx_qmap.bpf.c
> @@ -159,13 +159,7 @@ static s32 pick_direct_dispatch_cpu(struct task_struct *p, s32 prev_cpu)
>
> static struct task_ctx *lookup_task_ctx(struct task_struct *p)
> {
> - struct task_ctx *tctx;
> -
> - if (!(tctx = bpf_task_storage_get(&task_ctx_stor, p, 0, 0))) {
> - scx_bpf_error("task_ctx lookup failed");
> - return NULL;
> - }
> - return tctx;
> + return bpf_task_storage_get(&task_ctx_stor, p, 0, 0);
> }
>
> s32 BPF_STRUCT_OPS(qmap_select_cpu, struct task_struct *p,
> @@ -540,13 +534,9 @@ void BPF_STRUCT_OPS(qmap_dispatch, s32 cpu, struct task_struct *prev)
> */
> if (prev) {
> tctx = bpf_task_storage_get(&task_ctx_stor, prev, 0, 0);
> - if (!tctx) {
> - scx_bpf_error("task_ctx lookup failed");
> - return;
> - }
> -
> - tctx->core_sched_seq =
> - core_sched_tail_seqs[weight_to_idx(prev->scx.weight)]++;
> + if (tctx)
> + tctx->core_sched_seq =
> + core_sched_tail_seqs[weight_to_idx(prev->scx.weight)]++;
> }
> }
>
> @@ -584,10 +574,8 @@ static s64 task_qdist(struct task_struct *p)
> s64 qdist;
>
> tctx = bpf_task_storage_get(&task_ctx_stor, p, 0, 0);
> - if (!tctx) {
> - scx_bpf_error("task_ctx lookup failed");
> + if (!tctx)
> return 0;
> - }
>
> qdist = tctx->core_sched_seq - core_sched_head_seqs[idx];
>
> --
> 2.53.0
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v2 sched_ext/for-7.1-fixes] tools/sched_ext: scx_qmap: Silence task_ctx lookup miss
2026-04-21 6:13 [PATCH sched_ext/for-7.1-fixes] tools/sched_ext: scx_qmap: Silence task_ctx lookup miss Tejun Heo
2026-04-21 6:47 ` Andrea Righi
@ 2026-04-21 7:17 ` Tejun Heo
2026-04-21 8:40 ` Zhao Mengmeng
2026-04-21 16:39 ` Tejun Heo
1 sibling, 2 replies; 5+ messages in thread
From: Tejun Heo @ 2026-04-21 7:17 UTC (permalink / raw)
To: David Vernet, Andrea Righi, Changwoo Min
Cc: sched-ext, Emil Tsalapatis, linux-kernel
scx_fork() dispatches ops.init_task to exactly one scheduler - the one
owning the forking task's cgroup. A task forked inside a sub-scheduler's
cgroup is init'd into the sub only; the root scheduler has no task_ctx
entry for it. When that task later appears as @prev in the root's
qmap_dispatch() (or flows through core-sched comparison via task_qdist),
the bpf_task_storage_get() legitimately misses.
qmap treated those misses as fatal via scx_bpf_error("task_ctx lookup
failed") and aborted the scheduler as soon as the first cross-sched
task hit the root. Drop the error in the sites where the miss is
legitimate: lookup_task_ctx() (helper; callers already check for NULL),
qmap_dispatch()'s @prev branch (bookkeeping-only), task_qdist()
(returns 0 which makes the comparison a no-op), and qmap_select_cpu()
(returns prev_cpu as a no-op fallback instead of -ESRCH). The existing
scx_error was a paranoid guard from the pre-sub-sched world where every
task was owned by the one and only scheduler.
v2: qmap_select_cpu() returns prev_cpu on NULL instead of -ESRCH, so
the root scheduler doesn't error on cross-sched tasks that pass
through it (Andrea Righi).
Fixes: 4f8b122848db ("sched_ext: Add basic building blocks for nested sub-scheduler dispatching")
Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Andrea Righi <arighi@nvidia.com>
---
tools/sched_ext/scx_qmap.bpf.c | 24 ++++++------------------
1 file changed, 6 insertions(+), 18 deletions(-)
diff --git a/tools/sched_ext/scx_qmap.bpf.c b/tools/sched_ext/scx_qmap.bpf.c
index b68abb9e760b..aad698fe294b 100644
--- a/tools/sched_ext/scx_qmap.bpf.c
+++ b/tools/sched_ext/scx_qmap.bpf.c
@@ -159,13 +159,7 @@ static s32 pick_direct_dispatch_cpu(struct task_struct *p, s32 prev_cpu)
static struct task_ctx *lookup_task_ctx(struct task_struct *p)
{
- struct task_ctx *tctx;
-
- if (!(tctx = bpf_task_storage_get(&task_ctx_stor, p, 0, 0))) {
- scx_bpf_error("task_ctx lookup failed");
- return NULL;
- }
- return tctx;
+ return bpf_task_storage_get(&task_ctx_stor, p, 0, 0);
}
s32 BPF_STRUCT_OPS(qmap_select_cpu, struct task_struct *p,
@@ -175,7 +169,7 @@ s32 BPF_STRUCT_OPS(qmap_select_cpu, struct task_struct *p,
s32 cpu;
if (!(tctx = lookup_task_ctx(p)))
- return -ESRCH;
+ return prev_cpu;
if (p->scx.weight < 2 && !(p->flags & PF_KTHREAD))
return prev_cpu;
@@ -540,13 +534,9 @@ void BPF_STRUCT_OPS(qmap_dispatch, s32 cpu, struct task_struct *prev)
*/
if (prev) {
tctx = bpf_task_storage_get(&task_ctx_stor, prev, 0, 0);
- if (!tctx) {
- scx_bpf_error("task_ctx lookup failed");
- return;
- }
-
- tctx->core_sched_seq =
- core_sched_tail_seqs[weight_to_idx(prev->scx.weight)]++;
+ if (tctx)
+ tctx->core_sched_seq =
+ core_sched_tail_seqs[weight_to_idx(prev->scx.weight)]++;
}
}
@@ -584,10 +574,8 @@ static s64 task_qdist(struct task_struct *p)
s64 qdist;
tctx = bpf_task_storage_get(&task_ctx_stor, p, 0, 0);
- if (!tctx) {
- scx_bpf_error("task_ctx lookup failed");
+ if (!tctx)
return 0;
- }
qdist = tctx->core_sched_seq - core_sched_head_seqs[idx];
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v2 sched_ext/for-7.1-fixes] tools/sched_ext: scx_qmap: Silence task_ctx lookup miss
2026-04-21 7:17 ` [PATCH v2 " Tejun Heo
@ 2026-04-21 8:40 ` Zhao Mengmeng
2026-04-21 16:39 ` Tejun Heo
1 sibling, 0 replies; 5+ messages in thread
From: Zhao Mengmeng @ 2026-04-21 8:40 UTC (permalink / raw)
To: Tejun Heo
Cc: David Vernet, Andrea Righi, Changwoo Min, sched-ext,
Emil Tsalapatis, linux-kernel
On Mon, 20 Apr 2026 21:17:11 -1000, Tejun Heo <tj@kernel.org> wrote:
> diff --git a/tools/sched_ext/scx_qmap.bpf.c b/tools/sched_ext/scx_qmap.bpf.c
> index b68abb9e760b..aad698fe294b 100644
> --- a/tools/sched_ext/scx_qmap.bpf.c
> +++ b/tools/sched_ext/scx_qmap.bpf.c
> @@ -584,10 +574,8 @@ static s64 task_qdist(struct task_struct *p)
> s64 qdist;
>
> tctx = bpf_task_storage_get(&task_ctx_stor, p, 0, 0);
> - if (!tctx) {
> - scx_bpf_error("task_ctx lookup failed");
> + if (!tctx)
> return 0;
> - }
>
> qdist = tctx->core_sched_seq - core_sched_head_seqs[idx];
>
Hi Tejun,
I met this error also on the lastest for-next branch, trying to prepare a
fix and find your patch. Looks good to me.
Reviewed-by: Zhao Mengmeng <zhaomengmeng@kylinos.cn>
--
Zhao Mengmeng <zhaomengmeng@kylinos.cn>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH v2 sched_ext/for-7.1-fixes] tools/sched_ext: scx_qmap: Silence task_ctx lookup miss
2026-04-21 7:17 ` [PATCH v2 " Tejun Heo
2026-04-21 8:40 ` Zhao Mengmeng
@ 2026-04-21 16:39 ` Tejun Heo
1 sibling, 0 replies; 5+ messages in thread
From: Tejun Heo @ 2026-04-21 16:39 UTC (permalink / raw)
To: David Vernet, Andrea Righi, Changwoo Min
Cc: sched-ext, Emil Tsalapatis, linux-kernel, Zhao Mengmeng
Hello,
Applied to sched_ext/for-7.1-fixes with Zhao's Reviewed-by added.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-04-21 16:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-21 6:13 [PATCH sched_ext/for-7.1-fixes] tools/sched_ext: scx_qmap: Silence task_ctx lookup miss Tejun Heo
2026-04-21 6:47 ` Andrea Righi
2026-04-21 7:17 ` [PATCH v2 " Tejun Heo
2026-04-21 8:40 ` Zhao Mengmeng
2026-04-21 16:39 ` Tejun Heo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox