From: zhidao su <soolaugust@gmail.com>
To: sched-ext@lists.linux.dev
Cc: linux-kernel@vger.kernel.org, tj@kernel.org, void@manifault.com,
arighi@nvidia.com, changwoo@igalia.com, peterz@infradead.org,
mingo@redhat.com, zhidao su <suzhidao@xiaomi.com>
Subject: [PATCH 2/4] selftests/sched_ext: enq_immed: fix IMMED reenqueue livelock
Date: Fri, 27 Mar 2026 04:42:36 +0800 [thread overview]
Message-ID: <20260326204238.3755737-3-suzhidao@xiaomi.com> (raw)
In-Reply-To: <20260326204238.3755737-1-suzhidao@xiaomi.com>
When the IMMED slow path fires, ops.enqueue() is called with SCX_ENQ_REENQ
and SCX_TASK_REENQ_IMMED set. The original code fell through to the
normal enqueue path, which re-inserted the task into SCX_DSQ_LOCAL_ON|0
(CPU 0's local DSQ) with SCX_ENQ_IMMED still present.
This immediately re-triggered the slow path, which called ops.enqueue()
again, creating an infinite cycle. After SCX_REENQ_LOCAL_MAX_REPEAT (256)
iterations the kernel aborts with BUG_ON.
Additionally, the dispatch handler consumed from SCX_DSQ_GLOBAL even
though no tasks were ever placed there, so it was a no-op.
Fix by redirecting reenqueued tasks to SCX_DSQ_GLOBAL so they escape
the CPU 0 local DSQ orbit, breaking the cycle. Remove the now-pointless
scx_bpf_dsq_move_to_local(SCX_DSQ_GLOBAL) call from dispatch.
Fixes: c50dcf533149 ("selftests/sched_ext: Add tests for SCX_ENQ_IMMED and scx_bpf_dsq_reenq()")
Signed-off-by: zhidao su <suzhidao@xiaomi.com>
---
tools/testing/selftests/sched_ext/enq_immed.bpf.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/sched_ext/enq_immed.bpf.c b/tools/testing/selftests/sched_ext/enq_immed.bpf.c
index 805dd0256218..a006f07334ef 100644
--- a/tools/testing/selftests/sched_ext/enq_immed.bpf.c
+++ b/tools/testing/selftests/sched_ext/enq_immed.bpf.c
@@ -35,6 +35,15 @@ void BPF_STRUCT_OPS(enq_immed_enqueue, struct task_struct *p, u64 enq_flags)
if (reason == SCX_TASK_REENQ_IMMED)
__sync_fetch_and_add(&nr_immed_reenq, 1);
+
+ /*
+ * The slow path re-enqueues IMMED tasks that couldn't run
+ * immediately. Avoid re-pinning them to CPU 0's local DSQ,
+ * which would trigger another slow-path cycle (livelock).
+ * Send them to the global DSQ instead.
+ */
+ scx_bpf_dsq_insert(p, SCX_DSQ_GLOBAL, SCX_SLICE_DFL, enq_flags);
+ return;
}
if (p->tgid == (pid_t)test_tgid)
@@ -47,7 +56,6 @@ void BPF_STRUCT_OPS(enq_immed_enqueue, struct task_struct *p, u64 enq_flags)
void BPF_STRUCT_OPS(enq_immed_dispatch, s32 cpu, struct task_struct *prev)
{
- scx_bpf_dsq_move_to_local(SCX_DSQ_GLOBAL, 0);
}
void BPF_STRUCT_OPS(enq_immed_exit, struct scx_exit_info *ei)
--
2.43.0
next prev parent reply other threads:[~2026-03-26 20:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-26 20:42 [PATCH 0/4] sched_ext: fix three unreliable selftests and compat kfunc signature zhidao su
2026-03-26 20:42 ` [PATCH 1/4] tools/sched_ext: compat.bpf.h: fix scx_bpf_dsq_reenq___compat signature zhidao su
2026-03-27 0:42 ` Tejun Heo
2026-03-26 20:42 ` zhidao su [this message]
2026-03-26 20:42 ` [PATCH 3/4] selftests/sched_ext: dsq_reenq: fix reliability with two-DSQ design zhidao su
2026-03-26 20:42 ` [PATCH 4/4] selftests/sched_ext: consume_immed: fix reliability with CPU affinity zhidao su
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=20260326204238.3755737-3-suzhidao@xiaomi.com \
--to=soolaugust@gmail.com \
--cc=arighi@nvidia.com \
--cc=changwoo@igalia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=sched-ext@lists.linux.dev \
--cc=suzhidao@xiaomi.com \
--cc=tj@kernel.org \
--cc=void@manifault.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
all inboxes | Powered by JetHome®