bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexei Starovoitov <alexei.starovoitov@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	Andrii Nakryiko <andrii.nakryiko@gmail.com>,
	Jiri Olsa <jolsa@kernel.org>, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
	lkml <linux-kernel@vger.kernel.org>,
	Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
	Yonghong Song <yhs@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@chromium.org>
Subject: Re: [RFC bpf-next 4/4] selftests/bpf: Add attach bench test
Date: Thu, 28 Apr 2022 11:59:55 -0700	[thread overview]
Message-ID: <CAADnVQKi+4oBt2C__qz7QoHqTtXYLUjaqwTNFoSE=up9c9k4cA@mail.gmail.com> (raw)
In-Reply-To: <20220428095803.66c17c32@gandalf.local.home>

On Thu, Apr 28, 2022 at 6:58 AM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Sat, 16 Apr 2022 23:21:03 +0900
> Masami Hiramatsu <mhiramat@kernel.org> wrote:
>
> > OK, I also confirmed that __bpf_tramp_exit is listed. (others seems no notrace)
> >
> > /sys/kernel/tracing # cat available_filter_functions | grep __bpf_tramp
> > __bpf_tramp_image_release
> > __bpf_tramp_image_put_rcu
> > __bpf_tramp_image_put_rcu_tasks
> > __bpf_tramp_image_put_deferred
> > __bpf_tramp_exit
> >
> > My gcc is older one.
> > gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
> >
> > But it seems that __bpf_tramp_exit() doesn't call __fentry__. (I objdump'ed)
> >
> > ffffffff81208270 <__bpf_tramp_exit>:
> > ffffffff81208270:       55                      push   %rbp
> > ffffffff81208271:       48 89 e5                mov    %rsp,%rbp
> > ffffffff81208274:       53                      push   %rbx
> > ffffffff81208275:       48 89 fb                mov    %rdi,%rbx
> > ffffffff81208278:       e8 83 70 ef ff          callq  ffffffff810ff300 <__rcu_read_lock>
> > ffffffff8120827d:       31 d2                   xor    %edx,%edx
>
> You need to look deeper ;-)
> >
> >
> > >
> > > So it's quite bizarre and inconsistent.
> >
> > Indeed. I guess there is a bug in scripts/recordmcount.pl.
>
> No there isn't.
>
> I added the addresses it was mapping and found this:
>
> ffffffffa828f680 T __bpf_tramp_exit
>
> (which is relocated, but it's trivial to map it with the actual function).
>
> At the end of that function we have:
>
> ffffffff8128f767:       48 8d bb e0 00 00 00    lea    0xe0(%rbx),%rdi
> ffffffff8128f76e:       48 8b 40 08             mov    0x8(%rax),%rax
> ffffffff8128f772:       e8 89 28 d7 00          call   ffffffff82002000 <__x86_indirect_thunk_array>
>                         ffffffff8128f773: R_X86_64_PLT32        __x86_indirect_thunk_rax-0x4
> ffffffff8128f777:       e9 4a ff ff ff          jmp    ffffffff8128f6c6 <__bpf_tramp_exit+0x46>
> ffffffff8128f77c:       0f 1f 40 00             nopl   0x0(%rax)
> ffffffff8128f780:       e8 8b df dc ff          call   ffffffff8105d710 <__fentry__>
>                         ffffffff8128f781: R_X86_64_PLT32        __fentry__-0x4
> ffffffff8128f785:       b8 f4 fd ff ff          mov    $0xfffffdf4,%eax
> ffffffff8128f78a:       c3                      ret
> ffffffff8128f78b:       0f 1f 44 00 00          nopl   0x0(%rax,%rax,1)
>
>
> Notice the call to fentry!
>
> It's due to this:
>
> void notrace __bpf_tramp_exit(struct bpf_tramp_image *tr)
> {
>         percpu_ref_put(&tr->pcref);
> }
>
> int __weak
> arch_prepare_bpf_trampoline(struct bpf_tramp_image *tr, void *image, void *image_end,
>                             const struct btf_func_model *m, u32 flags,
>                             struct bpf_tramp_progs *tprogs,
>                             void *orig_call)
> {
>         return -ENOTSUPP;
> }
>
> The weak function gets a call to ftrace, but it still gets compiled into
> vmlinux but its symbol is dropped due to it being overridden. Thus, the
> mcount_loc finds this call to fentry, and maps it to the symbol that is
> before it, which just happened to be __bpf_tramp_exit.

Ouch. That _is_ a bug in recordmocount.

> I made that weak function "notrace" and the __bpf_tramp_exit disappeared
> from the available_filter_functions list.

That's a hack. We cannot rely on such hacks for all weak functions.

  parent reply	other threads:[~2022-04-28 19:00 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-07 12:52 [RFC bpf-next 0/4] bpf: Speed up symbol resolving in kprobe multi link Jiri Olsa
2022-04-07 12:52 ` [RFC bpf-next 1/4] kallsyms: Add kallsyms_lookup_names function Jiri Olsa
2022-04-08  0:57   ` Masami Hiramatsu
2022-04-13  7:27     ` Jiri Olsa
2022-04-08 23:19   ` Alexei Starovoitov
2022-04-09 20:24     ` Jiri Olsa
2022-04-12 20:46     ` Jiri Olsa
2022-04-15  0:47       ` Masami Hiramatsu
2022-04-15 22:39         ` Jiri Olsa
2022-04-11 22:15   ` Andrii Nakryiko
2022-04-12 20:28     ` Jiri Olsa
2022-04-07 12:52 ` [RFC bpf-next 2/4] fprobe: Resolve symbols with kallsyms_lookup_names Jiri Olsa
2022-04-08  0:58   ` Masami Hiramatsu
2022-04-07 12:52 ` [RFC bpf-next 3/4] bpf: Resolve symbols with kallsyms_lookup_names for kprobe multi link Jiri Olsa
2022-04-08 23:26   ` Alexei Starovoitov
2022-04-09 20:24     ` Jiri Olsa
2022-04-11 22:15     ` Andrii Nakryiko
2022-04-11 22:15   ` Andrii Nakryiko
2022-04-12 18:42     ` Jiri Olsa
2022-04-07 12:52 ` [RFC bpf-next 4/4] selftests/bpf: Add attach bench test Jiri Olsa
2022-04-11 22:15   ` Andrii Nakryiko
2022-04-12  0:49     ` Masami Hiramatsu
2022-04-12 22:51       ` Andrii Nakryiko
2022-04-16 14:21         ` Masami Hiramatsu
2022-04-18 17:33           ` Steven Rostedt
2022-04-28 13:58           ` Steven Rostedt
2022-04-28 13:59             ` Steven Rostedt
2022-04-28 18:59             ` Alexei Starovoitov [this message]
2022-04-28 20:05               ` Steven Rostedt
2022-04-28 23:32                 ` Andrii Nakryiko
2022-04-28 23:53                   ` Steven Rostedt
2022-04-29  0:09                     ` Steven Rostedt
2022-04-29  0:31                       ` Steven Rostedt
2022-04-13 16:44       ` Steven Rostedt
2022-04-13 16:45         ` Andrii Nakryiko
2022-04-13 16:59           ` Steven Rostedt
2022-04-13 19:02             ` Andrii Nakryiko
2022-04-12 15:44     ` Jiri Olsa
2022-04-12 22:59       ` Andrii Nakryiko
2022-04-08 23:29 ` [RFC bpf-next 0/4] bpf: Speed up symbol resolving in kprobe multi link Alexei Starovoitov
2022-04-09 20:24   ` Jiri Olsa
2022-04-11 22:15     ` Andrii Nakryiko
2022-04-11 22:18       ` Alexei Starovoitov
2022-04-11 22:21         ` Andrii Nakryiko
2022-04-12 15:46           ` 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='CAADnVQKi+4oBt2C__qz7QoHqTtXYLUjaqwTNFoSE=up9c9k4cA@mail.gmail.com' \
    --to=alexei.starovoitov@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kafai@fb.com \
    --cc=kpsingh@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=songliubraving@fb.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).