libbpf: Add debug messaging in dedup equivalence/identity matching
PATCH v2 1/1 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 cand_id[54222] canon_id[102820] shallow-equal but not equiv for field#23 '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/[email protected]/
Changes since v1:
- updated debug messages to refer to shallow-equal, added ids (Andrii)
--- tools/lib/bpf/btf.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-)
tools/lib/bpf/btf.c +29 -5
@@ -4431,11 +4431,14 @@ static bool btf_dedup_identical_types(struct btf_dedup *d, __u32 id1, __u32 id2,struct btf_type *t1, *t2;int k1, k2; recur: -if (depth <=0 ) -return false; - t1 =btf_type_by_id (d->btf, id1); t2 =btf_type_by_id (d->btf, id2); +if (depth <=0 ) { +pr_debug ("Reached depth limit for identical type comparison for '%s'/'%s'\n" , +btf__name_by_offset (d->btf, t1->name_off), +btf__name_by_offset (d->btf, t2->name_off)); +return false; + } k1 =btf_kind (t1); k2 =btf_kind (t2);
@@ -4497,8 +4500,17 @@ static bool btf_dedup_identical_types(struct btf_dedup *d, __u32 id1, __u32 id2,for (i =0 , n =btf_vlen (t1); i < n; i++, m1++, m2++) {if (m1->type == m2->type)continue ; -if (!btf_dedup_identical_types (d, m1->type, m2->type, depth -1 )) +if (!btf_dedup_identical_types (d, m1->type, m2->type, depth -1 )) { +/* Provide debug message for named types. */ +if (t1->name_off) { +pr_debug ("%s '%s' size=%d vlen=%d id1[%u] id2[%u] shallow-equal but not identical for field#%d '%s'\n" , + k1 ==BTF_KIND_STRUCT ?"STRUCT" :"UNION" , +btf__name_by_offset (d->btf, t1->name_off), + t1->size,btf_vlen (t1), id1, id2, i, +btf__name_by_offset (d->btf, m1->name_off)); + }return false; + } }return true; }
@@ -4739,8 +4751,20 @@ static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id, canon_m =btf_members (canon_type);for (i =0 ; i < vlen; i++) { eq =btf_dedup_is_equiv (d, cand_m->type, canon_m->type); -if (eq <=0 ) +if (eq <=0 ) { +/* +* Provide debug message for named types only; +* too many anon struct/unions match. +*/ +if (cand_type->name_off) { +pr_debug ("%s '%s' size=%d vlen=%d cand_id[%u] canon_id[%u] shallow-equal but not equiv for field#%d '%s': %d\n" , + cand_kind ==BTF_KIND_STRUCT ?"STRUCT" :"UNION" , +btf__name_by_offset (d->btf, cand_type->name_off), + cand_type->size, vlen, cand_id, canon_id, i, +btf__name_by_offset (d->btf, cand_m->name_off), eq); + }return eq; + } cand_m++; canon_m++; }
Signature · 1 line
2.39.3
Andrii Nakryiko
AppliedQuoted 48 lines · Alan Maguire
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 cand_id[54222] canon_id[102820] shallow-equal but not equiv for field#23 'sched_class': 0These 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/[email protected]/
Changes since v1:
- updated debug messages to refer to shallow-equal, added ids (Andrii)
Signed-off-by Alan Maguire <[email protected]>--- tools/lib/bpf/btf.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-)tools/lib/bpf/btf.c +6
-3@@ -4431,11 +4431,14 @@ static bool btf_dedup_identical_types(struct btf_dedup *d, __u32 id1, __u32 id2,struct btf_type *t1, *t2;int k1, k2; recur: -if (depth <=0 ) -return false; - t1 =btf_type_by_id (d->btf, id1); t2 =btf_type_by_id (d->btf, id2); +if (depth <=0 ) { +pr_debug ("Reached depth limit for identical type comparison for '%s'/'%s'\n" , +btf__name_by_offset (d->btf, t1->name_off), +btf__name_by_offset (d->btf, t2->name_off)); +return false; + } k1 =btf_kind (t1); k2 =btf_kind (t2);
tools/lib/bpf/btf.c static bool btf_dedup_identical_types(struct btf_dedup *d, __u32 id1, __u32 id2, · line 4504
Quoted 6 lines
tools/lib/bpf/btf.c +2
-1@@ -4497,8 +4500,17 @@ static bool btf_dedup_identical_types(struct btf_dedup *d, __u32 id1, __u32 id2,for (i =0 , n =btf_vlen (t1); i < n; i++, m1++, m2++) {if (m1->type == m2->type)continue ; -if (!btf_dedup_identical_types (d, m1->type, m2->type, depth -1 )) +if (!btf_dedup_identical_types (d, m1->type, m2->type, depth -1 )) { +/* Provide debug message for named types. */
applied the patch to bpf-next, but dropped this comment and the one below, so patchbot is not going to send a notification
Quoted 37 lines
tools/lib/bpf/btf.c +21
-2+if (t1->name_off) { +pr_debug ("%s '%s' size=%d vlen=%d id1[%u] id2[%u] shallow-equal but not identical for field#%d '%s'\n" , + k1 ==BTF_KIND_STRUCT ?"STRUCT" :"UNION" , +btf__name_by_offset (d->btf, t1->name_off), + t1->size,btf_vlen (t1), id1, id2, i, +btf__name_by_offset (d->btf, m1->name_off)); + }return false; + } }return true; }@@ -4739,8 +4751,20 @@ static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id, canon_m =btf_members (canon_type);for (i =0 ; i < vlen; i++) { eq =btf_dedup_is_equiv (d, cand_m->type, canon_m->type); -if (eq <=0 ) +if (eq <=0 ) { +/* +* Provide debug message for named types only; +* too many anon struct/unions match. +*/ +if (cand_type->name_off) { +pr_debug ("%s '%s' size=%d vlen=%d cand_id[%u] canon_id[%u] shallow-equal but not equiv for field#%d '%s': %d\n" , + cand_kind ==BTF_KIND_STRUCT ?"STRUCT" :"UNION" , +btf__name_by_offset (d->btf, cand_type->name_off), + cand_type->size, vlen, cand_id, canon_id, i, +btf__name_by_offset (d->btf, cand_m->name_off), eq); + }return eq; + } cand_m++; canon_m++; } --2.39.3