Skip to content

Commit 8bac72d

Browse files
theihorKernel Patches Daemon
authored andcommitted
bpf,docs: Add documentation for KF_IMPLICIT_PROG_AUX_ARG
Add a section explaining KF_IMPLICIT_PROG_AUX_ARG kfunc flag. Mark __prog annotation as deprecated. Signed-off-by: Ihor Solodrai <[email protected]>
1 parent 498f6e4 commit 8bac72d

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

Documentation/bpf/kfuncs.rst

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ Or::
160160
...
161161
}
162162

163-
2.2.6 __prog Annotation
163+
2.2.6 __prog Annotation (deprecated, use KF_IMPLICIT_PROG_AUX_ARG instead)
164164
---------------------------
165165
This annotation is used to indicate that the argument needs to be fixed up to
166166
the bpf_prog_aux of the caller BPF program. Any value passed into this argument
@@ -374,6 +374,43 @@ encouraged to make their use-cases known as early as possible, and participate
374374
in upstream discussions regarding whether to keep, change, deprecate, or remove
375375
those kfuncs if and when such discussions occur.
376376

377+
2.4.10 KF_IMPLICIT_PROG_AUX_ARG flag
378+
------------------------------------
379+
380+
The KF_IMPLICIT_PROG_AUX_ARG flag is used to indicate that the last
381+
argument of a BPF kfunc is a pointer to struct bpf_prog_aux of the
382+
caller BPF program, implicitly set by the verifier.
383+
384+
If a kfunc is marked with this flag, the function declaration in the
385+
kernel must have ``struct bpf_prog_aux *`` as the last argument.
386+
However in the kernel BTF (produced by pahole) this argument will be
387+
omitted, making it invisible to BPF programs calling the kfunc.
388+
389+
Note that the implicit argument is an actual BPF argument passed
390+
through a register, reducing the number of the available function
391+
arguments.
392+
393+
Example declaration:
394+
395+
.. code-block:: c
396+
397+
__bpf_kfunc int bpf_task_work_schedule_resume(struct task_struct *task, struct bpf_task_work *tw,
398+
void *map__map, bpf_task_work_callback_t callback,
399+
struct bpf_prog_aux *aux)
400+
{
401+
return bpf_task_work_schedule(task, tw, map__map, callback, aux, TWA_RESUME);
402+
}
403+
404+
BTF_ID_FLAGS(func, bpf_task_work_schedule_resume, KF_TRUSTED_ARGS | KF_IMPLICIT_PROG_AUX_ARG)
405+
406+
Example usage:
407+
408+
.. code-block:: c
409+
410+
/* note the last argument is ommitted */
411+
bpf_task_work_schedule_resume(task, &tw, &hmap, process_work);
412+
413+
377414
2.5 Registering the kfuncs
378415
--------------------------
379416

0 commit comments

Comments
 (0)