All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Delyan Kratunov <delyank@fb.com>
Cc: "daniel@iogearbox.net" <daniel@iogearbox.net>,
	"ast@kernel.org" <ast@kernel.org>,
	"andrii@kernel.org" <andrii@kernel.org>,
	"bpf@vger.kernel.org" <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf-next 3/5] bpf: allow sleepable uprobe programs to attach
Date: Thu, 28 Apr 2022 11:22:19 -0700	[thread overview]
Message-ID: <CAEf4BzZb5t5L4MuTxfm0QK0z9c_PmeBrYsj4qByZCWq0v8378A@mail.gmail.com> (raw)
In-Reply-To: <9bae67335d76cfffadf9777be79c32c0f1deb897.1651103126.git.delyank@fb.com>

On Thu, Apr 28, 2022 at 9:54 AM Delyan Kratunov <delyank@fb.com> wrote:
>
> uprobe and kprobe programs have the same program type, KPROBE, which is
> currently not allowed to load sleepable programs.
>
> To avoid adding a new UPROBE type, we instead allow sleepable KPROBE
> programs to load and defer the is-it-actually-a-uprobe-program check
> to attachment time, where we're already validating the corresponding
> perf_event.
>
> A corollary of this patch is that you can now load a sleepable kprobe
> program but cannot attach it.
>
> Signed-off-by: Delyan Kratunov <delyank@fb.com>
> ---
>  kernel/bpf/syscall.c  | 8 ++++++++
>  kernel/bpf/verifier.c | 4 ++--
>  2 files changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index e9e3e49c0eb7..3ce923f489d7 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -3009,6 +3009,14 @@ static int bpf_perf_link_attach(const union bpf_attr *attr, struct bpf_prog *pro
>         }
>
>         event = perf_file->private_data;
> +       if (prog->aux->sleepable) {
> +               if (!event->tp_event || (event->tp_event->flags & TRACE_EVENT_FL_UPROBE) == 0) {

so far TRACE_EVENT_FL_UPROBE was contained to within kernel/trace so
far, maybe it's better to instead expose a helper function to check if
perf_event represents uprobe?

> +                       err = -EINVAL;
> +                       bpf_link_cleanup(&link_primer);
> +                       goto out_put_file;
> +               }
> +       }
> +
>         err = perf_event_set_bpf_prog(event, prog, attr->link_create.perf_event.bpf_cookie);
>         if (err) {
>                 bpf_link_cleanup(&link_primer);
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 71827d14724a..c6258118dd75 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -14313,8 +14313,8 @@ static int check_attach_btf_id(struct bpf_verifier_env *env)
>         }
>
>         if (prog->aux->sleepable && prog->type != BPF_PROG_TYPE_TRACING &&
> -           prog->type != BPF_PROG_TYPE_LSM) {
> -               verbose(env, "Only fentry/fexit/fmod_ret and lsm programs can be sleepable\n");
> +           prog->type != BPF_PROG_TYPE_LSM && prog->type != BPF_PROG_TYPE_KPROBE) {
> +               verbose(env, "Only fentry/fexit/fmod_ret, lsm, and kprobe/uprobe programs can be sleepable\n");
>                 return -EINVAL;
>         }
>
> --
> 2.35.1

  reply	other threads:[~2022-04-28 18:22 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-28 16:53 [PATCH bpf-next 0/5] sleepable uprobe support Delyan Kratunov
2022-04-28 16:53 ` [PATCH bpf-next 4/5] libbpf: add support for sleepable kprobe and uprobe programs Delyan Kratunov
2022-04-28 18:33   ` Andrii Nakryiko
2022-04-28 19:11     ` Delyan Kratunov
2022-04-28 16:53 ` [PATCH bpf-next 5/5] selftests/bpf: add tests for sleepable kprobes and uprobes Delyan Kratunov
2022-04-28 18:41   ` Andrii Nakryiko
2022-04-28 16:53 ` [PATCH bpf-next 1/5] bpf: move bpf_prog to bpf.h Delyan Kratunov
2022-04-28 16:54 ` [PATCH bpf-next 2/5] bpf: implement sleepable uprobes by chaining tasks and normal rcu Delyan Kratunov
2022-04-28 18:19   ` Andrii Nakryiko
2022-04-28 19:15     ` Delyan Kratunov
2022-04-28 20:58       ` Alexei Starovoitov
2022-04-28 21:35         ` Delyan Kratunov
2022-04-28 22:52           ` Alexei Starovoitov
2022-05-02 17:31             ` Delyan Kratunov
2022-04-28 16:54 ` [PATCH bpf-next 3/5] bpf: allow sleepable uprobe programs to attach Delyan Kratunov
2022-04-28 18:22   ` Andrii Nakryiko [this message]
2022-04-28 18:40     ` Alexei Starovoitov

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=CAEf4BzZb5t5L4MuTxfm0QK0z9c_PmeBrYsj4qByZCWq0v8378A@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=delyank@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.