[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260124132706.183681-1-changwoo@igalia.com>
Date: Sat, 24 Jan 2026 22:27:04 +0900
From: Changwoo Min <changwoo@...lia.com>
To: Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>
Cc: Martin KaFai Lau <martin.lau@...ux.dev>,
Eduard Zingerman <eddyz87@...il.com>,
Song Liu <song@...nel.org>,
Yonghong Song <yonghong.song@...ux.dev>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>,
Stanislav Fomichev <sdf@...ichev.me>,
Hao Luo <haoluo@...gle.com>,
Jiri Olsa <jolsa@...nel.org>,
Shuah Khan <shuah@...nel.org>,
kernel-dev@...lia.com,
bpf@...r.kernel.org,
sched-ext@...ts.linux.dev,
linux-kernel@...r.kernel.org,
linux-kselftest@...r.kernel.org,
Changwoo Min <changwoo@...lia.com>
Subject: [PATCH bpf-next v2 0/2] selftests/bpf: Introduce execution context detection helpers
This series introduces four new BPF-native inline helpers -- bpf_in_nmi(),
bpf_in_hardirq(), bpf_in_serving_softirq(), and bpf_in_task() -- to allow
BPF programs to query the current execution context.
Following the feedback on v1, these are implemented in bpf_experimental.h
as inline helpers wrapping get_preempt_count(). This approach allows the
logic to be JIT-inlined for better performance compared to a kfunc call,
while providing the granular context detection (e.g., hardirq vs. softirq)
required by subsystems like sched_ext.
The series includes a new selftest suite, exe_ctx, which uses bpf_testmod
to verify context detection across Task, HardIRQ, and SoftIRQ boundaries
via irq_work and tasklets. NMI context testing is omitted as NMIs cannot
be triggered deterministically within software-only BPF CI environments.
ChangeLog v1 -> v2:
- Dropped the core kernel kfunc implementations, and implemented context
detection as inline BPF helpers in bpf_experimental.h.
- Renamed the selftest suite from ctx_kfunc to exe_ctx to reflect the
change from kfuncs to helpers.
- Updated BPF programs to use the new inline helpers.
- Swapped clean-up order between tasklet and irqwork in bpf_testmod to
avoid re-scheduling the already-killed tasklet (reported by bot+bpf-ci).
Changwoo Min (2):
selftests/bpf: Introduce execution context detection helpers
selftests/bpf: Add tests for execution context helpers
.../testing/selftests/bpf/bpf_experimental.h | 38 ++++++++++++
.../selftests/bpf/prog_tests/exe_ctx.c | 59 +++++++++++++++++++
tools/testing/selftests/bpf/progs/test_ctx.c | 48 +++++++++++++++
.../selftests/bpf/test_kmods/bpf_testmod.c | 32 ++++++++++
.../bpf/test_kmods/bpf_testmod_kfunc.h | 4 ++
5 files changed, 181 insertions(+)
create mode 100644 tools/testing/selftests/bpf/prog_tests/exe_ctx.c
create mode 100644 tools/testing/selftests/bpf/progs/test_ctx.c
--
2.52.0
Powered by blists - more mailing lists