From: Tao Cui <cui.tao@linux.dev>
To: Tejun Heo <tj@kernel.org>
Cc: David Vernet <void@manifault.com>,
Andrea Righi <arighi@nvidia.com>,
Changwoo Min <changwoo@igalia.com>,
sched-ext@lists.linux.dev, cui.tao@linux.dev,
Tao Cui <cuitao@kylinos.cn>
Subject: [PATCH 3/5] selftests/sched_ext: Fail loudly when EXIT_KIND is missing from BTF
Date: Fri, 9 Oct 2026 21:41:02 +0800 [thread overview]
Message-ID: <20261009134104.296891-4-cui.tao@linux.dev> (raw)
In-Reply-To: <20261009134104.296891-1-cui.tao@linux.dev>
From: Tao Cui <cuitao@kylinos.cn>
EXIT_KIND() resolves scx_exit_kind values through
__COMPAT_ENUM_OR_ZERO(), which maps a missing enum to 0. 0 is
SCX_EXIT_NONE, so on kernels whose BTF lacks the enum every
EXIT_KIND() comparison is meaningless.
Resolve the value with __COMPAT_read_enum() and fail the running test
when it is missing, matching SCX_ECODE_VAL() and SCX_KIND_VAL(). The
kick and nohz_tick polling helpers switch to UEI_EXITED() so they
keep their semantics without a BTF lookup.
Signed-off-by: Tao Cui <cuitao@kylinos.cn>
---
tools/testing/selftests/sched_ext/kick.c | 8 +++++---
tools/testing/selftests/sched_ext/nohz_tick.c | 6 +++---
tools/testing/selftests/sched_ext/scx_test.h | 17 ++++++++++++++++-
3 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/tools/testing/selftests/sched_ext/kick.c b/tools/testing/selftests/sched_ext/kick.c
index 7f01602c75b2..591c250d475d 100644
--- a/tools/testing/selftests/sched_ext/kick.c
+++ b/tools/testing/selftests/sched_ext/kick.c
@@ -97,7 +97,7 @@ static bool wait_for_state(struct kick *skel, u32 wanted)
for (i = 0; i < WAIT_LOOPS; i++) {
if (__atomic_load_n(&skel->bss->state, __ATOMIC_ACQUIRE) == wanted)
return true;
- if (skel->data->uei.kind != EXIT_KIND(SCX_EXIT_NONE))
+ if (UEI_EXITED(skel, uei))
return false;
usleep(1000);
}
@@ -111,7 +111,7 @@ static bool wait_for_counter(struct kick *skel, const u64 *counter, u64 wanted)
for (i = 0; i < WAIT_LOOPS; i++) {
if (__atomic_load_n(counter, __ATOMIC_ACQUIRE) >= wanted)
return true;
- if (skel->data->uei.kind != EXIT_KIND(SCX_EXIT_NONE))
+ if (UEI_EXITED(skel, uei))
return false;
usleep(1000);
}
@@ -421,6 +421,7 @@ static enum scx_test_status invalid_one(struct kick_ctx *ctx, u32 scenario)
enum scx_test_status ret = SCX_TEST_FAIL;
int cpu = ctx->target_cpu;
int i;
+ u64 error_kind;
victim = scx_test_spawn_gated_worker(cpu, false);
if (victim.pid < 0)
@@ -435,12 +436,13 @@ static enum scx_test_status invalid_one(struct kick_ctx *ctx, u32 scenario)
bpf_program__set_autoload(skel->progs.kick_wait_callback, false);
if (kick__load(skel))
goto out;
+ error_kind = EXIT_KIND(SCX_EXIT_ERROR);
ops_link = bpf_map__attach_struct_ops(skel->maps.kick_ops);
if (!ops_link || !scx_test_start_gated_worker(&victim))
goto out;
for (i = 0; i < WAIT_LOOPS; i++) {
- if (skel->data->uei.kind == EXIT_KIND(SCX_EXIT_ERROR)) {
+ if (UEI_EXITED(skel, uei) == error_kind) {
ret = SCX_TEST_PASS;
break;
}
diff --git a/tools/testing/selftests/sched_ext/nohz_tick.c b/tools/testing/selftests/sched_ext/nohz_tick.c
index df40976b9166..e19a97034b7f 100644
--- a/tools/testing/selftests/sched_ext/nohz_tick.c
+++ b/tools/testing/selftests/sched_ext/nohz_tick.c
@@ -165,7 +165,7 @@ static bool wait_for_counter(struct nohz_tick *skel, const u64 *counter, u64 val
for (elapsed = 0; elapsed < timeout_ms; elapsed++) {
if (__atomic_load_n(counter, __ATOMIC_RELAXED) >= value)
return true;
- if (skel->data->uei.kind != EXIT_KIND(SCX_EXIT_NONE))
+ if (UEI_EXITED(skel, uei))
return false;
usleep(1000);
}
@@ -182,7 +182,7 @@ static bool wait_for_tick_stop(struct nohz_tick *skel, const u64 *counter, int t
u64 curr;
usleep(1000);
- if (skel->data->uei.kind != EXIT_KIND(SCX_EXIT_NONE))
+ if (UEI_EXITED(skel, uei))
return false;
curr = __atomic_load_n(counter, __ATOMIC_RELAXED);
if (curr == prev) {
@@ -461,7 +461,7 @@ static enum scx_test_status run(void *ctx_ptr)
scx_test_stop_gated_worker(&challenger);
check_exit:
- if (skel->data->uei.kind != EXIT_KIND(SCX_EXIT_NONE)) {
+ if (UEI_EXITED(skel, uei)) {
SCX_ERR("Scheduler exited unexpectedly (kind=%llu code=%lld)",
(unsigned long long)skel->data->uei.kind,
(long long)skel->data->uei.exit_code);
diff --git a/tools/testing/selftests/sched_ext/scx_test.h b/tools/testing/selftests/sched_ext/scx_test.h
index 90b8d6915bb7..fe0e6dabe7a4 100644
--- a/tools/testing/selftests/sched_ext/scx_test.h
+++ b/tools/testing/selftests/sched_ext/scx_test.h
@@ -9,6 +9,7 @@
#define __SCX_TEST_H__
#include <errno.h>
+#include <unistd.h>
#include <scx/common.h>
#include <scx/compat.h>
@@ -18,7 +19,21 @@ enum scx_test_status {
SCX_TEST_FAIL,
};
-#define EXIT_KIND(__ent) __COMPAT_ENUM_OR_ZERO("scx_exit_kind", #__ent)
+/*
+ * EXIT_KIND - Resolve an scx_exit_kind enum value from kernel BTF.
+ *
+ * __COMPAT_ENUM_OR_ZERO() silently maps a missing enum to 0, which for
+ * exit kinds is indistinguishable from SCX_EXIT_NONE and would make
+ * every EXIT_KIND() comparison pass vacuously. Fail the test loudly
+ * instead, mirroring SCX_ECODE_VAL() and SCX_KIND_VAL() below.
+ */
+#define EXIT_KIND(__ent) ({ \
+ u64 __val = 0; \
+ \
+ if (!__COMPAT_read_enum("scx_exit_kind", #__ent, &__val)) \
+ SCX_FAIL("scx_exit_kind.%s not found in kernel BTF", #__ent); \
+ __val; \
+})
struct scx_test {
/**
--
2.53.0
next prev parent reply other threads:[~2026-10-09 13:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 13:40 [PATCH 0/5] sched_ext: selftest infrastructure fixes Tao Cui
2026-10-09 13:41 ` [PATCH 1/5] selftests/sched_ext: Fix reload_loop error-path use-after-free Tao Cui
2026-10-09 13:41 ` [PATCH 2/5] sched_ext: Add SCX_ECODE_RSN_CGROUP_OFFLINE to user_exit_info.h Tao Cui
2026-10-09 13:41 ` Tao Cui [this message]
2026-10-09 13:54 ` [PATCH 3/5] selftests/sched_ext: Fail loudly when EXIT_KIND is missing from BTF sashiko-bot
2026-10-09 13:41 ` [PATCH 4/5] selftests/sched_ext: Add SCX_ASSERT_ALIVE and adopt it Tao Cui
2026-10-09 13:41 ` [PATCH 5/5] selftests/sched_ext: Bound exit waits and report reload_loop failures Tao Cui
2026-10-09 13:48 ` sashiko-bot
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=20261009134104.296891-4-cui.tao@linux.dev \
--to=cui.tao@linux.dev \
--cc=arighi@nvidia.com \
--cc=changwoo@igalia.com \
--cc=cuitao@kylinos.cn \
--cc=sched-ext@lists.linux.dev \
--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