From: Jiri Olsa <olsajiri@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.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>,
Viktor Malik <vmalik@redhat.com>
Subject: Re: [PATCH RFCv2 bpf-next 2/4] bpf: Add bpf_kprobe_multi_is_return kfunc
Date: Thu, 29 Feb 2024 11:16:50 +0100 [thread overview]
Message-ID: <ZeBZkmZwYqT7o4So@krava> (raw)
In-Reply-To: <CAEf4Bzbga6PK8UNUO5ZHL0Zo3t6xQ8S0tY4Da6aB+AFvm_jjsQ@mail.gmail.com>
On Wed, Feb 28, 2024 at 05:23:45PM -0800, Andrii Nakryiko wrote:
SNIP
> > static int
> > kprobe_multi_link_prog_run(struct bpf_kprobe_multi_link *link,
> > - unsigned long entry_ip, struct pt_regs *regs)
> > + unsigned long entry_ip, struct pt_regs *regs,
> > + bool is_return)
> > {
> > struct bpf_kprobe_multi_run_ctx run_ctx = {
> > .link = link,
> > .entry_ip = entry_ip,
> > + .is_return = is_return,
> > };
> > struct bpf_run_ctx *old_run_ctx;
> > int err;
> > @@ -2830,7 +2833,7 @@ kprobe_multi_link_handler(struct fprobe *fp, unsigned long fentry_ip,
> > int err;
> >
> > link = container_of(fp, struct bpf_kprobe_multi_link, fp);
> > - err = kprobe_multi_link_prog_run(link, get_entry_ip(fentry_ip), regs);
> > + err = kprobe_multi_link_prog_run(link, get_entry_ip(fentry_ip), regs, false);
> > return link->is_wrapper ? err : 0;
> > }
> >
> > @@ -2842,7 +2845,7 @@ kprobe_multi_link_exit_handler(struct fprobe *fp, unsigned long fentry_ip,
> > struct bpf_kprobe_multi_link *link;
> >
> > link = container_of(fp, struct bpf_kprobe_multi_link, fp);
> > - kprobe_multi_link_prog_run(link, get_entry_ip(fentry_ip), regs);
> > + kprobe_multi_link_prog_run(link, get_entry_ip(fentry_ip), regs, true);
> > }
> >
> > static int symbols_cmp_r(const void *a, const void *b, const void *priv)
> > @@ -3111,6 +3114,46 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
> > kvfree(cookies);
> > return err;
> > }
> > +
> > +__bpf_kfunc_start_defs();
> > +
> > +__bpf_kfunc bool bpf_kprobe_multi_is_return(void)
>
> and for uprobes we'll have bpf_uprobe_multi_is_return?...
yes, but now I'm thinking maybe we could also have 'session' api and
have single 'bpf_session_is_return' because both kprobe and uprobe
are KPROBE program type.. and align it together with other session
kfuncs:
bpf_session_is_return
bpf_session_set_cookie
bpf_session_get_cookie
>
> BTW, have you tried implementing a "session cookie" idea?
yep, with a little fix [0] it's working on top of Masami's 'fprobe over fgraph'
changes, you can check last 2 patches in [1] .. I did not do this on top of the
current fprobe/rethook kernel code, because it seems it's about to go away
I still need to implement that on top of uprobes and I will send rfc, so we can
see all of it and discuss the interface
jirka
[0] https://lore.kernel.org/bpf/ZdyKaRiI-PnG80Q0@krava/
[1] https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git/log/?h=bpf/session_data
>
>
> > +{
> > + struct bpf_kprobe_multi_run_ctx *run_ctx;
> > +
> > + run_ctx = container_of(current->bpf_ctx, struct bpf_kprobe_multi_run_ctx, run_ctx);
> > + return run_ctx->is_return;
> > +}
> > +
> > +__bpf_kfunc_end_defs();
> > +
> > +BTF_KFUNCS_START(kprobe_multi_kfunc_set_ids)
> > +BTF_ID_FLAGS(func, bpf_kprobe_multi_is_return)
> > +BTF_KFUNCS_END(kprobe_multi_kfunc_set_ids)
> > +
> > +static int bpf_kprobe_multi_filter(const struct bpf_prog *prog, u32 kfunc_id)
> > +{
> > + if (!btf_id_set8_contains(&kprobe_multi_kfunc_set_ids, kfunc_id))
> > + return 0;
> > +
> > + if (prog->expected_attach_type != BPF_TRACE_KPROBE_MULTI)
> > + return -EACCES;
> > +
> > + return 0;
> > +}
> > +
> > +static const struct btf_kfunc_id_set bpf_kprobe_multi_kfunc_set = {
> > + .owner = THIS_MODULE,
> > + .set = &kprobe_multi_kfunc_set_ids,
> > + .filter = bpf_kprobe_multi_filter,
> > +};
> > +
> > +static int __init bpf_kprobe_multi_kfuncs_init(void)
> > +{
> > + return register_btf_kfunc_id_set(BPF_PROG_TYPE_KPROBE, &bpf_kprobe_multi_kfunc_set);
> > +}
> > +
> > +late_initcall(bpf_kprobe_multi_kfuncs_init);
> > #else /* !CONFIG_FPROBE */
> > int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog)
> > {
> > --
> > 2.43.2
> >
next prev parent reply other threads:[~2024-02-29 10:16 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-28 9:02 [PATCH RFCv2 bpf-next 0/4] bpf: Introduce kprobe multi wrapper attach Jiri Olsa
2024-02-28 9:02 ` [PATCH RFCv2 bpf-next 1/4] bpf: Add support for " Jiri Olsa
2024-02-29 1:23 ` Andrii Nakryiko
2024-02-29 10:20 ` Jiri Olsa
2024-02-28 9:02 ` [PATCH RFCv2 bpf-next 2/4] bpf: Add bpf_kprobe_multi_is_return kfunc Jiri Olsa
2024-02-29 1:23 ` Andrii Nakryiko
2024-02-29 10:16 ` Jiri Olsa [this message]
2024-03-01 18:01 ` Andrii Nakryiko
2024-03-04 8:28 ` Jiri Olsa
2024-02-28 9:02 ` [PATCH RFCv2 bpf-next 3/4] libbpf: Add support for kprobe multi wrapper attach Jiri Olsa
2024-02-29 1:23 ` Andrii Nakryiko
2024-02-29 10:24 ` Jiri Olsa
2024-02-28 9:02 ` [PATCH RFCv2 bpf-next 4/4] selftests/bpf: Add kprobe multi wrapper test 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=ZeBZkmZwYqT7o4So@krava \
--to=olsajiri@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=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@chromium.org \
--cc=mhiramat@kernel.org \
--cc=sdf@google.com \
--cc=songliubraving@fb.com \
--cc=vmalik@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 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.