diff mbox series

[bpf-next] tools/resolve_btfids: Warn when having multiple IDs for single type

Message ID 20210105153944.951019-1-jolsa@kernel.org (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series [bpf-next] tools/resolve_btfids: Warn when having multiple IDs for single type | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for bpf-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 4 maintainers not CCed: kpsingh@kernel.org andrii@kernel.org sdf@google.com jackmanb@google.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 23 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Jiri Olsa Jan. 5, 2021, 3:39 p.m. UTC
The kernel image can contain multiple types (structs/unions)
with the same name. This causes distinct type hierarchies in
BTF data and makes resolve_btfids fail with error like:

  BTFIDS  vmlinux
FAILED unresolved symbol udp6_sock

as reported by Qais Yousef [1].

This change adds warning when multiple types of the same name
are detected:

  BTFIDS  vmlinux
WARN: multiple IDs found for 'file' (526, 113351)
WARN: multiple IDs found for 'sk_buff' (2744, 113958)

We keep the lower ID for the given type instance and let the
build continue.

[1] https://lore.kernel.org/lkml/20201229151352.6hzmjvu3qh6p2qgg@e107158-lin/
Reported-by: Qais Yousef <qais.yousef@arm.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/bpf/resolve_btfids/main.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

Alexei Starovoitov Jan. 5, 2021, 7:37 p.m. UTC | #1
On Tue, Jan 5, 2021 at 7:39 AM Jiri Olsa <jolsa@kernel.org> wrote:
>
> The kernel image can contain multiple types (structs/unions)
> with the same name. This causes distinct type hierarchies in
> BTF data and makes resolve_btfids fail with error like:
>
>   BTFIDS  vmlinux
> FAILED unresolved symbol udp6_sock
>
> as reported by Qais Yousef [1].
>
> This change adds warning when multiple types of the same name
> are detected:
>
>   BTFIDS  vmlinux
> WARN: multiple IDs found for 'file' (526, 113351)
> WARN: multiple IDs found for 'sk_buff' (2744, 113958)
>
> We keep the lower ID for the given type instance and let the
> build continue.

I think it would make sense to mention this decision in the warning.
'WARN: multiple IDs' is ambiguous and confusing when action is not specified.
Jiri Olsa Jan. 5, 2021, 7:50 p.m. UTC | #2
On Tue, Jan 05, 2021 at 11:37:09AM -0800, Alexei Starovoitov wrote:
> On Tue, Jan 5, 2021 at 7:39 AM Jiri Olsa <jolsa@kernel.org> wrote:
> >
> > The kernel image can contain multiple types (structs/unions)
> > with the same name. This causes distinct type hierarchies in
> > BTF data and makes resolve_btfids fail with error like:
> >
> >   BTFIDS  vmlinux
> > FAILED unresolved symbol udp6_sock
> >
> > as reported by Qais Yousef [1].
> >
> > This change adds warning when multiple types of the same name
> > are detected:
> >
> >   BTFIDS  vmlinux
> > WARN: multiple IDs found for 'file' (526, 113351)
> > WARN: multiple IDs found for 'sk_buff' (2744, 113958)
> >
> > We keep the lower ID for the given type instance and let the
> > build continue.
> 
> I think it would make sense to mention this decision in the warning.
> 'WARN: multiple IDs' is ambiguous and confusing when action is not specified.

ok, how about:

WARN: multiple IDs found for 'file': 526, 113351 - using 526

jirka
Alexei Starovoitov Jan. 5, 2021, 8:02 p.m. UTC | #3
On Tue, Jan 5, 2021 at 11:50 AM Jiri Olsa <jolsa@redhat.com> wrote:
>
> On Tue, Jan 05, 2021 at 11:37:09AM -0800, Alexei Starovoitov wrote:
> > On Tue, Jan 5, 2021 at 7:39 AM Jiri Olsa <jolsa@kernel.org> wrote:
> > >
> > > The kernel image can contain multiple types (structs/unions)
> > > with the same name. This causes distinct type hierarchies in
> > > BTF data and makes resolve_btfids fail with error like:
> > >
> > >   BTFIDS  vmlinux
> > > FAILED unresolved symbol udp6_sock
> > >
> > > as reported by Qais Yousef [1].
> > >
> > > This change adds warning when multiple types of the same name
> > > are detected:
> > >
> > >   BTFIDS  vmlinux
> > > WARN: multiple IDs found for 'file' (526, 113351)
> > > WARN: multiple IDs found for 'sk_buff' (2744, 113958)
> > >
> > > We keep the lower ID for the given type instance and let the
> > > build continue.
> >
> > I think it would make sense to mention this decision in the warning.
> > 'WARN: multiple IDs' is ambiguous and confusing when action is not specified.
>
> ok, how about:
>
> WARN: multiple IDs found for 'file': 526, 113351 - using 526

yep. much better imo.
Please add a comment to .c file with the suggestion that such types should
be renamed to avoid ambiguity.
Adding 'please rename' to WARN is probably overkill.
Andrii Nakryiko Jan. 5, 2021, 9:15 p.m. UTC | #4
On Tue, Jan 5, 2021 at 7:41 AM Jiri Olsa <jolsa@kernel.org> wrote:
>
> The kernel image can contain multiple types (structs/unions)
> with the same name. This causes distinct type hierarchies in
> BTF data and makes resolve_btfids fail with error like:
>
>   BTFIDS  vmlinux
> FAILED unresolved symbol udp6_sock
>
> as reported by Qais Yousef [1].
>
> This change adds warning when multiple types of the same name
> are detected:
>
>   BTFIDS  vmlinux
> WARN: multiple IDs found for 'file' (526, 113351)
> WARN: multiple IDs found for 'sk_buff' (2744, 113958)
>
> We keep the lower ID for the given type instance and let the
> build continue.
>
> [1] https://lore.kernel.org/lkml/20201229151352.6hzmjvu3qh6p2qgg@e107158-lin/
> Reported-by: Qais Yousef <qais.yousef@arm.com>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---

see comments below, but otherwise lgtm

Acked-by: Andrii Nakryiko <andrii@kernel.org>

>  tools/bpf/resolve_btfids/main.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
> index e3ea569ee125..36a3b1024cdc 100644
> --- a/tools/bpf/resolve_btfids/main.c
> +++ b/tools/bpf/resolve_btfids/main.c
> @@ -139,6 +139,8 @@ int eprintf(int level, int var, const char *fmt, ...)
>  #define pr_debug2(fmt, ...) pr_debugN(2, pr_fmt(fmt), ##__VA_ARGS__)
>  #define pr_err(fmt, ...) \
>         eprintf(0, verbose, pr_fmt(fmt), ##__VA_ARGS__)
> +#define pr_info(fmt, ...) \
> +       eprintf(0, verbose, pr_fmt(fmt), ##__VA_ARGS__)

how is it different from pr_err? Did you forget to update verboseness
levels or it's intentional?

>
>  static bool is_btf_id(const char *name)
>  {
> @@ -526,8 +528,13 @@ static int symbols_resolve(struct object *obj)
>
>                 id = btf_id__find(root, str);
>                 if (id) {
> -                       id->id = type_id;
> -                       (*nr)--;
> +                       if (id->id) {
> +                               pr_info("WARN: multiple IDs found for '%s' (%d, %d)\n",
> +                                       str, id->id, type_id);
> +                       } else {
> +                               id->id = type_id;
> +                               (*nr)--;

btw, there is a nasty shadowing of nr variable, which is used both for
the for() loop condition (as int) and as `int *` inside the loop body.
It's better to rename inner (or outer) nr, it's extremely confusing as
is.

> +                       }
>                 }
>         }
>
> --
> 2.26.2
>
Jiri Olsa Jan. 5, 2021, 10:47 p.m. UTC | #5
On Tue, Jan 05, 2021 at 01:15:39PM -0800, Andrii Nakryiko wrote:
> On Tue, Jan 5, 2021 at 7:41 AM Jiri Olsa <jolsa@kernel.org> wrote:
> >
> > The kernel image can contain multiple types (structs/unions)
> > with the same name. This causes distinct type hierarchies in
> > BTF data and makes resolve_btfids fail with error like:
> >
> >   BTFIDS  vmlinux
> > FAILED unresolved symbol udp6_sock
> >
> > as reported by Qais Yousef [1].
> >
> > This change adds warning when multiple types of the same name
> > are detected:
> >
> >   BTFIDS  vmlinux
> > WARN: multiple IDs found for 'file' (526, 113351)
> > WARN: multiple IDs found for 'sk_buff' (2744, 113958)
> >
> > We keep the lower ID for the given type instance and let the
> > build continue.
> >
> > [1] https://lore.kernel.org/lkml/20201229151352.6hzmjvu3qh6p2qgg@e107158-lin/
> > Reported-by: Qais Yousef <qais.yousef@arm.com>
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> 
> see comments below, but otherwise lgtm
> 
> Acked-by: Andrii Nakryiko <andrii@kernel.org>
> 
> >  tools/bpf/resolve_btfids/main.c | 11 +++++++++--
> >  1 file changed, 9 insertions(+), 2 deletions(-)
> >
> > diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
> > index e3ea569ee125..36a3b1024cdc 100644
> > --- a/tools/bpf/resolve_btfids/main.c
> > +++ b/tools/bpf/resolve_btfids/main.c
> > @@ -139,6 +139,8 @@ int eprintf(int level, int var, const char *fmt, ...)
> >  #define pr_debug2(fmt, ...) pr_debugN(2, pr_fmt(fmt), ##__VA_ARGS__)
> >  #define pr_err(fmt, ...) \
> >         eprintf(0, verbose, pr_fmt(fmt), ##__VA_ARGS__)
> > +#define pr_info(fmt, ...) \
> > +       eprintf(0, verbose, pr_fmt(fmt), ##__VA_ARGS__)
> 
> how is it different from pr_err? Did you forget to update verboseness
> levels or it's intentional?

intentional, I'm using pr_err to print in error paths,
so I wanted to add new one for other 'info' messages without -v

> 
> >
> >  static bool is_btf_id(const char *name)
> >  {
> > @@ -526,8 +528,13 @@ static int symbols_resolve(struct object *obj)
> >
> >                 id = btf_id__find(root, str);
> >                 if (id) {
> > -                       id->id = type_id;
> > -                       (*nr)--;
> > +                       if (id->id) {
> > +                               pr_info("WARN: multiple IDs found for '%s' (%d, %d)\n",
> > +                                       str, id->id, type_id);
> > +                       } else {
> > +                               id->id = type_id;
> > +                               (*nr)--;
> 
> btw, there is a nasty shadowing of nr variable, which is used both for
> the for() loop condition (as int) and as `int *` inside the loop body.
> It's better to rename inner (or outer) nr, it's extremely confusing as
> is.

nice, I'll change that

thanks,
jirka

> 
> > +                       }
> >                 }
> >         }
> >
> > --
> > 2.26.2
> >
>
diff mbox series

Patch

diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
index e3ea569ee125..36a3b1024cdc 100644
--- a/tools/bpf/resolve_btfids/main.c
+++ b/tools/bpf/resolve_btfids/main.c
@@ -139,6 +139,8 @@  int eprintf(int level, int var, const char *fmt, ...)
 #define pr_debug2(fmt, ...) pr_debugN(2, pr_fmt(fmt), ##__VA_ARGS__)
 #define pr_err(fmt, ...) \
 	eprintf(0, verbose, pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_info(fmt, ...) \
+	eprintf(0, verbose, pr_fmt(fmt), ##__VA_ARGS__)
 
 static bool is_btf_id(const char *name)
 {
@@ -526,8 +528,13 @@  static int symbols_resolve(struct object *obj)
 
 		id = btf_id__find(root, str);
 		if (id) {
-			id->id = type_id;
-			(*nr)--;
+			if (id->id) {
+				pr_info("WARN: multiple IDs found for '%s' (%d, %d)\n",
+					str, id->id, type_id);
+			} else {
+				id->id = type_id;
+				(*nr)--;
+			}
 		}
 	}