From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379464; b=Y8ASC/7MqWwOvFvvFthU5IVs9sSL79Cc6Op7M0RflIr5Sq1kBNJqKGBFoIxO3663XWRh 5HOXILckmLXJFrGsaIoDmp90xrf4KCsjs/cgOxriZvgjq0D+tJ96G5ZCjtm022kCIWReh lcw6DKD37qJDlL/g56qrtkujsmgMxoN8j6PK8wkBohAIEt4FG9kwVCbjYdPRmoO0o0Cd4 TMfBlF8Ly52BRMz6x7yx9Mdlr9O79uOOxi6dXC3Zo3Kjj7fUdyxnq5cMXANYxzHWR5Cgu qBpvRZnCfgWS0MYHgnHFbWT1weH03DdOegRNb0xwmyeEUU6KHix1MPoCCJiGtlpcrDQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379464; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=GXlGcUAnORcLyYSaW4hwS0cW0P7XZs6fCxeaIR/oz6Q=; b=EP4Zt1yK9aCMISFAsl/Ww8fhJFuOXzFtJCZPV+2FJQV5FOmMCkD89NFE9tfFdDGTqU9H oZsWcbwH5RucJKgnd970/pY39Oq3Qam7NHXlfRC5k+A64tjAlRAzTo0p12EjodbunVD4D ORsqtxxBbcBXN8k5dErLRJa2SjZlPCg1qF4eeGCwLXZ6WUzk/7fAWfPPFOqyGqYz2YzTV E1hpvbznQ8Gy6MS4zYAAzrSD3pmuwwoBTAicpTSmx1F4vwp+jzcvyMbN8oQ6g47KJ5cNO lhksF4O1/ZQPCxQ+b5XOYH8GA2i79kgq11v+GDZdCyFX6Zsa5LNcQuD2e2P2sXwwbxQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=QnEYeYkf; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1AC28606A322; Fri, 4 Dec 2026 10:17:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=QnEYeYkf Received: by smtp.kernel.org (Postfix) with ESMTPSA id 909B41F000CE; Fri, 4 Dec 2026 10:17:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379464; bh=GXlGcUAnORcLyYSaW4hwS0cW0P7XZs6fCxeaIR/oz6Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=QnEYeYkfOWV8bjy2OPae3JxIgqqiIJgaJSPnhULxvuNdjCKCDnLQ9Uo9kFsVC6YsL 1NHUiU1Jl5Ii3Kcb1gYAbhYV4wHXPvFM1eCAvud28c8EMHMKuxDy54KM8P6YNC7eTL w2Num6xCF9ckjOsLC7V+n9VE/LTo0wJWbqGwOms0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexei Starovoitov , KaFai Wan , Leon Hwang , Tiezhu Yang , Eduard Zingerman , Sasha Levin Subject: [PATCH 6.12 038/555] bpf: Introduce jit_required flag and remove bpf_prog_has_kfunc_call() Date: Fri, 4 Dec 2026 19:01:21 +0900 Message-ID: <20261204100607.262185105@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tiezhu Yang [ Upstream commit 9a6df65d5c6a9947ddab4e563e329720f44b8747 ] Introduce a 'jit_required' bitfield flag in struct bpf_prog to track whether a BPF program strictly requires the JIT compiler to run. This prevents a dangerous runtime fallback to the interpreter for features that are only implemented in the JIT compiler. Currently, bpf_prog_has_kfunc_call() is used only for kernel function calls, replace the kfunc-specific helper with the new 'jit_required' flag. This makes it easy to support other JIT-only BPF features, such as inlined helpers. Suggested-by: Alexei Starovoitov Suggested-by: KaFai Wan Suggested-by: Leon Hwang Acked-by: Leon Hwang Signed-off-by: Tiezhu Yang Signed-off-by: Eduard Zingerman [edit] Adapt the bpf_fixup_call_args() change to fixup_call_args() in kernel/bpf/verifier.c, and the __bpf_prog_select_runtime() change to bpf_prog_select_runtime() in kernel/bpf/core.c. Signed-off-by: Leon Hwang Signed-off-by: Sasha Levin --- include/linux/bpf.h | 9 ++------- kernel/bpf/core.c | 7 ++----- kernel/bpf/verifier.c | 12 ++++-------- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 98f816a37d3be..f2df5c47bef74 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1587,8 +1587,9 @@ struct bpf_prog_aux { struct bpf_prog { u16 pages; /* Number of allocated pages */ - u16 jited:1, /* Is our filter JIT'ed? */ + u32 jited:1, /* Is our filter JIT'ed? */ jit_requested:1,/* archs need to JIT the prog */ + jit_required:1, /* program strictly requires JIT compiler */ gpl_compatible:1, /* Is filter GPL compatible? */ cb_access:1, /* Is control block accessed? */ dst_needed:1, /* Do we need dst entry? */ @@ -2694,7 +2695,6 @@ const struct bpf_func_proto *bpf_base_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog); void bpf_task_storage_free(struct task_struct *task); void bpf_cgrp_storage_free(struct cgroup *cgroup); -bool bpf_prog_has_kfunc_call(const struct bpf_prog *prog); const struct btf_func_model * bpf_jit_find_kfunc_model(const struct bpf_prog *prog, const struct bpf_insn *insn); @@ -2963,11 +2963,6 @@ static inline void bpf_task_storage_free(struct task_struct *task) { } -static inline bool bpf_prog_has_kfunc_call(const struct bpf_prog *prog) -{ - return false; -} - static inline const struct btf_func_model * bpf_jit_find_kfunc_model(const struct bpf_prog *prog, const struct bpf_insn *insn) diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index de2c0ffb30252..f94524481f27b 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -122,6 +122,7 @@ struct bpf_prog *bpf_prog_alloc_no_stats(unsigned int size, gfp_t gfp_extra_flag fp->aux = aux; fp->aux->prog = fp; fp->jit_requested = ebpf_jit_enabled(); + fp->jit_required = IS_ENABLED(CONFIG_BPF_JIT_ALWAYS_ON); fp->blinding_requested = bpf_jit_blinding_enabled(fp); #ifdef CONFIG_CGROUP_BPF aux->cgroup_atype = CGROUP_BPF_ATTACH_TYPE_INVALID; @@ -2531,15 +2532,11 @@ struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err) /* In case of BPF to BPF calls, verifier did all the prep * work with regards to JITing, etc. */ - bool jit_needed = false; + bool jit_needed = fp->jit_required; if (fp->bpf_func) goto finalize; - if (IS_ENABLED(CONFIG_BPF_JIT_ALWAYS_ON) || - bpf_prog_has_kfunc_call(fp)) - jit_needed = true; - if (!bpf_prog_select_interpreter(fp)) jit_needed = true; diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index a5ffecbaa7bf9..f25dfaecb3732 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -2974,6 +2974,8 @@ static int add_kfunc_call(struct bpf_verifier_env *env, u32 func_id, s16 offset) prog_aux->kfunc_tab = tab; } + env->prog->jit_required = 1; + /* func_id == 0 is always invalid, but instead of returning an error, be * conservative and wait until the code elimination pass before returning * error, so that invalid calls that get pruned out can be in BPF programs @@ -3082,11 +3084,6 @@ static void sort_kfunc_descs_by_imm_off(struct bpf_prog *prog) kfunc_desc_cmp_by_imm_off, NULL); } -bool bpf_prog_has_kfunc_call(const struct bpf_prog *prog) -{ - return !!prog->aux->kfunc_tab; -} - const struct btf_func_model * bpf_jit_find_kfunc_model(const struct bpf_prog *prog, const struct bpf_insn *insn) @@ -20970,7 +20967,6 @@ static int fixup_call_args(struct bpf_verifier_env *env) #ifndef CONFIG_BPF_JIT_ALWAYS_ON struct bpf_prog *prog = env->prog; struct bpf_insn *insn = prog->insnsi; - bool has_kfunc_call = bpf_prog_has_kfunc_call(prog); int i, depth; #endif int err = 0; @@ -20984,8 +20980,8 @@ static int fixup_call_args(struct bpf_verifier_env *env) return err; } #ifndef CONFIG_BPF_JIT_ALWAYS_ON - if (has_kfunc_call) { - verbose(env, "calling kernel functions are not allowed in non-JITed programs\n"); + if (prog->jit_required) { + verbose(env, "program requires BPF JIT compiler but it is not available\n"); return -EINVAL; } if (env->subprog_cnt > 1 && env->prog->aux->tail_call_reachable) { -- 2.53.0