linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Jiri Olsa <jolsa@kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	 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>,
	Steven Rostedt <rostedt@goodmis.org>,
	 Masami Hiramatsu <mhiramat@kernel.org>,
	linux-kernel@vger.kernel.org,
	 linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCHv2 bpf-next 3/9] bpf: Add support for uprobe multi session context
Date: Tue, 2 Jul 2024 14:31:25 -0700	[thread overview]
Message-ID: <CAEf4BzbvA98fVtc9yf5zP2Bf3WbJ1wc7ZeXSR3FSvG-VV3zAKA@mail.gmail.com> (raw)
In-Reply-To: <20240701164115.723677-4-jolsa@kernel.org>

On Mon, Jul 1, 2024 at 9:42 AM Jiri Olsa <jolsa@kernel.org> wrote:
>
> Placing bpf_session_run_ctx layer in between bpf_run_ctx and
> bpf_uprobe_multi_run_ctx, so the session data can be retrieved
> from uprobe_multi link.
>
> Plus granting session kfuncs access to uprobe session programs.
>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  kernel/trace/bpf_trace.c | 23 +++++++++++++++--------
>  1 file changed, 15 insertions(+), 8 deletions(-)
>

Acked-by: Andrii Nakryiko <andrii@kernel.org>


> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index 1b19c1cdb5e1..d431b880ca11 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -3184,7 +3184,7 @@ struct bpf_uprobe_multi_link {
>  };
>
>  struct bpf_uprobe_multi_run_ctx {
> -       struct bpf_run_ctx run_ctx;
> +       struct bpf_session_run_ctx session_ctx;
>         unsigned long entry_ip;
>         struct bpf_uprobe *uprobe;
>  };
> @@ -3297,10 +3297,15 @@ static const struct bpf_link_ops bpf_uprobe_multi_link_lops = {
>
>  static int uprobe_prog_run(struct bpf_uprobe *uprobe,
>                            unsigned long entry_ip,
> -                          struct pt_regs *regs)
> +                          struct pt_regs *regs,
> +                          bool is_return, void *data)
>  {
>         struct bpf_uprobe_multi_link *link = uprobe->link;
>         struct bpf_uprobe_multi_run_ctx run_ctx = {
> +               .session_ctx = {
> +                       .is_return = is_return,
> +                       .data = data,
> +               },
>                 .entry_ip = entry_ip,
>                 .uprobe = uprobe,
>         };
> @@ -3319,7 +3324,7 @@ static int uprobe_prog_run(struct bpf_uprobe *uprobe,
>
>         migrate_disable();
>
> -       old_run_ctx = bpf_set_run_ctx(&run_ctx.run_ctx);
> +       old_run_ctx = bpf_set_run_ctx(&run_ctx.session_ctx.run_ctx);
>         err = bpf_prog_run(link->link.prog, regs);
>         bpf_reset_run_ctx(old_run_ctx);
>
> @@ -3349,7 +3354,7 @@ uprobe_multi_link_handler(struct uprobe_consumer *con, struct pt_regs *regs,
>         struct bpf_uprobe *uprobe;
>
>         uprobe = container_of(con, struct bpf_uprobe, consumer);
> -       return uprobe_prog_run(uprobe, instruction_pointer(regs), regs);
> +       return uprobe_prog_run(uprobe, instruction_pointer(regs), regs, false, data);
>  }
>
>  static int
> @@ -3359,14 +3364,15 @@ uprobe_multi_link_ret_handler(struct uprobe_consumer *con, unsigned long func, s
>         struct bpf_uprobe *uprobe;
>
>         uprobe = container_of(con, struct bpf_uprobe, consumer);
> -       return uprobe_prog_run(uprobe, func, regs);
> +       return uprobe_prog_run(uprobe, func, regs, true, data);
>  }
>
>  static u64 bpf_uprobe_multi_entry_ip(struct bpf_run_ctx *ctx)
>  {
>         struct bpf_uprobe_multi_run_ctx *run_ctx;
>
> -       run_ctx = container_of(current->bpf_ctx, struct bpf_uprobe_multi_run_ctx, run_ctx);
> +       run_ctx = container_of(current->bpf_ctx, struct bpf_uprobe_multi_run_ctx,
> +                              session_ctx.run_ctx);
>         return run_ctx->entry_ip;
>  }
>
> @@ -3374,7 +3380,8 @@ static u64 bpf_uprobe_multi_cookie(struct bpf_run_ctx *ctx)
>  {
>         struct bpf_uprobe_multi_run_ctx *run_ctx;
>
> -       run_ctx = container_of(current->bpf_ctx, struct bpf_uprobe_multi_run_ctx, run_ctx);
> +       run_ctx = container_of(current->bpf_ctx, struct bpf_uprobe_multi_run_ctx,
> +                              session_ctx.run_ctx);
>         return run_ctx->uprobe->cookie;
>  }
>
> @@ -3565,7 +3572,7 @@ 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 (!is_kprobe_session(prog))
> +       if (!is_kprobe_session(prog) && !is_uprobe_session(prog))
>                 return -EACCES;
>
>         return 0;
> --
> 2.45.2
>
>

  reply	other threads:[~2024-07-02 21:31 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-01 16:41 [PATCHv2 bpf-next 0/9] uprobe, bpf: Add session support Jiri Olsa
2024-07-01 16:41 ` [PATCHv2 bpf-next 1/9] uprobe: Add support for session consumer Jiri Olsa
2024-07-02 13:04   ` Peter Zijlstra
2024-07-02 16:10     ` Jiri Olsa
2024-07-02 20:52       ` Andrii Nakryiko
2024-07-03 15:31         ` Jiri Olsa
2024-07-03 16:20           ` Jiri Olsa
2024-07-03 21:41           ` Andrii Nakryiko
2024-07-02 20:51   ` Andrii Nakryiko
2024-07-03  8:10     ` Peter Zijlstra
2024-07-03 18:31       ` Andrii Nakryiko
2024-07-03 20:36         ` Kees Cook
2024-07-05  7:10           ` Peter Zijlstra
2024-07-05 23:10             ` Kees Cook
2024-07-03 17:13     ` Jiri Olsa
2024-07-03 21:48       ` Andrii Nakryiko
2024-07-05 13:29         ` Jiri Olsa
2024-07-02 23:55   ` Masami Hiramatsu
2024-07-03  0:13     ` Andrii Nakryiko
2024-07-03 16:09       ` Jiri Olsa
2024-07-03 21:43         ` Andrii Nakryiko
2024-07-05  8:35           ` Masami Hiramatsu
2024-07-05 13:38             ` Jiri Olsa
2024-07-08  9:41               ` Peter Zijlstra
2024-07-01 16:41 ` [PATCHv2 bpf-next 2/9] bpf: Add support for uprobe multi session attach Jiri Olsa
2024-07-02 21:30   ` Andrii Nakryiko
2024-07-01 16:41 ` [PATCHv2 bpf-next 3/9] bpf: Add support for uprobe multi session context Jiri Olsa
2024-07-02 21:31   ` Andrii Nakryiko [this message]
2024-07-01 16:41 ` [PATCHv2 bpf-next 4/9] libbpf: Add support for uprobe multi session attach Jiri Olsa
2024-07-02 21:34   ` Andrii Nakryiko
2024-07-03 17:14     ` Jiri Olsa
2024-07-01 16:41 ` [PATCHv2 bpf-next 5/9] libbpf: Add uprobe session attach type names to attach_type_name Jiri Olsa
2024-07-02 21:56   ` Andrii Nakryiko
2024-07-03 17:15     ` Jiri Olsa
2024-07-01 16:41 ` [PATCHv2 bpf-next 6/9] selftests/bpf: Add uprobe session test Jiri Olsa
2024-07-02 21:57   ` Andrii Nakryiko
2024-07-01 16:41 ` [PATCHv2 bpf-next 7/9] selftests/bpf: Add uprobe session cookie test Jiri Olsa
2024-07-02 21:58   ` Andrii Nakryiko
2024-07-01 16:41 ` [PATCHv2 bpf-next 8/9] selftests/bpf: Add uprobe session recursive test Jiri Olsa
2024-07-02 22:01   ` Andrii Nakryiko
2024-07-03 17:16     ` Jiri Olsa
2024-07-01 16:41 ` [PATCHv2 bpf-next 9/9] selftests/bpf: Add uprobe session consumers test Jiri Olsa
2024-07-02 22:10   ` Andrii Nakryiko
2024-07-03 17:22     ` 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=CAEf4BzbvA98fVtc9yf5zP2Bf3WbJ1wc7ZeXSR3FSvG-VV3zAKA@mail.gmail.com \
    --to=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=jolsa@kernel.org \
    --cc=kafai@fb.com \
    --cc=kpsingh@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.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;
as well as URLs for NNTP newsgroup(s).