All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: KP Singh <kpsingh@chromium.org>
Cc: open list <linux-kernel@vger.kernel.org>,
	bpf <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Paul Turner <pjt@google.com>,
	Florent Revest <revest@chromium.org>,
	Brendan Jackman <jackmanb@chromium.org>
Subject: Re: [PATCH bpf-next 6/7] bpf: Add test ops for BPF_PROG_TYPE_TRACING
Date: Tue, 3 Mar 2020 14:51:57 -0800	[thread overview]
Message-ID: <CAEf4BzZwazh1DnGJKBgFgrp4m5B_3AwjsxkJVBh6cxQceiLcBA@mail.gmail.com> (raw)
In-Reply-To: <20200303140950.6355-7-kpsingh@chromium.org>

On Tue, Mar 3, 2020 at 6:12 AM KP Singh <kpsingh@chromium.org> wrote:
>
> From: KP Singh <kpsingh@google.com>
>
> The current fexit and fentry tests rely on a different program to
> exercise the functions they attach to. Instead of doing this, implement
> the test operations for tracing which will also be used for
> BPF_OVERRIDE_RETURN in a subsequent patch.

typo: BPF_OVERRIDE_RETURN -> BPF_MODIFY_RETURN?

>
> Also, clean up the fexit test to use the generated skeleton.
>
> Signed-off-by: KP Singh <kpsingh@google.com>
> ---

Nice clean up for fexit_test, thank you!

