mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH bpf-next v1 0/2] bpf: Introduce execution context detection kfuncs
@ 2026-01-23  8:42 Changwoo Min
  2026-01-23  8:42 ` [PATCH bpf-next v1 1/2] " Changwoo Min
  2026-01-23  8:42 ` [PATCH bpf-next v1 2/2] selftests/bpf: Add tests for execution context kfuncs Changwoo Min
  0 siblings, 2 replies; 6+ messages in thread
From: Changwoo Min @ 2026-01-23  8:42 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 kfuncs -- bpf_in_nmi(), bpf_in_hardirq(), 
bpf_in_serving_softirq(), and bpf_in_task() -- to allow BPF programs to 
query the current execution context.

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 kfuncs provide a reliable way to branch logic based on the 
current CPU execution state.

The series includes a new selftest suite, ctx_kfunc, which uses 
bpf_testmod to verify context detection across Task, HardIRQ, and 
SoftIRQ boundaries via irq_work and tasklets. NMI context testing is 
omitted from the suite as NMIs cannot be triggered deterministically 
within the software-only environments typically used for BPF CI.

Changwoo Min (2):
  bpf: Introduce execution context detection kfuncs
  selftests/bpf: Add tests for execution context kfuncs

 kernel/bpf/helpers.c                          | 44 ++++++++++++++
 .../selftests/bpf/prog_tests/ctx_kfunc.c      | 59 +++++++++++++++++++
 tools/testing/selftests/bpf/progs/test_ctx.c  | 51 ++++++++++++++++
 .../selftests/bpf/test_kmods/bpf_testmod.c    | 32 ++++++++++
 .../bpf/test_kmods/bpf_testmod_kfunc.h        |  4 ++
 5 files changed, 190 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/ctx_kfunc.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_ctx.c

-- 
2.52.0


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

end of thread, other threads:[~2026-01-24 11:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-23  8:42 [PATCH bpf-next v1 0/2] bpf: Introduce execution context detection kfuncs Changwoo Min
2026-01-23  8:42 ` [PATCH bpf-next v1 1/2] " Changwoo Min
2026-01-23 16:37   ` Alexei Starovoitov
2026-01-24 11:29     ` Changwoo Min
2026-01-23  8:42 ` [PATCH bpf-next v1 2/2] selftests/bpf: Add tests for execution context kfuncs Changwoo Min
2026-01-23  9:08   ` bot+bpf-ci

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

all inboxes | Powered by JetHome®