From: Puranjay Mohan <puranjay@kernel.org>
To: Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>,
bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org,
daniel@iogearbox.net, kafai@meta.com, kernel-team@meta.com,
eddyz87@gmail.com
Cc: Mykyta Yatsenko <yatsenko@meta.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>
Subject: Re: [PATCH bpf-next v3 4/4] selftests/bpf: Add tests for sleepable raw tracepoint programs
Date: Wed, 11 Mar 2026 23:41:19 +0000 [thread overview]
Message-ID: <m2bjguj5nk.fsf@kernel.org> (raw)
In-Reply-To: <20260311-sleepable_tracepoints-v3-4-3e9bbde5bd22@meta.com>
Mykyta Yatsenko <mykyta.yatsenko5@gmail.com> writes:
> From: Mykyta Yatsenko <yatsenko@meta.com>
>
> Add tests for sleepable raw tracepoint programs:
> - success: Attach a sleepable BPF program to the faultable sys_enter
> tracepoint (tp_btf.s/sys_enter). Verify the program is triggered by
> a syscall.
> - reject_non_faultable: Verify that loading a sleepable BPF program
> targeting a non-faultable tracepoint (tp_btf.s/sched_switch) is
> rejected by the verifier.
>
> Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
Acked-by: Puranjay Mohan <puranjay@kernel.org>
> ---
> .../selftests/bpf/prog_tests/sleepable_raw_tp.c | 40 ++++++++++++++++++++
> .../selftests/bpf/progs/test_sleepable_raw_tp.c | 43 ++++++++++++++++++++++
> .../bpf/progs/test_sleepable_raw_tp_fail.c | 18 +++++++++
> tools/testing/selftests/bpf/verifier/sleepable.c | 17 ++++++++-
> 4 files changed, 116 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/prog_tests/sleepable_raw_tp.c b/tools/testing/selftests/bpf/prog_tests/sleepable_raw_tp.c
> new file mode 100644
> index 000000000000..e902b41591e7
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/sleepable_raw_tp.c
> @@ -0,0 +1,40 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */
> +
> +#include <test_progs.h>
> +#include <time.h>
> +#include "test_sleepable_raw_tp.skel.h"
> +#include "test_sleepable_raw_tp_fail.skel.h"
> +
> +static void test_sleepable_raw_tp_success(void)
> +{
> + struct test_sleepable_raw_tp *skel;
> + int err;
> +
> + skel = test_sleepable_raw_tp__open_and_load();
> + if (!ASSERT_OK_PTR(skel, "skel_open_load"))
> + return;
> +
> + skel->bss->target_pid = getpid();
> +
> + err = test_sleepable_raw_tp__attach(skel);
> + if (!ASSERT_OK(err, "skel_attach"))
> + goto cleanup;
> +
> + syscall(__NR_nanosleep, &(struct timespec){ .tv_nsec = 555 }, NULL);
> +
> + ASSERT_EQ(skel->bss->triggered, 1, "triggered");
> + ASSERT_EQ(skel->bss->err, 0, "err");
> + ASSERT_EQ(skel->bss->copied_tv_nsec, 555, "copied_tv_nsec");
> +
> +cleanup:
> + test_sleepable_raw_tp__destroy(skel);
> +}
> +
> +void test_sleepable_raw_tp(void)
> +{
> + if (test__start_subtest("success"))
> + test_sleepable_raw_tp_success();
> +
> + RUN_TESTS(test_sleepable_raw_tp_fail);
> +}
> diff --git a/tools/testing/selftests/bpf/progs/test_sleepable_raw_tp.c b/tools/testing/selftests/bpf/progs/test_sleepable_raw_tp.c
> new file mode 100644
> index 000000000000..ebacc766df57
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/test_sleepable_raw_tp.c
> @@ -0,0 +1,43 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */
> +
> +#include <vmlinux.h>
> +#include <asm/unistd.h>
> +#include <bpf/bpf_tracing.h>
> +#include <bpf/bpf_core_read.h>
> +#include <bpf/bpf_helpers.h>
> +
> +char _license[] SEC("license") = "GPL";
> +
> +int target_pid;
> +int triggered;
> +long err;
> +long copied_tv_nsec;
> +
> +SEC("tp_btf.s/sys_enter")
> +int BPF_PROG(test_sleepable_sys_enter, struct pt_regs *regs, long id)
> +{
> + struct task_struct *task = bpf_get_current_task_btf();
> + struct __kernel_timespec *ts;
> + long tv_nsec;
> +
> + if (task->pid != target_pid)
> + return 0;
> +
> + if (id != __NR_nanosleep)
> + return 0;
> +
> + ts = (void *)PT_REGS_PARM1_CORE_SYSCALL(regs);
> +
> + /*
> + * Use bpf_copy_from_user() - a sleepable helper - to read user memory.
> + * This exercises the sleepable execution path of raw tracepoints.
> + */
> + err = bpf_copy_from_user(&tv_nsec, sizeof(tv_nsec), &ts->tv_nsec);
> + if (err)
> + return err;
> +
> + copied_tv_nsec = tv_nsec;
> + triggered = 1;
> + return 0;
> +}
> diff --git a/tools/testing/selftests/bpf/progs/test_sleepable_raw_tp_fail.c b/tools/testing/selftests/bpf/progs/test_sleepable_raw_tp_fail.c
> new file mode 100644
> index 000000000000..54100899f728
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/test_sleepable_raw_tp_fail.c
> @@ -0,0 +1,18 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */
> +
> +#include <vmlinux.h>
> +#include <bpf/bpf_tracing.h>
> +#include <bpf/bpf_helpers.h>
> +#include "bpf_misc.h"
> +
> +char _license[] SEC("license") = "GPL";
> +
> +/* Sleepable program on a non-faultable tracepoint should fail to load */
> +SEC("tp_btf.s/sched_switch")
> +__failure __msg("Sleepable program cannot attach to non-faultable tracepoint")
> +int BPF_PROG(test_sleepable_sched_switch, bool preempt,
> + struct task_struct *prev, struct task_struct *next)
> +{
> + return 0;
> +}
> diff --git a/tools/testing/selftests/bpf/verifier/sleepable.c b/tools/testing/selftests/bpf/verifier/sleepable.c
> index 1f0d2bdc673f..6dabc5522945 100644
> --- a/tools/testing/selftests/bpf/verifier/sleepable.c
> +++ b/tools/testing/selftests/bpf/verifier/sleepable.c
> @@ -76,7 +76,20 @@
> .runs = -1,
> },
> {
> - "sleepable raw tracepoint reject",
> + "sleepable raw tracepoint accept",
> + .insns = {
> + BPF_MOV64_IMM(BPF_REG_0, 0),
> + BPF_EXIT_INSN(),
> + },
> + .prog_type = BPF_PROG_TYPE_TRACING,
> + .expected_attach_type = BPF_TRACE_RAW_TP,
> + .kfunc = "sys_enter",
> + .result = ACCEPT,
> + .flags = BPF_F_SLEEPABLE,
> + .runs = -1,
> +},
> +{
> + "sleepable raw tracepoint reject non-faultable",
> .insns = {
> BPF_MOV64_IMM(BPF_REG_0, 0),
> BPF_EXIT_INSN(),
> @@ -85,7 +98,7 @@
> .expected_attach_type = BPF_TRACE_RAW_TP,
> .kfunc = "sched_switch",
> .result = REJECT,
> - .errstr = "Only fentry/fexit/fmod_ret, lsm, iter, uprobe, and struct_ops programs can be sleepable",
> + .errstr = "Sleepable program cannot attach to non-faultable tracepoint",
> .flags = BPF_F_SLEEPABLE,
> .runs = -1,
> },
>
> --
> 2.52.0
next prev parent reply other threads:[~2026-03-11 23:41 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-11 18:22 [PATCH bpf-next v3 0/4] bpf: Add support for sleepable raw tracepoint programs Mykyta Yatsenko
2026-03-11 18:22 ` [PATCH bpf-next v3 1/4] bpf: Add sleepable execution path for " Mykyta Yatsenko
2026-03-11 19:25 ` Emil Tsalapatis
2026-03-11 23:39 ` Puranjay Mohan
2026-03-12 20:51 ` Andrii Nakryiko
2026-03-11 18:22 ` [PATCH bpf-next v3 2/4] bpf: Verifier support for sleepable " Mykyta Yatsenko
2026-03-11 18:49 ` Emil Tsalapatis
2026-03-11 18:53 ` bot+bpf-ci
2026-03-11 23:07 ` Kumar Kartikeya Dwivedi
2026-03-12 5:50 ` Leon Hwang
2026-03-12 6:21 ` Menglong Dong
2026-03-12 6:43 ` Leon Hwang
2026-03-11 23:08 ` Kumar Kartikeya Dwivedi
2026-03-11 23:40 ` Puranjay Mohan
2026-03-12 20:59 ` Andrii Nakryiko
2026-03-11 18:22 ` [PATCH bpf-next v3 3/4] libbpf: Add tp_btf.s section handler for sleepable raw tracepoints Mykyta Yatsenko
2026-03-11 18:54 ` Emil Tsalapatis
2026-03-11 23:40 ` Puranjay Mohan
2026-03-12 20:59 ` Andrii Nakryiko
2026-03-11 18:22 ` [PATCH bpf-next v3 4/4] selftests/bpf: Add tests for sleepable raw tracepoint programs Mykyta Yatsenko
2026-03-11 19:12 ` Emil Tsalapatis
2026-03-11 23:41 ` Puranjay Mohan [this message]
2026-03-12 21:03 ` Andrii Nakryiko
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=m2bjguj5nk.fsf@kernel.org \
--to=puranjay@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=kafai@meta.com \
--cc=kernel-team@meta.com \
--cc=memxor@gmail.com \
--cc=mykyta.yatsenko5@gmail.com \
--cc=yatsenko@meta.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