Skip to contentSkip to conversation

tools/sched_ext: Document clang requirement for arena schedulers

PATCH Applied Shaojie Sun 2 participants 2 messages Nov 26

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/sched_ext: Document clang requirement for arena schedulers

Schedulers that use BPF arena (address space 1), such as scx_qmap, only load correctly when built with clang 22 or newer. Older compilers do not insert addr_space_cast around inlined memory intrinsics (llvm.memset(), llvm.memcpy(), ...) on arena pointers, so the verifier may reject the program with "invalid mem access 'scalar'". LLVM fixed this in 22:
"[BPF] Handle certain mem intrinsic functions with addr-space arguments".

Mention the requirement in the toolchain dependency list and add a load failure entry with the characteristic libbpf error, so that users can tell it apart from other load failures.

---
 tools/sched_ext/README.md | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
tools/sched_ext/README.md +29 -0
index 0ee5a3d997e5..10d767f3a7c6 100644
@@ -33,6 +33,9 @@ is actively working on adding a BPF backend compiler as well, but are still
 missing some features such as BTF type tags which are necessary for using
 kptrs.
 
+Schedulers that use BPF arena (address space 1) need clang 22 or newer. See
+the [troubleshooting entry](#bpf-arena-schedulers-require-clang-22).
+
 2. pahole >= 1.25
 
 You may need pahole in order to generate BTF from DWARF.
@@ -246,6 +249,32 @@ In order to resolve this, please follow the steps above in
 [Getting a vmlinux.h file](#getting-a-vmlinuxh-file) in order to ensure your
 schedulers are using a vmlinux.h file that includes the requisite types.
 
+## Load Failures
+
+### BPF arena schedulers require clang 22
+
+Schedulers that use BPF arena (address space 1), such as `scx_qmap`, need
+clang 22 or newer. With older compilers the program may be rejected by the
+verifier, for example:
+
+```
+libbpf: prog 'qmap_dequeue': BPF program load failed: -EACCES
+...
+R7 invalid mem access 'scalar'
+...
+libbpf: failed to load object 'scx_qmap'
+```
+
+The register number varies with the program. Clang older than 22 does not
+insert `addr_space_cast` around inlined memory intrinsics (`llvm.memset()`,
+`llvm.memcpy()`, ...) on arena pointers, so the verifier sees a plain scalar
+being dereferenced. This was fixed in LLVM 22 ("[BPF] Handle certain mem
+intrinsic functions with addr-space arguments"):
+https://github.com/llvm/llvm-project/commit/94f290fffd80bd7c7d65db1df78cdacab633aab4
+
+Rebuild the scheduler with a sufficiently new clang; run `make clean` in this
+directory first if the object files were built with an older compiler.
+
 ## Misc
 
 ### llvm: [OFF]
Signature · 1 line
2.50.1
reviewer Applied
#1 lore raw

Applied to sched_ext/for-7.5.

Thanks.

--
tejun