Skip to content

Commit d87a513

Browse files
ameryhungMartin KaFai Lau
authored andcommitted
bpf: Allow struct_ops to get map id by kdata
Add bpf_struct_ops_id() to enable struct_ops implementors to use struct_ops map id as the unique id of a struct_ops in their subsystem. A subsystem that wishes to create a mapping between id and struct_ops instance pointer can update the mapping accordingly during bpf_struct_ops::reg(), unreg(), and update(). Signed-off-by: Amery Hung <[email protected]> Signed-off-by: Martin KaFai Lau <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent f3af62b commit d87a513

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

include/linux/bpf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,6 +1985,7 @@ static inline void bpf_module_put(const void *data, struct module *owner)
19851985
module_put(owner);
19861986
}
19871987
int bpf_struct_ops_link_create(union bpf_attr *attr);
1988+
u32 bpf_struct_ops_id(const void *kdata);
19881989

19891990
#ifdef CONFIG_NET
19901991
/* Define it here to avoid the use of forward declaration */

kernel/bpf/bpf_struct_ops.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,18 @@ void bpf_struct_ops_put(const void *kdata)
11741174
bpf_map_put(&st_map->map);
11751175
}
11761176

1177+
u32 bpf_struct_ops_id(const void *kdata)
1178+
{
1179+
struct bpf_struct_ops_value *kvalue;
1180+
struct bpf_struct_ops_map *st_map;
1181+
1182+
kvalue = container_of(kdata, struct bpf_struct_ops_value, data);
1183+
st_map = container_of(kvalue, struct bpf_struct_ops_map, kvalue);
1184+
1185+
return st_map->map.id;
1186+
}
1187+
EXPORT_SYMBOL_GPL(bpf_struct_ops_id);
1188+
11771189
static bool bpf_struct_ops_valid_to_reg(struct bpf_map *map)
11781190
{
11791191
struct bpf_struct_ops_map *st_map = (struct bpf_struct_ops_map *)map;

0 commit comments

Comments
 (0)