bpf: pass btf object id in bpf_map_info.
Include btf object id (btf_obj_id) in bpf_map_info so that tools (ex: bpftools struct_ops dump) know the correct btf from the kernel to look up type information of struct_ops types. Since struct_ops types can be defined and registered in a module. The type information of a struct_ops type are defined in the btf of the module defining it. The userspace tools need to know which btf is for the module defining a struct_ops type. Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com> Link: https://lore.kernel.org/r/20240119225005.668602-7-thinker.li@gmail.com Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
This commit is contained in:
parent
47f4f657ac
commit
1338b93346
|
@ -1732,6 +1732,7 @@ struct bpf_dummy_ops {
|
|||
int bpf_struct_ops_test_run(struct bpf_prog *prog, const union bpf_attr *kattr,
|
||||
union bpf_attr __user *uattr);
|
||||
#endif
|
||||
void bpf_map_struct_ops_info_fill(struct bpf_map_info *info, struct bpf_map *map);
|
||||
#else
|
||||
static inline const struct bpf_struct_ops_desc *bpf_struct_ops_find(u32 type_id)
|
||||
{
|
||||
|
@ -1759,6 +1760,9 @@ static inline int bpf_struct_ops_link_create(union bpf_attr *attr)
|
|||
{
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
static inline void bpf_map_struct_ops_info_fill(struct bpf_map_info *info, struct bpf_map *map)
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -6487,7 +6487,7 @@ struct bpf_map_info {
|
|||
__u32 btf_id;
|
||||
__u32 btf_key_type_id;
|
||||
__u32 btf_value_type_id;
|
||||
__u32 :32; /* alignment pad */
|
||||
__u32 btf_vmlinux_id;
|
||||
__u64 map_extra;
|
||||
} __attribute__((aligned(8)));
|
||||
|
||||
|
|
|
@ -947,3 +947,10 @@ err_out:
|
|||
kfree(link);
|
||||
return err;
|
||||
}
|
||||
|
||||
void bpf_map_struct_ops_info_fill(struct bpf_map_info *info, struct bpf_map *map)
|
||||
{
|
||||
struct bpf_struct_ops_map *st_map = (struct bpf_struct_ops_map *)map;
|
||||
|
||||
info->btf_vmlinux_id = btf_obj_id(st_map->btf);
|
||||
}
|
||||
|
|
|
@ -4691,6 +4691,8 @@ static int bpf_map_get_info_by_fd(struct file *file,
|
|||
info.btf_value_type_id = map->btf_value_type_id;
|
||||
}
|
||||
info.btf_vmlinux_value_type_id = map->btf_vmlinux_value_type_id;
|
||||
if (map->map_type == BPF_MAP_TYPE_STRUCT_OPS)
|
||||
bpf_map_struct_ops_info_fill(&info, map);
|
||||
|
||||
if (bpf_map_is_offloaded(map)) {
|
||||
err = bpf_map_offload_info_fill(&info, map);
|
||||
|
|
|
@ -6487,7 +6487,7 @@ struct bpf_map_info {
|
|||
__u32 btf_id;
|
||||
__u32 btf_key_type_id;
|
||||
__u32 btf_value_type_id;
|
||||
__u32 :32; /* alignment pad */
|
||||
__u32 btf_vmlinux_id;
|
||||
__u64 map_extra;
|
||||
} __attribute__((aligned(8)));
|
||||
|
||||
|
|
Loading…
Reference in New Issue