aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin KaFai Lau <kafai@fb.com>2017-09-27 17:37:54 -0400
committerDavid S. Miller <davem@davemloft.net>2017-09-29 01:17:05 -0400
commit88cda1c9da02c8aa31e1d5dcf22e8a35cc8c19f2 (patch)
tree5096ddd73981e33a2164606461a45b56a189889c
parentad5b177bd73f5107d97c36f56395c4281fb6f089 (diff)
bpf: libbpf: Provide basic API support to specify BPF obj name
This patch extends the libbpf to provide API support to allow specifying BPF object name. In tools/lib/bpf/libbpf, the C symbol of the function and the map is used. Regarding section name, all maps are under the same section named "maps". Hence, section name is not a good choice for map's name. To be consistent with map, bpf_prog also follows and uses its function symbol as the prog's name. This patch adds logic to collect function's symbols in libbpf. There is existing codes to collect the map's symbols and no change is needed. The bpf_load_program_name() and bpf_map_create_name() are added to take the name argument. For the other bpf_map_create_xxx() variants, a name argument is directly added to them. In samples/bpf, bpf_load.c in particular, the symbol is also used as the map's name and the map symbols has already been collected in the existing code. For bpf_prog, bpf_load.c does not collect the function symbol name. We can consider to collect them later if there is a need to continue supporting the bpf_load.c. Signed-off-by: Martin KaFai Lau <kafai@fb.com> Acked-by: Alexei Starovoitov <ast@fb.com> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--samples/bpf/bpf_load.c2
-rw-r--r--samples/bpf/map_perf_test_user.c1
-rw-r--r--tools/include/uapi/linux/bpf.h10
-rw-r--r--tools/lib/bpf/bpf.c57
-rw-r--r--tools/lib/bpf/bpf.h23
-rw-r--r--tools/lib/bpf/libbpf.c109
-rw-r--r--tools/testing/selftests/bpf/test_verifier.c2
7 files changed, 157 insertions, 47 deletions
diff --git a/samples/bpf/bpf_load.c b/samples/bpf/bpf_load.c
index 6aa50098dfb8..18b1c8dd0391 100644
--- a/samples/bpf/bpf_load.c
+++ b/samples/bpf/bpf_load.c
@@ -221,6 +221,7 @@ static int load_maps(struct bpf_map_data *maps, int nr_maps,
221 int inner_map_fd = map_fd[maps[i].def.inner_map_idx]; 221 int inner_map_fd = map_fd[maps[i].def.inner_map_idx];
222 222
223 map_fd[i] = bpf_create_map_in_map_node(maps[i].def.type, 223 map_fd[i] = bpf_create_map_in_map_node(maps[i].def.type,
224 maps[i].name,
224 maps[i].def.key_size, 225 maps[i].def.key_size,
225 inner_map_fd, 226 inner_map_fd,
226 maps[i].def.max_entries, 227 maps[i].def.max_entries,
@@ -228,6 +229,7 @@ static int load_maps(struct bpf_map_data *maps, int nr_maps,
228 numa_node); 229 numa_node);
229 } else { 230 } else {
230 map_fd[i] = bpf_create_map_node(maps[i].def.type, 231 map_fd[i] = bpf_create_map_node(maps[i].def.type,
232 maps[i].name,
231 maps[i].def.key_size, 233 maps[i].def.key_size,
232 maps[i].def.value_size, 234 maps[i].def.value_size,
233 maps[i].def.max_entries, 235 maps[i].def.max_entries,
diff --git a/samples/bpf/map_perf_test_user.c b/samples/bpf/map_perf_test_user.c
index a0310fc70057..519d9af4b04a 100644
--- a/samples/bpf/map_perf_test_user.c
+++ b/samples/bpf/map_perf_test_user.c
@@ -137,6 +137,7 @@ static void do_test_lru(enum test_type test, int cpu)
137 137
138 inner_lru_map_fds[cpu] = 138 inner_lru_map_fds[cpu] =
139 bpf_create_map_node(BPF_MAP_TYPE_LRU_HASH, 139 bpf_create_map_node(BPF_MAP_TYPE_LRU_HASH,
140 test_map_names[INNER_LRU_HASH_PREALLOC],
140 sizeof(uint32_t), 141 sizeof(uint32_t),
141 sizeof(long), 142 sizeof(long),
142 inner_lru_hash_size, 0, 143 inner_lru_hash_size, 0,
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index e43491ac4823..6d2137b4cf38 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -175,6 +175,8 @@ enum bpf_attach_type {
175/* Specify numa node during map creation */ 175/* Specify numa node during map creation */
176#define BPF_F_NUMA_NODE (1U << 2) 176#define BPF_F_NUMA_NODE (1U << 2)
177 177
178#define BPF_OBJ_NAME_LEN 16U
179
178union bpf_attr { 180union bpf_attr {
179 struct { /* anonymous struct used by BPF_MAP_CREATE command */ 181 struct { /* anonymous struct used by BPF_MAP_CREATE command */
180 __u32 map_type; /* one of enum bpf_map_type */ 182 __u32 map_type; /* one of enum bpf_map_type */
@@ -188,6 +190,7 @@ union bpf_attr {
188 __u32 numa_node; /* numa node (effective only if 190 __u32 numa_node; /* numa node (effective only if
189 * BPF_F_NUMA_NODE is set). 191 * BPF_F_NUMA_NODE is set).
190 */ 192 */
193 __u8 map_name[BPF_OBJ_NAME_LEN];
191 }; 194 };
192 195
193 struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */ 196 struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
@@ -210,6 +213,7 @@ union bpf_attr {
210 __aligned_u64 log_buf; /* user supplied buffer */ 213 __aligned_u64 log_buf; /* user supplied buffer */
211 __u32 kern_version; /* checked when prog_type=kprobe */ 214 __u32 kern_version; /* checked when prog_type=kprobe */
212 __u32 prog_flags; 215 __u32 prog_flags;
216 __u8 prog_name[BPF_OBJ_NAME_LEN];
213 }; 217 };
214 218
215 struct { /* anonymous struct used by BPF_OBJ_* commands */ 219 struct { /* anonymous struct used by BPF_OBJ_* commands */
@@ -812,6 +816,11 @@ struct bpf_prog_info {
812 __u32 xlated_prog_len; 816 __u32 xlated_prog_len;
813 __aligned_u64 jited_prog_insns; 817 __aligned_u64 jited_prog_insns;
814 __aligned_u64 xlated_prog_insns; 818 __aligned_u64 xlated_prog_insns;
819 __u64 load_time; /* ns since boottime */
820 __u32 created_by_uid;
821 __u32 nr_map_ids;
822 __aligned_u64 map_ids;
823 __u8 name[BPF_OBJ_NAME_LEN];
815} __attribute__((aligned(8))); 824} __attribute__((aligned(8)));
816 825
817struct bpf_map_info { 826struct bpf_map_info {
@@ -821,6 +830,7 @@ struct bpf_map_info {
821 __u32 value_size; 830 __u32 value_size;
822 __u32 max_entries; 831 __u32 max_entries;
823 __u32 map_flags; 832 __u32 map_flags;
833 __u8 name[BPF_OBJ_NAME_LEN];
824} __attribute__((aligned(8))); 834} __attribute__((aligned(8)));
825 835
826/* User bpf_sock_ops struct to access socket values and specify request ops 836/* User bpf_sock_ops struct to access socket values and specify request ops
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index 1d6907d379c9..daf624e4c720 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -46,6 +46,8 @@
46# endif 46# endif
47#endif 47#endif
48 48
49#define min(x, y) ((x) < (y) ? (x) : (y))
50
49static inline __u64 ptr_to_u64(const void *ptr) 51static inline __u64 ptr_to_u64(const void *ptr)
50{ 52{
51 return (__u64) (unsigned long) ptr; 53 return (__u64) (unsigned long) ptr;
@@ -57,10 +59,11 @@ static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr,
57 return syscall(__NR_bpf, cmd, attr, size); 59 return syscall(__NR_bpf, cmd, attr, size);
58} 60}
59 61
60int bpf_create_map_node(enum bpf_map_type map_type, int key_size, 62int bpf_create_map_node(enum bpf_map_type map_type, const char *name,
61 int value_size, int max_entries, __u32 map_flags, 63 int key_size, int value_size, int max_entries,
62 int node) 64 __u32 map_flags, int node)
63{ 65{
66 __u32 name_len = name ? strlen(name) : 0;
64 union bpf_attr attr; 67 union bpf_attr attr;
65 68
66 memset(&attr, '\0', sizeof(attr)); 69 memset(&attr, '\0', sizeof(attr));
@@ -70,6 +73,8 @@ int bpf_create_map_node(enum bpf_map_type map_type, int key_size,
70 attr.value_size = value_size; 73 attr.value_size = value_size;
71 attr.max_entries = max_entries; 74 attr.max_entries = max_entries;
72 attr.map_flags = map_flags; 75 attr.map_flags = map_flags;
76 memcpy(attr.map_name, name, min(name_len, BPF_OBJ_NAME_LEN - 1));
77
73 if (node >= 0) { 78 if (node >= 0) {
74 attr.map_flags |= BPF_F_NUMA_NODE; 79 attr.map_flags |= BPF_F_NUMA_NODE;
75 attr.numa_node = node; 80 attr.numa_node = node;
@@ -81,14 +86,23 @@ int bpf_create_map_node(enum bpf_map_type map_type, int key_size,
81int bpf_create_map(enum bpf_map_type map_type, int key_size, 86int bpf_create_map(enum bpf_map_type map_type, int key_size,
82 int value_size, int max_entries, __u32 map_flags) 87 int value_size, int max_entries, __u32 map_flags)
83{ 88{
84 return bpf_create_map_node(map_type, key_size, value_size, 89 return bpf_create_map_node(map_type, NULL, key_size, value_size,
85 max_entries, map_flags, -1); 90 max_entries, map_flags, -1);
86} 91}
87 92
88int bpf_create_map_in_map_node(enum bpf_map_type map_type, int key_size, 93int bpf_create_map_name(enum bpf_map_type map_type, const char *name,
89 int inner_map_fd, int max_entries, 94 int key_size, int value_size, int max_entries,
95 __u32 map_flags)
96{
97 return bpf_create_map_node(map_type, name, key_size, value_size,
98 max_entries, map_flags, -1);
99}
100
101int bpf_create_map_in_map_node(enum bpf_map_type map_type, const char *name,
102 int key_size, int inner_map_fd, int max_entries,
90 __u32 map_flags, int node) 103 __u32 map_flags, int node)
91{ 104{
105 __u32 name_len = name ? strlen(name) : 0;
92 union bpf_attr attr; 106 union bpf_attr attr;
93 107
94 memset(&attr, '\0', sizeof(attr)); 108 memset(&attr, '\0', sizeof(attr));
@@ -99,6 +113,8 @@ int bpf_create_map_in_map_node(enum bpf_map_type map_type, int key_size,
99 attr.inner_map_fd = inner_map_fd; 113 attr.inner_map_fd = inner_map_fd;
100 attr.max_entries = max_entries; 114 attr.max_entries = max_entries;
101 attr.map_flags = map_flags; 115 attr.map_flags = map_flags;
116 memcpy(attr.map_name, name, min(name_len, BPF_OBJ_NAME_LEN - 1));
117
102 if (node >= 0) { 118 if (node >= 0) {
103 attr.map_flags |= BPF_F_NUMA_NODE; 119 attr.map_flags |= BPF_F_NUMA_NODE;
104 attr.numa_node = node; 120 attr.numa_node = node;
@@ -107,19 +123,24 @@ int bpf_create_map_in_map_node(enum bpf_map_type map_type, int key_size,
107 return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); 123 return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr));
108} 124}
109 125
110int bpf_create_map_in_map(enum bpf_map_type map_type, int key_size, 126int bpf_create_map_in_map(enum bpf_map_type map_type, const char *name,
111 int inner_map_fd, int max_entries, __u32 map_flags) 127 int key_size, int inner_map_fd, int max_entries,
128 __u32 map_flags)
112{ 129{
113 return bpf_create_map_in_map_node(map_type, key_size, inner_map_fd, 130 return bpf_create_map_in_map_node(map_type, name, key_size,
114 max_entries, map_flags, -1); 131 inner_map_fd, max_entries, map_flags,
132 -1);
115} 133}
116 134
117int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns, 135int bpf_load_program_name(enum bpf_prog_type type, const char *name,
118 size_t insns_cnt, const char *license, 136 const struct bpf_insn *insns,
119 __u32 kern_version, char *log_buf, size_t log_buf_sz) 137 size_t insns_cnt, const char *license,
138 __u32 kern_version, char *log_buf,
139 size_t log_buf_sz)
120{ 140{
121 int fd; 141 int fd;
122 union bpf_attr attr; 142 union bpf_attr attr;
143 __u32 name_len = name ? strlen(name) : 0;
123 144
124 bzero(&attr, sizeof(attr)); 145 bzero(&attr, sizeof(attr));
125 attr.prog_type = type; 146 attr.prog_type = type;
@@ -130,6 +151,7 @@ int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns,
130 attr.log_size = 0; 151 attr.log_size = 0;
131 attr.log_level = 0; 152 attr.log_level = 0;
132 attr.kern_version = kern_version; 153 attr.kern_version = kern_version;
154 memcpy(attr.prog_name, name, min(name_len, BPF_OBJ_NAME_LEN - 1));
133 155
134 fd = sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); 156 fd = sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
135 if (fd >= 0 || !log_buf || !log_buf_sz) 157 if (fd >= 0 || !log_buf || !log_buf_sz)
@@ -143,6 +165,15 @@ int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns,
143 return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); 165 return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr));
144} 166}
145 167
168int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns,
169 size_t insns_cnt, const char *license,
170 __u32 kern_version, char *log_buf,
171 size_t log_buf_sz)
172{
173 return bpf_load_program_name(type, NULL, insns, insns_cnt, license,
174 kern_version, log_buf, log_buf_sz);
175}
176
146int bpf_verify_program(enum bpf_prog_type type, const struct bpf_insn *insns, 177int bpf_verify_program(enum bpf_prog_type type, const struct bpf_insn *insns,
147 size_t insns_cnt, int strict_alignment, 178 size_t insns_cnt, int strict_alignment,
148 const char *license, __u32 kern_version, 179 const char *license, __u32 kern_version,
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index b8ea5843c39e..118d00535a0d 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -24,19 +24,28 @@
24#include <linux/bpf.h> 24#include <linux/bpf.h>
25#include <stddef.h> 25#include <stddef.h>
26 26
27int bpf_create_map_node(enum bpf_map_type map_type, int key_size, 27int bpf_create_map_node(enum bpf_map_type map_type, const char *name,
28 int value_size, int max_entries, __u32 map_flags, 28 int key_size, int value_size, int max_entries,
29 int node); 29 __u32 map_flags, int node);
30int bpf_create_map_name(enum bpf_map_type map_type, const char *name,
31 int key_size, int value_size, int max_entries,
32 __u32 map_flags);
30int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size, 33int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size,
31 int max_entries, __u32 map_flags); 34 int max_entries, __u32 map_flags);
32int bpf_create_map_in_map_node(enum bpf_map_type map_type, int key_size, 35int bpf_create_map_in_map_node(enum bpf_map_type map_type, const char *name,
33 int inner_map_fd, int max_entries, 36 int key_size, int inner_map_fd, int max_entries,
34 __u32 map_flags, int node); 37 __u32 map_flags, int node);
35int bpf_create_map_in_map(enum bpf_map_type map_type, int key_size, 38int bpf_create_map_in_map(enum bpf_map_type map_type, const char *name,
36 int inner_map_fd, int max_entries, __u32 map_flags); 39 int key_size, int inner_map_fd, int max_entries,
40 __u32 map_flags);
37 41
38/* Recommend log buffer size */ 42/* Recommend log buffer size */
39#define BPF_LOG_BUF_SIZE 65536 43#define BPF_LOG_BUF_SIZE 65536
44int bpf_load_program_name(enum bpf_prog_type type, const char *name,
45 const struct bpf_insn *insns,
46 size_t insns_cnt, const char *license,
47 __u32 kern_version, char *log_buf,
48 size_t log_buf_sz);
40int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns, 49int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns,
41 size_t insns_cnt, const char *license, 50 size_t insns_cnt, const char *license,
42 __u32 kern_version, char *log_buf, 51 __u32 kern_version, char *log_buf,
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 35f6dfcdc565..4f402dcdf372 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -171,6 +171,7 @@ int libbpf_strerror(int err, char *buf, size_t size)
171struct bpf_program { 171struct bpf_program {
172 /* Index in elf obj file, for relocation use. */ 172 /* Index in elf obj file, for relocation use. */
173 int idx; 173 int idx;
174 char *name;
174 char *section_name; 175 char *section_name;
175 struct bpf_insn *insns; 176 struct bpf_insn *insns;
176 size_t insns_cnt; 177 size_t insns_cnt;
@@ -283,6 +284,7 @@ static void bpf_program__exit(struct bpf_program *prog)
283 prog->clear_priv = NULL; 284 prog->clear_priv = NULL;
284 285
285 bpf_program__unload(prog); 286 bpf_program__unload(prog);
287 zfree(&prog->name);
286 zfree(&prog->section_name); 288 zfree(&prog->section_name);
287 zfree(&prog->insns); 289 zfree(&prog->insns);
288 zfree(&prog->reloc_desc); 290 zfree(&prog->reloc_desc);
@@ -293,26 +295,27 @@ static void bpf_program__exit(struct bpf_program *prog)
293} 295}
294 296
295static int 297static int
296bpf_program__init(void *data, size_t size, char *name, int idx, 298bpf_program__init(void *data, size_t size, char *section_name, int idx,
297 struct bpf_program *prog) 299 struct bpf_program *prog)
298{ 300{
299 if (size < sizeof(struct bpf_insn)) { 301 if (size < sizeof(struct bpf_insn)) {
300 pr_warning("corrupted section '%s'\n", name); 302 pr_warning("corrupted section '%s'\n", section_name);
301 return -EINVAL; 303 return -EINVAL;
302 } 304 }
303 305
304 bzero(prog, sizeof(*prog)); 306 bzero(prog, sizeof(*prog));
305 307
306 prog->section_name = strdup(name); 308 prog->section_name = strdup(section_name);
307 if (!prog->section_name) { 309 if (!prog->section_name) {
308 pr_warning("failed to alloc name for prog %s\n", 310 pr_warning("failed to alloc name for prog under section %s\n",
309 name); 311 section_name);
310 goto errout; 312 goto errout;
311 } 313 }
312 314
313 prog->insns = malloc(size); 315 prog->insns = malloc(size);
314 if (!prog->insns) { 316 if (!prog->insns) {
315 pr_warning("failed to alloc insns for %s\n", name); 317 pr_warning("failed to alloc insns for prog under section %s\n",
318 section_name);
316 goto errout; 319 goto errout;
317 } 320 }
318 prog->insns_cnt = size / sizeof(struct bpf_insn); 321 prog->insns_cnt = size / sizeof(struct bpf_insn);
@@ -331,12 +334,12 @@ errout:
331 334
332static int 335static int
333bpf_object__add_program(struct bpf_object *obj, void *data, size_t size, 336bpf_object__add_program(struct bpf_object *obj, void *data, size_t size,
334 char *name, int idx) 337 char *section_name, int idx)
335{ 338{
336 struct bpf_program prog, *progs; 339 struct bpf_program prog, *progs;
337 int nr_progs, err; 340 int nr_progs, err;
338 341
339 err = bpf_program__init(data, size, name, idx, &prog); 342 err = bpf_program__init(data, size, section_name, idx, &prog);
340 if (err) 343 if (err)
341 return err; 344 return err;
342 345
@@ -350,8 +353,8 @@ bpf_object__add_program(struct bpf_object *obj, void *data, size_t size,
350 * is still valid, so don't need special treat for 353 * is still valid, so don't need special treat for
351 * bpf_close_object(). 354 * bpf_close_object().
352 */ 355 */
353 pr_warning("failed to alloc a new program '%s'\n", 356 pr_warning("failed to alloc a new program under section '%s'\n",
354 name); 357 section_name);
355 bpf_program__exit(&prog); 358 bpf_program__exit(&prog);
356 return -ENOMEM; 359 return -ENOMEM;
357 } 360 }
@@ -364,6 +367,54 @@ bpf_object__add_program(struct bpf_object *obj, void *data, size_t size,
364 return 0; 367 return 0;
365} 368}
366 369
370static int
371bpf_object__init_prog_names(struct bpf_object *obj)
372{
373 Elf_Data *symbols = obj->efile.symbols;
374 struct bpf_program *prog;
375 size_t pi, si;
376
377 for (pi = 0; pi < obj->nr_programs; pi++) {
378 char *name = NULL;
379
380 prog = &obj->programs[pi];
381
382 for (si = 0; si < symbols->d_size / sizeof(GElf_Sym) && !name;
383 si++) {
384 GElf_Sym sym;
385
386 if (!gelf_getsym(symbols, si, &sym))
387 continue;
388 if (sym.st_shndx != prog->idx)
389 continue;
390
391 name = elf_strptr(obj->efile.elf,
392 obj->efile.strtabidx,
393 sym.st_name);
394 if (!name) {
395 pr_warning("failed to get sym name string for prog %s\n",
396 prog->section_name);
397 return -LIBBPF_ERRNO__LIBELF;
398 }
399 }
400
401 if (!name) {
402 pr_warning("failed to find sym for prog %s\n",
403 prog->section_name);
404 return -EINVAL;
405 }
406
407 prog->name = strdup(name);
408 if (!prog->name) {
409 pr_warning("failed to allocate memory for prog sym %s\n",
410 name);
411 return -ENOMEM;
412 }
413 }
414
415 return 0;
416}
417
367static struct bpf_object *bpf_object__new(const char *path, 418static struct bpf_object *bpf_object__new(const char *path,
368 void *obj_buf, 419 void *obj_buf,
369 size_t obj_buf_sz) 420 size_t obj_buf_sz)
@@ -766,8 +817,12 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
766 pr_warning("Corrupted ELF file: index of strtab invalid\n"); 817 pr_warning("Corrupted ELF file: index of strtab invalid\n");
767 return LIBBPF_ERRNO__FORMAT; 818 return LIBBPF_ERRNO__FORMAT;
768 } 819 }
769 if (obj->efile.maps_shndx >= 0) 820 if (obj->efile.maps_shndx >= 0) {
770 err = bpf_object__init_maps(obj); 821 err = bpf_object__init_maps(obj);
822 if (err)
823 goto out;
824 }
825 err = bpf_object__init_prog_names(obj);
771out: 826out:
772 return err; 827 return err;
773} 828}
@@ -870,11 +925,12 @@ bpf_object__create_maps(struct bpf_object *obj)
870 struct bpf_map_def *def = &obj->maps[i].def; 925 struct bpf_map_def *def = &obj->maps[i].def;
871 int *pfd = &obj->maps[i].fd; 926 int *pfd = &obj->maps[i].fd;
872 927
873 *pfd = bpf_create_map(def->type, 928 *pfd = bpf_create_map_name(def->type,
874 def->key_size, 929 obj->maps[i].name,
875 def->value_size, 930 def->key_size,
876 def->max_entries, 931 def->value_size,
877 0); 932 def->max_entries,
933 0);
878 if (*pfd < 0) { 934 if (*pfd < 0) {
879 size_t j; 935 size_t j;
880 int err = *pfd; 936 int err = *pfd;
@@ -982,7 +1038,7 @@ static int bpf_object__collect_reloc(struct bpf_object *obj)
982} 1038}
983 1039
984static int 1040static int
985load_program(enum bpf_prog_type type, struct bpf_insn *insns, 1041load_program(enum bpf_prog_type type, const char *name, struct bpf_insn *insns,
986 int insns_cnt, char *license, u32 kern_version, int *pfd) 1042 int insns_cnt, char *license, u32 kern_version, int *pfd)
987{ 1043{
988 int ret; 1044 int ret;
@@ -995,8 +1051,8 @@ load_program(enum bpf_prog_type type, struct bpf_insn *insns,
995 if (!log_buf) 1051 if (!log_buf)
996 pr_warning("Alloc log buffer for bpf loader error, continue without log\n"); 1052 pr_warning("Alloc log buffer for bpf loader error, continue without log\n");
997 1053
998 ret = bpf_load_program(type, insns, insns_cnt, license, 1054 ret = bpf_load_program_name(type, name, insns, insns_cnt, license,
999 kern_version, log_buf, BPF_LOG_BUF_SIZE); 1055 kern_version, log_buf, BPF_LOG_BUF_SIZE);
1000 1056
1001 if (ret >= 0) { 1057 if (ret >= 0) {
1002 *pfd = ret; 1058 *pfd = ret;
@@ -1021,9 +1077,9 @@ load_program(enum bpf_prog_type type, struct bpf_insn *insns,
1021 if (type != BPF_PROG_TYPE_KPROBE) { 1077 if (type != BPF_PROG_TYPE_KPROBE) {
1022 int fd; 1078 int fd;
1023 1079
1024 fd = bpf_load_program(BPF_PROG_TYPE_KPROBE, insns, 1080 fd = bpf_load_program_name(BPF_PROG_TYPE_KPROBE, name,
1025 insns_cnt, license, kern_version, 1081 insns, insns_cnt, license,
1026 NULL, 0); 1082 kern_version, NULL, 0);
1027 if (fd >= 0) { 1083 if (fd >= 0) {
1028 close(fd); 1084 close(fd);
1029 ret = -LIBBPF_ERRNO__PROGTYPE; 1085 ret = -LIBBPF_ERRNO__PROGTYPE;
@@ -1067,8 +1123,8 @@ bpf_program__load(struct bpf_program *prog,
1067 pr_warning("Program '%s' is inconsistent: nr(%d) != 1\n", 1123 pr_warning("Program '%s' is inconsistent: nr(%d) != 1\n",
1068 prog->section_name, prog->instances.nr); 1124 prog->section_name, prog->instances.nr);
1069 } 1125 }
1070 err = load_program(prog->type, prog->insns, prog->insns_cnt, 1126 err = load_program(prog->type, prog->name, prog->insns,
1071 license, kern_version, &fd); 1127 prog->insns_cnt, license, kern_version, &fd);
1072 if (!err) 1128 if (!err)
1073 prog->instances.fds[0] = fd; 1129 prog->instances.fds[0] = fd;
1074 goto out; 1130 goto out;
@@ -1096,7 +1152,8 @@ bpf_program__load(struct bpf_program *prog,
1096 continue; 1152 continue;
1097 } 1153 }
1098 1154
1099 err = load_program(prog->type, result.new_insn_ptr, 1155 err = load_program(prog->type, prog->name,
1156 result.new_insn_ptr,
1100 result.new_insn_cnt, 1157 result.new_insn_cnt,
1101 license, kern_version, &fd); 1158 license, kern_version, &fd);
1102 1159
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
index a0426147523d..290d5056c165 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -6939,7 +6939,7 @@ static int create_map_in_map(void)
6939 return inner_map_fd; 6939 return inner_map_fd;
6940 } 6940 }
6941 6941
6942 outer_map_fd = bpf_create_map_in_map(BPF_MAP_TYPE_ARRAY_OF_MAPS, 6942 outer_map_fd = bpf_create_map_in_map(BPF_MAP_TYPE_ARRAY_OF_MAPS, NULL,
6943 sizeof(int), inner_map_fd, 1, 0); 6943 sizeof(int), inner_map_fd, 1, 0);
6944 if (outer_map_fd < 0) 6944 if (outer_map_fd < 0)
6945 printf("Failed to create array of maps '%s'!\n", 6945 printf("Failed to create array of maps '%s'!\n",