]> www.infradead.org Git - users/jedix/linux-maple.git/commit
selftests/bpf: Introduce experimental bpf_in_interrupt()
authorLeon Hwang <leon.hwang@linux.dev>
Wed, 3 Sep 2025 14:04:37 +0000 (22:04 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 4 Sep 2025 16:05:58 +0000 (09:05 -0700)
commit4b69e31329b6ef22dc80b45d4a865f57c2346d44
tree516c35ec9a9c6513a74ddc2ef6f1726f8dbcfa51
parent929adf8838f7765f0bd57235f0e6f365ff628a0d
selftests/bpf: Introduce experimental bpf_in_interrupt()

Filtering pid_tgid is meanlingless when the current task is preempted by
an interrupt.

To address this, introduce 'bpf_in_interrupt()' helper function, which
allows BPF programs to determine whether they are executing in interrupt
context.

'get_preempt_count()':

* On x86, '*(int *) bpf_this_cpu_ptr(&__preempt_count)'.
* On arm64, 'bpf_get_current_task_btf()->thread_info.preempt.count'.

Then 'bpf_in_interrupt()' will be:

* If !PREEMPT_RT, 'get_preempt_count() & (NMI_MASK | HARDIRQ_MASK
  | SOFTIRQ_MASK)'.
* If PREEMPT_RT, '(get_preempt_count() & (NMI_MASK | HARDIRQ_MASK))
  | (bpf_get_current_task_btf()->softirq_disable_cnt & SOFTIRQ_MASK)'.

As for other archs, it can be added support by updating
'get_preempt_count()'.

Suggested-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
Link: https://lore.kernel.org/r/20250903140438.59517-2-leon.hwang@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/testing/selftests/bpf/bpf_experimental.h