From: Leon Hwang <leon.hwang@linux.dev>
To: Viktor Malik <vmalik@redhat.com>, bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
John Fastabend <john.fastabend@gmail.com>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@fomichev.me>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>, Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>, Shuah Khan <shuah@kernel.org>
Subject: Re: [PATCH bpf-next v2 1/3] bpf: Always allow sleepable programs on syscalls
Date: Mon, 9 Mar 2026 10:37:38 +0800 [thread overview]
Message-ID: <4b3512ea-34a5-4ffd-8b73-1b2c95929b77@linux.dev> (raw)
In-Reply-To: <df4e8730627c311b18fb0634989070eaa1567c75.1772804199.git.vmalik@redhat.com>
On 6/3/26 21:40, Viktor Malik wrote:
> Sleepable BPF programs can only be attached to selected functions. For
> convenience, the error injection list was originally used, which
> contains syscalls and several other functions.
>
> When error injection is disabled (CONFIG_FUNCTION_ERROR_INJECTION=n),
> that list is empty and sleepable tracing programs are effectively
> unavailable. In such a case, at least enable sleepable programs on
> syscalls. For discussion why syscalls were chosen, see [1].
>
> To detect that a function is a syscall handler, we check for
> arch-specific prefixes for the most common architectures. Unfortunately,
> the prefixes are hard-coded in arch syscall code so we need to hard-code
> them, too.
>
> [1] https://lore.kernel.org/bpf/CAADnVQK6qP8izg+k9yV0vdcT-+=axtFQ2fKw7D-2Ei-V6WS5Dw@mail.gmail.com/
>
> Signed-off-by: Viktor Malik <vmalik@redhat.com>
> ---
> kernel/bpf/verifier.c | 58 ++++++++++++++++++++++++++++++++++++++-----
> 1 file changed, 52 insertions(+), 6 deletions(-)
>
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index d92cf2821657..458fc528ccc6 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -24930,6 +24930,8 @@ static int check_attach_modify_return(unsigned long addr, const char *func_name)
> return -EINVAL;
> }
>
> +#ifdef CONFIG_FUNCTION_ERROR_INJECTION
> +
> /* list of non-sleepable functions that are otherwise on
> * ALLOW_ERROR_INJECTION list
> */
> @@ -24951,6 +24953,55 @@ static int check_non_sleepable_error_inject(u32 btf_id)
> return btf_id_set_contains(&btf_non_sleepable_error_inject, btf_id);
> }
>
> +static int check_attach_sleepable(u32 btf_id, unsigned long addr, const char *func_name)
> +{
> + /* fentry/fexit/fmod_ret progs can be sleepable if they are
> + * attached to ALLOW_ERROR_INJECTION and are not in denylist.
> + */
> + if (!check_non_sleepable_error_inject(btf_id) &&
> + within_error_injection_list(addr))
> + return 0;
> +
> + return -EINVAL;
> +}
> +
> +#else
> +
> +/* Unfortunately, the arch-specific prefixes are hard-coded in arch syscall code
> + * so we need to hard-code them, too. Ftrace has arch_syscall_match_sym_name()
> + * but that just compares two concrete function names.
> + */> +static bool has_arch_syscall_prefix(const char *func_name)
> +{
> +#if defined(__x86_64__)
> + return !strncmp(func_name, "__x64_", 6);
> +#elif defined(__i386__)
> + return !strncmp(func_name, "__ia32_", 7);
> +#elif defined(__s390x__)
> + return !strncmp(func_name, "__s390x_", 8);
> +#elif defined(__aarch64__)
> + return !strncmp(func_name, "__arm64_", 8);
> +#elif defined(__riscv)
> + return !strncmp(func_name, "__riscv_", 8);
> +#elif defined(__powerpc__) || defined(__powerpc64__)
> + return !strncmp(func_name, "sys_", 4);
LoongArch is missing here, as LoongArch supports trampoline.
#elif defined(__loongarch__)
return !strncmp(func_name, "sys_", 4);
After adding it,
Acked-by: Leon Hwang <leon.hwang@linux.dev>
Thanks,
Leon
> +#else
> + return false;
> +#endif
> +}
> +
> +/* Without error injection, allow sleepable progs on syscalls. */
> +
> +static int check_attach_sleepable(u32 btf_id, unsigned long addr, const char *func_name)
> +{
> + if (has_arch_syscall_prefix(func_name))
> + return 0;
> +
> + return -EINVAL;
> +}
> +
> +#endif /* CONFIG_FUNCTION_ERROR_INJECTION */
> +
> int bpf_check_attach_target(struct bpf_verifier_log *log,
> const struct bpf_prog *prog,
> const struct bpf_prog *tgt_prog,
> @@ -25230,12 +25281,7 @@ int bpf_check_attach_target(struct bpf_verifier_log *log,
> ret = -EINVAL;
> switch (prog->type) {
> case BPF_PROG_TYPE_TRACING:
> -
> - /* fentry/fexit/fmod_ret progs can be sleepable if they are
> - * attached to ALLOW_ERROR_INJECTION and are not in denylist.
> - */
> - if (!check_non_sleepable_error_inject(btf_id) &&
> - within_error_injection_list(addr))
> + if (!check_attach_sleepable(btf_id, addr, tname))
> ret = 0;
> /* fentry/fexit/fmod_ret progs can also be sleepable if they are
> * in the fmodret id set with the KF_SLEEPABLE flag.
next prev parent reply other threads:[~2026-03-09 2:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-06 13:40 [PATCH bpf-next v2 0/3] Always allow sleepable and fmod_ret programs on syscalls Viktor Malik
2026-03-06 13:40 ` [PATCH bpf-next v2 1/3] bpf: Always allow sleepable " Viktor Malik
2026-03-06 16:13 ` Kumar Kartikeya Dwivedi
2026-03-09 2:37 ` Leon Hwang [this message]
2026-03-06 13:40 ` [PATCH bpf-next v2 2/3] bpf: Always allow fmod_ret " Viktor Malik
2026-03-06 16:13 ` Kumar Kartikeya Dwivedi
2026-03-09 2:40 ` Leon Hwang
2026-03-06 13:40 ` [PATCH bpf-next v2 3/3] selftests/bpf: Move sleepable refcounted_kptr tests to syscalls Viktor Malik
2026-03-06 16:13 ` Kumar Kartikeya Dwivedi
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=4b3512ea-34a5-4ffd-8b73-1b2c95929b77@linux.dev \
--to=leon.hwang@linux.dev \
--cc=alex@ghiti.fr \
--cc=andrii@kernel.org \
--cc=aou@eecs.berkeley.edu \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=sdf@fomichev.me \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=vmalik@redhat.com \
--cc=yonghong.song@linux.dev \
/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.