Commit ad5b177b authored by Martin KaFai Lau's avatar Martin KaFai Lau Committed by David S. Miller

bpf: Add map_name to bpf_map_info

This patch allows userspace to specify a name for a map
during BPF_MAP_CREATE.

The map's name can later be exported to user space
via BPF_OBJ_GET_INFO_BY_FD.
Signed-off-by: default avatarMartin KaFai Lau <kafai@fb.com>
Acked-by: default avatarAlexei Starovoitov <ast@fb.com>
Acked-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent cb4d2b3f
...@@ -56,6 +56,7 @@ struct bpf_map { ...@@ -56,6 +56,7 @@ struct bpf_map {
struct work_struct work; struct work_struct work;
atomic_t usercnt; atomic_t usercnt;
struct bpf_map *inner_map_meta; struct bpf_map *inner_map_meta;
u8 name[BPF_OBJ_NAME_LEN];
}; };
/* function argument constraints */ /* function argument constraints */
......
...@@ -190,6 +190,7 @@ union bpf_attr { ...@@ -190,6 +190,7 @@ union bpf_attr {
__u32 numa_node; /* numa node (effective only if __u32 numa_node; /* numa node (effective only if
* BPF_F_NUMA_NODE is set). * BPF_F_NUMA_NODE is set).
*/ */
__u8 map_name[BPF_OBJ_NAME_LEN];
}; };
struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */ struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
...@@ -829,6 +830,7 @@ struct bpf_map_info { ...@@ -829,6 +830,7 @@ struct bpf_map_info {
__u32 value_size; __u32 value_size;
__u32 max_entries; __u32 max_entries;
__u32 map_flags; __u32 map_flags;
__u8 name[BPF_OBJ_NAME_LEN];
} __attribute__((aligned(8))); } __attribute__((aligned(8)));
/* User bpf_sock_ops struct to access socket values and specify request ops /* User bpf_sock_ops struct to access socket values and specify request ops
......
...@@ -339,7 +339,7 @@ static int bpf_obj_name_cpy(char *dst, const char *src) ...@@ -339,7 +339,7 @@ static int bpf_obj_name_cpy(char *dst, const char *src)
return 0; return 0;
} }
#define BPF_MAP_CREATE_LAST_FIELD numa_node #define BPF_MAP_CREATE_LAST_FIELD map_name
/* called via syscall */ /* called via syscall */
static int map_create(union bpf_attr *attr) static int map_create(union bpf_attr *attr)
{ {
...@@ -361,6 +361,10 @@ static int map_create(union bpf_attr *attr) ...@@ -361,6 +361,10 @@ static int map_create(union bpf_attr *attr)
if (IS_ERR(map)) if (IS_ERR(map))
return PTR_ERR(map); return PTR_ERR(map);
err = bpf_obj_name_cpy(map->name, attr->map_name);
if (err)
goto free_map_nouncharge;
atomic_set(&map->refcnt, 1); atomic_set(&map->refcnt, 1);
atomic_set(&map->usercnt, 1); atomic_set(&map->usercnt, 1);
...@@ -1462,6 +1466,7 @@ static int bpf_map_get_info_by_fd(struct bpf_map *map, ...@@ -1462,6 +1466,7 @@ static int bpf_map_get_info_by_fd(struct bpf_map *map,
info.value_size = map->value_size; info.value_size = map->value_size;
info.max_entries = map->max_entries; info.max_entries = map->max_entries;
info.map_flags = map->map_flags; info.map_flags = map->map_flags;
memcpy(info.name, map->name, sizeof(map->name));
if (copy_to_user(uinfo, &info, info_len) || if (copy_to_user(uinfo, &info, info_len) ||
put_user(info_len, &uattr->info.info_len)) put_user(info_len, &uattr->info.info_len))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment