Skip to content

Commit 9805af8

Browse files
kkdwvdAlexei Starovoitov
authored andcommitted
bpf: Document UAPI details for special BPF types
The kernel recognizes some special BPF types in map values or local kptrs. Document that only bpf_spin_lock and bpf_timer will preserve backwards compatibility, and kptr will preserve backwards compatibility for the operations on the pointer, not the types supported for such kptrs. For local kptrs, document that there are no stability guarantees at all. Finally, document that 'bpf_' namespace is reserved for adding future special fields, hence BPF programs must not declare types with such names in their programs and still expect backwards compatibility. Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Acked-by: David Vernet <void@manifault.com> Link: https://lore.kernel.org/r/20221103191013.1236066-2-memxor@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 07ec7b5 commit 9805af8

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

Documentation/bpf/bpf_design_QA.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,47 @@ A: NO.
298298

299299
The BTF_ID macro does not cause a function to become part of the ABI
300300
any more than does the EXPORT_SYMBOL_GPL macro.
301+
302+
Q: What is the compatibility story for special BPF types in map values?
303+
-----------------------------------------------------------------------
304+
Q: Users are allowed to embed bpf_spin_lock, bpf_timer fields in their BPF map
305+
values (when using BTF support for BPF maps). This allows to use helpers for
306+
such objects on these fields inside map values. Users are also allowed to embed
307+
pointers to some kernel types (with __kptr and __kptr_ref BTF tags). Will the
308+
kernel preserve backwards compatibility for these features?
309+
310+
A: It depends. For bpf_spin_lock, bpf_timer: YES, for kptr and everything else:
311+
NO, but see below.
312+
313+
For struct types that have been added already, like bpf_spin_lock and bpf_timer,
314+
the kernel will preserve backwards compatibility, as they are part of UAPI.
315+
316+
For kptrs, they are also part of UAPI, but only with respect to the kptr
317+
mechanism. The types that you can use with a __kptr and __kptr_ref tagged
318+
pointer in your struct are NOT part of the UAPI contract. The supported types can
319+
and will change across kernel releases. However, operations like accessing kptr
320+
fields and bpf_kptr_xchg() helper will continue to be supported across kernel
321+
releases for the supported types.
322+
323+
For any other supported struct type, unless explicitly stated in this document
324+
and added to bpf.h UAPI header, such types can and will arbitrarily change their
325+
size, type, and alignment, or any other user visible API or ABI detail across
326+
kernel releases. The users must adapt their BPF programs to the new changes and
327+
update them to make sure their programs continue to work correctly.
328+
329+
NOTE: BPF subsystem specially reserves the 'bpf_' prefix for type names, in
330+
order to introduce more special fields in the future. Hence, user programs must
331+
avoid defining types with 'bpf_' prefix to not be broken in future releases. In
332+
other words, no backwards compatibility is guaranteed if one using a type in BTF
333+
with 'bpf_' prefix.
334+
335+
Q: What is the compatibility story for special BPF types in local kptrs?
336+
------------------------------------------------------------------------
337+
Q: Same as above, but for local kptrs (i.e. pointers to objects allocated using
338+
bpf_obj_new for user defined structures). Will the kernel preserve backwards
339+
compatibility for these features?
340+
341+
A: NO.
342+
343+
Unlike map value types, there are no stability guarantees for this case. The
344+
whole local kptr API itself is unstable (since it is exposed through kfuncs).

0 commit comments

Comments
 (0)