bpf: btf: Clean up btf.h in uapi
authorMartin KaFai Lau <kafai@fb.com>
Sat, 21 Apr 2018 16:48:23 +0000 (09:48 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Mon, 23 Apr 2018 09:32:01 +0000 (11:32 +0200)
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>
include/uapi/linux/btf.h
kernel/bpf/btf.c
tools/include/uapi/linux/btf.h
tools/lib/bpf/btf.c

index 74a30b1090dfcfe58c95d707671a1b09745d6cab..bcb56ee4701461a6b4a0134903a1eeef8e275ca6 100644 (file)
@@ -6,9 +6,7 @@
 #include <linux/types.h>
 
 #define BTF_MAGIC      0xeB9F
-#define BTF_MAGIC_SWAP 0x9FeB
 #define BTF_VERSION    1
-#define BTF_FLAGS_COMPR        0x01
 
 struct btf_header {
        __u16   magic;
@@ -43,7 +41,7 @@ struct btf_header {
 #define BTF_STR_OFFSET(ref)    ((ref) & BTF_MAX_NAME_OFFSET)
 
 struct btf_type {
-       __u32 name;
+       __u32 name_off;
        /* "info" bits arrangement
         * bits  0-15: vlen (e.g. # of struct's members)
         * bits 16-23: unused
@@ -105,7 +103,7 @@ struct btf_type {
  * info in "struct btf_type").
  */
 struct btf_enum {
-       __u32   name;
+       __u32   name_off;
        __s32   val;
 };
 
@@ -122,7 +120,7 @@ struct btf_array {
  * "struct btf_type").
  */
 struct btf_member {
-       __u32   name;
+       __u32   name_off;
        __u32   type;
        __u32   offset; /* offset in bits */
 };
index eb56ac7605473f5626e34c245206d9638a915144..22e1046a1a86ae1740e277eedf9292386283b237 100644 (file)
@@ -473,7 +473,7 @@ __printf(4, 5) static void __btf_verifier_log_type(struct btf_verifier_env *env,
        __btf_verifier_log(log, "[%u] %s %s%s",
                           env->log_type_id,
                           btf_kind_str[kind],
-                          btf_name_by_offset(btf, t->name),
+                          btf_name_by_offset(btf, t->name_off),
                           log_details ? " " : "");
 
        if (log_details)
@@ -517,7 +517,7 @@ static void btf_verifier_log_member(struct btf_verifier_env *env,
                btf_verifier_log_type(env, struct_type, NULL);
 
        __btf_verifier_log(log, "\t%s type_id=%u bits_offset=%u",
-                          btf_name_by_offset(btf, member->name),
+                          btf_name_by_offset(btf, member->name_off),
                           member->type, member->offset);
 
        if (fmt && *fmt) {
@@ -1419,10 +1419,10 @@ static s32 btf_struct_check_meta(struct btf_verifier_env *env,
        btf_verifier_log_type(env, t, NULL);
 
        for_each_member(i, t, member) {
-               if (!btf_name_offset_valid(btf, member->name)) {
+               if (!btf_name_offset_valid(btf, member->name_off)) {
                        btf_verifier_log_member(env, t, member,
                                                "Invalid member name_offset:%u",
-                                               member->name);
+                                               member->name_off);
                        return -EINVAL;
                }
 
@@ -1605,14 +1605,14 @@ static s32 btf_enum_check_meta(struct btf_verifier_env *env,
        btf_verifier_log_type(env, t, NULL);
 
        for (i = 0; i < nr_enums; i++) {
-               if (!btf_name_offset_valid(btf, enums[i].name)) {
+               if (!btf_name_offset_valid(btf, enums[i].name_off)) {
                        btf_verifier_log(env, "\tInvalid name_offset:%u",
-                                        enums[i].name);
+                                        enums[i].name_off);
                        return -EINVAL;
                }
 
                btf_verifier_log(env, "\t%s val=%d\n",
-                                btf_name_by_offset(btf, enums[i].name),
+                                btf_name_by_offset(btf, enums[i].name_off),
                                 enums[i].val);
        }
 
@@ -1636,7 +1636,7 @@ static void btf_enum_seq_show(const struct btf *btf, const struct btf_type *t,
        for (i = 0; i < nr_enums; i++) {
                if (v == enums[i].val) {
                        seq_printf(m, "%s",
-                                  btf_name_by_offset(btf, enums[i].name));
+                                  btf_name_by_offset(btf, enums[i].name_off));
                        return;
                }
        }
@@ -1687,9 +1687,9 @@ static s32 btf_check_meta(struct btf_verifier_env *env,
                return -EINVAL;
        }
 
-       if (!btf_name_offset_valid(env->btf, t->name)) {
+       if (!btf_name_offset_valid(env->btf, t->name_off)) {
                btf_verifier_log(env, "[%u] Invalid name_offset:%u",
-                                env->log_type_id, t->name);
+                                env->log_type_id, t->name_off);
                return -EINVAL;
        }
 
index 74a30b1090dfcfe58c95d707671a1b09745d6cab..bcb56ee4701461a6b4a0134903a1eeef8e275ca6 100644 (file)
@@ -6,9 +6,7 @@
 #include <linux/types.h>
 
 #define BTF_MAGIC      0xeB9F
-#define BTF_MAGIC_SWAP 0x9FeB
 #define BTF_VERSION    1
-#define BTF_FLAGS_COMPR        0x01
 
 struct btf_header {
        __u16   magic;
@@ -43,7 +41,7 @@ struct btf_header {
 #define BTF_STR_OFFSET(ref)    ((ref) & BTF_MAX_NAME_OFFSET)
 
 struct btf_type {
-       __u32 name;
+       __u32 name_off;
        /* "info" bits arrangement
         * bits  0-15: vlen (e.g. # of struct's members)
         * bits 16-23: unused
@@ -105,7 +103,7 @@ struct btf_type {
  * info in "struct btf_type").
  */
 struct btf_enum {
-       __u32   name;
+       __u32   name_off;
        __s32   val;
 };
 
@@ -122,7 +120,7 @@ struct btf_array {
  * "struct btf_type").
  */
 struct btf_member {
-       __u32   name;
+       __u32   name_off;
        __u32   type;
        __u32   offset; /* offset in bits */
 };
index 58b6255abc7ad410b8302ce49aec7e157a188b9d..2bac710e3194d861ea7fa4b8196146059972e900 100644 (file)
@@ -281,7 +281,7 @@ int32_t btf__find_by_name(const struct btf *btf, const char *type_name)
 
        for (i = 1; i <= btf->nr_types; i++) {
                const struct btf_type *t = btf->types[i];
-               const char *name = btf_name_by_offset(btf, t->name);
+               const char *name = btf_name_by_offset(btf, t->name_off);
 
                if (name && !strcmp(type_name, name))
                        return i;