* [PATCH bpf-next] bpf: btf: Clean up btf.h in uapi
@ 2018-04-21 16:48 Martin KaFai Lau
2018-04-22 4:57 ` Alexei Starovoitov
2018-04-23 9:34 ` Daniel Borkmann
0 siblings, 2 replies; 3+ messages in thread
From: Martin KaFai Lau @ 2018-04-21 16:48 UTC (permalink / raw)
To: netdev; +Cc: Alexei Starovoitov, Daniel Borkmann, kernel-team
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>
---
include/uapi/linux/btf.h | 8 +++-----
kernel/bpf/btf.c | 20 ++++++++++----------
tools/include/uapi/linux/btf.h | 8 +++-----
tools/lib/bpf/btf.c | 2 +-
4 files changed, 17 insertions(+), 21 deletions(-)
diff --git a/include/uapi/linux/btf.h b/include/uapi/linux/btf.h
index 74a30b1090df..bcb56ee47014 100644
--- a/include/uapi/linux/btf.h
+++ b/include/uapi/linux/btf.h
@@ -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 */
};
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index eb56ac760547..22e1046a1a86 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -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;
}
diff --git a/tools/include/uapi/linux/btf.h b/tools/include/uapi/linux/btf.h
index 74a30b1090df..bcb56ee47014 100644
--- a/tools/include/uapi/linux/btf.h
+++ b/tools/include/uapi/linux/btf.h
@@ -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 */
};
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 58b6255abc7a..2bac710e3194 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -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;
--
2.9.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] bpf: btf: Clean up btf.h in uapi
2018-04-21 16:48 [PATCH bpf-next] bpf: btf: Clean up btf.h in uapi Martin KaFai Lau
@ 2018-04-22 4:57 ` Alexei Starovoitov
2018-04-23 9:34 ` Daniel Borkmann
1 sibling, 0 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2018-04-22 4:57 UTC (permalink / raw)
To: Martin KaFai Lau; +Cc: netdev, Alexei Starovoitov, Daniel Borkmann, kernel-team
On Sat, Apr 21, 2018 at 09:48:23AM -0700, Martin KaFai Lau wrote:
> 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>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] bpf: btf: Clean up btf.h in uapi
2018-04-21 16:48 [PATCH bpf-next] bpf: btf: Clean up btf.h in uapi Martin KaFai Lau
2018-04-22 4:57 ` Alexei Starovoitov
@ 2018-04-23 9:34 ` Daniel Borkmann
1 sibling, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2018-04-23 9:34 UTC (permalink / raw)
To: Martin KaFai Lau, netdev; +Cc: Alexei Starovoitov, kernel-team
On 04/21/2018 06:48 PM, Martin KaFai Lau wrote:
> 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>
Applied to bpf-next, thanks Martin!
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-04-23 9:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-21 16:48 [PATCH bpf-next] bpf: btf: Clean up btf.h in uapi Martin KaFai Lau
2018-04-22 4:57 ` Alexei Starovoitov
2018-04-23 9:34 ` Daniel Borkmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).