public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: Yonghong Song <yonghong.song@linux.dev>,
	Yafang Shao <laoar.shao@gmail.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>, bpf <bpf@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>,
	Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
	"Masami Hiramatsu (Google)" <mhiramat@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>
Subject: Re: [PATCH bpf-next 1/3] bpf: Add support for bpf_get_func_ip helper for uprobe program
Date: Wed, 2 Aug 2023 09:15:18 +0200	[thread overview]
Message-ID: <ZMoChnLuNsKzp82w@krava> (raw)
In-Reply-To: <CAADnVQKmSbcYG75=jkhsvekaOkrz26+eO0gSrcbimCD_a-OBoA@mail.gmail.com>

On Tue, Aug 01, 2023 at 01:43:53PM -0700, Alexei Starovoitov wrote:
> On Tue, Aug 1, 2023 at 1:18 PM Yonghong Song <yonghong.song@linux.dev> wrote:
> >
> >
> >
> > On 8/1/23 12:44 PM, Yonghong Song wrote:
> > >
> > >
> > > On 8/1/23 4:53 AM, Yafang Shao wrote:
> > >> On Tue, Aug 1, 2023 at 3:30 PM Jiri Olsa <jolsa@kernel.org> wrote:
> > >>>
> > >>> Adding support for bpf_get_func_ip helper for uprobe program to return
> > >>> probed address for both uprobe and return uprobe.
> > >>>
> > >>> We discussed this in [1] and agreed that uprobe can have special use
> > >>> of bpf_get_func_ip helper that differs from kprobe.
> > >>>
> > >>> The kprobe bpf_get_func_ip returns:
> > >>>    - address of the function if probe is attach on function entry
> > >>>      for both kprobe and return kprobe
> > >>>    - 0 if the probe is not attach on function entry
> > >>>
> > >>> The uprobe bpf_get_func_ip returns:
> > >>>    - address of the probe for both uprobe and return uprobe
> > >>>
> > >>> The reason for this semantic change is that kernel can't really tell
> > >>> if the probe user space address is function entry.
> > >>>
> > >>> The uprobe program is actually kprobe type program attached as uprobe.
> > >>> One of the consequences of this design is that uprobes do not have its
> > >>> own set of helpers, but share them with kprobes.
> > >>>
> > >>> As we need different functionality for bpf_get_func_ip helper for
> > >>> uprobe,
> > >>> I'm adding the bool value to the bpf_trace_run_ctx, so the helper can
> > >>> detect that it's executed in uprobe context and call specific code.
> > >>>
> > >>> The is_uprobe bool is set as true in bpf_prog_run_array_sleepable which
> > >>> is currently used only for executing bpf programs in uprobe.
> > >>
> > >> That is error-prone.  If we don't intend to rename
> > >> bpf_prog_run_array_sleepable() to bpf_prog_run_array_uprobe(), I think
> > >> we'd better introduce a new parameter 'bool is_uprobe' into it.
> > >
> > > Agree that renaming bpf_prog_run_array_sleepable() to
> > > bpf_prog_run_array_uprobe() probably better. This way, it is
> > > self-explainable for `run_ctx.is_uprobe = true`.
> > >
> > > If unlikely case in the future, another sleepable run prog array
> > > is needed. They can have their own bpf_prog_run_array_<..>
> > > and underlying bpf_prog_run_array_sleepable() can be factored out.
> >
> > Or if want to avoid unnecessary code churn, at least add
> > a comment in bpf_prog_run_array_sleepable() to explain
> > that why it is safe to do `run_ctx.is_uprobe = true;`.
> 
> I think renaming to _uprobe() is a good idea.
> I would prefer if we can remove the bool is_uprobe run-time check,
> but don't see a way to do it cleanly.

ok, I'll rename it

thanks,
jirka

  reply	other threads:[~2023-08-02  7:15 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-01  7:29 [PATCH bpf-next 0/3] bpf: Support bpf_get_func_ip helper in uprobes Jiri Olsa
2023-08-01  7:30 ` [PATCH bpf-next 1/3] bpf: Add support for bpf_get_func_ip helper for uprobe program Jiri Olsa
2023-08-01 11:53   ` Yafang Shao
2023-08-01 19:44     ` Yonghong Song
2023-08-01 20:18       ` Yonghong Song
2023-08-01 20:43         ` Alexei Starovoitov
2023-08-02  7:15           ` Jiri Olsa [this message]
2023-08-02 11:21   ` Alan Maguire
2023-08-02 12:23     ` Jiri Olsa
2023-08-01  7:30 ` [PATCH bpf-next 2/3] selftests/bpf: Add bpf_get_func_ip tests for uprobe on function entry Jiri Olsa
2023-08-01  7:30 ` [PATCH bpf-next 3/3] selftests/bpf: Add bpf_get_func_ip test for uprobe inside function Jiri Olsa
2023-08-02 11:30   ` Alan Maguire
2023-08-02 12:26     ` Jiri Olsa
2023-08-02 12:42       ` Alan Maguire

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=ZMoChnLuNsKzp82w@krava \
    --to=olsajiri@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@chromium.org \
    --cc=laoar.shao@gmail.com \
    --cc=mhiramat@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=sdf@google.com \
    --cc=songliubraving@fb.com \
    --cc=yhs@fb.com \
    --cc=yonghong.song@linux.dev \
    /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