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


Reply via email to