Re: [PATCH bpf-next v1] veristat: load struct_ops programs only once

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

 



On Thu, 2025-01-16 at 15:15 -0800, Andrii Nakryiko wrote:

[...]

> > +/* Make sure only target program is referenced from struct_ops map,
> > + * otherwise libbpf would automatically set autocreate for all
> > + * referenced programs.
> > + * See libbpf.c:bpf_object_adjust_struct_ops_autoload.
> > + */
> > +static void mask_unrelated_struct_ops_progs(struct bpf_object *obj,
> > +                                           struct bpf_map *map,
> > +                                           struct bpf_program *prog)
> > +{
> > +       struct btf *btf = bpf_object__btf(obj);
> > +       const struct btf_type *t, *mt;
> > +       struct btf_member *m;
> > +       int i, ptr_sz, moff;
> > +       size_t data_sz;
> > +       void *data;
> > +
> > +       t = btf__type_by_id(btf, bpf_map__btf_value_type_id(map));
> > +       if (!btf_is_struct(t))
> > +               return;
> > +
> > +       data = bpf_map__initial_value(map, &data_sz);
> > +       ptr_sz = min(btf__pointer_size(btf), sizeof(void *));
> 
> btf__pointer_size() for .bpf.o should always be 8, so this min is
> pointless, I think. I can simplify to just ptr_sz = sizeof(void *)
> while applying, if you agree. Let me know.

I wanted to be pedantic, but am ok if you prefer to switch it to
'ptr_sz = sizeof(void *)'. Can send v2, or if you change it when
applying, that would be great.

> 
> Other than that looks good.
> 
> > +       for (i = 0; i < btf_vlen(t); i++) {
> > +               m = &btf_members(t)[i];
> > +               mt = btf__type_by_id(btf, m->type);
> > +               if (!btf_is_ptr(mt))
> > +                       continue;
> > +               moff = m->offset / 8;
> > +               if (moff + ptr_sz > data_sz)
> > +                       continue;
> > +               if (memcmp(data + moff, &prog, ptr_sz) == 0)
> > +                       continue;
> > +               memset(data + moff, 0, ptr_sz);
> > +       }
> > +}
> > +

[...]






[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