From: Martin KaFai Lau Date: Wed, 27 Sep 2017 21:37:53 +0000 (-0700) Subject: BACKPORT: bpf: Add map_name to bpf_map_info X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a16bf5f2c7c488d5bbc14c421d8e8f90b487239e;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git BACKPORT: 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. Change-Id: I96b8d74b09c14f2413d421bba61cfa63d1730bc3 Signed-off-by: Martin KaFai Lau Acked-by: Alexei Starovoitov Acked-by: Daniel Borkmann Signed-off-by: David S. Miller --- diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 4cf933f3b0aa..54471accf697 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -69,6 +69,7 @@ struct bpf_map { atomic_t refcnt; atomic_t usercnt; struct work_struct work; + u8 name[BPF_OBJ_NAME_LEN]; }; /* function argument constraints */ diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 143d4a2aedec..ff5108529961 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -195,6 +195,7 @@ union bpf_attr { __u32 numa_node; /* numa node (effective only if * BPF_F_NUMA_NODE is set). */ + __u8 map_name[BPF_OBJ_NAME_LEN]; }; struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */ @@ -824,6 +825,7 @@ struct bpf_map_info { __u32 value_size; __u32 max_entries; __u32 map_flags; + __u8 name[BPF_OBJ_NAME_LEN]; } __attribute__((aligned(8))); /* User bpf_sock_ops struct to access socket values and specify request ops diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index de4b76cae4fd..bfac2c458335 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -379,7 +379,7 @@ static int bpf_obj_name_cpy(char *dst, const char *src) return 0; } -#define BPF_MAP_CREATE_LAST_FIELD numa_node +#define BPF_MAP_CREATE_LAST_FIELD map_name /* called via syscall */ static int map_create(union bpf_attr *attr) { @@ -406,6 +406,10 @@ static int map_create(union bpf_attr *attr) if (IS_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->usercnt, 1); @@ -1569,6 +1573,7 @@ static int bpf_map_get_info_by_fd(struct bpf_map *map, info.value_size = map->value_size; info.max_entries = map->max_entries; info.map_flags = map->map_flags; + memcpy(info.name, map->name, sizeof(map->name)); if (copy_to_user(uinfo, &info, info_len) || put_user(info_len, &uattr->info.info_len))