netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii@kernel.org>
To: <bpf@vger.kernel.org>, <netdev@vger.kernel.org>, <ast@fb.com>,
	<daniel@iogearbox.net>
Cc: <andrii@kernel.org>, <kernel-team@fb.com>
Subject: [PATCH bpf-next 09/11] libbpf: accomodate DWARF/compiler bug with duplicated identical arrays
Date: Wed, 28 Oct 2020 17:59:00 -0700	[thread overview]
Message-ID: <20201029005902.1706310-10-andrii@kernel.org> (raw)
In-Reply-To: <20201029005902.1706310-1-andrii@kernel.org>

In some cases compiler seems to generate distinct DWARF types for identical
arrays within the same CU. That seems like a bug, but it's already out there
and breaks type graph equivalence checks, so accommodate it anyway by checking
for identical arrays, regardless of their type ID.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 tools/lib/bpf/btf.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index c760a5809d4d..4643b0482686 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -3786,6 +3786,19 @@ static inline __u16 btf_fwd_kind(struct btf_type *t)
 	return btf_kflag(t) ? BTF_KIND_UNION : BTF_KIND_STRUCT;
 }
 
+/* Check if given two types are identical ARRAY definitions */
+static int btf_dedup_identical_arrays(struct btf_dedup *d, __u32 id1, __u32 id2)
+{
+	struct btf_type *t1, *t2;
+
+	t1 = btf_type_by_id(d->btf, id1);
+	t2 = btf_type_by_id(d->btf, id2);
+	if (!btf_is_array(t1) || !btf_is_array(t2))
+		return 0;
+
+	return btf_equal_array(t1, t2);
+}
+
 /*
  * Check equivalence of BTF type graph formed by candidate struct/union (we'll
  * call it "candidate graph" in this description for brevity) to a type graph
@@ -3896,8 +3909,18 @@ static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id,
 	canon_id = resolve_fwd_id(d, canon_id);
 
 	hypot_type_id = d->hypot_map[canon_id];
-	if (hypot_type_id <= BTF_MAX_NR_TYPES)
-		return hypot_type_id == cand_id;
+	if (hypot_type_id <= BTF_MAX_NR_TYPES) {
+		/* In some cases compiler will generate different DWARF types
+		 * for *identical* array type definitions and use them for
+		 * different fields within the *same* struct. This breaks type
+		 * equivalence check, which makes an assumption that candidate
+		 * types sub-graph has a consistent and deduped-by-compiler
+		 * types within a single CU. So work around that by explicitly
+		 * allowing identical array types here.
+		 */
+		return hypot_type_id == cand_id ||
+		       btf_dedup_identical_arrays(d, hypot_type_id, cand_id);
+	}
 
 	if (btf_dedup_hypot_map_add(d, canon_id, cand_id))
 		return -ENOMEM;
-- 
2.24.1


  parent reply	other threads:[~2020-10-29  0:59 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-29  0:58 [PATCH bpf-next 00/11] libbpf: split BTF support Andrii Nakryiko
2020-10-29  0:58 ` [PATCH bpf-next 01/11] libbpf: factor out common operations in BTF writing APIs Andrii Nakryiko
2020-10-30  0:36   ` Song Liu
2020-10-29  0:58 ` [PATCH bpf-next 02/11] selftest/bpf: relax btf_dedup test checks Andrii Nakryiko
2020-10-30 16:43   ` Song Liu
2020-10-30 18:44     ` Andrii Nakryiko
2020-10-30 22:30       ` Song Liu
2020-10-29  0:58 ` [PATCH bpf-next 03/11] libbpf: unify and speed up BTF string deduplication Andrii Nakryiko
2020-10-30 23:32   ` Song Liu
2020-11-03  4:51     ` Andrii Nakryiko
2020-11-03  4:59   ` Alexei Starovoitov
2020-11-03  6:01     ` Andrii Nakryiko
2020-10-29  0:58 ` [PATCH bpf-next 04/11] libbpf: implement basic split BTF support Andrii Nakryiko
2020-11-02 23:23   ` Song Liu
2020-11-03  5:02     ` Andrii Nakryiko
2020-11-03  5:41       ` Song Liu
2020-11-04 23:51         ` Andrii Nakryiko
2020-10-29  0:58 ` [PATCH bpf-next 05/11] selftests/bpf: add split BTF basic test Andrii Nakryiko
2020-11-02 23:36   ` Song Liu
2020-11-03  5:10     ` Andrii Nakryiko
2020-10-29  0:58 ` [PATCH bpf-next 06/11] selftests/bpf: add checking of raw type dump in BTF writer APIs selftests Andrii Nakryiko
2020-11-03  0:08   ` Song Liu
2020-11-03  5:14     ` Andrii Nakryiko
2020-10-29  0:58 ` [PATCH bpf-next 07/11] libbpf: fix BTF data layout checks and allow empty BTF Andrii Nakryiko
2020-11-03  0:51   ` Song Liu
2020-11-03  5:18     ` Andrii Nakryiko
2020-11-03  5:44       ` Song Liu
2020-10-29  0:58 ` [PATCH bpf-next 08/11] libbpf: support BTF dedup of split BTFs Andrii Nakryiko
2020-11-03  2:49   ` Song Liu
2020-11-03  5:25     ` Andrii Nakryiko
2020-11-03  5:59       ` Song Liu
2020-11-03  6:31         ` Andrii Nakryiko
2020-11-03 17:15           ` Song Liu
2020-11-03  5:10   ` Alexei Starovoitov
2020-11-03  6:27     ` Andrii Nakryiko
2020-11-03 17:55       ` Alexei Starovoitov
2020-10-29  0:59 ` Andrii Nakryiko [this message]
2020-11-03  2:52   ` [PATCH bpf-next 09/11] libbpf: accomodate DWARF/compiler bug with duplicated identical arrays Song Liu
2020-10-29  0:59 ` [PATCH bpf-next 10/11] selftests/bpf: add split BTF dedup selftests Andrii Nakryiko
2020-11-03  5:35   ` Song Liu
2020-11-03  6:05     ` Andrii Nakryiko
2020-11-03  6:30       ` Song Liu
2020-10-29  0:59 ` [PATCH bpf-next 11/11] tools/bpftool: add bpftool support for split BTF Andrii Nakryiko
2020-11-03  6:03   ` Song Liu
2020-10-30  0:33 ` [PATCH bpf-next 00/11] libbpf: split BTF support Song Liu
2020-10-30  2:33   ` Andrii Nakryiko
2020-10-30  6:45     ` Song Liu
2020-10-30 12:04     ` Alan Maguire
2020-10-30 18:30       ` Andrii Nakryiko

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=20201029005902.1706310-10-andrii@kernel.org \
    --to=andrii@kernel.org \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    /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).