Skip to content

Commit fbcf93e

Browse files
iamkafaiborkmann
authored andcommitted
bpf: btf: Clean up btf.h in uapi
This patch cleans up btf.h in uapi: 1) Rename "name" to "name_off" to better reflect it is an offset to the string section instead of a char array. 2) Remove unused value BTF_FLAGS_COMPR and BTF_MAGIC_SWAP Suggested-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Martin KaFai Lau <kafai@fb.com> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent aaa6452 commit fbcf93e

4 files changed

Lines changed: 17 additions & 21 deletions

File tree

‎include/uapi/linux/btf.h‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
#include <linux/types.h>
77

88
#define BTF_MAGIC 0xeB9F
9-
#define BTF_MAGIC_SWAP 0x9FeB
109
#define BTF_VERSION 1
11-
#define BTF_FLAGS_COMPR 0x01
1210

1311
struct btf_header {
1412
__u16 magic;
@@ -43,7 +41,7 @@ struct btf_header {
4341
#define BTF_STR_OFFSET(ref) ((ref) & BTF_MAX_NAME_OFFSET)
4442

4543
struct btf_type {
46-
__u32 name;
44+
__u32 name_off;
4745
/* "info" bits arrangement
4846
* bits 0-15: vlen (e.g. # of struct's members)
4947
* bits 16-23: unused
@@ -105,7 +103,7 @@ struct btf_type {
105103
* info in "struct btf_type").
106104
*/
107105
struct btf_enum {
108-
__u32 name;
106+
__u32 name_off;
109107
__s32 val;
110108
};
111109

@@ -122,7 +120,7 @@ struct btf_array {
122120
* "struct btf_type").
123121
*/
124122
struct btf_member {
125-
__u32 name;
123+
__u32 name_off;
126124
__u32 type;
127125
__u32 offset; /* offset in bits */
128126
};

‎kernel/bpf/btf.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ __printf(4, 5) static void __btf_verifier_log_type(struct btf_verifier_env *env,
473473
__btf_verifier_log(log, "[%u] %s %s%s",
474474
env->log_type_id,
475475
btf_kind_str[kind],
476-
btf_name_by_offset(btf, t->name),
476+
btf_name_by_offset(btf, t->name_off),
477477
log_details ? " " : "");
478478

479479
if (log_details)
@@ -517,7 +517,7 @@ static void btf_verifier_log_member(struct btf_verifier_env *env,
517517
btf_verifier_log_type(env, struct_type, NULL);
518518

519519
__btf_verifier_log(log, "\t%s type_id=%u bits_offset=%u",
520-
btf_name_by_offset(btf, member->name),
520+
btf_name_by_offset(btf, member->name_off),
521521
member->type, member->offset);
522522

523523
if (fmt && *fmt) {
@@ -1419,10 +1419,10 @@ static s32 btf_struct_check_meta(struct btf_verifier_env *env,
14191419
btf_verifier_log_type(env, t, NULL);
14201420

14211421
for_each_member(i, t, member) {
1422-
if (!btf_name_offset_valid(btf, member->name)) {
1422+
if (!btf_name_offset_valid(btf, member->name_off)) {
14231423
btf_verifier_log_member(env, t, member,
14241424
"Invalid member name_offset:%u",
1425-
member->name);
1425+
member->name_off);
14261426
return -EINVAL;
14271427
}
14281428

@@ -1605,14 +1605,14 @@ static s32 btf_enum_check_meta(struct btf_verifier_env *env,
16051605
btf_verifier_log_type(env, t, NULL);
16061606

16071607
for (i = 0; i < nr_enums; i++) {
1608-
if (!btf_name_offset_valid(btf, enums[i].name)) {
1608+
if (!btf_name_offset_valid(btf, enums[i].name_off)) {
16091609
btf_verifier_log(env, "\tInvalid name_offset:%u",
1610-
enums[i].name);
1610+
enums[i].name_off);
16111611
return -EINVAL;
16121612
}
16131613

16141614
btf_verifier_log(env, "\t%s val=%d\n",
1615-
btf_name_by_offset(btf, enums[i].name),
1615+
btf_name_by_offset(btf, enums[i].name_off),
16161616
enums[i].val);
16171617
}
16181618

@@ -1636,7 +1636,7 @@ static void btf_enum_seq_show(const struct btf *btf, const struct btf_type *t,
16361636
for (i = 0; i < nr_enums; i++) {
16371637
if (v == enums[i].val) {
16381638
seq_printf(m, "%s",
1639-
btf_name_by_offset(btf, enums[i].name));
1639+
btf_name_by_offset(btf, enums[i].name_off));
16401640
return;
16411641
}
16421642
}
@@ -1687,9 +1687,9 @@ static s32 btf_check_meta(struct btf_verifier_env *env,
16871687
return -EINVAL;
16881688
}
16891689

1690-
if (!btf_name_offset_valid(env->btf, t->name)) {
1690+
if (!btf_name_offset_valid(env->btf, t->name_off)) {
16911691
btf_verifier_log(env, "[%u] Invalid name_offset:%u",
1692-
env->log_type_id, t->name);
1692+
env->log_type_id, t->name_off);
16931693
return -EINVAL;
16941694
}
16951695

‎tools/include/uapi/linux/btf.h‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
#include <linux/types.h>
77

88
#define BTF_MAGIC 0xeB9F
9-
#define BTF_MAGIC_SWAP 0x9FeB
109
#define BTF_VERSION 1
11-
#define BTF_FLAGS_COMPR 0x01
1210

1311
struct btf_header {
1412
__u16 magic;
@@ -43,7 +41,7 @@ struct btf_header {
4341
#define BTF_STR_OFFSET(ref) ((ref) & BTF_MAX_NAME_OFFSET)
4442

4543
struct btf_type {
46-
__u32 name;
44+
__u32 name_off;
4745
/* "info" bits arrangement
4846
* bits 0-15: vlen (e.g. # of struct's members)
4947
* bits 16-23: unused
@@ -105,7 +103,7 @@ struct btf_type {
105103
* info in "struct btf_type").
106104
*/
107105
struct btf_enum {
108-
__u32 name;
106+
__u32 name_off;
109107
__s32 val;
110108
};
111109

@@ -122,7 +120,7 @@ struct btf_array {
122120
* "struct btf_type").
123121
*/
124122
struct btf_member {
125-
__u32 name;
123+
__u32 name_off;
126124
__u32 type;
127125
__u32 offset; /* offset in bits */
128126
};

‎tools/lib/bpf/btf.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ int32_t btf__find_by_name(const struct btf *btf, const char *type_name)
281281

282282
for (i = 1; i <= btf->nr_types; i++) {
283283
const struct btf_type *t = btf->types[i];
284-
const char *name = btf_name_by_offset(btf, t->name);
284+
const char *name = btf_name_by_offset(btf, t->name_off);
285285

286286
if (name && !strcmp(type_name, name))
287287
return i;

0 commit comments

Comments
 (0)