History

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

Martin KaFai Lau committed 8 years ago

Commit fbcf93e1 parent aaa64524 files · +17 −21Browse files

Unified · Split

4 files
  1. include/uapi/linux/btf.h +3 −5
  2. kernel/bpf/btf.c +10 −10
  3. tools/include/uapi/linux/btf.h +3 −5
  4. tools/lib/bpf/btf.c +1 −1
include/uapi/linux/btf.h+3−5
@@ -6,9 +6,7 @@ · 5 unmodified lines
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 { · 28 unmodified lines
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 { · 55 unmodified lines
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 { · 10 unmodified lines
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+10−10
@@ -473,7 +473,7 @@ __printf(4, 5) static void __btf_verifier_log_type(struct btf_verifier_env *env, · 472 unmodified lines
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, · 37 unmodified lines
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, · 895 unmodified lines
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, · 176 unmodified lines
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, · 17 unmodified lines
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, · 44 unmodified lines
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+3−5
@@ -6,9 +6,7 @@ · 5 unmodified lines
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 { · 28 unmodified lines
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 { · 55 unmodified lines
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 { · 10 unmodified lines
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+1−1
@@ -281,7 +281,7 @@ int32_t btf__find_by_name(const struct btf *btf, const char *type_name) · 280 unmodified lines
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;