From: Anton Protopopov <aspsk@isovalent.com>
To: Daniel Borkmann <daniel@iogearbox.net>
Cc: David Vernet <void@manifault.com>,
Alexei Starovoitov <alexei.starovoitov@gmail.com>,
Yonghong Song <yonghong.song@linux.dev>,
bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>, LKML <linux-kernel@vger.kernel.org>,
Kernel Team <kernel-team@meta.com>,
kernel test robot <lkp@intel.com>
Subject: Re: [PATCH bpf-next] bpf: Disable -Wmissing-declarations for globally-linked kfuncs
Date: Thu, 17 Aug 2023 14:45:35 +0000 [thread overview]
Message-ID: <ZN4yj/3tSzqMyVyY@zh-lab-node-5> (raw)
In-Reply-To: <d49a61ba-10c0-2094-10c9-60a723776f04@iogearbox.net>
On Thu, Aug 17, 2023 at 04:35:26PM +0200, Daniel Borkmann wrote:
> On 8/17/23 6:01 AM, David Vernet wrote:
> > 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.
>
> 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:
>
> diff --git a/include/linux/btf.h b/include/linux/btf.h
> index df64cc642074..6a873a652001 100644
> --- a/include/linux/btf.h
> +++ b/include/linux/btf.h
> @@ -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.
> +#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
> diff --git a/net/core/filter.c b/net/core/filter.c
> index c2b32b94c6bd..08dd0dd710dd 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -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
next prev parent reply other threads:[~2023-08-17 14:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-16 15:06 David Vernet
2023-08-17 3:38 ` Yonghong Song
2023-08-17 3:48 ` Alexei Starovoitov
2023-08-17 4:01 ` David Vernet
2023-08-17 14:35 ` Daniel Borkmann
2023-08-17 14:45 ` Anton Protopopov [this message]
2023-08-17 6:08 ` Yonghong Song
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZN4yj/3tSzqMyVyY@zh-lab-node-5 \
--to=aspsk@isovalent.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kernel-team@meta.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
--cc=martin.lau@linux.dev \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=void@manifault.com \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®