sched_ext selftest enable_cmask fails to load on 7.4-rc2: verifier rejects arena pointer cast from scx_enable_args.cmask_arena_addr
Subsystems (3)
From: Zhijian Han <[email protected]>
Hello,
The enable_cmask selftest (tools/testing/selftests/sched_ext/, added in the recent merge window via d781d1b78acf "selftests/sched_ext: Check the cmask cid-form ops.enable() receives") fails to load on v7.4-rc2 and linux-next-20261105. The BPF program enable_cmask_enable is rejected by the verifier at load time:
libbpf: prog 'enable_cmask_enable': BPF program load failed: -EACCES 94: (61) r1 = *(u32 *)(r8 +0)
R8 invalid mem access 'scalar'
Verification failed: Register Type Safety: Invalid dereference
The test follows the usage documented in kernel/sched/ext/internal.h:
struct scx_enable_args {
u64 cmask_arena_addr;
}; /*
* ... The address is a plain value rather than a typed pointer ...
* Cast it to struct scx_cmask __arena * before use.
*/
i.e. enable_cmask.bpf.c:101:
struct scx_cmask __arena *m =
(struct scx_cmask __arena *)args->cmask_arena_addr;The C cast does not emit an addr_space_cast insn: in the generated bytecode the member load (insn 1: r7 = *(u64 *)(r2 + 0)) produces R7=scalar(), which stays scalar across the cast and the inlined check_mask() prologue, so the first dereference m->base (insn 94) is rejected.
The same selftest was verified by Tejun on the for-7.3-fixes branch (per the v3 cover letter, 20260919002838.1960071-1-tj, 16-CPU VM, three standalone runs plus the full suite); the verifier-side arena handling that changed during the 7.4 merge window appears to no longer accept this pattern. The struct_ops argument path (direct __arena args, e.g. ops.set_cmask) still works — only the u64-carried address form is affected.
Reproducer (deterministic, two consecutive runs identical):
# kernel: defconfig + SCHED_CLASS_EXT, DEBUG_INFO_BTF, FUNCTION_TRACER
make O=build -j$(nproc)
cd tools/testing/selftests/sched_ext
make LLVM=1 O=$PWD/../../../../../build OUTPUT=out/ TEST_GEN_MODS_DIR=
# initrd with out/runner + out/build + libs + busybox + kernel .config
# at /boot/config-$(uname -r); then:
qemu-system-x86_64 -enable-kvm -smp 4 -m 2G -nographic \
-kernel build/arch/x86/boot/bzImage -initrd initrd.cpio.gz \
-append "console=ttyS0" /root # ./runner -t enable_cmask
not ok 1 enable_cmask #
Tested on:
v7.4-rc2 (7475ea8b5): FAIL (verifier rejects at load) next-20261105 (gddfe51b0a0f5): FAIL (same rejection) v7.3: SKIP (struct scx_enable_args not present)
Compiler versions tried: clang 18 and clang 19 — identical bytecode around the failing insn, identical rejection, so this does not look compiler-dependent.
The other 40 tests in the suite pass on both 7.4-rc2 and next (after enabling CONFIG_FUNCTION_TRACER, without which the fentry-based tests maximal/kick_immediate/reload_loop fail with -EBUSY — worth a note in the selftest docs, but that part is config, not a bug).
Possible directions (not investigated in depth):
- a kfunc or verifier-supported way to convert the u64 carried in scx_enable_args into a PTR_TO_ARENA,
- or an __arena-typed member/alias in scx_enable_args once BTF can express arena pointer members (the internal.h comment already anticipates this),
- or adjusting the test to obtain the cmask through a path the verifier accepts.
Full verifier log and QEMU boot log available on request.
Tejun Heo
reviewerPATCH 1/1 selftests/sched_ext: Fix enable_cmask load failure on older clangs
enable_cmask casts the u64 arena address of the task's cmask to an __arena pointer without cast_kern(). Older clangs without __BPF_FEATURE_ADDR_SPACE_CAST need the explicit cast, so the test fails to load there. Add it.
---
Applied to sched_ext/for-7.5.
tools/testing/selftests/sched_ext/enable_cmask.bpf.c | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/sched_ext/enable_cmask.bpf.c +1 -0
@@ -104,6 +104,7 @@ void BPF_STRUCT_OPS(enable_cmask_enable, struct task_struct *p, struct scx_enablint ret; asmvolatile ("" ::"r" (&arena)); +cast_kern (m); tctx =lookup_task_ctx (p);if (!tctx)return ;
Signature · 1 line
2.56.0
[email protected]
AI reviewRe: [PATCH sched_ext/for-7.5] selftests/sched_ext: Fix enable_cmask load failure on older clangs
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] selftests/sched_ext: missing Fixes: trailer for enable_cmask_enable() fix --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] selftests/sched_ext: missing Fixes: trailer for enable_cmask_enable() fix
--
commit 948cafa51d1e3328d46bf77feab57f93ed6e21e0
Author: Tejun Heo <[email protected]>
Quoted 10 lines
selftests/sched_ext: Fix
enable_cmaskload failure on older clangs
enable_cmaskcasts the u64 arena address of the task's cmask to an__arenapointer withoutcast_kern(). Older clangs without__BPF_FEATURE_ADDR_SPACE_CASTneed the explicit cast, so the test fails to load there. Add it.Reported-by Zhijian Han <[email protected]>Signed-off-by Tejun Heo <[email protected]>
[Severity: Low]
Should this commit include a Fixes: tag for the commit that added the test?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1