Skip to content

Commit 51d6504

Browse files
juntongdengMartin KaFai Lau
authored andcommitted
bpf: Add struct_ops context information to struct bpf_prog_aux
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
1 parent e16e64f commit 51d6504

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

include/linux/bpf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,7 @@ struct bpf_prog_aux {
15211521
u32 real_func_cnt; /* includes hidden progs, only used for JIT and freeing progs */
15221522
u32 func_idx; /* 0 for non-func prog, the index in func array for func prog */
15231523
u32 attach_btf_id; /* in-kernel BTF type id to attach to */
1524+
u32 attach_st_ops_member_off;
15241525
u32 ctx_arg_info_size;
15251526
u32 max_rdonly_access;
15261527
u32 max_rdwr_access;
@@ -1566,6 +1567,7 @@ struct bpf_prog_aux {
15661567
#endif
15671568
struct bpf_ksym ksym;
15681569
const struct bpf_prog_ops *ops;
1570+
const struct bpf_struct_ops *st_ops;
15691571
struct bpf_map **used_maps;
15701572
struct mutex used_maps_mutex; /* mutex for used_maps and used_map_cnt */
15711573
struct btf_mod_pair *used_btfs;

kernel/bpf/verifier.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22736,7 +22736,7 @@ static int check_struct_ops_btf_id(struct bpf_verifier_env *env)
2273622736
const struct btf_member *member;
2273722737
struct bpf_prog *prog = env->prog;
2273822738
bool has_refcounted_arg = false;
22739-
u32 btf_id, member_idx;
22739+
u32 btf_id, member_idx, member_off;
2274022740
struct btf *btf;
2274122741
const char *mname;
2274222742
int i, err;
@@ -22787,7 +22787,8 @@ static int check_struct_ops_btf_id(struct bpf_verifier_env *env)
2278722787
return -EINVAL;
2278822788
}
2278922789

22790-
err = bpf_struct_ops_supported(st_ops, __btf_member_bit_offset(t, member) / 8);
22790+
member_off = __btf_member_bit_offset(t, member) / 8;
22791+
err = bpf_struct_ops_supported(st_ops, member_off);
2279122792
if (err) {
2279222793
verbose(env, "attach to unsupported member %s of struct %s\n",
2279322794
mname, st_ops->name);
@@ -22826,6 +22827,9 @@ static int check_struct_ops_btf_id(struct bpf_verifier_env *env)
2282622827
}
2282722828
}
2282822829

22830+
prog->aux->st_ops = st_ops;
22831+
prog->aux->attach_st_ops_member_off = member_off;
22832+
2282922833
prog->aux->attach_func_proto = func_proto;
2283022834
prog->aux->attach_func_name = mname;
2283122835
env->ops = st_ops->verifier_ops;

0 commit comments

Comments
 (0)