public inbox for dwarves@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v1 0/6] bpf: implicit bpf_prog_aux argument for kfuncs
@ 2025-09-24 21:17 Ihor Solodrai
  2025-09-24 21:17 ` [PATCH bpf-next v1 1/6] bpf: implement KF_IMPLICIT_PROG_AUX_ARG flag Ihor Solodrai
                   ` (5 more replies)
  0 siblings, 6 replies; 23+ messages in thread
From: Ihor Solodrai @ 2025-09-24 21:17 UTC (permalink / raw)
  To: bpf, andrii, ast; +Cc: dwarves, alan.maguire, acme, eddyz87, tj, kernel-team

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


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

end of thread, other threads:[~2025-09-26 15:11 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-24 21:17 [PATCH bpf-next v1 0/6] bpf: implicit bpf_prog_aux argument for kfuncs Ihor Solodrai
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

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