]> git.ipfire.org Git - thirdparty/linux.git/commit
selftests/bpf: Introduce execution context detection helpers
authorChangwoo Min <changwoo@igalia.com>
Sun, 25 Jan 2026 11:54:12 +0000 (20:54 +0900)
committerAlexei Starovoitov <ast@kernel.org>
Sun, 25 Jan 2026 16:20:50 +0000 (08:20 -0800)
commitc31df36bd26a5ed8898bb3fcc8c37ea9157ba784
tree9fe4b90fa2c15887572aba0283ed00d71d180dcc
parentc390adfda2440e4a907ecedae03ff392511bcf95
selftests/bpf: Introduce execution context detection helpers

Introduce bpf_in_nmi(), bpf_in_hardirq(), bpf_in_serving_softirq(), and
bpf_in_task() inline helpers in bpf_experimental.h. These allow BPF
programs to query the current execution context with higher granularity
than the existing bpf_in_interrupt() helper.

While BPF programs can often infer their context from attachment points,
subsystems like sched_ext may call the same BPF logic from multiple
contexts (e.g., task-to-task wake-ups vs. interrupt-to-task wake-ups).
These helpers provide a reliable way for logic to branch based on
the current CPU execution state.

Implementing these as BPF-native inline helpers wrapping
get_preempt_count() allows the compiler and JIT to inline the logic. The
implementation accounts for differences in preempt_count layout between
standard and PREEMPT_RT kernels.

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