bpf: implicit bpf_prog_aux argument for kfuncs
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest6 patches 16 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/6 | bpf: implement KF_IMPLICIT_PROG_AUX_ARG flaginclude/ kernel/ | +39 | 9 replies | |
| 2/6 | bpf,docs: Add documentation for KF_IMPLICIT_PROG_AUX_ARGDocumentation/ | +38 | 0 replies | |
| 3/6 | selftests/bpf: update bpf_wq_set_callback macrotools/ | +6 | 3 replies | |
| 4/6 | bpf: implement bpf_wq_set_callback kfunc with implicit prog_auxkernel/ kernel/ tools/ | +24 | 0 replies | |
| 5/6 | bpf: mark bpf_stream_vprink kfunc with KF_IMPLICIT_PROG_AUX_ARGkernel/ kernel/ tools/ +1 more | +7 | 3 replies | |
| 6/6 | bpf: mark bpf_task_work_* kfuncs with KF_IMPLICIT_PROG_AUX_ARGkernel/ tools/ tools/ +1 more | +16 | 1 reply |
Reviews trailers per patch
1 of 6 patches has a Reviewed-by or Acked-by.
| Patch | Mykyta Yatsenko |
|---|---|
| 1/6 | |
| 2/6 | |
| 3/6 | |
| 4/6 | |
| 5/6 | |
| 6/6 | A-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH bpf-next v1 0/6] bpf: implicit bpf_prog_aux argument for kfuncs
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/[email protected]/
[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(-)
Signature · 1 line
2.51.0