Re: [PATCH bpf-next v2 4/5] libbpf: fix error when st-prefix_ops and ops from differ btf

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

 



On Thu, Dec 12, 2024 at 02:24:46PM -0800, Andrii Nakryiko wrote:
> On Mon, Dec 9, 2024 at 8:04 PM D. Wythe <alibuda@xxxxxxxxxxxxxxxxx> wrote:
> >
> > When a struct_ops named xxx_ops was registered by a module, and
> > it will be used in both built-in modules and the module itself,
> > so that the btf_type of xxx_ops will be present in btf_vmlinux
> 
> instead of using find_btf_by_prefix_kind, let's have:
> 
> 1) snprintf(STRUCT_OPS_VALUE_PREFIX, tname) right here in this
> function, so we have expected type constructed and ready to be used
> and reused, if necessary
> 2) call btf__find_by_name_kind() instead of find_btf_by_prefix_kind()
> 3) if (kern_vtype_id < 0 && !*mod_btf)
>       kern_vtype_id = find_ksym_btf_id(...)
> 4) if (kern_vtype_id < 0) /* now emit error and error out */

Got it. This looks more concise, I will modify it in the next version in
this way.

Thanks,
D. Wythe

> 
> >         if (kern_vtype_id < 0) {
> > -               pr_warn("struct_ops init_kern: struct %s%s is not found in kernel BTF\n",
> > -                       STRUCT_OPS_VALUE_PREFIX, tname);
> > -               return kern_vtype_id;
> > +               if (kern_vtype_id == -ENOENT && !*mod_btf)
> > +                       kern_vtype_id =
> > +                               find_ksym_btf_id_by_prefix_kind(obj, STRUCT_OPS_VALUE_PREFIX,
> > +                                                               tname, BTF_KIND_STRUCT, &btf,
> > +                                                               mod_btf);
> > +               if (kern_vtype_id < 0) {
> > +                       pr_warn("struct_ops init_kern: struct %s%s is not found in kernel BTF\n",
> > +                               STRUCT_OPS_VALUE_PREFIX, tname);
> > +                       return kern_vtype_id;
> > +               }
> >         }
> >         kern_vtype = btf__type_by_id(btf, kern_vtype_id);
> >
> > --
> > 2.45.0
> >




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Kernel Development]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite Info]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Linux Media]     [Device Mapper]

  Powered by Linux