From: Martin KaFai Lau <kafai@fb.com>
To: Yonghong Song <yhs@fb.com>
Cc: <bpf@vger.kernel.org>, <netdev@vger.kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>, <kernel-team@fb.com>,
Michal Kubecek <mkubecek@suse.cz>
Subject: Re: [PATCH bpf] bpf: fix "unresolved symbol" build error with resolve_btfids
Date: Wed, 30 Sep 2020 15:59:41 -0700 [thread overview]
Message-ID: <20200930225941.zq2vaxsuphfbga4s@kafai-mbp.dhcp.thefacebook.com> (raw)
In-Reply-To: <d5d8091d-e02e-3903-6203-c136b8d70c09@fb.com>
On Wed, Sep 30, 2020 at 03:50:10PM -0700, Yonghong Song wrote:
>
>
> On 9/30/20 1:58 PM, Martin KaFai Lau wrote:
> > On Wed, Sep 30, 2020 at 09:41:09AM -0700, Yonghong Song wrote:
> > > Michal reported a build failure likes below:
> > > BTFIDS vmlinux
> > > FAILED unresolved symbol tcp_timewait_sock
> > > make[1]: *** [/.../linux-5.9-rc7/Makefile:1176: vmlinux] Error 255
> > >
> > > This error can be triggered when config has CONFIG_NET enabled
> > > but CONFIG_INET disabled. In this case, there is no user of
> > > structs inet_timewait_sock and tcp_timewait_sock and hence vmlinux BTF
> > > types are not generated for these two structures.
> > >
> > > To fix the problem, omit the above two types for BTF_SOCK_TYPE_xxx
> > > macro if CONFIG_INET is not defined.
> > >
> > > Fixes: fce557bcef11 ("bpf: Make btf_sock_ids global")
> > > Reported-by: Michal Kubecek <mkubecek@suse.cz>
> > > Signed-off-by: Yonghong Song <yhs@fb.com>
> > > ---
> > > include/linux/btf_ids.h | 20 ++++++++++++++++----
> > > 1 file changed, 16 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/include/linux/btf_ids.h b/include/linux/btf_ids.h
> > > index 4867d549e3c1..d9a1e18d0921 100644
> > > --- a/include/linux/btf_ids.h
> > > +++ b/include/linux/btf_ids.h
> > > @@ -102,24 +102,36 @@ asm( \
> > > * skc_to_*_sock() helpers. All these sockets should have
> > > * sock_common as the first argument in its memory layout.
> > > */
> > > -#define BTF_SOCK_TYPE_xxx \
> > > +
> > > +#define __BTF_SOCK_TYPE_xxx \
> > > BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET, inet_sock) \
> > > BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_CONN, inet_connection_sock) \
> > > BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_REQ, inet_request_sock) \
> > > - BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock) \
> > > BTF_SOCK_TYPE(BTF_SOCK_TYPE_REQ, request_sock) \
> > > BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK, sock) \
> > > BTF_SOCK_TYPE(BTF_SOCK_TYPE_SOCK_COMMON, sock_common) \
> > > BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP, tcp_sock) \
> > > BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_REQ, tcp_request_sock) \
> > > - BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock) \
> > > BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock) \
> > > BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock) \
> > > BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock)
> > > +#define __BTF_SOCK_TW_TYPE_xxx \
> > > + BTF_SOCK_TYPE(BTF_SOCK_TYPE_INET_TW, inet_timewait_sock) \
> > > + BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP_TW, tcp_timewait_sock)
> > > +
> > > +#ifdef CONFIG_INET
> > > +#define BTF_SOCK_TYPE_xxx \
> > > + __BTF_SOCK_TYPE_xxx \
> > > + __BTF_SOCK_TW_TYPE_xxx
> > > +#else
> > > +#define BTF_SOCK_TYPE_xxx __BTF_SOCK_TYPE_xxx
> > BTF_SOCK_TYPE_xxx is used in BTF_ID_LIST_GLOBAL(btf_sock_ids) in filter.c
> > which does not include BTF_SOCK_TYPE_TCP_TW.
> > However, btf_sock_ids[BTF_SOCK_TYPE_TCP_TW] is still used
> > in bpf_skc_to_tcp_timewait_sock_proto.
> >
> > > +#endif
> > > +
> > > enum {
> > > #define BTF_SOCK_TYPE(name, str) name,
> > > -BTF_SOCK_TYPE_xxx
> > > +__BTF_SOCK_TYPE_xxx
> > > +__BTF_SOCK_TW_TYPE_xxx
> > BTF_SOCK_TYPE_TCP_TW is at the end of this enum.
> >
> > Would btf_sock_ids[BTF_SOCK_TYPE_TCP_TW] always be 0?
>
> No. If CONFIG_INET is y, the above BTF_SOCK_TYPE_xxx contains
> __BTF_SOCK_TW_TYPE_xxx
> and
> btf_sock_ids[BTF_SOCK_TYPE_TCP_TW] will be calculated properly.
>
> But if CONFIG_INET is n, then BTF_SOCK_TYPE_xxx will not contain
> __BTF_SOCK_TW_TYPE_xxx
> so btf_sock_ids[BTF_SOCK_TYPE_TCP_TW] will have default value 0
> as btf_sock_ids is a global.
I could be missing something here.
Why btf_sock_ids[BTF_SOCK_TYPE_TCP_TW] must be 0?
How does BTF_ID_LIST_GLOBAL() know there is a
btf_sock_ids[BTF_SOCK_TYPE_TCP_TW]?
I would expect at least BTF_ID_UNUSED is required.
Otherwise, the value will be whatever follow the last
btf_sock_ids[BTF_SOCK_TYPE_UDP6].
>
> Will send v2 to add some comments to make it easy to understand.
>
> >
> > > #undef BTF_SOCK_TYPE
> > > MAX_BTF_SOCK_TYPE,
> > > };
> > > --
> > > 2.24.1
> > >
next prev parent reply other threads:[~2020-09-30 23:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-30 16:41 [PATCH bpf] bpf: fix "unresolved symbol" build error with resolve_btfids Yonghong Song
2020-09-30 18:40 ` Andrii Nakryiko
2020-09-30 19:24 ` Yonghong Song
2020-09-30 19:44 ` Andrii Nakryiko
2020-09-30 20:58 ` Martin KaFai Lau
2020-09-30 22:50 ` Yonghong Song
2020-09-30 22:59 ` Martin KaFai Lau [this message]
2020-10-01 1:00 ` 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=20200930225941.zq2vaxsuphfbga4s@kafai-mbp.dhcp.thefacebook.com \
--to=kafai@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=mkubecek@suse.cz \
--cc=netdev@vger.kernel.org \
--cc=yhs@fb.com \
/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;
as well as URLs for NNTP newsgroup(s).