[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4Bza5H0+96Pgz1wmWJP=ABGikv3iEmMc9EMWMpZ0+c9Gpbg@mail.gmail.com>
Date: Wed, 5 Aug 2020 14:57:10 -0700
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Jiri Olsa <jolsa@...hat.com>
Cc: Jiri Olsa <jolsa@...nel.org>, Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andriin@...com>,
Networking <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
Martin KaFai Lau <kafai@...com>,
David Miller <davem@...hat.com>,
John Fastabend <john.fastabend@...il.com>,
Wenbo Zhang <ethercflow@...il.com>,
KP Singh <kpsingh@...omium.org>,
Brendan Gregg <bgregg@...flix.com>,
Florent Revest <revest@...omium.org>,
Al Viro <viro@...iv.linux.org.uk>
Subject: Re: [PATCH v9 bpf-next 08/14] bpf: Add btf_struct_ids_match function
On Wed, Aug 5, 2020 at 2:31 PM Jiri Olsa <jolsa@...hat.com> wrote:
>
> 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
>
I see, ok, probably no need. Just let it be for now, I guess.
> jirka
>
Powered by blists - more mailing lists