From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>,
Daniel Borkmann <daniel@iogearbox.net>,
"Paul E . McKenney" <paulmck@kernel.org>,
Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>,
Kernel Team <kernel-team@fb.com>
Subject: Re: [PATCH RFC v3 bpf-next 4/4] selftests/bpf: basic sleepable tests
Date: Thu, 18 Jun 2020 15:43:04 -0700 [thread overview]
Message-ID: <CAEf4Bzb3xfowOkrFC-KzHF5C_8_YMTwrut=s-b+hrh_sEuVHoQ@mail.gmail.com> (raw)
In-Reply-To: <20200611222340.24081-5-alexei.starovoitov@gmail.com>
On Thu, Jun 11, 2020 at 3:25 PM Alexei Starovoitov
<alexei.starovoitov@gmail.com> wrote:
>
> From: Alexei Starovoitov <ast@kernel.org>
>
> Modify few tests to sanity test sleepable bpf functionality.
>
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
> Acked-by: KP Singh <kpsingh@google.com>
> ---
> tools/testing/selftests/bpf/bench.c | 2 ++
> .../selftests/bpf/benchs/bench_trigger.c | 17 +++++++++++++++++
> tools/testing/selftests/bpf/progs/lsm.c | 14 ++++++++++++--
> .../testing/selftests/bpf/progs/trigger_bench.c | 7 +++++++
> 4 files changed, 38 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/bench.c b/tools/testing/selftests/bpf/bench.c
> index 944ad4721c83..1a427685a8a8 100644
> --- a/tools/testing/selftests/bpf/bench.c
> +++ b/tools/testing/selftests/bpf/bench.c
> @@ -317,6 +317,7 @@ extern const struct bench bench_trig_tp;
> extern const struct bench bench_trig_rawtp;
> extern const struct bench bench_trig_kprobe;
> extern const struct bench bench_trig_fentry;
> +extern const struct bench bench_trig_fentry_sleep;
> extern const struct bench bench_trig_fmodret;
> extern const struct bench bench_rb_libbpf;
> extern const struct bench bench_rb_custom;
> @@ -338,6 +339,7 @@ static const struct bench *benchs[] = {
> &bench_trig_rawtp,
> &bench_trig_kprobe,
> &bench_trig_fentry,
> + &bench_trig_fentry_sleep,
Can you please add results to commit description for fentry and
fentry_sleep benchmark, just for comparison?
> &bench_trig_fmodret,
> &bench_rb_libbpf,
> &bench_rb_custom,
[...]
>
> @@ -28,6 +30,9 @@ int BPF_PROG(test_int_hook, struct vm_area_struct *vma,
> is_stack = (vma->vm_start <= vma->vm_mm->start_stack &&
> vma->vm_end >= vma->vm_mm->start_stack);
>
> + bpf_copy_from_user(args, sizeof(args), (void *)vma->vm_mm->arg_start);
is there some way to ensure that user memory definitely is not paged
in (and do it from user-space selftest part), so that
bpf_copy_from_user() *definitely* sleeps? That would be the real test.
As is, even bpf_probe_read_user() might succeed as well, isn't that
right?
Seems like doing madvise(MADV_DONTNEED) should be able to accomplish
that? So instead of reading arg_start, we can pre-setup mmap()'ed
file, MADV_DONTNEED it, then trigger LSM program and let it attempt
reading that chunk of memory?
> + /*bpf_printk("args=%s\n", args);*/
debugging leftover?
> +
> if (is_stack && monitored_pid == pid) {
> mprotect_count++;
> ret = -EPERM;
> @@ -36,7 +41,7 @@ int BPF_PROG(test_int_hook, struct vm_area_struct *vma,
> return ret;
> }
>
> -SEC("lsm/bprm_committed_creds")
> +SEC("lsm.s/bprm_committed_creds")
> int BPF_PROG(test_void_hook, struct linux_binprm *bprm)
> {
> __u32 pid = bpf_get_current_pid_tgid() >> 32;
> @@ -46,3 +51,8 @@ int BPF_PROG(test_void_hook, struct linux_binprm *bprm)
>
> return 0;
> }
nit: empty line here, don't squash those functions together :)
> +SEC("lsm/task_free") /* lsm/ is ok, lsm.s/ fails */
> +int BPF_PROG(test_task_free, struct task_struct *task)
> +{
> + return 0;
> +}
> diff --git a/tools/testing/selftests/bpf/progs/trigger_bench.c b/tools/testing/selftests/bpf/progs/trigger_bench.c
> index 8b36b6640e7e..9a4d09590b3d 100644
> --- a/tools/testing/selftests/bpf/progs/trigger_bench.c
> +++ b/tools/testing/selftests/bpf/progs/trigger_bench.c
> @@ -39,6 +39,13 @@ int bench_trigger_fentry(void *ctx)
> return 0;
> }
>
> +SEC("fentry.s/__x64_sys_getpgid")
> +int bench_trigger_fentry_sleep(void *ctx)
> +{
> + __sync_add_and_fetch(&hits, 1);
> + return 0;
> +}
> +
> SEC("fmod_ret/__x64_sys_getpgid")
> int bench_trigger_fmodret(void *ctx)
> {
> --
> 2.23.0
>
prev parent reply other threads:[~2020-06-18 22:43 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-11 22:23 [PATCH RFC v3 bpf-next 0/4] bpf: Introduce minimal support for sleepable progs Alexei Starovoitov
2020-06-11 22:23 ` [PATCH RFC v3 bpf-next 1/4] bpf: Introduce sleepable BPF programs Alexei Starovoitov
2020-06-11 22:29 ` Alexei Starovoitov
2020-06-12 0:04 ` Paul E. McKenney
2020-06-12 2:13 ` Alexei Starovoitov
2020-06-12 3:40 ` Paul E. McKenney
2020-06-11 22:23 ` [PATCH RFC v3 bpf-next 2/4] bpf: Add bpf_copy_from_user() helper Alexei Starovoitov
2020-06-18 22:33 ` Andrii Nakryiko
2020-06-30 0:28 ` Alexei Starovoitov
2020-06-30 18:23 ` Andrii Nakryiko
2020-06-30 18:53 ` Alexei Starovoitov
2020-06-11 22:23 ` [PATCH RFC v3 bpf-next 3/4] libbpf: support sleepable progs Alexei Starovoitov
2020-06-18 22:34 ` Andrii Nakryiko
2020-06-11 22:23 ` [PATCH RFC v3 bpf-next 4/4] selftests/bpf: basic sleepable tests Alexei Starovoitov
2020-06-18 22:43 ` Andrii Nakryiko [this message]
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='CAEf4Bzb3xfowOkrFC-KzHF5C_8_YMTwrut=s-b+hrh_sEuVHoQ@mail.gmail.com' \
--to=andrii.nakryiko@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.org \
--cc=paulmck@kernel.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 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).