Re: [PATCH v9 bpf-next 08/14] bpf: Add btf_struct_ids_match function

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

 



On Wed, Aug 05, 2020 at 07:56:51PM +0200, Jiri Olsa wrote:
> On Tue, Aug 04, 2020 at 11:27:55PM -0700, Andrii Nakryiko wrote:
> 
> SNIP
> 
> > > diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> > > index 7bacc2f56061..ba05b15ad599 100644
> > > --- a/kernel/bpf/btf.c
> > > +++ b/kernel/bpf/btf.c
> > > @@ -4160,6 +4160,37 @@ int btf_struct_access(struct bpf_verifier_log *log,
> > >         return -EINVAL;
> > >  }
> > >
> > > +bool btf_struct_ids_match(struct bpf_verifier_log *log,
> > > +                         int off, u32 id, u32 need_type_id)
> > > +{
> > > +       const struct btf_type *type;
> > > +       int err;
> > > +
> > > +       /* Are we already done? */
> > > +       if (need_type_id == id && off == 0)
> > > +               return true;
> > > +
> > > +again:
> > > +       type = btf_type_by_id(btf_vmlinux, id);
> > > +       if (!type)
> > > +               return false;
> > > +       err = btf_struct_walk(log, type, off, 1, &id);
> > 
> > nit: this size=1 looks a bit artificial, seems like btf_struct_walk()
> > will work with size==0 just as well, no?
> 
> right, it will work the same for 0 ... not sure why I put
> originaly 1 byte for size.. probably got mixed up by some
> condition in btf_struct_walk that I thought 0 wouldn't pass,
> but it should work, I'll change it, it's less tricky

ok, I found why it's 1 ;-) it's this condition in btf_struct_walk:

        for_each_member(i, t, member) {
                /* offset of the field in bytes */
                moff = btf_member_bit_offset(t, member) / 8;
                if (off + size <= moff)
                        /* won't find anything, field is already too far */
                        break;

I originaly chose to use 'size = 1' not to medle with this (and probably causing
other issues) and in any case we expect that anything we find have at least byte
size, so it has some logic ;-)

we could make 0 size a special case and don't break the loop for it,
but I wonder there's already someone calling it with zero and is
expecting it to fail

jirka




[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