dwarves.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Jiri Olsa <jolsa@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	dwarves@vger.kernel.org, bpf <bpf@vger.kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andriin@fb.com>, Yonghong Song <yhs@fb.com>,
	Hao Luo <haoluo@google.com>, "Frank Ch. Eigler" <fche@redhat.com>,
	Mark Wielaard <mjw@redhat.com>
Subject: Re: [PATCH 2/2] btf_encoder: Change functions check due to broken dwarf
Date: Tue, 3 Nov 2020 11:23:33 -0800	[thread overview]
Message-ID: <CAEf4BzbMOzAdsyMT736idoGnJ1RuxRa5y9wf-egh+LKz406m1g@mail.gmail.com> (raw)
In-Reply-To: <20201103190559.GI3597846@krava>

On Tue, Nov 3, 2020 at 11:06 AM Jiri Olsa <jolsa@redhat.com> wrote:
>
> On Tue, Nov 03, 2020 at 10:58:58AM -0800, Andrii Nakryiko wrote:
> > On Mon, Nov 2, 2020 at 2:57 PM Jiri Olsa <jolsa@redhat.com> wrote:
> > >
> > > On Mon, Nov 02, 2020 at 10:59:08PM +0100, Jiri Olsa wrote:
> > > > On Sat, Oct 31, 2020 at 11:31:31PM +0100, Jiri Olsa wrote:
> > > > > We need to generate just single BTF instance for the
> > > > > function, while DWARF data contains multiple instances
> > > > > of DW_TAG_subprogram tag.
> > > > >
> > > > > Unfortunately we can no longer rely on DW_AT_declaration
> > > > > tag (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97060)
> > > > >
> > > > > Instead we apply following checks:
> > > > >   - argument names are defined for the function
> > > > >   - there's symbol and address defined for the function
> > > > >   - function is generated only once
> > > > >
> > > > > Also because we want to follow kernel's ftrace traceable
> > > > > functions, this patchset is adding extra check that the
> > > > > function is one of the ftrace's functions.
> > > > >
> > > > > All ftrace functions addresses are stored in vmlinux
> > > > > binary within symbols:
> > > > >   __start_mcount_loc
> > > > >   __stop_mcount_loc
> > > >
> > > > hum, for some reason this does not pass through bpf internal
> > > > functions like bpf_iter_bpf_map.. I learned it hard way ;-)
> >
> > what's the exact name of the function that was missing?
> > bpf_iter_bpf_map doesn't exist. And if it's __init function, why does
> > it matter, it's not going to be even available at runtime, right?
> >
>
> bpf_map iter definition:
>
> DEFINE_BPF_ITER_FUNC(bpf_map, struct bpf_iter_meta *meta, struct bpf_map *map)
>
> goes to:
>
> #define DEFINE_BPF_ITER_FUNC(target, args...)                   \
>         extern int bpf_iter_ ## target(args);                   \
>         int __init bpf_iter_ ## target(args) { return 0; }
>
> that creates __init bpf_iter_bpf_map function that will make
> it into BTF where it's expected when opening iterator, but the
> code will be freed because it's __init function

hm... should we just drop __init there?

Yonghong, is __init strictly necessary, or was just an optimization to
save a tiny bit of space?

>
> there are few iteratos functions like that, and I was going to
> check if there's more
>
> >
> > > > will check
> > >
> > > so it gets filtered out because it's __init function
> > > I'll check if the fix below catches all internal functions,
> > > but I guess we should do something more robust
> > >
> > > jirka
> > >
> > >
> > > ---
> > > diff --git a/btf_encoder.c b/btf_encoder.c
> > > index 0a378aa92142..3cd94280c35b 100644
> > > --- a/btf_encoder.c
> > > +++ b/btf_encoder.c
> > > @@ -143,7 +143,8 @@ static int filter_functions(struct btf_elf *btfe, struct mcount_symbols *ms)
> > >                 /* Do not enable .init section functions. */
> > >                 if (init_filter &&
> > >                     func->addr >= ms->init_begin &&
> > > -                   func->addr <  ms->init_end)
> > > +                   func->addr <  ms->init_end &&
> > > +                   strncmp("bpf_", func->name, 4))
> >
> > this looks like a very wrong way to do this? Can you please elaborate
> > on what's missing and why it shouldn't be missing?
>
> yes, it's just a hack, we should do something more
> robust as I mentioned above
>
> it just allowed me to use iterators finaly ;-)

sure, I get it, I was just trying to understand why there is such a
problem in the first place. Turns out we need FUNCs not just for
fentry/fexit and similar, but also for bpf_iter, which is an entirely
different use case (similar to raw_tp, but raw_tp is using typedef ->
func_proto approach).

So I don't know, we might as well just not do mcount checks?.. As an
alternative, but it's not great as well.

>
> jirka
>

  reply	other threads:[~2020-11-03 19:23 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-31 22:31 [PATCHv2 0/2] pahole: Workaround dwarf bug for function encoding Jiri Olsa
2020-10-31 22:31 ` [PATCH 1/2] btf_encoder: Move find_all_percpu_vars in generic collect_symbols Jiri Olsa
2020-11-02 18:29   ` Hao Luo
2020-11-03 17:31     ` Arnaldo Carvalho de Melo
2020-10-31 22:31 ` [PATCH 2/2] btf_encoder: Change functions check due to broken dwarf Jiri Olsa
2020-11-02 21:59   ` Jiri Olsa
2020-11-02 22:56     ` Jiri Olsa
2020-11-03 18:58       ` Andrii Nakryiko
2020-11-03 19:05         ` Jiri Olsa
2020-11-03 19:23           ` Andrii Nakryiko [this message]
2020-11-03 19:34             ` Jiri Olsa
2020-11-03 20:27             ` Yonghong Song
2020-11-03 23:18               ` Jiri Olsa
2020-11-03 18:55   ` Andrii Nakryiko
2020-11-03 23:22     ` Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAEf4BzbMOzAdsyMT736idoGnJ1RuxRa5y9wf-egh+LKz406m1g@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=acme@kernel.org \
    --cc=andriin@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=dwarves@vger.kernel.org \
    --cc=fche@redhat.com \
    --cc=haoluo@google.com \
    --cc=jolsa@kernel.org \
    --cc=jolsa@redhat.com \
    --cc=mjw@redhat.com \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).