From: Ihor Solodrai <ihor.solodrai@linux.dev>
To: bpf@vger.kernel.org, andrii@kernel.org, ast@kernel.org
Cc: dwarves@vger.kernel.org, alan.maguire@oracle.com,
acme@kernel.org, eddyz87@gmail.com, tj@kernel.org,
kernel-team@meta.com
Subject: [PATCH bpf-next v1 0/6] bpf: implicit bpf_prog_aux argument for kfuncs
Date: Wed, 24 Sep 2025 14:17:10 -0700 [thread overview]
Message-ID: <20250924211716.1287715-1-ihor.solodrai@linux.dev> (raw)
This series implements KF_IMPLICIT_PROG_AUX_ARG kfunc flag. The flag
indicates that the last argument of a BPF kfunc is a pointer to struct
bpf_prog_aux implicitly set by the verifier.
There is already a mechanism for passing bpf_prog_aux to kfuncs:
__prog kfunc parameter annotation [1]. While it works technically, it
requires explicit declaration of the argument in kfunc prototype in
BPF (for example, in vmlinux.h) and a dummy actual parameter on call
sites. Which then prompts adding macros like the following:
#define bpf_wq_set_callback(timer, cb, flags) \
bpf_wq_set_callback_impl(timer, cb, flags, NULL)
This is cumbersome in light of potentially many more kfuncs requiring
access to bpf_prog_aux data [2].
An alternative approach is implemented in this series in combination
with a change in pahole's BTF encoding [3].
When a kfunc needs access to bpf_prog_aux, it's declaration on the
kernel side must have struct bpf_prog_aux pointer as it's *last*
argument, and the kfunc must have KF_IMPLICIT_PROG_AUX_ARG flag set in
its BTF_ID_FLAGS entry.
When generating BTF pahole recognizes KF_IMPLICIT_PROG_AUX_ARG flag
and does not emit the last argument of the kfunc to BTF.
During BPF patching in the verifier KF_IMPLICIT_PROG_AUX_ARG is
checked for to set the actual pointer, exactly as it happens for
__prog annotation currently.
For backwards compatibility __prog annotation handling is preserved in
the verifier. Existing kfuncs that use __prog annotation are updated
to KF_IMPLICIT_PROG_AUX_ARG in this series.
Successful BPF CI run with modified pahole:
https://github.com/kernel-patches/bpf/actions/runs/17987713438
[1] https://docs.kernel.org/bpf/kfuncs.html#prog-annotation
[2] https://lore.kernel.org/bpf/20250920005931.2753828-42-tj@kernel.org/
[3] https://github.com/theihor/dwarves/tree/prog-aux.v1
Ihor Solodrai (6):
bpf: implement KF_IMPLICIT_PROG_AUX_ARG flag
bpf,docs: Add documentation for KF_IMPLICIT_PROG_AUX_ARG
selftests/bpf: update bpf_wq_set_callback macro
bpf: implement bpf_wq_set_callback kfunc with implicit prog_aux
bpf: mark bpf_stream_vprink kfunc with KF_IMPLICIT_PROG_AUX_ARG
bpf: mark bpf_task_work_* kfuncs with KF_IMPLICIT_PROG_AUX_ARG
Documentation/bpf/kfuncs.rst | 39 ++++++++++++-
include/linux/btf.h | 3 +
kernel/bpf/helpers.c | 36 +++++++-----
kernel/bpf/stream.c | 3 +-
kernel/bpf/verifier.c | 58 ++++++++++++++-----
tools/lib/bpf/bpf_helpers.h | 4 +-
.../testing/selftests/bpf/bpf_experimental.h | 7 ++-
.../testing/selftests/bpf/progs/stream_fail.c | 6 +-
tools/testing/selftests/bpf/progs/task_work.c | 6 +-
.../selftests/bpf/progs/task_work_fail.c | 8 +--
.../selftests/bpf/progs/task_work_stress.c | 2 +-
.../testing/selftests/bpf/progs/wq_failures.c | 4 +-
12 files changed, 130 insertions(+), 46 deletions(-)
--
2.51.0
next reply other threads:[~2025-09-24 21:17 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-24 21:17 Ihor Solodrai [this message]
2025-09-24 21:17 ` [PATCH bpf-next v1 1/6] bpf: implement KF_IMPLICIT_PROG_AUX_ARG flag Ihor Solodrai
2025-09-25 9:49 ` Alexei Starovoitov
2025-09-25 16:13 ` Ihor Solodrai
2025-09-25 17:23 ` Andrii Nakryiko
2025-09-25 19:34 ` Alexei Starovoitov
2025-09-25 22:54 ` Andrii Nakryiko
2025-09-25 22:57 ` Kumar Kartikeya Dwivedi
2025-09-25 23:07 ` Andrii Nakryiko
2025-09-26 12:10 ` Alexei Starovoitov
2025-09-26 15:11 ` Andrii Nakryiko
2025-09-24 21:17 ` [PATCH bpf-next v1 2/6] bpf,docs: Add documentation for KF_IMPLICIT_PROG_AUX_ARG Ihor Solodrai
2025-09-24 21:17 ` [PATCH bpf-next v1 3/6] selftests/bpf: update bpf_wq_set_callback macro Ihor Solodrai
2025-09-25 9:53 ` Alexei Starovoitov
2025-09-25 16:19 ` Ihor Solodrai
2025-09-25 17:24 ` Andrii Nakryiko
2025-09-24 21:17 ` [PATCH bpf-next v1 4/6] bpf: implement bpf_wq_set_callback kfunc with implicit prog_aux Ihor Solodrai
2025-09-24 21:17 ` [PATCH bpf-next v1 5/6] bpf: mark bpf_stream_vprink kfunc with KF_IMPLICIT_PROG_AUX_ARG Ihor Solodrai
2025-09-25 10:01 ` Alexei Starovoitov
2025-09-25 16:32 ` Ihor Solodrai
2025-09-25 17:28 ` Andrii Nakryiko
2025-09-24 21:17 ` [PATCH bpf-next v1 6/6] bpf: mark bpf_task_work_* kfuncs " Ihor Solodrai
2025-09-25 14:05 ` Mykyta Yatsenko
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=20250924211716.1287715-1-ihor.solodrai@linux.dev \
--to=ihor.solodrai@linux.dev \
--cc=acme@kernel.org \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dwarves@vger.kernel.org \
--cc=eddyz87@gmail.com \
--cc=kernel-team@meta.com \
--cc=tj@kernel.org \
/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