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
6#include <linux/types.h>6#include <linux/types.h>
7 7
8#define BTF_MAGIC 0xeB9F8#define BTF_MAGIC 0xeB9F
9#define BTF_MAGIC_SWAP 0x9FeB
10#define BTF_VERSION 19#define BTF_VERSION 1
11#define BTF_FLAGS_COMPR 0x01
12 10
13struct btf_header {11struct btf_header {
14 __u16 magic;12 __u16 magic;
@@ -43,7 +41,7 @@ struct btf_header { · 28 unmodified lines
43#define BTF_STR_OFFSET(ref) ((ref) & BTF_MAX_NAME_OFFSET)41#define BTF_STR_OFFSET(ref) ((ref) & BTF_MAX_NAME_OFFSET)
44 42
45struct btf_type {43struct btf_type {
46 __u32 name;44 __u32 name_off;
47 /* "info" bits arrangement45 /* "info" bits arrangement
48 * bits 0-15: vlen (e.g. # of struct's members)46 * bits 0-15: vlen (e.g. # of struct's members)
49 * bits 16-23: unused47 * bits 16-23: unused
@@ -105,7 +103,7 @@ struct btf_type { · 55 unmodified lines
105 * info in "struct btf_type").103 * info in "struct btf_type").
106 */104 */
107struct btf_enum {105struct btf_enum {
108 __u32 name;106 __u32 name_off;
109 __s32 val;107 __s32 val;
110};108};
111 109
@@ -122,7 +120,7 @@ struct btf_array { · 10 unmodified lines
122 * "struct btf_type").120 * "struct btf_type").
123 */121 */
124struct btf_member {122struct btf_member {
125 __u32 name;123 __u32 name_off;
126 __u32 type;124 __u32 type;
127 __u32 offset; /* offset in bits */125 __u32 offset; /* offset in bits */
128};126};
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
473 __btf_verifier_log(log, "[%u] %s %s%s",473 __btf_verifier_log(log, "[%u] %s %s%s",
474 env->log_type_id,474 env->log_type_id,
475 btf_kind_str[kind],475 btf_kind_str[kind],
476 btf_name_by_offset(btf, t->name),476 btf_name_by_offset(btf, t->name_off),
477 log_details ? " " : "");477 log_details ? " " : "");
478 478
479 if (log_details)479 if (log_details)
@@ -517,7 +517,7 @@ static void btf_verifier_log_member(struct btf_verifier_env *env, · 37 unmodified lines
517 btf_verifier_log_type(env, struct_type, NULL);517 btf_verifier_log_type(env, struct_type, NULL);
518 518
519 __btf_verifier_log(log, "\t%s type_id=%u bits_offset=%u",519 __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),
521 member->type, member->offset);521 member->type, member->offset);
522 522
523 if (fmt && *fmt) {523 if (fmt && *fmt) {
@@ -1419,10 +1419,10 @@ static s32 btf_struct_check_meta(struct btf_verifier_env *env, · 895 unmodified lines
1419 btf_verifier_log_type(env, t, NULL);1419 btf_verifier_log_type(env, t, NULL);
1420 1420
1421 for_each_member(i, t, member) {1421 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)) {
1423 btf_verifier_log_member(env, t, member,1423 btf_verifier_log_member(env, t, member,
1424 "Invalid member name_offset:%u",1424 "Invalid member name_offset:%u",
1425 member->name);1425 member->name_off);
1426 return -EINVAL;1426 return -EINVAL;
1427 }1427 }
1428 1428
@@ -1605,14 +1605,14 @@ static s32 btf_enum_check_meta(struct btf_verifier_env *env, · 176 unmodified lines
1605 btf_verifier_log_type(env, t, NULL);1605 btf_verifier_log_type(env, t, NULL);
1606 1606
1607 for (i = 0; i < nr_enums; i++) {1607 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)) {
1609 btf_verifier_log(env, "\tInvalid name_offset:%u",1609 btf_verifier_log(env, "\tInvalid name_offset:%u",
1610 enums[i].name);1610 enums[i].name_off);
1611 return -EINVAL;1611 return -EINVAL;
1612 }1612 }
1613 1613
1614 btf_verifier_log(env, "\t%s val=%d\n",1614 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),
1616 enums[i].val);1616 enums[i].val);
1617 }1617 }
1618 1618
@@ -1636,7 +1636,7 @@ static void btf_enum_seq_show(const struct btf *btf, const struct btf_type *t, · 17 unmodified lines
1636 for (i = 0; i < nr_enums; i++) {1636 for (i = 0; i < nr_enums; i++) {
1637 if (v == enums[i].val) {1637 if (v == enums[i].val) {
1638 seq_printf(m, "%s",1638 seq_printf(m, "%s",
1639 btf_name_by_offset(btf, enums[i].name));1639 btf_name_by_offset(btf, enums[i].name_off));
1640 return;1640 return;
1641 }1641 }
1642 }1642 }
@@ -1687,9 +1687,9 @@ static s32 btf_check_meta(struct btf_verifier_env *env, · 44 unmodified lines
1687 return -EINVAL;1687 return -EINVAL;
1688 }1688 }
1689 1689
1690 if (!btf_name_offset_valid(env->btf, t->name)) {1690 if (!btf_name_offset_valid(env->btf, t->name_off)) {
1691 btf_verifier_log(env, "[%u] Invalid name_offset:%u",1691 btf_verifier_log(env, "[%u] Invalid name_offset:%u",
1692 env->log_type_id, t->name);1692 env->log_type_id, t->name_off);
1693 return -EINVAL;1693 return -EINVAL;
1694 }1694 }
1695 1695
tools/include/uapi/linux/btf.h+3−5
@@ -6,9 +6,7 @@ · 5 unmodified lines
6#include <linux/types.h>6#include <linux/types.h>
7 7
8#define BTF_MAGIC 0xeB9F8#define BTF_MAGIC 0xeB9F
9#define BTF_MAGIC_SWAP 0x9FeB
10#define BTF_VERSION 19#define BTF_VERSION 1
11#define BTF_FLAGS_COMPR 0x01
12 10
13struct btf_header {11struct btf_header {
14 __u16 magic;12 __u16 magic;
@@ -43,7 +41,7 @@ struct btf_header { · 28 unmodified lines
43#define BTF_STR_OFFSET(ref) ((ref) & BTF_MAX_NAME_OFFSET)41#define BTF_STR_OFFSET(ref) ((ref) & BTF_MAX_NAME_OFFSET)
44 42
45struct btf_type {43struct btf_type {
46 __u32 name;44 __u32 name_off;
47 /* "info" bits arrangement45 /* "info" bits arrangement
48 * bits 0-15: vlen (e.g. # of struct's members)46 * bits 0-15: vlen (e.g. # of struct's members)
49 * bits 16-23: unused47 * bits 16-23: unused
@@ -105,7 +103,7 @@ struct btf_type { · 55 unmodified lines
105 * info in "struct btf_type").103 * info in "struct btf_type").
106 */104 */
107struct btf_enum {105struct btf_enum {
108 __u32 name;106 __u32 name_off;
109 __s32 val;107 __s32 val;
110};108};
111 109
@@ -122,7 +120,7 @@ struct btf_array { · 10 unmodified lines
122 * "struct btf_type").120 * "struct btf_type").
123 */121 */
124struct btf_member {122struct btf_member {
125 __u32 name;123 __u32 name_off;
126 __u32 type;124 __u32 type;
127 __u32 offset; /* offset in bits */125 __u32 offset; /* offset in bits */
128};126};
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
281 281
282 for (i = 1; i <= btf->nr_types; i++) {282 for (i = 1; i <= btf->nr_types; i++) {
283 const struct btf_type *t = btf->types[i];283 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);
285 285
286 if (name && !strcmp(type_name, name))286 if (name && !strcmp(type_name, name))
287 return i;287 return i;