From: Masami Hiramatsu <mhiramat@kernel.org>
To: Jiri Olsa <jolsa@redhat.com>
Cc: Yonghong Song <yhs@fb.com>, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andriin@fb.com>,
netdev@vger.kernel.org, bpf@vger.kernel.org,
Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@chromium.org>
Subject: Re: [PATCH bpf-next 4/5] bpf: Add bpf_get_func_ip helper for kprobe programs
Date: Thu, 1 Jul 2021 22:10:18 +0900 [thread overview]
Message-ID: <20210701221018.2ce894f2eea36936d1df2ceb@kernel.org> (raw)
In-Reply-To: <YN1+9osJ4NhqZK/j@krava>
On Thu, 1 Jul 2021 10:38:14 +0200
Jiri Olsa <jolsa@redhat.com> wrote:
> On Thu, Jul 01, 2021 at 08:58:54AM +0900, Masami Hiramatsu wrote:
>
> SNIP
>
> > > > return &bpf_override_return_proto;
> > > > #endif
> > > > + case BPF_FUNC_get_func_ip:
> > > > + return &bpf_get_func_ip_proto_kprobe;
> > > > default:
> > > > return bpf_tracing_func_proto(func_id, prog);
> > > > }
> > > > diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
> > > > index ea6178cb5e33..b07d5888db14 100644
> > > > --- a/kernel/trace/trace_kprobe.c
> > > > +++ b/kernel/trace/trace_kprobe.c
> > > > @@ -1570,6 +1570,18 @@ static int kretprobe_event_define_fields(struct trace_event_call *event_call)
> > > > }
> > > >
> > > > #ifdef CONFIG_PERF_EVENTS
> > > > +/* Used by bpf get_func_ip helper */
> > > > +DEFINE_PER_CPU(u64, current_kprobe_addr) = 0;
> > >
> > > Didn't check other architectures. But this should work
> > > for x86 where if nested kprobe happens, the second
> > > kprobe will not call kprobe handlers.
> >
> > No problem, other architecture also does not call nested kprobes handlers.
> > However, you don't need this because you can use kprobe_running()
> > in kprobe context.
> >
> > kp = kprobe_running();
> > if (kp)
> > return kp->addr;
>
> great, that's easier
>
> >
> > BTW, I'm not sure why don't you use instruction_pointer(regs)?
>
> I tried that but it returns function address + 1,
> and I thought that could be different on each arch
> and we'd need arch specific code to deal with that
Oh, I got it. Yes, since it emulates the int3 interruption, the
regs->ip must be kp->addr + 1 on x86. And indeed, it depends
on each arch.
Thank you,
>
> thanks,
> jirka
>
--
Masami Hiramatsu <mhiramat@kernel.org>
next prev parent reply other threads:[~2021-07-01 13:10 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-29 19:29 [RFC bpf-next 0/5] bpf, x86: Add bpf_get_func_ip helper Jiri Olsa
2021-06-29 19:29 ` [PATCH bpf-next 1/5] bpf, x86: Store caller's ip in trampoline stack Jiri Olsa
2021-06-29 19:29 ` [PATCH bpf-next 2/5] bpf: Enable BPF_TRAMP_F_IP_ARG for trampolines with call_get_func_ip Jiri Olsa
2021-06-29 19:29 ` [PATCH bpf-next 3/5] bpf: Add bpf_get_func_ip helper for tracing programs Jiri Olsa
2021-06-29 19:29 ` [PATCH bpf-next 4/5] bpf: Add bpf_get_func_ip helper for kprobe programs Jiri Olsa
2021-06-30 17:47 ` Yonghong Song
2021-06-30 23:58 ` Masami Hiramatsu
2021-07-01 1:45 ` Yonghong Song
2021-07-01 2:01 ` Masami Hiramatsu
2021-07-01 8:38 ` Jiri Olsa
2021-07-01 13:10 ` Masami Hiramatsu [this message]
2021-07-01 8:34 ` Jiri Olsa
2021-06-29 19:29 ` [PATCH bpf-next 5/5] selftests/bpf: Add test for bpf_get_func_ip helper Jiri Olsa
2021-07-01 17:22 ` [RFC bpf-next 0/5] bpf, x86: Add " Alan Maguire
2021-07-02 8:16 ` 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=20210701221018.2ce894f2eea36936d1df2ceb@kernel.org \
--to=mhiramat@kernel.org \
--cc=andriin@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=john.fastabend@gmail.com \
--cc=jolsa@redhat.com \
--cc=kafai@fb.com \
--cc=kpsingh@chromium.org \
--cc=netdev@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.