On Wed, Aug 16, 2023 at 08:48:16PM -0700, Alexei Starovoitov wrote:
> On Wed, Aug 16, 2023 at 8:38 PM Yonghong Song <yonghong.song@linux.dev> wrote:
> >
> >
> >
> > On 8/16/23 8:06 AM, David Vernet wrote:
> > > 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/202308162115.Hn23vv3n-lkp@intel.com/
> >
> > 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?
>
> 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
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.
@@ -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)
{
@@ -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)
{
@@ -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.
@@ -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)
{
@@ -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)
{
@@ -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)
@@ -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
@@ -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;
@@ -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.
*
@@ -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.
@@ -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
*
@@ -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
*
@@ -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
*
@@ -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
*
@@ -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 int
bpf_testmod_test_struct_arg_1(struct bpf_testmod_struct_arg_2 a, int b, int c) {