Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70D4933C1B4 for ; Tue, 24 Feb 2026 21:26:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771968367; cv=none; b=Yj1mcxA6Cue4pgFS/74T4CnqLOgquy5nysvEr68APyIipwjzt9BIWZKHZA7tlh9ZsLDCuxBLASICD9dFxzXWREBrb14xvTe6U20Rm97/ylfumVryv26pauBsB8ZzsfYaq5hE14cvZ5pgzRGcBWIgXCcC8LNsFGmc0HS5ZMYptcA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771968367; c=relaxed/simple; bh=pZkuqWPNl3sq4ongB4ipVgFuZ6g5V6oYZG+OuZqBZ9w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IPi0lw2oB55CIzp09dZrkyr6sKsthhZKMgcpOjzfL6jb6HGyarET74hZKjpKGzbncsKhFXYbVO4l7Pf30y9VsGuw2pqGsPM+2Qn9zGtZZN0fgiU09Veps/+IBBA4aoRkhx75GKhBXQYtCz0eG+N8VyLHTxDMNmDaWSRVhlDAlRo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kEU5xL3v; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kEU5xL3v" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21280C116D0; Tue, 24 Feb 2026 21:26:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771968367; bh=pZkuqWPNl3sq4ongB4ipVgFuZ6g5V6oYZG+OuZqBZ9w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kEU5xL3vsaPHX2RJ/XZNx9B+0DhPHB/BiW+dHJXT6W0arMgc+4q0wanN9chMCbTq7 g/tmMQ79CyKxMPMTz1wBxUU9cZYjG1DXuerK5H47UWh+8TGdnkW54j79WB9c9Ldhdd JTzj3HF8neAnqvAT9C6zQMpPZIRp558ITDA6gpFwwYW9Rwwf+Snk8gPKWkEyOJ/ZIh vbu/UGk3HCcAn4nHi38GsgG6xwUd0RyKBUzsWFlnDkZveWM6Od8aEBzxzsVxKRXtgU SAF3ufsvmbQSj7b1UO6ys6dWnd43tzvgXuO6te8b7ChbFzpIgUCbV304X0cFs2O4Tu qu6ydvB8ghUSw== From: Puranjay Mohan To: bpf@vger.kernel.org Cc: Puranjay Mohan , Puranjay Mohan , Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Martin KaFai Lau , Eduard Zingerman , Kumar Kartikeya Dwivedi , Mykyta Yatsenko , kernel-team@meta.com Subject: [PATCH bpf-next v4 2/7] bpf: consolidate sleepable checks in check_helper_call() Date: Tue, 24 Feb 2026 13:25:24 -0800 Message-ID: <20260224212535.1165151-3-puranjay@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260224212535.1165151-1-puranjay@kernel.org> References: <20260224212535.1165151-1-puranjay@kernel.org> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit check_helper_call() prints the error message for every env->cur_state->active* element when calling a sleepable helper. Consolidate all of them into a single print statement. The check for env->cur_state->active_locks was not part of the removed print statements and will not be triggered with the consolidated print as well because it is checked in do_check() before check_helper_call() is even reached. Signed-off-by: Puranjay Mohan --- kernel/bpf/verifier.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index af18cda06dc1..ddfb88b8ddd2 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -11581,6 +11581,19 @@ static inline bool in_sleepable_context(struct bpf_verifier_env *env) in_sleepable(env); } +static const char *non_sleepable_context_description(struct bpf_verifier_env *env) +{ + if (env->cur_state->active_rcu_locks) + return "rcu_read_lock region"; + if (env->cur_state->active_preempt_locks) + return "non-preemptible region"; + if (env->cur_state->active_irq_id) + return "IRQ-disabled region"; + if (env->cur_state->active_locks) + return "lock region"; + return "non-sleepable context"; +} + static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn, int *insn_idx_p) { @@ -11641,28 +11654,11 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn return err; } - if (env->cur_state->active_rcu_locks) { - if (fn->might_sleep) { - verbose(env, "sleepable helper %s#%d in rcu_read_lock region\n", - func_id_name(func_id), func_id); - return -EINVAL; - } - } - - if (env->cur_state->active_preempt_locks) { - if (fn->might_sleep) { - verbose(env, "sleepable helper %s#%d in non-preemptible region\n", - func_id_name(func_id), func_id); - return -EINVAL; - } - } - - if (env->cur_state->active_irq_id) { - if (fn->might_sleep) { - verbose(env, "sleepable helper %s#%d in IRQ-disabled region\n", - func_id_name(func_id), func_id); - return -EINVAL; - } + if (fn->might_sleep && !in_sleepable_context(env)) { + verbose(env, "sleepable helper %s#%d in %s\n", + func_id_name(func_id), func_id, + non_sleepable_context_description(env)); + return -EINVAL; } /* Track non-sleepable context for helpers. */ -- 2.47.3