bpf: Disable -Wmissing-declarations for globally-linked kfuncs
Subsystems (15)
PATCH 1/1 bpf: Disable -Wmissing-declarations for globally-linked kfuncs
We recently got an lkp warning about missing declarations, as in e.g. [0]. This warning is largely redundant with -Wmissing-prototypes, which we already disable for kfuncs that have global linkage and are meant to be exported in BTF, and called from BPF programs. Let's also disable -Wmissing-declarations for kfuncs. For what it's worth, I wasn't able to reproduce the warning even on W <= 3, so I can't actually be 100% sure this fixes the issue.
[0]: https://lore.kernel.org/all/[email protected]/
--- Documentation/bpf/kfuncs.rst | 4 +++- kernel/bpf/bpf_iter.c | 2 ++ kernel/bpf/cpumask.c | 2 ++ kernel/bpf/helpers.c | 2 ++ kernel/bpf/map_iter.c | 2 ++ kernel/cgroup/rstat.c | 2 ++ kernel/trace/bpf_trace.c | 2 ++ net/bpf/test_run.c | 2 ++ net/core/filter.c | 4 ++++ net/core/xdp.c | 2 ++ net/ipv4/fou_bpf.c | 2 ++ net/netfilter/nf_conntrack_bpf.c | 2 ++ net/netfilter/nf_nat_bpf.c | 2 ++ net/xfrm/xfrm_interface_bpf.c | 2 ++ tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c | 2 ++ 15 files changed, 33 insertions(+), 1 deletion(-)
Documentation/bpf/kfuncs.rst +3 -1
@@ -36,10 +36,12 @@ prototype in a header for the wrapper kfunc. An example is given below:: - /* Disables missing prototype warnings */ + /* Disables missing prototypes and declarations warnings */ __diag_push(); __diag_ignore_all("-Wmissing-prototypes", "Global kfuncs as their definitions will be in BTF"); + __diag_ignore_all("-Wmissing-declarations", + "Global kfuncs as their definitions will be in BTF"); __bpf_kfunc struct task_struct *bpf_find_get_task_by_vpid(pid_t nr) {
kernel/bpf/bpf_iter.c +2 -0
@@ -785,6 +785,8 @@ struct bpf_iter_num_kern {__diag_push ();__diag_ignore_all ("-Wmissing-prototypes" ,"Global functions as their definitions will be in vmlinux BTF" ); +__diag_ignore_all ("-Wmissing-declarations" , +"Global functions as their definitions will be in vmlinux BTF" ); __bpf_kfunc int bpf_iter_num_new(struct bpf_iter_num *it, int start, int end) {
kernel/bpf/cpumask.c +2 -0
@@ -37,6 +37,8 @@ static bool cpu_valid(u32 cpu)__diag_push ();__diag_ignore_all ("-Wmissing-prototypes" ,"Global kfuncs as their definitions will be in BTF" ); +__diag_ignore_all ("-Wmissing-declarations" , +"Global kfuncs as their definitions will be in BTF" );/** * bpf_cpumask_create() - Create a mutable BPF cpumask.
kernel/bpf/helpers.c +2 -0
@@ -1885,6 +1885,8 @@ void bpf_rb_root_free(const struct btf_field *field, void *rb_root,__diag_push ();__diag_ignore_all ("-Wmissing-prototypes" ,"Global functions as their definitions will be in vmlinux BTF" ); +__diag_ignore_all ("-Wmissing-declarations" , +"Global functions as their definitions will be in vmlinux BTF" ); __bpf_kfunc void *bpf_obj_new_impl(u64 local_type_id__k, void *meta__ign) {
kernel/bpf/map_iter.c +2 -0
@@ -196,6 +196,8 @@ late_initcall(bpf_map_iter_init);__diag_push ();__diag_ignore_all ("-Wmissing-prototypes" ,"Global functions as their definitions will be in vmlinux BTF" ); +__diag_ignore_all ("-Wmissing-declarations" , +"Global functions as their definitions will be in vmlinux BTF" ); __bpf_kfunc s64 bpf_map_sum_elem_count(const struct bpf_map *map) {
kernel/cgroup/rstat.c +2 -0
@@ -162,6 +162,8 @@ static struct cgroup *cgroup_rstat_cpu_pop_updated(struct cgroup *pos,__diag_push ();__diag_ignore_all ("-Wmissing-prototypes" ,"kfuncs which will be used in BPF programs" ); +__diag_ignore_all ("-Wmissing-declarations" , +"kfuncs which will be used in BPF programs" ); __weak noinline void bpf_rstat_flush(struct cgroup *cgrp,struct cgroup *parent,int cpu)
kernel/trace/bpf_trace.c +2 -0
@@ -1224,6 +1224,8 @@ static const struct bpf_func_proto bpf_get_func_arg_cnt_proto = {__diag_push ();__diag_ignore_all ("-Wmissing-prototypes" ,"kfuncs which will be used in BPF programs" ); +__diag_ignore_all ("-Wmissing-declarations" , +"kfuncs which will be used in BPF programs" );/** * bpf_lookup_user_key - lookup a key by its serial
net/bpf/test_run.c +2 -0
@@ -506,6 +506,8 @@ static int bpf_test_finish(const union bpf_attr *kattr,__diag_push ();__diag_ignore_all ("-Wmissing-prototypes" ,"Global functions as their definitions will be in vmlinux BTF" ); +__diag_ignore_all ("-Wmissing-declarations" , +"Global functions as their definitions will be in vmlinux BTF" ); __bpf_kfunc int bpf_fentry_test1(int a) {return a +1 ;
net/core/filter.c +4 -0
@@ -11727,6 +11727,8 @@ bpf_sk_base_func_proto(enum bpf_func_id func_id)__diag_push ();__diag_ignore_all ("-Wmissing-prototypes" ,"Global functions as their definitions will be in vmlinux BTF" ); +__diag_ignore_all ("-Wmissing-declarations" , +"Global functions as their definitions will be in vmlinux BTF" ); __bpf_kfunc int bpf_dynptr_from_skb(struct sk_buff *skb, u64 flags,struct bpf_dynptr_kern *ptr__uninit) {
@@ -11808,6 +11810,8 @@ late_initcall(bpf_kfunc_init);__diag_push ();__diag_ignore_all ("-Wmissing-prototypes" ,"Global functions as their definitions will be in vmlinux BTF" ); +__diag_ignore_all ("-Wmissing-declarations" , +"Global functions as their definitions will be in vmlinux BTF" );/* bpf_sock_destroy: Destroy the given socket with ECONNABORTED error code. *
net/core/xdp.c +2 -0
@@ -699,6 +699,8 @@ struct xdp_frame *xdpf_clone(struct xdp_frame *xdpf)__diag_push ();__diag_ignore_all ("-Wmissing-prototypes" ,"Global functions as their definitions will be in vmlinux BTF" ); +__diag_ignore_all ("-Wmissing-declarations" , +"Global functions as their definitions will be in vmlinux BTF" );/** * bpf_xdp_metadata_rx_timestamp - Read XDP frame RX timestamp.
net/ipv4/fou_bpf.c +2 -0
@@ -25,6 +25,8 @@ enum bpf_fou_encap_type {__diag_push ();__diag_ignore_all ("-Wmissing-prototypes" ,"Global functions as their definitions will be in BTF" ); +__diag_ignore_all ("-Wmissing-declarations" , +"Global functions as their definitions will be in BTF" );/* bpf_skb_set_fou_encap - Set FOU encap parameters *
net/netfilter/nf_conntrack_bpf.c +2 -0
@@ -233,6 +233,8 @@ static int _nf_conntrack_btf_struct_access(struct bpf_verifier_log *log,__diag_push ();__diag_ignore_all ("-Wmissing-prototypes" ,"Global functions as their definitions will be in nf_conntrack BTF" ); +__diag_ignore_all ("-Wmissing-declarations" , +"Global functions as their definitions will be in nf_conntrack BTF" );/* bpf_xdp_ct_alloc - Allocate a new CT entry *
net/netfilter/nf_nat_bpf.c +2 -0
@@ -15,6 +15,8 @@__diag_push ();__diag_ignore_all ("-Wmissing-prototypes" ,"Global functions as their definitions will be in nf_nat BTF" ); +__diag_ignore_all ("-Wmissing-declarations" , +"Global functions as their definitions will be in nf_nat BTF" );/* bpf_ct_set_nat_info - Set source or destination nat address *
net/xfrm/xfrm_interface_bpf.c +2 -0
@@ -30,6 +30,8 @@ struct bpf_xfrm_info {__diag_push ();__diag_ignore_all ("-Wmissing-prototypes" ,"Global functions as their definitions will be in xfrm_interface BTF" ); +__diag_ignore_all ("-Wmissing-declarations" , +"Global functions as their definitions will be in xfrm_interface BTF" );/* bpf_skb_get_xfrm_info - Get XFRM metadata *
tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c +2 -0
@@ -42,6 +42,8 @@ struct bpf_testmod_struct_arg_4 {__diag_push ();__diag_ignore_all ("-Wmissing-prototypes" ,"Global functions as their definitions will be in bpf_testmod.ko BTF" ); +__diag_ignore_all ("-Wmissing-declarations" , +"Global functions as their definitions will be in bpf_testmod.ko BTF" ); noinline intbpf_testmod_test_struct_arg_1 (struct bpf_testmod_struct_arg_2 a,int b,int c) {
Signature · 1 line
2.41.0
Yonghong Song
maintainerQuoted 9 lines · David Vernet
We recently got an lkp warning about missing declarations, as in e.g. [0]. This warning is largely redundant with -Wmissing-prototypes, which we already disable for kfuncs that have global linkage and are meant to be exported in BTF, and called from BPF programs. Let's also disable -Wmissing-declarations for kfuncs. For what it's worth, I wasn't able to reproduce the warning even on W <= 3, so I can't actually be 100% sure this fixes the issue.
Okay, I just got a similar email to [0] which complains
bpf_obj_new_impl, ..., bpf_cast_to_kern_ctx
missing declarations.
In the email, the used compiler is
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
Unfortunately, I did not have gcc-7 to verify this. Also, what is the minimum gcc version kernel supports? 5.1?
Quoted 53 lines
Reported-by kernel test robot <[email protected]>Signed-off-by David Vernet <[email protected]>--- Documentation/bpf/kfuncs.rst | 4 +++- kernel/bpf/bpf_iter.c | 2 ++ kernel/bpf/cpumask.c | 2 ++ kernel/bpf/helpers.c | 2 ++ kernel/bpf/map_iter.c | 2 ++ kernel/cgroup/rstat.c | 2 ++ kernel/trace/bpf_trace.c | 2 ++ net/bpf/test_run.c | 2 ++ net/core/filter.c | 4 ++++ net/core/xdp.c | 2 ++ net/ipv4/fou_bpf.c | 2 ++ net/netfilter/nf_conntrack_bpf.c | 2 ++ net/netfilter/nf_nat_bpf.c | 2 ++ net/xfrm/xfrm_interface_bpf.c | 2 ++ tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c | 2 ++ 15 files changed, 33 insertions(+), 1 deletion(-)Documentation/bpf/kfuncs.rst +3
-1@@ -36,10 +36,12 @@ prototype in a header for the wrapper kfunc. An example is given below:: - /* Disables missing prototype warnings */ + /* Disables missing prototypes and declarations warnings */ __diag_push(); __diag_ignore_all("-Wmissing-prototypes", "Global kfuncs as their definitions will be in BTF"); + __diag_ignore_all("-Wmissing-declarations", + "Global kfuncs as their definitions will be in BTF"); __bpf_kfunc struct task_struct *bpf_find_get_task_by_vpid(pid_t nr) {kernel/bpf/bpf_iter.c +2
-0@@ -785,6 +785,8 @@ struct bpf_iter_num_kern {__diag_push ();__diag_ignore_all ("-Wmissing-prototypes" ,"Global functions as their definitions will be in vmlinux BTF" ); +__diag_ignore_all ("-Wmissing-declarations" , +"Global functions as their definitions will be in vmlinux BTF" ); __bpf_kfunc int bpf_iter_num_new(struct bpf_iter_num *it, int start, int end) {
[...]
Quoted 18 lines · Yonghong Song
Quoted 9 lines · David Vernet
We recently got an lkp warning about missing declarations, as in e.g. [0]. This warning is largely redundant with -Wmissing-prototypes, which we already disable for kfuncs that have global linkage and are meant to be exported in BTF, and called from BPF programs. Let's also disable -Wmissing-declarations for kfuncs. For what it's worth, I wasn't able to reproduce the warning even on W <= 3, so I can't actually be 100% sure this fixes the issue.
Okay, I just got a similar email to [0] which complains
bpf_obj_new_impl, ...,bpf_cast_to_kern_ctx
missing declarations.
Quoted 5 lines
In the email, the used compiler is
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0Unfortunately, I did not have gcc-7 to verify this. Also, what is the minimum gcc version kernel supports? 5.1?
pahole and BTF might be broken in such old GCC too. Maybe we should add:
config BPF_SYSCALL
depends on GCC_VERSION >= 90000 || CLANG_VERSION >= 130000
Quoted 22 lines · Alexei Starovoitov
Quoted 21 lines · Yonghong Song
Quoted 9 lines · David Vernet
We recently got an lkp warning about missing declarations, as in e.g. [0]. This warning is largely redundant with -Wmissing-prototypes, which we already disable for kfuncs that have global linkage and are meant to be exported in BTF, and called from BPF programs. Let's also disable -Wmissing-declarations for kfuncs. For what it's worth, I wasn't able to reproduce the warning even on W <= 3, so I can't actually be 100% sure this fixes the issue.
Okay, I just got a similar email to [0] which complains
bpf_obj_new_impl, ...,bpf_cast_to_kern_ctx
missing declarations.In the email, the used compiler is
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
Quoted 7 lines
Quoted 2 lines
Unfortunately, I did not have gcc-7 to verify this. Also, what is the minimum gcc version kernel supports? 5.1?
pahole and BTF might be broken in such old GCC too. Maybe we should add:
configBPF_SYSCALLdepends on GCC_VERSION >= 90000 || CLANG_VERSION >= 130000
It seems prudent to formally declare minimum compiler versions. Though modern gcc and clang also support -Wmissing-declarations, so maybe we should merge this patch regardless? Just unfortunate to have to add even more boilerplate just to get the compiler off our backs.
Daniel Borkmann
maintainerQuoted 28 lines · David Vernet
Quoted 19 lines · Alexei Starovoitov
Quoted 18 lines · Yonghong Song
Quoted 9 lines · David Vernet
We recently got an lkp warning about missing declarations, as in e.g. [0]. This warning is largely redundant with -Wmissing-prototypes, which we already disable for kfuncs that have global linkage and are meant to be exported in BTF, and called from BPF programs. Let's also disable -Wmissing-declarations for kfuncs. For what it's worth, I wasn't able to reproduce the warning even on W <= 3, so I can't actually be 100% sure this fixes the issue.
Okay, I just got a similar email to [0] which complains
bpf_obj_new_impl, ..., bpf_cast_to_kern_ctxmissing declarations.
In the email, the used compiler is
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0Quoted 7 lines
Quoted 2 lines
Unfortunately, I did not have gcc-7 to verify this. Also, what is the minimum gcc version kernel supports? 5.1?
pahole and BTF might be broken in such old GCC too. Maybe we should add:
configBPF_SYSCALLdepends on GCC_VERSION >= 90000 || CLANG_VERSION >= 130000
Quoted 4 lines
It seems prudent to formally declare minimum compiler versions. Though modern gcc and clang also support -Wmissing-declarations, so maybe we should merge this patch regardless? Just unfortunate to have to add even more boilerplate just to get the compiler off our backs.
Urgh, to restrict BPF syscall with such depends on would be super ugly. Why can't we just move this boilerplate behind a macro instead of copying this everywhere? For example the below on top of your patch builds just fine on my side:
include/linux/btf.h +10 -0
@@ -83,6 +83,16 @@*/ #define __bpf_kfunc __used noinline +#define __bpf_kfunc_start \ + __diag_push(); \ + __diag_ignore_all("-Wmissing-prototypes", \ + "Global functions as their definitions will be in vmlinux BTF"); \ + __diag_ignore_all("-Wmissing-declarations", \ + "Global functions as their definitions will be in vmlinux BTF"); + +#define __bpf_kfunc_end \ + __diag_pop(); +/* * Return the name of the passed struct, if exists, or halt the build if for * example the structure gets renamed. In this way, developers have to revisit
net/core/filter.c +2 -6
@@ -11724,11 +11724,7 @@ bpf_sk_base_func_proto(enum bpf_func_id func_id)return func; } -__diag_push (); -__diag_ignore_all ("-Wmissing-prototypes" , -"Global functions as their definitions will be in vmlinux BTF" ); -__diag_ignore_all ("-Wmissing-declarations" , -"Global functions as their definitions will be in vmlinux BTF" ); +__bpf_kfunc_start __bpf_kfunc int bpf_dynptr_from_skb(struct sk_buff *skb, u64 flags,struct bpf_dynptr_kern *ptr__uninit) {
@@ -11754,7 +11750,7 @@ __bpf_kfunc int bpf_dynptr_from_xdp(struct xdp_buff *xdp, u64 flags,return 0 ; } -__diag_pop (); +__bpf_kfunc_end int bpf_dynptr_from_skb_rdonly(struct sk_buff *skb, u64 flags,struct bpf_dynptr_kern *ptr__uninit)
Thanks,
Daniel
Quoted 44 lines · Daniel Borkmann
Quoted 28 lines · David Vernet
Quoted 19 lines · Alexei Starovoitov
Quoted 18 lines · Yonghong Song
Quoted 9 lines · David Vernet
We recently got an lkp warning about missing declarations, as in e.g. [0]. This warning is largely redundant with -Wmissing-prototypes, which we already disable for kfuncs that have global linkage and are meant to be exported in BTF, and called from BPF programs. Let's also disable -Wmissing-declarations for kfuncs. For what it's worth, I wasn't able to reproduce the warning even on W <= 3, so I can't actually be 100% sure this fixes the issue.
Okay, I just got a similar email to [0] which complains
bpf_obj_new_impl, ..., bpf_cast_to_kern_ctxmissing declarations.
In the email, the used compiler is
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0Quoted 7 lines
Quoted 2 lines
Unfortunately, I did not have gcc-7 to verify this. Also, what is the minimum gcc version kernel supports? 5.1?
pahole and BTF might be broken in such old GCC too. Maybe we should add:
configBPF_SYSCALLdepends on GCC_VERSION >= 90000 || CLANG_VERSION >= 130000Quoted 4 lines
It seems prudent to formally declare minimum compiler versions. Though modern gcc and clang also support -Wmissing-declarations, so maybe we should merge this patch regardless? Just unfortunate to have to add even more boilerplate just to get the compiler off our backs.
Urgh, to restrict BPF syscall with such
depends onwould be super ugly. Why can't we just move this boilerplate behind a macro instead of copying this everywhere? For example the below on top of your patch builds just fine on my side:include/linux/btf.h +0
-0
include/linux/btf.h line 92
Quoted 10 lines
include/linux/btf.h +7
-0@@ -83,6 +83,16 @@*/ #define __bpf_kfunc __used noinline +#define __bpf_kfunc_start \ + __diag_push(); \ + __diag_ignore_all("-Wmissing-prototypes", \ + "Global functions as their definitions will be in vmlinux BTF"); \ + __diag_ignore_all("-Wmissing-declarations", \ + "Global functions as their definitions will be in vmlinux BTF"); +
This will not solve the robot's compain, as it fails on gcc7. The __diag_ignore_all for gcc is defined as
#if GCC_VERSION >= 80000
#define __diag_GCC_8(s) __diag(s)
#else
#define __diag_GCC_8(s)
#endif
#define __diag_ignore_all(option, comment) \
__diag_GCC(8, ignore, option)so adding more __diag_ignore_all's will not do anything. This is better to patch __diag_ignore_all to include older gcc versions if anybody needs them.
Quoted 35 lines
include/linux/btf.h +3
-0+#define __bpf_kfunc_end \ + __diag_pop(); +/* * Return the name of the passed struct, if exists, or halt the build if for * example the structure gets renamed. In this way, developers have to revisit net/core/filter.c +2
-6@@ -11724,11 +11724,7 @@ bpf_sk_base_func_proto(enum bpf_func_id func_id)return func; } -__diag_push (); -__diag_ignore_all ("-Wmissing-prototypes" , -"Global functions as their definitions will be in vmlinux BTF" ); -__diag_ignore_all ("-Wmissing-declarations" , -"Global functions as their definitions will be in vmlinux BTF" ); +__bpf_kfunc_start __bpf_kfunc int bpf_dynptr_from_skb(struct sk_buff *skb, u64 flags,struct bpf_dynptr_kern *ptr__uninit) {@@ -11754,7 +11750,7 @@ __bpf_kfunc int bpf_dynptr_from_xdp(struct xdp_buff *xdp, u64 flags,return 0 ; } -__diag_pop (); +__bpf_kfunc_end int bpf_dynptr_from_skb_rdonly(struct sk_buff *skb, u64 flags,struct bpf_dynptr_kern *ptr__uninit)Thanks,
Daniel
Yonghong Song
maintainerQuoted 22 lines · Alexei Starovoitov
Quoted 21 lines · Yonghong Song
Quoted 9 lines · David Vernet
We recently got an lkp warning about missing declarations, as in e.g. [0]. This warning is largely redundant with -Wmissing-prototypes, which we already disable for kfuncs that have global linkage and are meant to be exported in BTF, and called from BPF programs. Let's also disable -Wmissing-declarations for kfuncs. For what it's worth, I wasn't able to reproduce the warning even on W <= 3, so I can't actually be 100% sure this fixes the issue.
Okay, I just got a similar email to [0] which complains
bpf_obj_new_impl, ..., bpf_cast_to_kern_ctxmissing declarations.
In the email, the used compiler is
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
Quoted 7 lines
Quoted 2 lines
Unfortunately, I did not have gcc-7 to verify this. Also, what is the minimum gcc version kernel supports? 5.1?
pahole and BTF might be broken in such old GCC too. Maybe we should add:
configBPF_SYSCALLdepends on GCC_VERSION >= 90000 || CLANG_VERSION >= 130000
Do you remember what kind of issues pahole/BTF have for < 9.0 gcc and < 13.0 clang?