Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

libbpf: Add identical pointer detection to btf_dedup_is_equiv()

Recently as a side-effect of

commit ac053946f5c4 ("compiler.h: introduce TYPEOF_UNQUAL() macro")

issues were observed in deduplication between modules and kernel BTF
such that a large number of kernel types were not deduplicated so
were found in module BTF (task_struct, bpf_prog etc). The root cause
appeared to be a failure to dedup struct types, specifically those
with members that were pointers with __percpu annotations.

The issue in dedup is at the point that we are deduplicating structures,
we have not yet deduplicated reference types like pointers. If multiple
copies of a pointer point at the same (deduplicated) integer as in this
case, we do not see them as identical. Special handling already exists
to deal with structures and arrays, so add pointer handling here too.

Reported-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20250429161042.2069678-1-alan.maguire@oracle.com

authored by

Alan Maguire and committed by
Andrii Nakryiko
8e64c387 224ee866

+16
+16
tools/lib/bpf/btf.c
··· 4396 4396 return true; 4397 4397 } 4398 4398 4399 + static bool btf_dedup_identical_ptrs(struct btf_dedup *d, __u32 id1, __u32 id2) 4400 + { 4401 + struct btf_type *t1, *t2; 4402 + 4403 + t1 = btf_type_by_id(d->btf, id1); 4404 + t2 = btf_type_by_id(d->btf, id2); 4405 + 4406 + if (!btf_is_ptr(t1) || !btf_is_ptr(t2)) 4407 + return false; 4408 + 4409 + return t1->type == t2->type; 4410 + } 4411 + 4399 4412 /* 4400 4413 * Check equivalence of BTF type graph formed by candidate struct/union (we'll 4401 4414 * call it "candidate graph" in this description for brevity) to a type graph ··· 4540 4527 * complicated and requires a many-to-many equivalence mapping. 4541 4528 */ 4542 4529 if (btf_dedup_identical_structs(d, hypot_type_id, cand_id)) 4530 + return 1; 4531 + /* A similar case is again observed for PTRs. */ 4532 + if (btf_dedup_identical_ptrs(d, hypot_type_id, cand_id)) 4543 4533 return 1; 4544 4534 return 0; 4545 4535 }