Re: [PATCH bpf-next v1 09/14] selftests/bpf: Test non-sleepable kfunc context

Eduard Zingerman <[email protected]>
Newsgroups org.kernel.vger.bpf
Message-ID <[email protected]>
On Sun, 2026-08-16 at 03:57 +0200, Kumar Kartikeya Dwivedi wrote:

...

> --- a/tools/testing/selftests/bpf/progs/preempt_lock.c
> +++ b/tools/testing/selftests/bpf/progs/preempt_lock.c
> @@ -6,6 +6,8 @@
>  #include "bpf_experimental.h"
>  
>  extern int bpf_copy_from_user_str(void *dst, u32 dst__sz, const void *unsafe_ptr__ign, u64 flags) __weak __ksym;
> +extern void bpf_rcu_read_lock(void) __ksym;
> +extern void bpf_rcu_read_unlock(void) __ksym;
>  
>  SEC("?tc")
>  __failure __msg("BPF_EXIT instruction in main prog cannot be used inside bpf_preempt_disable-ed region")
> @@ -127,6 +129,19 @@ int preempt_sleepable_kfunc(void *ctx)
>  	return 0;
>  }
>  
> +SEC("?fentry/" SYS_PREFIX "sys_getpgid")
> +__failure __msg("program must be sleepable to call sleepable kfunc bpf_copy_from_user_str")
> +__msg("cannot be used in non-sleepable program")
> +int non_sleepable_kfunc_in_rcu(void *ctx)
> +{
> +	u32 data;
> +
> +	bpf_rcu_read_lock();
> +	bpf_copy_from_user_str(&data, sizeof(data), NULL, 0);
> +	bpf_rcu_read_unlock();
> +	return 0;
> +}
> +

Tbh, I'd just add two tests: one with a call inside rcu, another from
a program context and match new messages. We are going to switch away
from those anyway.

>  int __noinline preempt_global_subprog(void)
>  {
>  	preempt_balance_subprog();
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.