BPF List
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Puranjay Mohan <puranjay@kernel.org>, bpf@vger.kernel.org
Cc: Puranjay Mohan <puranjay12@gmail.com>,
	Alexei Starovoitov <ast@kernel.org>,
	 Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Martin KaFai Lau	 <martin.lau@kernel.org>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>,
	kernel-team@meta.com
Subject: Re: [PATCH bpf-next 2/5] bpf: Add KF_FORBID_SLEEP modifier for KF_ACQUIRE kfuncs
Date: Thu, 19 Feb 2026 14:19:21 -0800	[thread overview]
Message-ID: <99fd7227e0abc0558a2954e95c1e049edc9ba7b3.camel@gmail.com> (raw)
In-Reply-To: <20260218182555.1501495-3-puranjay@kernel.org>

On Wed, 2026-02-18 at 10:25 -0800, Puranjay Mohan wrote:

[...]

> @@ -10510,6 +10514,8 @@ static int release_reference_nomark(struct bpf_verifier_state *state, int ref_ob
>  		if (state->refs[i].type != REF_TYPE_PTR)
>  			continue;
>  		if (state->refs[i].id == ref_obj_id) {
> +			if (state->refs[i].forbid_sleep)
> +				state->forbid_sleep_count--;

Nit: I'd do it inside release_reference_state() just to have a
     fool-proof point for decrementing this counter.
     As it stands release_reference_state() is called from two
     more places and one need to think if .forbid_sleep_count
     needs to be handled there as well (it is not, at the moment).

>  			release_reference_state(state, i);
>  			return 0;
>  		}
> @@ -10847,7 +10853,8 @@ static int check_func_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
>  
>  		if (env->subprog_info[subprog].might_sleep &&
>  		    (env->cur_state->active_rcu_locks || env->cur_state->active_preempt_locks ||
> -		     env->cur_state->active_irq_id || !in_sleepable(env))) {
> +		     env->cur_state->active_irq_id || env->cur_state->forbid_sleep_count ||
> +		     !in_sleepable(env))) {

The whole expression is the same as '!in_sleepable_context(env)', right?

>  			verbose(env, "global functions that may sleep are not allowed in non-sleepable context,\n"
>  				     "i.e., in a RCU/IRQ/preempt-disabled section, or in\n"
>  				     "a non-sleepable BPF program context\n");
> @@ -11435,6 +11442,11 @@ static int check_resource_leak(struct bpf_verifier_env *env, bool exception_exit
>  		return -EINVAL;
>  	}
>  
> +	if (check_lock && env->cur_state->forbid_sleep_count) {
> +		verbose(env, "%s cannot be used inside nosleep region\n", prefix);
> +		return -EINVAL;
> +	}
> +

Is this check really necessary?
Some resource is forbidding sleep here, so there would be an error report already.

[...]

> @@ -11658,6 +11671,14 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn
>  		}
>  	}
>  
> +	if (env->cur_state->forbid_sleep_count) {
> +		if (fn->might_sleep) {
> +			verbose(env, "sleepable helper %s#%d in nosleep region\n",
> +				func_id_name(func_id), func_id);
> +			return -EINVAL;
> +		}
> +	}
> +

Wdyt about consolidating this code as something like:

  if (fn->might_sleep && !in_sleepable_context(env)) {
	verbose(env, "sleepable helper %s#%d in %s region\n",
		func_id_name(func_id), func_id, non_sleepable_context_description(env));
	return -EINVAL;
  }

?

[...]

> @@ -14113,6 +14139,11 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
>  		return -EACCES;
>  	}
>  
> +	if (sleepable && env->cur_state->forbid_sleep_count) {
> +		verbose(env, "sleepable kfunc %s in nosleep region\n", func_name);
> +		return -EACCES;
> +	}
> +

Above this check there is:

        if (sleepable && !in_sleepable(env)) {
                verbose(env, "program must be sleepable to call sleepable kfunc %s\n", func_name);
                return -EACCES;
        }

Should it be `sleepable && !in_sleepable_context(env)` instead?
If it should, then this hunk would be redundant.

[...]

  parent reply	other threads:[~2026-02-19 22:19 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-18 18:25 [PATCH bpf-next 0/5] Introduce KF_FORBID_SLEEP modifier for acquire/release kfuncs Puranjay Mohan
2026-02-18 18:25 ` [PATCH bpf-next 1/5] bpf: Add KF_ACQUIRE and KF_RELEASE support for iterators Puranjay Mohan
2026-02-19 17:45   ` Mykyta Yatsenko
2026-02-19 20:37   ` Eduard Zingerman
2026-02-20  1:05     ` Puranjay Mohan
2026-02-20  1:09       ` Eduard Zingerman
2026-02-18 18:25 ` [PATCH bpf-next 2/5] bpf: Add KF_FORBID_SLEEP modifier for KF_ACQUIRE kfuncs Puranjay Mohan
2026-02-19  3:24   ` Alexei Starovoitov
2026-02-20  0:14     ` Puranjay Mohan
2026-02-19 22:19   ` Eduard Zingerman [this message]
2026-02-20  0:51     ` Puranjay Mohan
2026-02-18 18:25 ` [PATCH bpf-next 3/5] bpf: Move locking to bpf_iter_task_vma_next() Puranjay Mohan
2026-02-18 18:25 ` [PATCH bpf-next 4/5] bpf: Add split iteration support to task_vma iterator Puranjay Mohan
2026-02-18 18:25 ` [PATCH bpf-next 5/5] selftests/bpf: Add tests for split " Puranjay Mohan

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=99fd7227e0abc0558a2954e95c1e049edc9ba7b3.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@meta.com \
    --cc=martin.lau@kernel.org \
    --cc=memxor@gmail.com \
    --cc=mykyta.yatsenko5@gmail.com \
    --cc=puranjay12@gmail.com \
    --cc=puranjay@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