Skip to content

Commit 9b2cf32

Browse files
iamkafaiborkmann
authored andcommitted
bpf: btf: Rename btf_key_id and btf_value_id in bpf_map_info
In "struct bpf_map_info", the name "btf_id", "btf_key_id" and "btf_value_id" could cause confusion because the "id" of "btf_id" means the BPF obj id given to the BTF object while "btf_key_id" and "btf_value_id" means the BTF type id within that BTF object. To make it clear, btf_key_id and btf_value_id are renamed to btf_key_type_id and btf_value_type_id. Suggested-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Martin KaFai Lau <kafai@fb.com> Acked-by: Yonghong Song <yhs@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent aea2f7b commit 9b2cf32

4 files changed

Lines changed: 16 additions & 16 deletions

File tree

‎include/linux/bpf.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ struct bpf_map {
6969
u32 pages;
7070
u32 id;
7171
int numa_node;
72-
u32 btf_key_id;
73-
u32 btf_value_id;
72+
u32 btf_key_type_id;
73+
u32 btf_value_type_id;
7474
struct btf *btf;
7575
bool unpriv_array;
7676
/* 55 bytes hole */

‎include/uapi/linux/bpf.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ union bpf_attr {
284284
char map_name[BPF_OBJ_NAME_LEN];
285285
__u32 map_ifindex; /* ifindex of netdev to create on */
286286
__u32 btf_fd; /* fd pointing to a BTF type data */
287-
__u32 btf_key_id; /* BTF type_id of the key */
288-
__u32 btf_value_id; /* BTF type_id of the value */
287+
__u32 btf_key_type_id; /* BTF type_id of the key */
288+
__u32 btf_value_type_id; /* BTF type_id of the value */
289289
};
290290

291291
struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
@@ -2219,8 +2219,8 @@ struct bpf_map_info {
22192219
__u64 netns_dev;
22202220
__u64 netns_ino;
22212221
__u32 btf_id;
2222-
__u32 btf_key_id;
2223-
__u32 btf_value_id;
2222+
__u32 btf_key_type_id;
2223+
__u32 btf_value_type_id;
22242224
} __attribute__((aligned(8)));
22252225

22262226
struct bpf_btf_info {

‎kernel/bpf/arraymap.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ static void array_map_seq_show_elem(struct bpf_map *map, void *key,
352352
}
353353

354354
seq_printf(m, "%u: ", *(u32 *)key);
355-
btf_type_seq_show(map->btf, map->btf_value_id, value, m);
355+
btf_type_seq_show(map->btf, map->btf_value_type_id, value, m);
356356
seq_puts(m, "\n");
357357

358358
rcu_read_unlock();

‎kernel/bpf/syscall.c‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ static int bpf_obj_name_cpy(char *dst, const char *src)
422422
return 0;
423423
}
424424

425-
#define BPF_MAP_CREATE_LAST_FIELD btf_value_id
425+
#define BPF_MAP_CREATE_LAST_FIELD btf_value_type_id
426426
/* called via syscall */
427427
static int map_create(union bpf_attr *attr)
428428
{
@@ -457,10 +457,10 @@ static int map_create(union bpf_attr *attr)
457457
atomic_set(&map->usercnt, 1);
458458

459459
if (bpf_map_support_seq_show(map) &&
460-
(attr->btf_key_id || attr->btf_value_id)) {
460+
(attr->btf_key_type_id || attr->btf_value_type_id)) {
461461
struct btf *btf;
462462

463-
if (!attr->btf_key_id || !attr->btf_value_id) {
463+
if (!attr->btf_key_type_id || !attr->btf_value_type_id) {
464464
err = -EINVAL;
465465
goto free_map_nouncharge;
466466
}
@@ -471,16 +471,16 @@ static int map_create(union bpf_attr *attr)
471471
goto free_map_nouncharge;
472472
}
473473

474-
err = map->ops->map_check_btf(map, btf, attr->btf_key_id,
475-
attr->btf_value_id);
474+
err = map->ops->map_check_btf(map, btf, attr->btf_key_type_id,
475+
attr->btf_value_type_id);
476476
if (err) {
477477
btf_put(btf);
478478
goto free_map_nouncharge;
479479
}
480480

481481
map->btf = btf;
482-
map->btf_key_id = attr->btf_key_id;
483-
map->btf_value_id = attr->btf_value_id;
482+
map->btf_key_type_id = attr->btf_key_type_id;
483+
map->btf_value_type_id = attr->btf_value_type_id;
484484
}
485485

486486
err = security_bpf_map_alloc(map);
@@ -2013,8 +2013,8 @@ static int bpf_map_get_info_by_fd(struct bpf_map *map,
20132013

20142014
if (map->btf) {
20152015
info.btf_id = btf_id(map->btf);
2016-
info.btf_key_id = map->btf_key_id;
2017-
info.btf_value_id = map->btf_value_id;
2016+
info.btf_key_type_id = map->btf_key_type_id;
2017+
info.btf_value_type_id = map->btf_value_type_id;
20182018
}
20192019

20202020
if (bpf_map_is_dev_bound(map)) {

0 commit comments

Comments
 (0)