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. Signed-off-by: Kumar Kartikeya Dwivedi --- include/linux/compiler_types.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h index c5921f139007..e97ee2d4d1df 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -51,6 +51,8 @@ # define __iomem __attribute__((noderef, address_space(__iomem))) # define __percpu __attribute__((noderef, address_space(__percpu))) # define __rcu __attribute__((noderef, address_space(__rcu))) +# define __arena +# define __nullable static inline void __chk_user_ptr(const volatile void __user *ptr) { } static inline void __chk_io_ptr(const volatile void __iomem *ptr) { } /* other */ @@ -70,6 +72,14 @@ static inline void __chk_io_ptr(const volatile void __iomem *ptr) { } # define __iomem # define __percpu __percpu_qual BTF_TYPE_TAG(percpu) # define __rcu BTF_TYPE_TAG(rcu) +/* + * 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 kernel struct members; to kernel + * code the pointers are ordinary. + */ +# define __arena BTF_TYPE_TAG(arena) +# define __nullable BTF_TYPE_TAG(nullable) # define __chk_user_ptr(x) (void)0 # define __chk_io_ptr(x) (void)0 -- 2.53.0-Meta