Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH bpf-next v3 0/2] selftests/bpf: Introduce execution context detection helpers
@ 2026-01-25 11:54 Changwoo Min
  2026-01-25 11:54 ` [PATCH bpf-next v3 1/2] " Changwoo Min
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Changwoo Min @ 2026-01-25 11:54 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	Shuah Khan, kernel-dev, bpf, sched-ext, linux-kernel,
	linux-kselftest, Changwoo Min

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 v2 -> v3:
- Added exe_ctx to DENYLIST.s390x since new helpers are supported only
  on x86 and arm64 (patch 2).
- Added comments to helpers describing supported architectures (patch 1).

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

 tools/testing/selftests/bpf/DENYLIST.s390x    |  1 +
 .../testing/selftests/bpf/bpf_experimental.h  | 58 ++++++++++++++++++
 .../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 ++
 6 files changed, 202 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-01-25 16:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-25 11:54 [PATCH bpf-next v3 0/2] selftests/bpf: Introduce execution context detection helpers Changwoo Min
2026-01-25 11:54 ` [PATCH bpf-next v3 1/2] " Changwoo Min
2026-01-25 11:54 ` [PATCH bpf-next v3 2/2] selftests/bpf: Add tests for execution context helpers Changwoo Min
2026-01-25 16:40 ` [PATCH bpf-next v3 0/2] selftests/bpf: Introduce execution context detection helpers patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox