mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
bpf: Add the __arena and __nullable BTF type tags
Kernel structures increasingly want to publish pointers into a BPF arena to the BPF programs they are shared with, and some pointer members that reach programs as trusted are legitimately NULL at times. Neither can be expressed today: a pointer member reaches the program as an ordinary kernel pointer, and sched_ext resorts to a plain u64 holding a pre-translated arena address that programs cast before use. Define __arena and __nullable as BTF type tags, the way __user, __rcu and __percpu already are, so that tagged members survive into vmlinux and module BTF and the verifier can act on them. To kernel code and to sparse the qualifiers are empty: the pointers are ordinary kernel pointers. The verifier side follows in the next patches. The tags live in a header of their own, bpf_compiler_types.h, rather than in compiler_types.h. They mean something to the BPF verifier only, and only the few structures shared with BPF programs that want to publish such a pointer carry them, so the code that declares such a structure includes the header and the rest of the kernel never sees the qualifiers. Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://patch.msgid.link/20261019132203.3034698-6-memxor@gmail.com
This commit is contained in:
parent
d837f008bf
commit
10832993c9
21
include/linux/bpf_compiler_types.h
Normal file
21
include/linux/bpf_compiler_types.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
#ifndef __LINUX_BPF_COMPILER_TYPES_H
|
||||
#define __LINUX_BPF_COMPILER_TYPES_H
|
||||
|
||||
#include <linux/compiler_types.h>
|
||||
|
||||
/*
|
||||
* Qualifiers for the BPF verifier rather than address spaces: __arena marks a
|
||||
* pointer into a BPF arena, __nullable a pointer that may be NULL. They reach
|
||||
* BPF programs as BTF type tags on the members of kernel structs shared with
|
||||
* them; to kernel code and to sparse the pointers are ordinary.
|
||||
*/
|
||||
#ifdef __CHECKER__
|
||||
# define __arena
|
||||
# define __nullable
|
||||
#else
|
||||
# define __arena BTF_TYPE_TAG(arena)
|
||||
# define __nullable BTF_TYPE_TAG(nullable)
|
||||
#endif
|
||||
|
||||
#endif /* __LINUX_BPF_COMPILER_TYPES_H */
|
||||
Loading…
Reference in New Issue
Block a user