From: Jiri Olsa <olsajiri@gmail.com>
To: Alan Maguire <alan.maguire@oracle.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
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 14:23:35 +0200 [thread overview]
Message-ID: <ZMpKx4Ce3NSl7Jn0@krava> (raw)
In-Reply-To: <e34ef898-28ca-6d17-ff5e-889e9f046ea6@oracle.com>
On Wed, Aug 02, 2023 at 12:21:59PM +0100, Alan Maguire wrote:
SNIP
> > diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> > index c92eb8c6ff08..7930a91ca7f3 100644
> > --- a/kernel/trace/bpf_trace.c
> > +++ b/kernel/trace/bpf_trace.c
> > @@ -1057,9 +1057,28 @@ static unsigned long get_entry_ip(unsigned long fentry_ip)
> > #define get_entry_ip(fentry_ip) fentry_ip
> > #endif
> >
> > +#ifdef CONFIG_UPROBES
> > +static unsigned long bpf_get_func_ip_uprobe(struct pt_regs *regs)
> > +{
> > + struct uprobe_dispatch_data *udd;
> > +
> > + udd = (struct uprobe_dispatch_data *) current->utask->vaddr;
> > + return udd->bp_addr;
> > +}
> > +#else
> > +#define bpf_get_func_ip_uprobe(regs) (u64) -1
>
> Small thing - I don't think this value is exposed to users due to the
> run_ctx->is_uprobe predicate, but would it be worth using -EOPNOTSUPP
> here maybe?
I initially thought of putting WARN_ON_ONCE in here, but as you said it
won't trigger so ended up with -1 .. but I don't mind using -EOPNOTSUPP
jirka
>
> > +#endif
> > +
> > BPF_CALL_1(bpf_get_func_ip_kprobe, struct pt_regs *, regs)
> > {
> > - struct kprobe *kp = kprobe_running();
> > + struct bpf_trace_run_ctx *run_ctx;
> > + struct kprobe *kp;
> > +
> > + run_ctx = container_of(current->bpf_ctx, struct bpf_trace_run_ctx, run_ctx);
> > + if (run_ctx->is_uprobe)
> > + return bpf_get_func_ip_uprobe(regs);
> > +
> > + kp = kprobe_running();
> >
> > if (!kp || !(kp->flags & KPROBE_FLAG_ON_FUNC_ENTRY))
> > return 0;
> > diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h
> > index 01ea148723de..7dde806be91e 100644
> > --- a/kernel/trace/trace_probe.h
> > +++ b/kernel/trace/trace_probe.h
> > @@ -519,3 +519,8 @@ void __trace_probe_log_err(int offset, int err);
> >
> > #define trace_probe_log_err(offs, err) \
> > __trace_probe_log_err(offs, TP_ERR_##err)
> > +
> > +struct uprobe_dispatch_data {
> > + struct trace_uprobe *tu;
> > + unsigned long bp_addr;
> > +};
> > diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
> > index 555c223c3232..fc76c3985672 100644
> > --- a/kernel/trace/trace_uprobe.c
> > +++ b/kernel/trace/trace_uprobe.c
> > @@ -88,11 +88,6 @@ static struct trace_uprobe *to_trace_uprobe(struct dyn_event *ev)
> > static int register_uprobe_event(struct trace_uprobe *tu);
> > static int unregister_uprobe_event(struct trace_uprobe *tu);
> >
> > -struct uprobe_dispatch_data {
> > - struct trace_uprobe *tu;
> > - unsigned long bp_addr;
> > -};
> > -
> > static int uprobe_dispatcher(struct uprobe_consumer *con, struct pt_regs *regs);
> > static int uretprobe_dispatcher(struct uprobe_consumer *con,
> > unsigned long func, struct pt_regs *regs);
> > diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
> > index 70da85200695..d21deb46f49f 100644
> > --- a/tools/include/uapi/linux/bpf.h
> > +++ b/tools/include/uapi/linux/bpf.h
> > @@ -5086,9 +5086,14 @@ union bpf_attr {
> > * u64 bpf_get_func_ip(void *ctx)
> > * Description
> > * Get address of the traced function (for tracing and kprobe programs).
> > + *
> > + * When called for kprobe program attached as uprobe it returns
> > + * probe address for both entry and return uprobe.
> > + *
> > * Return
> > - * Address of the traced function.
> > + * Address of the traced function for kprobe.
> > * 0 for kprobes placed within the function (not at the entry).
> > + * Address of the probe for uprobe and return uprobe.
> > *
> > * u64 bpf_get_attach_cookie(void *ctx)
> > * Description
next prev parent reply other threads:[~2023-08-02 12:23 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
2023-08-02 11:21 ` Alan Maguire
2023-08-02 12:23 ` Jiri Olsa [this message]
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=ZMpKx4Ce3NSl7Jn0@krava \
--to=olsajiri@gmail.com \
--cc=alan.maguire@oracle.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=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
--cc=sdf@google.com \
--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