From: Changwoo Min <changwoo@igalia.com>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>
Cc: Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>, Shuah Khan <shuah@kernel.org>,
kernel-dev@igalia.com, bpf@vger.kernel.org,
sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org,
Changwoo Min <changwoo@igalia.com>
Subject: [PATCH bpf-next v1 0/2] bpf: Introduce execution context detection kfuncs
Date: Fri, 23 Jan 2026 17:42:46 +0900 [thread overview]
Message-ID: <20260123084248.259278-1-changwoo@igalia.com> (raw)
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
next reply other threads:[~2026-01-23 8:43 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-23 8:42 Changwoo Min [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260123084248.259278-1-changwoo@igalia.com \
--to=changwoo@igalia.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kernel-dev@igalia.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=sched-ext@lists.linux.dev \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®