Re: [PATCH bpf-next v5 6/9] bpftool: Implement relocations recording for BTFGen

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

 



On Thu, Feb 3, 2022 at 10:20 PM Rafael David Tinoco
<rafaeldtinoco@xxxxxxxxx> wrote:
>
> >>> As in, do you substitute forward declarations for types that are
> >>> never directly used? If not, that's going to be very suboptimal for
> >>> something like task_struct and any other type that's part of a big
> >>> cluster of types.
>
> >> We decided to include the whole types and all direct and indirect
> >> types referenced from a structure field for type-based relocations.
> >> Our reasoning is that we don't know if the matching algorithm of
> >> libbpf could be changed to require more information in the future and
> >> type-based relocations are few compared to field based relocations.
>
> > It will depend on application and which type is used in relocation.
> > task_struct reaches tons of types and will add a very noticeable size
> > to minimized BTF, for no good reason, IMO. If we discover that we do
> > need those types, we'll update bpftool to generate more.
>
> Just to see if I understood this part correctly. IIRC, we started type
> based relocations support in btfgen because of this particular case:
>
>         union kernfs_node_id {
>             struct {
>                 u32 ino;
>                 u32 generation;
>             };
>             u64 id;
>         };
>
>         struct kernfs_node___older_v55 {
>             const char *name;
>             union kernfs_node_id id;
>         };
>
>         struct kernfs_node___rh8 {
>             const char *name;
>             union {
>                 u64 id;
>                 struct {
>                     union kernfs_node_id id;
>                 } rh_kabi_hidden_172;
>                 union { };
>             };
>         };
>
> So we have 3 situations:
>
> (struct kernfs_node *)->id as u64
>
>         [29] STRUCT 'kernfs_node' size=128 vlen=1
>                 'id' type_id=42 bits_offset=832
>         [42] TYPEDEF 'u64' type_id=10
>
> (struct kernfs_node___older_v55 *)->id as u64 (union kernfs_node_id)->id
>
>         [79] STRUCT 'kernfs_node' size=128 vlen=1
>                 'id' type_id=69 bits_offset=832
>         [69] UNION 'kernfs_node_id' size=8 vlen=2
>                 '(anon)' type_id=132 bits_offset=0
>                 'id' type_id=40 bits_offset=0
>         [40] TYPEDEF 'u64' type_id=12
>
> (struct kernfs_node___rh8 *)->id = (anon union)->id
>
>         [56] STRUCT 'kernfs_node' size=128 vlen=1
>                 '(anon)' type_id=24 bits_offset=832
>         [24] UNION '(anon)' size=8 vlen=1
>                 'id' type_id=40 bits_offset=0
>         [40] TYPEDEF 'u64' type_id=11
>
> We're finding needed BTF types, that should be added to generated BTF,
> based on fields/members of CORE relo info. How we would know we had to
> add the anon union of the last case if it does not exist in the local
> BTF ? What is your suggestion ?
>

I'd need to see real BPF program code for this situation, but if you
don't have field-based relocation that needs that anonymous union,
then it shouldn't matter if that union is there or not. I suspect you
do have field-based relocations that access fields of struct
kernfs_node___rh8 and kernfs_node___older_v55, so both structs and
necessary fields should be marked as "used" by btfgen algorithm.

> Thanks!
>
> -rafaeldtinoco



[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