Skip to content

Commit 75c2826

Browse files
alan-maguireKernel Patches Daemon
authored andcommitted
libbpf: Add debug messaging in dedup equivalence/identity matching
We have seen a number of issues like [1]; failures to deduplicate key kernel data structures like task_struct. These are often hard to debug from pahole even with verbose output, especially when identity/equivalence checks fail deep in a nested struct comparison. Here we add debug messages of the form libbpf: struct 'task_struct' (size 2560 vlen 194) appears equivalent but differs for 23-indexed cand/canon member 'sched_class'/'sched_class': 0 These will be emitted during dedup from pahole when --verbose/-V is specified. This greatly helps identify exactly where dedup failures are experienced. [1] https://lore.kernel.org/bpf/b8e8b560-bce5-414b-846d-0da6d22a9983@oracle.com/ Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
1 parent 44cbecf commit 75c2826

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

tools/lib/bpf/btf.c

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4431,11 +4431,14 @@ static bool btf_dedup_identical_types(struct btf_dedup *d, __u32 id1, __u32 id2,
44314431
struct btf_type *t1, *t2;
44324432
int k1, k2;
44334433
recur:
4434-
if (depth <= 0)
4435-
return false;
4436-
44374434
t1 = btf_type_by_id(d->btf, id1);
44384435
t2 = btf_type_by_id(d->btf, id2);
4436+
if (depth <= 0) {
4437+
pr_debug("Reached depth limit for identical type comparison for '%s'/'%s'\n",
4438+
btf__name_by_offset(d->btf, t1->name_off),
4439+
btf__name_by_offset(d->btf, t2->name_off));
4440+
return false;
4441+
}
44394442

44404443
k1 = btf_kind(t1);
44414444
k2 = btf_kind(t2);
@@ -4497,8 +4500,18 @@ static bool btf_dedup_identical_types(struct btf_dedup *d, __u32 id1, __u32 id2,
44974500
for (i = 0, n = btf_vlen(t1); i < n; i++, m1++, m2++) {
44984501
if (m1->type == m2->type)
44994502
continue;
4500-
if (!btf_dedup_identical_types(d, m1->type, m2->type, depth - 1))
4503+
if (!btf_dedup_identical_types(d, m1->type, m2->type, depth - 1)) {
4504+
/* provide debug message for named types. */
4505+
if (t1->name_off) {
4506+
pr_debug("%s '%s' (size %d vlen %d) appears equal but differs for %d-indexed members '%s'/'%s'\n",
4507+
k1 == BTF_KIND_STRUCT ? "struct" : "union",
4508+
btf__name_by_offset(d->btf, t1->name_off),
4509+
t1->size, btf_vlen(t1), i,
4510+
btf__name_by_offset(d->btf, m1->name_off),
4511+
btf__name_by_offset(d->btf, m2->name_off));
4512+
}
45014513
return false;
4514+
}
45024515
}
45034516
return true;
45044517
}
@@ -4739,8 +4752,21 @@ static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id,
47394752
canon_m = btf_members(canon_type);
47404753
for (i = 0; i < vlen; i++) {
47414754
eq = btf_dedup_is_equiv(d, cand_m->type, canon_m->type);
4742-
if (eq <= 0)
4755+
if (eq <= 0) {
4756+
/* provide debug message for named types only;
4757+
* too many anon struct/unions match.
4758+
*/
4759+
if (cand_type->name_off) {
4760+
pr_debug("%s '%s' (size %d vlen %d) appears equivalent but differs for %d-indexed cand/canon member '%s'/'%s': %d\n",
4761+
cand_kind == BTF_KIND_STRUCT ? "struct" : "union",
4762+
btf__name_by_offset(d->btf, cand_type->name_off),
4763+
vlen, cand_type->size, i,
4764+
btf__name_by_offset(d->btf, cand_m->name_off),
4765+
btf__name_by_offset(d->btf, canon_m->name_off),
4766+
eq);
4767+
}
47434768
return eq;
4769+
}
47444770
cand_m++;
47454771
canon_m++;
47464772
}

0 commit comments

Comments
 (0)