@@ -1779,7 +1779,6 @@ struct btf_member;
* @type: BTF type.
* @value_type: Value type.
* @name: The name of the struct bpf_struct_ops object.
- * @func_models: Func models
* @type_id: BTF type id.
* @value_id: BTF value id.
*/
@@ -1799,7 +1798,6 @@ struct bpf_struct_ops {
void *cfi_stubs;
struct module *owner;
const char *name;
- struct btf_func_model func_models[BPF_STRUCT_OPS_MAX_NR_MEMBERS];
};
/* Every member of a struct_ops type has an instance even a member is not
@@ -1825,6 +1823,8 @@ struct bpf_struct_ops_desc {
/* Collection of argument information for each member */
struct bpf_struct_ops_arg_info *arg_info;
+
+ struct btf_func_model func_models[BPF_STRUCT_OPS_MAX_NR_MEMBERS];
};
enum bpf_struct_ops_state {
@@ -397,7 +397,7 @@ int bpf_struct_ops_desc_init(struct bpf_struct_ops_desc *st_ops_desc,
if (btf_distill_func_proto(log, btf,
func_proto, mname,
- &st_ops->func_models[i])) {
+ &st_ops_desc->func_models[i])) {
pr_warn("Error in parsing func ptr %s in struct %s\n",
mname, st_ops->name);
err = -EINVAL;
@@ -777,7 +777,7 @@ static long bpf_struct_ops_map_update_elem(struct bpf_map *map, void *key,
trampoline_start = image_off;
err = bpf_struct_ops_prepare_trampoline(tlinks, link,
- &st_ops->func_models[i],
+ &st_ops_desc->func_models[i],
*(void **)(st_ops->cfi_stubs + moff),
&image, &image_off,
st_map->image_pages_cnt < MAX_TRAMP_IMAGE_PAGES);
@@ -129,7 +129,7 @@ extern const struct bpf_link_ops bpf_struct_ops_link_lops;
int bpf_struct_ops_test_run(struct bpf_prog *prog, const union bpf_attr *kattr,
union bpf_attr __user *uattr)
{
- const struct bpf_struct_ops *st_ops = &bpf_bpf_dummy_ops;
+ static typeof_member(struct bpf_struct_ops_desc, func_models) func_models;
const struct btf_type *func_proto;
struct bpf_dummy_ops_test_args *args;
struct bpf_tramp_links *tlinks = NULL;
@@ -175,7 +175,7 @@ int bpf_struct_ops_test_run(struct bpf_prog *prog, const union bpf_attr *kattr,
op_idx = prog->expected_attach_type;
err = bpf_struct_ops_prepare_trampoline(tlinks, link,
- &st_ops->func_models[op_idx],
+ &func_models[op_idx],
&dummy_ops_test_ret_function,
&image, &image_off,
true);
The func_models are the only member of struct bpf_struct_ops which are modified by the BPF core. Moving it into bpf_struct_ops_desc allows the static definitions of bpf_struct_ops throughout the tree being moved into read-only memory. The dummy ops don't have access to a bpf_struct_ops_desc. For them declare a dedicated static variable for the func_members. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> --- include/linux/bpf.h | 4 ++-- kernel/bpf/bpf_struct_ops.c | 4 ++-- net/bpf/bpf_dummy_struct_ops.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)