Skip to content

Commit 7c021ed

Browse files
theihorKernel Patches Daemon
authored andcommitted
bpf,docs: Document KF_MAGIC_ARGS flag and __magic annotation
Add sections explaining KF_MAGIC_ARGS kfunc flag and __magic argument annotation. Mark __prog annotation as deprecated. Signed-off-by: Ihor Solodrai <[email protected]>
1 parent 1377641 commit 7c021ed

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

Documentation/bpf/kfuncs.rst

Lines changed: 48 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 __magic 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
@@ -177,6 +177,37 @@ An example is given below::
177177
...
178178
}
179179

180+
.. _magic_annotation:
181+
182+
2.2.7 __magic Annotation
183+
---------------------------
184+
This annotation is used in kfuncs with KF_MAGIC_ARGS flag to indicate the
185+
arguments that are omitted in the BPF signature of the kfunc. The actual
186+
values for __magic arguments are set by the verifier at load time, and
187+
depend on the argument type.
188+
189+
Currently only ``struct bpf_prog_aux *`` type is supported.
190+
191+
Example declaration:
192+
193+
.. code-block:: c
194+
195+
__bpf_kfunc int bpf_wq_set_callback(struct bpf_wq *wq,
196+
int (callback_fn)(void *map, int *key, void *value),
197+
unsigned int flags,
198+
struct bpf_prog_aux *aux__magic)
199+
{
200+
...
201+
}
202+
203+
Example usage:
204+
205+
.. code-block:: c
206+
207+
/* note the last argument is omitted */
208+
if (bpf_wq_set_callback(wq, callback_fn, 0))
209+
return -1;
210+
180211
.. _BPF_kfunc_nodef:
181212

182213
2.3 Using an existing kernel function
@@ -374,6 +405,22 @@ encouraged to make their use-cases known as early as possible, and participate
374405
in upstream discussions regarding whether to keep, change, deprecate, or remove
375406
those kfuncs if and when such discussions occur.
376407

408+
2.4.10 KF_MAGIC_ARGS flag
409+
------------------------------------
410+
411+
The KF_MAGIC_ARGS flag is used to indicate that the BPF signature of the kfunc
412+
is different from it's kernel signature, and the values for arguments annotated
413+
with __magic suffix are provided at load time by the verifier.
414+
415+
A kfunc with KF_MAGIC_ARGS flag therefore has two types in BTF: one function
416+
matching the kernel declaration (with _impl suffix by convention), and another
417+
matching the intended BPF API.
418+
419+
Verifier allows calls to both _impl and non-_impl versions of a magic kfunc.
420+
421+
Note that only arguments of particular types can be __magic.
422+
See :ref:`magic_annotation`.
423+
377424
2.5 Registering the kfuncs
378425
--------------------------
379426

0 commit comments

Comments
 (0)