All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv2 bpf-next] tools/resolve_btfids: Warn when having multiple IDs for single type
@ 2021-01-05 23:42 Jiri Olsa
  2021-01-06  2:21 ` Alexei Starovoitov
  0 siblings, 1 reply; 2+ messages in thread
From: Jiri Olsa @ 2021-01-05 23:42 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
  Cc: Andrii Nakryiko, netdev, bpf, Martin KaFai Lau, Song Liu,
	Yonghong Song, John Fastabend, KP Singh, Qais Yousef

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 - using 526
WARN: multiple IDs found for 'sk_buff': 2744, 113958 - using 2744

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

Also changing the 'nr' variable name to 'nr_types' to avoid confusion.

[1] https://lore.kernel.org/lkml/20201229151352.6hzmjvu3qh6p2qgg@e107158-lin/
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
v2 changes:
  - changed the warning message [Alexei]
  - renamed 'nr' to 'nr_types' [Andrii]

 tools/bpf/resolve_btfids/main.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
index e3ea569ee125..7409d7860aa6 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)
 {
@@ -472,7 +474,7 @@ static int symbols_resolve(struct object *obj)
 	int nr_funcs    = obj->nr_funcs;
 	int err, type_id;
 	struct btf *btf;
-	__u32 nr;
+	__u32 nr_types;
 
 	btf = btf__parse(obj->btf ?: obj->path, NULL);
 	err = libbpf_get_error(btf);
@@ -483,12 +485,12 @@ static int symbols_resolve(struct object *obj)
 	}
 
 	err = -1;
-	nr  = btf__get_nr_types(btf);
+	nr_types = btf__get_nr_types(btf);
 
 	/*
 	 * Iterate all the BTF types and search for collected symbol IDs.
 	 */
-	for (type_id = 1; type_id <= nr; type_id++) {
+	for (type_id = 1; type_id <= nr_types; type_id++) {
 		const struct btf_type *type;
 		struct rb_root *root;
 		struct btf_id *id;
@@ -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 - using %d\n",
+					str, id->id, type_id, id->id);
+			} else {
+				id->id = type_id;
+				(*nr)--;
+			}
 		}
 	}
 
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCHv2 bpf-next] tools/resolve_btfids: Warn when having multiple IDs for single type
  2021-01-05 23:42 [PATCHv2 bpf-next] tools/resolve_btfids: Warn when having multiple IDs for single type Jiri Olsa
@ 2021-01-06  2:21 ` Alexei Starovoitov
  0 siblings, 0 replies; 2+ messages in thread
From: Alexei Starovoitov @ 2021-01-06  2:21 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Andrii Nakryiko, Network Development, bpf, Martin KaFai Lau,
	Song Liu, Yonghong Song, John Fastabend, KP Singh, Qais Yousef

On Tue, Jan 5, 2021 at 3:42 PM 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 - using 526
> WARN: multiple IDs found for 'sk_buff': 2744, 113958 - using 2744
>
> We keep the lower ID for the given type instance and let the
> build continue.
>
> Also changing the 'nr' variable name to 'nr_types' to avoid confusion.
>
> [1] https://lore.kernel.org/lkml/20201229151352.6hzmjvu3qh6p2qgg@e107158-lin/
> Acked-by: Andrii Nakryiko <andrii@kernel.org>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
> v2 changes:
>   - changed the warning message [Alexei]
>   - renamed 'nr' to 'nr_types' [Andrii]

Applied to bpf tree. I think it's more appropriate there.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-01-06  2:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-05 23:42 [PATCHv2 bpf-next] tools/resolve_btfids: Warn when having multiple IDs for single type Jiri Olsa
2021-01-06  2:21 ` Alexei Starovoitov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.