Re: Question about duplicated types in BTF and btf__dedup()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Oct 25, 2021 at 6:42 PM Mauricio Vásquez Bernal
<mauricio@xxxxxxxxxx> wrote:
>
> Hi. I found out that some of the BTF files provided by BTFHub contain
> a lot of duplicated types definitions:
>
> $ mkdir -p /tmp/foo
> $ cd /tmp/foo/
> $ wget https://github.com/aquasecurity/btfhub/raw/main/ubuntu/20.04/x86_64/5.4.0-88-generic.btf.tar.xz
> $ tar -xf 5.4.0-88-generic.btf.tar.xz
>
> $ bpftool btf dump file 5.4.0-88-generic.btf | grep "STRUCT 'dentry'"
> [954] STRUCT 'dentry' size=192 vlen=16
> [28359] STRUCT 'dentry' size=192 vlen=16
>
> $ bpftool btf dump file 5.4.0-88-generic.btf | grep "STRUCT 'task_struct'"
> [146] STRUCT 'task_struct' size=9216 vlen=213
> [28317] STRUCT 'task_struct' size=9216 vlen=213
>
> $ bpftool btf dump file 5.4.0-88-generic.btf | grep "STRUCT 'file'"
> [640] STRUCT 'file' size=256 vlen=21
> [28416] STRUCT 'file' size=256 vlen=21
>
> I tried to use btf__dedup() but the result is just the same file. Is
> this expected to have duplicated types in the BTF files? Why aren't
> those types getting deduplicated by the algorithm?
>
> btw, I also noted that the /sys/kernel/btf/vmlinux file contains
> duplicated types in some kernels, so I don't think it's an issue
> related to BTFHub.

It's most probably due to different struct ring_buffer in different
files. Long story short, those struct task_struct types eventually
reference struct ring_buffer. Kernel used to have two very different
struct ring_buffer definitions. So depending on #includes, in some
files struct task_struct (through many other types, not directly)
reference either one or the other struct ring_buffer. From BTF dedup
algorithm point of view, those hierarchies of types that reference
those two different struct ring_buffers are different, so BTF dedup
keeps two copies.

struct ring_buffer is just one such case. There were more different
types with the same name, so this duplication of types can happen.

Basically, this is an unfortunate, but expected thing. Most common
cases of such conflicting types since got renamed, but if you try to
compile all drivers with allyesconfig, you'll inevitably have more
type collisions which will result in more type duplication.

Good news is that libbpf handles this just fine.

>
> Thanks
> Mauricio.




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux