]> git.ipfire.org Git - thirdparty/linux.git/commit
selftests/bpf: Make bpf get_preempt_count() work for v6.14+ kernels
authorChangwoo Min <changwoo@igalia.com>
Fri, 30 Jan 2026 02:18:43 +0000 (11:18 +0900)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 30 Jan 2026 20:20:25 +0000 (12:20 -0800)
commitcd77618c418254b827f2a807b4c27b97088fdb52
tree92cf649933dd1040c55d66bf5b264359661d4597
parentb18a761ca0f6ef7c07b0ae5cee28315a0c5478a8
selftests/bpf: Make bpf get_preempt_count() work for v6.14+ kernels

Recent x86 kernels export __preempt_count as a ksym, while some old kernels
between v6.1 and v6.14 expose the preemption counter via
pcpu_hot.preempt_count. The existing selftest helper unconditionally
dereferenced __preempt_count, which breaks BPF program loading on such old
kernels.

Make the x86 preemption count lookup version-agnostic by:
- Marking __preempt_count and pcpu_hot as weak ksyms.
- Introducing a BTF-described pcpu_hot___local layout with
  preserve_access_index.
- Selecting the appropriate access path at runtime using ksym availability
  and bpf_ksym_exists() and bpf_core_field_exists().

This allows a single BPF binary to run correctly across kernel versions
(e.g., v6.18 vs. v6.13) without relying on compile-time version checks.

Signed-off-by: Changwoo Min <changwoo@igalia.com>
Link: https://lore.kernel.org/r/20260130021843.154885-1-changwoo@igalia.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/bpf_experimental.h