Re: [PATCH v2 2/2] tools/sched_ext: scx_sdt: Fix BPF verifier rejection on older LLVMs
From: Alexei Starovoitov
Date: Mon Mar 09 2026 - 12:47:15 EST
On Mon, Mar 9, 2026 at 9:40 AM Emil Tsalapatis <emil@xxxxxxxxxxxxxxx> wrote:
>
> On Sun Mar 8, 2026 at 10:28 PM EDT, Zhao Mengmeng wrote:
> > From: Zhao Mengmeng <zhaomengmeng@xxxxxxxxxx>
> >
> > Under Clang 17/18, when running scx_sdt scheduler, it fails with:
> >
> > libbpf: prog 'sdt_init_task': BPF program load failed: -EACCES
> > libbpf: prog 'sdt_init_task': -- BEGIN PROG LOAD LOG --
> > ...
> > ; desc = desc_find_empty(alloc->root, &idx); @ scx_sdt.bpf.c:479
> > 43: (79) r8 = *(u64 *)(r6 +32) ; frame1: R6=map_value(map=scx_sdt.bss,ks=4,vs=200,off=120) R8=scalar()
> > ; for (level = zero; level < SDT_TASK_LEVELS && can_loop; level++) { @ scx_sdt.bpf.c:407
> > 44: (e5) may_goto pc+51
> > ; idx |= pos; @ scx_sdt.bpf.c:418
> > 96: (bf) r7 = r2 ; frame1: R2=0 R7=0
> > 97: (bf) r1 = r10 ; frame1: R1=fp0 R10=fp0
> > ; @ scx_sdt.bpf.c:0
> > 98: (07) r1 += -56 ; frame1: R1=fp-56
> > ; bpf_for(u, 0, SDT_TASK_LEVELS) { @ scx_sdt.bpf.c:447
> > 99: (b4) w2 = 0 ; frame1: R2=0
> > 100: (b4) w3 = 3 ; frame1: R3=3
> > 101: (85) call bpf_iter_num_new#82234 ; frame1: R0=scalar() fp-56=iter_num(ref_id=2,state=active,depth=0)
> > 102: (18) r9 = 0x1ffffffffffffff8 ; frame1: R9=0x1ffffffffffffff8
> > 104: (bf) r1 = r10 ; frame1: R1=fp0 R10=fp0
> > ; @ scx_sdt.bpf.c:0
> > 105: (07) r1 += -56 ; frame1: R1=fp-56
> > ; bpf_for(u, 0, SDT_TASK_LEVELS) { @ scx_sdt.bpf.c:447
> > 106: (85) call bpf_iter_num_next#82235 ; frame1: R0=0 fp-56=iter_num(ref_id=2,state=drained,depth=0)
> > 107: (15) if r0 == 0x0 goto pc+29 ; frame1: R0=0
> > ; if (tmp->nr_free > 0) @ scx_sdt.bpf.c:456
> > 137: (bf) r1 = r10 ; frame1: R1=fp0 R10=fp0
> > ; bpf_for(u, 0, SDT_TASK_LEVELS) { @ scx_sdt.bpf.c:447
> > 138: (07) r1 += -56 ; frame1: R1=fp-56
> > 139: (85) call bpf_iter_num_destroy#82232 ; frame1:
> > 140: (b7) r9 = 0 ; frame1: R9=0
> > ; if (unlikely(desc == NULL)) { @ scx_sdt.bpf.c:480
> > 141: (15) if r8 == 0x0 goto pc+15 ; frame1: R8=scalar(umin=1)
> > ; chunk = desc->chunk; @ scx_sdt.bpf.c:485
> > 142: (79) r4 = *(u64 *)(r8 +72)
> > R8 invalid mem access 'scalar'
> >
> > The reason is these older compilers lacks native support for
> > __BPF_FEATURE_ADDR_SPACE_CAST, __arena macro is defined as empty.
> >
> > Fix it by adding cast_kern when dereferencing variables with __arena tag.
> >
>
> I am not sure if we want to support older Clang versions at this point.
> This issue is fixed for Clang 19, and adding the macros back in makes it
> confusing for those who use the code as a starting point. And while
> it would be nice to support older Clang versions, we already don't
> handle Clang 15/16 that don't have arena support. So it's not
> unreasonable if we say Clang 17/18 are also incompatible with this
> example.
+1
People should upgrade their compilers.