summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEduard Zingerman <eddyz87@gmail.com>2026-08-08 03:03:27 -0700
committerEduard Zingerman <eddyz87@gmail.com>2026-08-08 03:03:27 -0700
commitd114bb98936770c501c958bf2bc5fb6b7c0bad7b (patch)
tree7b0c3ece84cb01379c2d2e9bb9d7c3bd4d2fa1f7 /include
parent8b365b3c68b474a1053ec0755dacdc751578afb0 (diff)
parent4976cce08baa12e4b7ea6dbd1a820d66b09014db (diff)
downloadlinux-d114bb98936770c501c958bf2bc5fb6b7c0bad7b.tar.gz
linux-d114bb98936770c501c958bf2bc5fb6b7c0bad7b.zip
Merge branch 'add-arena-argument-support-to-kfuncs-and-struct_ops'
Kumar Kartikeya Dwivedi says: ==================== Add arena argument support to kfuncs and struct_ops This is a continuation of patches in [0], with mostly minor changes and reordering. The motivation is covered in that link. A major change is moving to two tags (__arena and __arena__nullable) and moving the changes to JIT to emit more optimized sequences. Please see commit logs for details. [0]: https://lore.kernel.org/bpf/20260713024414.3759854-1-tj@kernel.org Changelog: ---------- v4 -> v5 v4: https://lore.kernel.org/bpf/20260805210427.3218326-1-memxor@gmail.com * Remove the redundant patch-8 capability comment and duplicate nullable kfunc test coverage. (Eduard) * Introduce the final bpf_tramp_arena_base() interface directly with function-model argument flags, avoiding temporary slot bitmaps and arena_nullable state; simplify struct_ops pointer validation. (Eduard) * Simplify kfunc arena nullability classification by using the common nullable path for both arena suffixes while leaving the function model to distinguish JIT NULL preservation. (Amery) * Keep bpf_prog_has_arena_ctx_arg() in bpf_verifier.h from its introduction so trampoline and verifier users share one inline definition, avoiding BPF_JIT/BPF_SYSCALL link dependencies. (Eduard, BPF CI Bot) * Reject both tracing and extension attachments to struct_ops programs with arena context arguments, and add fentry, fexit, and freplace rejection tests. (Eduard, Sashiko) v3 -> v4 v3: https://lore.kernel.org/bpf/20260803125115.2264733-1-memxor@gmail.com * Rename __arena_nullable to __arena__nullable and prioritize the composite suffix over __nullable during argument classification. (Sashiko, Eduard) * Resolve instructions before collecting subprograms and kfuncs so kfunc prototype validation can use associated arena state. * Move the arena kfunc and JIT-sequence test entry points into prog_tests/verifier.c. (Eduard) * Match the generated L0 target and call in nullable JIT assertions. (Eduard) * Route arena kfunc validation through the common argument-checking path. (Amery) * Reuse btf_func_model argument flags for struct_ops arena arguments instead of maintaining separate trampoline slot metadata. (Eduard) * Check the generic-trampoline arena argument invariant at link time and warn once on violations. (Eduard) * Reject tracing attachments to struct_ops programs with arena context arguments whose indirect trampolines convert the pointers. (Sashiko) v2 -> v3 v2: https://lore.kernel.org/bpf/20260726013105.3689867-1-memxor@gmail.com * Rebase onto current bpf-next to resolve conflicts. v1 -> v2 v1: https://lore.kernel.org/bpf/20260715220052.1590783-1-memxor@gmail.com * Fix documentation to only mention x86 for now. (Sashiko) * Move arg bitmap from insn_aux_data to kfunc descriptor. (Eduard) ==================== Link: https://patch.msgid.link/20260808003938.3486067-1-memxor@gmail.com Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Diffstat (limited to 'include')
-rw-r--r--include/linux/bpf.h15
-rw-r--r--include/linux/bpf_verifier.h14
-rw-r--r--include/linux/filter.h1
3 files changed, 28 insertions, 2 deletions
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index d79bf7557ef6..b4a10c9878cf 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -1195,6 +1195,12 @@ struct bpf_prog_offload {
/* The argument is signed. */
#define BTF_FMODEL_SIGNED_ARG BIT(1)
+/* The argument is an arena pointer. */
+#define BTF_FMODEL_ARENA_ARG BIT(2)
+
+/* The argument is nullable. */
+#define BTF_FMODEL_NULLABLE_ARG BIT(3)
+
struct btf_func_model {
u8 ret_size;
u8 ret_flags;
@@ -1268,6 +1274,15 @@ struct bpf_tramp_nodes {
int nr_nodes;
};
+/*
+ * The arena base against which a struct_ops trampoline converts the
+ * arguments marked with BTF_FMODEL_ARENA_ARG while saving them into the BPF
+ * ctx, ctx[arg] = (u32)(kaddr - kern_vm_start). Zero when the trampoline
+ * converts nothing.
+ */
+u64 bpf_tramp_arena_base(const struct btf_func_model *m,
+ struct bpf_tramp_nodes *tnodes, u32 flags);
+
struct bpf_tramp_run_ctx;
/* Different use cases for BPF trampoline:
diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
index 2c74d676ede9..93f7c2075eea 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -1172,8 +1172,8 @@ static inline void bpf_trampoline_unpack_key(u64 key, u32 *obj_id, u32 *btf_id)
*btf_id = key & 0x7FFFFFFF;
}
-int bpf_check_btf_info_early(struct bpf_verifier_env *env,
- const union bpf_attr *attr, bpfptr_t uattr);
+int bpf_prepare_btf_info(struct bpf_verifier_env *env,
+ const union bpf_attr *attr, bpfptr_t uattr);
int bpf_check_btf_info(struct bpf_verifier_env *env,
const union bpf_attr *attr, bpfptr_t uattr);
@@ -1297,6 +1297,16 @@ static inline u32 type_flag(u32 type)
return type & ~BPF_BASE_TYPE_MASK;
}
+static inline bool bpf_prog_has_arena_ctx_arg(const struct bpf_prog *prog)
+{
+ int i;
+
+ for (i = 0; i < prog->aux->ctx_arg_info_size; i++)
+ if (base_type(prog->aux->ctx_arg_info[i].reg_type) == PTR_TO_ARENA)
+ return true;
+ return false;
+}
+
static inline enum bpf_prog_type resolve_prog_type(const struct bpf_prog *prog)
{
return (prog->type == BPF_PROG_TYPE_EXT && prog->aux->saved_dst_prog_type) ?
diff --git a/include/linux/filter.h b/include/linux/filter.h
index 41b02d53e222..4edba8182db1 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -1214,6 +1214,7 @@ bool bpf_jit_supports_subprog_tailcalls(void);
bool bpf_jit_supports_percpu_insn(void);
bool bpf_jit_supports_kfunc_call(void);
bool bpf_jit_supports_stack_args(void);
+bool bpf_jit_supports_arena_args(void);
bool bpf_jit_supports_far_kfunc_call(void);
bool bpf_jit_supports_exceptions(void);
bool bpf_jit_supports_ptr_xchg(void);