160160 ...
161161 }
162162
163- 2.2.6 __prog Annotation
163+ 2.2.6 __prog Annotation (deprecated, use __magic instead)
164164---------------------------
165165This annotation is used to indicate that the argument needs to be fixed up to
166166the 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
1822132.3 Using an existing kernel function
@@ -374,6 +405,22 @@ encouraged to make their use-cases known as early as possible, and participate
374405in upstream discussions regarding whether to keep, change, deprecate, or remove
375406those 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+
3774242.5 Registering the kfuncs
378425--------------------------
379426
0 commit comments