libbpf: Add debug messaging in dedup equivalence/identity matching
PATCH 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) 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/[email protected]/
--- tools/lib/bpf/btf.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-)
tools/lib/bpf/btf.c +31 -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,18 @@ 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) appears equal but differs for %d-indexed members '%s'/'%s'\n" , + k1 ==BTF_KIND_STRUCT ?"struct" :"union" , +btf__name_by_offset (d->btf, t1->name_off), + t1->size,btf_vlen (t1), i, +btf__name_by_offset (d->btf, m1->name_off), +btf__name_by_offset (d->btf, m2->name_off)); + }return false; + } }return true; }
@@ -4739,8 +4752,21 @@ 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) appears equivalent but differs for %d-indexed cand/canon member '%s'/'%s': %d\n" , + cand_kind ==BTF_KIND_STRUCT ?"struct" :"union" , +btf__name_by_offset (d->btf, cand_type->name_off), + vlen, cand_type->size, i, +btf__name_by_offset (d->btf, cand_m->name_off), +btf__name_by_offset (d->btf, canon_m->name_off), + eq); + }return eq; + } cand_m++; canon_m++; }
Signature · 1 line
2.39.3
Eduard Zingerman
maintainerQuoted 10 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) appears equivalent but differs for 23-indexed cand/canon member 'sched_class'/'sched_class': 0
Quoted 8 lines
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]/
Signed-off-by Alan Maguire <[email protected]>---
Lgtm, but maybe also add id1/id2, cand_id/canon_id to the print out?
[...]
Quoted 15 lines · Eduard Zingerman
Quoted 14 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) appears equivalent but differs for 23-indexed cand/canon member 'sched_class'/'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.
Quoted 9 lines
Quoted 4 lines
[1] https://lore.kernel.org/bpf/[email protected]/
Signed-off-by Alan Maguire <[email protected]>---
Lgtm, but maybe also add id1/id2, cand_id/canon_id to the print out?
[...]
I experimented with that originally alright; problem is the ids at the time the message is generated don't really relate to the final ids in the (mostly) deduplicated BTF. As a result I figured it was best to stick with type/member names. Thanks for taking a look!
Quoted 23 lines · Alan Maguire
Quoted 22 lines · Eduard Zingerman
Quoted 10 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) appears equivalent but differs for 23-indexed cand/canon member 'sched_class'/'sched_class': 0Quoted 8 lines
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]/
Signed-off-by Alan Maguire <[email protected]>---
Lgtm, but maybe also add id1/id2, cand_id/canon_id to the print out?
Quoted 7 lines
Quoted 2 lines
[...]
I experimented with that originally alright; problem is the ids at the time the message is generated don't really relate to the final ids in the (mostly) deduplicated BTF. As a result I figured it was best to stick with type/member names. Thanks for taking a look!
Oh, makes sense, thank you for explaining.
Quoted 44 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) appears equivalent but differs for 23-indexed cand/canon member 'sched_class'/'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]/
Signed-off-by Alan Maguire <[email protected]>--- tools/lib/bpf/btf.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 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 4506
Quoted 8 lines
tools/lib/bpf/btf.c +4
-1@@ -4497,8 +4500,18 @@ 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) appears equal but differs for %d-indexed members '%s'/'%s'\n",
Honestly, reading this message in the commit description above I was a bit confused about what it actually means... "appears equal" refers to shallow equality check passing, right? Given this is for debugging, just use consistent terminology here, maybe? It's for you, me, Eduard, Ihor, maybe a few more people, so we don't have to invent UX-friendly allegories here :) Just say "are shallow-equal" or something like that, maybe? As for "%d-indexed", IMO, "field #%d" would be unambiguous.
Also, I saw you reply to Eduard, but I still think that if I were to
debug this I'd like to know original type IDs of structs involved to be able to look at raw BTF dump and dive deeper? We have consistent "[%u] %s" pattern for referring to BTF types, let's use that here to identify two structs/unions involved?
Also, is size/vlen really useful? I bet you'd still be looking at raw BTF output to check details about the struct/union, and there the size/vlen is readily available. Just curious if it's really that useful to have it here.
pw-bot: cr
tools/lib/bpf/btf.c static bool btf_dedup_identical_types(struct btf_dedup *d, __u32 id1, __u32 id2, · line 4511
Quoted 5 lines
tools/lib/bpf/btf.c +5
-0+ k1 ==BTF_KIND_STRUCT ?"struct" :"union" , +btf__name_by_offset (d->btf, t1->name_off), + t1->size,btf_vlen (t1), i, +btf__name_by_offset (d->btf, m1->name_off), + btf__name_by_offset(d->btf, m2->name_off));
field names will be identical, guaranteed by shallow-equal check, why logging twice?
tools/lib/bpf/btf.c static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id, · line 4756
Quoted 13 lines
tools/lib/bpf/btf.c +4
-1+ }return false; + } }return true; }@@ -4739,8 +4752,21 @@ 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;
please use more "canonical" comment style
tools/lib/bpf/btf.c static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id, · line 4765
Quoted 9 lines
tools/lib/bpf/btf.c +9
-0+* too many anon struct/unions match. +*/ +if (cand_type->name_off) { + pr_debug("%s '%s' (size %d vlen %d) appears equivalent but differs for %d-indexed cand/canon member '%s'/'%s': %d\n", + cand_kind == BTF_KIND_STRUCT ? "struct" : "union", + btf__name_by_offset(d->btf, cand_type->name_off), + vlen, cand_type->size, i, + btf__name_by_offset(d->btf, cand_m->name_off), + btf__name_by_offset(d->btf, canon_m->name_off),
same question about field names, can they be different here ever?
Quoted 10 lines
tools/lib/bpf/btf.c +3
-1+ eq); + }return eq; + } cand_m++; canon_m++; } --2.39.3
Quoted 63 lines · Andrii Nakryiko
Quoted 44 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) appears equivalent but differs for 23-indexed cand/canon member 'sched_class'/'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]/
Signed-off-by Alan Maguire <[email protected]>--- tools/lib/bpf/btf.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 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 4506
Quoted 8 lines
tools/lib/bpf/btf.c +4
-1@@ -4497,8 +4500,18 @@ 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) appears equal but differs for %d-indexed members '%s'/'%s'\n",Honestly, reading this message in the commit description above I was a bit confused about what it actually means... "appears equal" refers to shallow equality check passing, right? Given this is for debugging, just use consistent terminology here, maybe? It's for you, me, Eduard, Ihor, maybe a few more people, so we don't have to invent UX-friendly allegories here :) Just say "are shallow-equal" or something like that, maybe? As for "%d-indexed", IMO, "field #%d" would be unambiguous.
Quoted 6 lines
Also, I saw you reply to Eduard, but I still think that if I were to
debug this I'd like to know original type IDs of structs involved to be able to look at raw BTF dump and dive deeper? We have consistent "[%u] %s" pattern for referring to BTF types, let's use that here to identify two structs/unions involved?
Sure; how about this format:
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
Quoted 5 lines
Also, is size/vlen really useful? I bet you'd still be looking at raw BTF output to check details about the struct/union, and there the size/vlen is readily available. Just curious if it's really that useful to have it here.
In the above form we can basically take the
STRUCT 'task_struct' size=2560 vlen=194
and grep for those details. Useful if we have name-conflicted types. In a dedup failure we could potentially have such ambiguites where CUs have different views of structs with different fields compiled in, so while I didn't strictly need it this time I suspect it will be helpful in clarifying exactly which object we're talking about.
Quoted 11 lines
pw-bot: cr
tools/lib/bpf/btf.c static bool btf_dedup_identical_types(struct btf_dedup *d, __u32 id1, __u32 id2, · line 4511
Quoted 5 lines
tools/lib/bpf/btf.c +5
-0+ k1 ==BTF_KIND_STRUCT ?"struct" :"union" , +btf__name_by_offset (d->btf, t1->name_off), + t1->size,btf_vlen (t1), i, +btf__name_by_offset (d->btf, m1->name_off), + btf__name_by_offset(d->btf, m2->name_off));field names will be identical, guaranteed by shallow-equal check, why logging twice?
yep, good point, will remove.
Quoted 27 lines
Quoted 8 lines
tools/lib/bpf/btf.c +2
-0+ }return false; + } }return true; }tools/lib/bpf/btf.c static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id, · line 4756
Quoted 6 lines
tools/lib/bpf/btf.c +2
-1@@ -4739,8 +4752,21 @@ 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; please use more "canonical" comment style
tools/lib/bpf/btf.c static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id, · line 4765
Quoted 9 lines
tools/lib/bpf/btf.c +9
-0+* too many anon struct/unions match. +*/ +if (cand_type->name_off) { + pr_debug("%s '%s' (size %d vlen %d) appears equivalent but differs for %d-indexed cand/canon member '%s'/'%s': %d\n", + cand_kind == BTF_KIND_STRUCT ? "struct" : "union", + btf__name_by_offset(d->btf, cand_type->name_off), + vlen, cand_type->size, i, + btf__name_by_offset(d->btf, cand_m->name_off), + btf__name_by_offset(d->btf, canon_m->name_off),
Quoted 2 lines
same question about field names, can they be different here ever?
My read of shallow equality means name equivalence is guaranteed; will remove.
Will send a v2 if the above proposed format looks good. Thanks!
Alan
Quoted 72 lines · Alan Maguire
Quoted 63 lines · Andrii Nakryiko
Quoted 44 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) appears equivalent but differs for 23-indexed cand/canon member 'sched_class'/'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]/
Signed-off-by Alan Maguire <[email protected]>--- tools/lib/bpf/btf.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 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 4506
Quoted 8 lines
tools/lib/bpf/btf.c +4
-1@@ -4497,8 +4500,18 @@ 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) appears equal but differs for %d-indexed members '%s'/'%s'\n",Honestly, reading this message in the commit description above I was a bit confused about what it actually means... "appears equal" refers to shallow equality check passing, right? Given this is for debugging, just use consistent terminology here, maybe? It's for you, me, Eduard, Ihor, maybe a few more people, so we don't have to invent UX-friendly allegories here :) Just say "are shallow-equal" or something like that, maybe? As for "%d-indexed", IMO, "field #%d" would be unambiguous.
Quoted 6 lines
Also, I saw you reply to Eduard, but I still think that if I were to
debug this I'd like to know original type IDs of structs involved to be able to look at raw BTF dump and dive deeper? We have consistent "[%u] %s" pattern for referring to BTF types, let's use that here to identify two structs/unions involved?
Quoted 5 lines
Sure; how about this format:
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
lgtm
Quoted 9 lines
Quoted 6 lines
Also, is size/vlen really useful? I bet you'd still be looking at raw BTF output to check details about the struct/union, and there the size/vlen is readily available. Just curious if it's really that useful to have it here.
In the above form we can basically take the
Quoted 8 lines
STRUCT '
task_struct' size=2560 vlen=194and grep for those details. Useful if we have name-conflicted types. In a dedup failure we could potentially have such ambiguites where CUs have different views of structs with different fields compiled in, so while I didn't strictly need it this time I suspect it will be helpful in clarifying exactly which object we're talking about.
ok
Quoted 52 lines
Quoted 5 lines
pw-bot: cr
Quoted 8 lines
tools/lib/bpf/btf.c static bool btf_dedup_identical_types(struct btf_dedup *d, __u32 id1, __u32 id2, · line 4511
Quoted 5 lines
tools/lib/bpf/btf.c +5
-0+ k1 ==BTF_KIND_STRUCT ?"struct" :"union" , +btf__name_by_offset (d->btf, t1->name_off), + t1->size,btf_vlen (t1), i, +btf__name_by_offset (d->btf, m1->name_off), + btf__name_by_offset(d->btf, m2->name_off));field names will be identical, guaranteed by shallow-equal check, why logging twice?
yep, good point, will remove.
Quoted 27 lines
Quoted 8 lines
tools/lib/bpf/btf.c +2
-0+ }return false; + } }return true; }tools/lib/bpf/btf.c static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id, · line 4756
Quoted 6 lines
tools/lib/bpf/btf.c +2
-1@@ -4739,8 +4752,21 @@ 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; please use more "canonical" comment style
tools/lib/bpf/btf.c static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id, · line 4765
Quoted 9 lines
tools/lib/bpf/btf.c +9
-0+* too many anon struct/unions match. +*/ +if (cand_type->name_off) { + pr_debug("%s '%s' (size %d vlen %d) appears equivalent but differs for %d-indexed cand/canon member '%s'/'%s': %d\n", + cand_kind == BTF_KIND_STRUCT ? "struct" : "union", + btf__name_by_offset(d->btf, cand_type->name_off), + vlen, cand_type->size, i, + btf__name_by_offset(d->btf, cand_m->name_off), + btf__name_by_offset(d->btf, canon_m->name_off),Quoted 2 lines
same question about field names, can they be different here ever?
My read of shallow equality means name equivalence is guaranteed; will remove.
Will send a v2 if the above proposed format looks good. Thanks!
Alan