>  include/linux/bpf.h                           | 10 +++
>  kernel/trace/bpf_trace.c                      |  1 +
>  net/bpf/test_run.c                            | 38 +++++++---
>  .../selftests/bpf/prog_tests/fentry_fexit.c   | 12 +---
>  .../selftests/bpf/prog_tests/fentry_test.c    | 14 ++--
>  .../selftests/bpf/prog_tests/fexit_test.c     | 69 ++++++-------------
>  6 files changed, 68 insertions(+), 76 deletions(-)
>
> diff --git a/include/linux/bpf.h b/include/linux/bpf.h
> index 3cfdc216a2f4..c00919025532 100644
> --- a/include/linux/bpf.h
> +++ b/include/linux/bpf.h
> @@ -1156,6 +1156,9 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
>                           union bpf_attr __user *uattr);
>  int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
>                           union bpf_attr __user *uattr);
> +int bpf_prog_test_run_tracing(struct bpf_prog *prog,
> +                             const union bpf_attr *kattr,
> +                             union bpf_attr __user *uattr);
>  int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog,
>                                      const union bpf_attr *kattr,
>                                      union bpf_attr __user *uattr);
> @@ -1313,6 +1316,13 @@ static inline int bpf_prog_test_run_skb(struct bpf_prog *prog,
>         return -ENOTSUPP;
>  }
>
> +static inline int bpf_prog_test_run_tracing(struct bpf_prog *prog,
> +                                           const union bpf_attr *kattr,
> +                                           union bpf_attr __user *uattr)
> +{
> +       return -ENOTSUPP;
> +}
> +
>  static inline int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog,
>                                                    const union bpf_attr *kattr,
>                                                    union bpf_attr __user *uattr)
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index 07764c761073..363e0a2c75cf 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -1266,6 +1266,7 @@ const struct bpf_verifier_ops tracing_verifier_ops = {
>  };
>
>  const struct bpf_prog_ops tracing_prog_ops = {
> +       .test_run = bpf_prog_test_run_tracing,
>  };
>
>  static bool raw_tp_writable_prog_is_valid_access(int off, int size,
> diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
> index 562443f94133..fb54b45285b4 100644
> --- a/net/bpf/test_run.c
> +++ b/net/bpf/test_run.c
> @@ -160,18 +160,38 @@ static void *bpf_test_init(const union bpf_attr *kattr, u32 size,
>                 kfree(data);
>                 return ERR_PTR(-EFAULT);
>         }
> -       if (bpf_fentry_test1(1) != 2 ||
> -           bpf_fentry_test2(2, 3) != 5 ||
> -           bpf_fentry_test3(4, 5, 6) != 15 ||
> -           bpf_fentry_test4((void *)7, 8, 9, 10) != 34 ||
> -           bpf_fentry_test5(11, (void *)12, 13, 14, 15) != 65 ||
> -           bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) != 111) {
> -               kfree(data);
> -               return ERR_PTR(-EFAULT);
> -       }
> +
>         return data;
>  }
>
> +int bpf_prog_test_run_tracing(struct bpf_prog *prog,
> +                             const union bpf_attr *kattr,
> +                             union bpf_attr __user *uattr)
> +{
> +       int err = -EFAULT;
> +
> +       switch (prog->expected_attach_type) {
> +       case BPF_TRACE_FENTRY:
> +       case BPF_TRACE_FEXIT:
> +               if (bpf_fentry_test1(1) != 2 ||
> +                   bpf_fentry_test2(2, 3) != 5 ||
> +                   bpf_fentry_test3(4, 5, 6) != 15 ||
> +                   bpf_fentry_test4((void *)7, 8, 9, 10) != 34 ||
> +                   bpf_fentry_test5(11, (void *)12, 13, 14, 15) != 65 ||
> +                   bpf_fentry_test6(16, (void *)17, 18, 19, (void *)20, 21) != 111)
> +                       goto out;
> +               break;
> +       default:
> +               goto out;
> +       }

No trace_bpf_test_finish here?

> +
> +       return 0;
> +
> +out:
> +       trace_bpf_test_finish(&err);
> +       return err;
> +}
> +
>  static void *bpf_ctx_init(const union bpf_attr *kattr, u32 max_size)
>  {
>         void __user *data_in = u64_to_user_ptr(kattr->test.ctx_in);

[...]

  reply	other threads:[~2020-03-03 22:52 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-03 14:09 [PATCH bpf-next 0/7] Introduce BPF_MODIFY_RET tracing progs KP Singh
2020-03-03 14:09 ` [PATCH bpf-next 1/7] bpf: Refactor trampoline update code KP Singh
2020-03-03 22:12   ` Andrii Nakryiko
2020-03-03 22:24     ` KP Singh
2020-03-03 23:03       ` Andrii Nakryiko
2020-03-03 23:08         ` KP Singh
2020-03-03 14:09 ` [PATCH bpf-next 2/7] bpf: JIT helpers for fmod_ret progs KP Singh
2020-03-03 22:26   ` Andrii Nakryiko
2020-03-03 22:28     ` KP Singh
2020-03-03 23:56       ` Alexei Starovoitov
2020-03-04  1:26         ` KP Singh
2020-03-03 14:09 ` [PATCH bpf-next 3/7] bpf: Introduce BPF_MODIFY_RETURN KP Singh
2020-03-03 22:37   ` Andrii Nakryiko
2020-03-03 22:51     ` KP Singh
2020-03-03 14:09 ` [PATCH bpf-next 4/7] bpf: Attachment verification for BPF_MODIFY_RETURN KP Singh
2020-03-03 22:44   ` Andrii Nakryiko
2020-03-03 23:21     ` KP Singh
2020-03-04  0:03       ` Alexei Starovoitov
2020-03-04  1:06         ` KP Singh
2020-03-03 14:09 ` [PATCH bpf-next 5/7] tools/libbpf: Add support " KP Singh
2020-03-03 22:45   ` Andrii Nakryiko
2020-03-03 14:09 ` [PATCH bpf-next 6/7] bpf: Add test ops for BPF_PROG_TYPE_TRACING KP Singh
2020-03-03 22:51   ` Andrii Nakryiko [this message]
2020-03-03 22:57     ` KP Singh
2020-03-03 14:09 ` [PATCH bpf-next 7/7] bpf: Add selftests for BPF_MODIFY_RETURN KP Singh
2020-03-03 22:58   ` Andrii Nakryiko
2020-03-03 22:12 ` [PATCH bpf-next 0/7] Introduce BPF_MODIFY_RET tracing progs Andrii Nakryiko
2020-03-03 22:25   ` KP Singh

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=CAEf4BzZwazh1DnGJKBgFgrp4m5B_3AwjsxkJVBh6cxQceiLcBA@mail.gmail.com \
    --to=andrii.nakryiko@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=jackmanb@chromium.org \
    --cc=kpsingh@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pjt@google.com \
    --cc=revest@chromium.org \
    /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.