]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bpf: Add struct_ops context information to struct bpf_prog_aux
authorJuntong Deng <juntong.deng@outlook.com>
Wed, 19 Mar 2025 21:53:48 +0000 (14:53 -0700)
committerMartin KaFai Lau <martin.lau@kernel.org>
Thu, 20 Mar 2025 23:54:41 +0000 (16:54 -0700)
This patch adds struct_ops context information to struct bpf_prog_aux.

This context information will be used in the kfunc filter.

Currently the added context information includes struct_ops member
offset and a pointer to struct bpf_struct_ops.

Signed-off-by: Juntong Deng <juntong.deng@outlook.com>
Signed-off-by: Amery Hung <ameryhung@gmail.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Link: https://patch.msgid.link/20250319215358.2287371-2-ameryhung@gmail.com
include/linux/bpf.h
kernel/bpf/verifier.c

index 973a88d9b52bc9786929a03456d2726d27e93700..111bea4e507fa82caa12d7b0a353cb4573b423bc 100644 (file)
@@ -1521,6 +1521,7 @@ struct bpf_prog_aux {
        u32 real_func_cnt; /* includes hidden progs, only used for JIT and freeing progs */
        u32 func_idx; /* 0 for non-func prog, the index in func array for func prog */
        u32 attach_btf_id; /* in-kernel BTF type id to attach to */
+       u32 attach_st_ops_member_off;
        u32 ctx_arg_info_size;
        u32 max_rdonly_access;
        u32 max_rdwr_access;
@@ -1566,6 +1567,7 @@ struct bpf_prog_aux {
 #endif
        struct bpf_ksym ksym;
        const struct bpf_prog_ops *ops;
+       const struct bpf_struct_ops *st_ops;
        struct bpf_map **used_maps;
        struct mutex used_maps_mutex; /* mutex for used_maps and used_map_cnt */
        struct btf_mod_pair *used_btfs;
index 9f8cbd5c61bc6dc69931c67615f802700d34d1e7..41fd93db825842d68c926fcf6d8b0217ad744ba2 100644 (file)
@@ -22736,7 +22736,7 @@ static int check_struct_ops_btf_id(struct bpf_verifier_env *env)
        const struct btf_member *member;
        struct bpf_prog *prog = env->prog;
        bool has_refcounted_arg = false;
-       u32 btf_id, member_idx;
+       u32 btf_id, member_idx, member_off;
        struct btf *btf;
        const char *mname;
        int i, err;
@@ -22787,7 +22787,8 @@ static int check_struct_ops_btf_id(struct bpf_verifier_env *env)
                return -EINVAL;
        }
 
-       err = bpf_struct_ops_supported(st_ops, __btf_member_bit_offset(t, member) / 8);
+       member_off = __btf_member_bit_offset(t, member) / 8;
+       err = bpf_struct_ops_supported(st_ops, member_off);
        if (err) {
                verbose(env, "attach to unsupported member %s of struct %s\n",
                        mname, st_ops->name);
@@ -22826,6 +22827,9 @@ static int check_struct_ops_btf_id(struct bpf_verifier_env *env)
                }
        }
 
+       prog->aux->st_ops = st_ops;
+       prog->aux->attach_st_ops_member_off = member_off;
+
        prog->aux->attach_func_proto = func_proto;
        prog->aux->attach_func_name = mname;
        env->ops = st_ops->verifier_ops;