提交 b87fc8a4 编写于 作者: Y Yonghong Song 提交者: Zheng Zengkai

bpf: Rename BTF_KIND_TAG to BTF_KIND_DECL_TAG

mainline inclusion
from mainline-5.16-rc1
commit 223f903e
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5EUVD
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=223f903e9c832699f4e5f422281a60756c1c6cfe

-------------------------------------------------

Patch set [1] introduced BTF_KIND_TAG to allow tagging
declarations for struct/union, struct/union field, var, func
and func arguments and these tags will be encoded into
dwarf. They are also encoded to btf by llvm for the bpf target.

After BTF_KIND_TAG is introduced, we intended to use it
for kernel __user attributes. But kernel __user is actually
a type attribute. Upstream and internal discussion showed
it is not a good idea to mix declaration attribute and
type attribute. So we proposed to introduce btf_type_tag
as a type attribute and existing btf_tag renamed to
btf_decl_tag ([2]).

This patch renamed BTF_KIND_TAG to BTF_KIND_DECL_TAG and some
other declarations with *_tag to *_decl_tag to make it clear
the tag is for declaration. In the future, BTF_KIND_TYPE_TAG
might be introduced per [3].

 [1] https://lore.kernel.org/bpf/20210914223004.244411-1-yhs@fb.com/
 [2] https://reviews.llvm.org/D111588
 [3] https://reviews.llvm.org/D111199

Fixes: b5ea834d ("bpf: Support for new btf kind BTF_KIND_TAG")
Fixes: 5b84bd10 ("libbpf: Add support for BTF_KIND_TAG")
Fixes: 5c07f2fe ("bpftool: Add support for BTF_KIND_TAG")
Signed-off-by: NYonghong Song <yhs@fb.com>
Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211012164838.3345699-1-yhs@fb.com
(cherry picked from commit 223f903e)
Signed-off-by: NWang Yufen <wangyufen@huawei.com>

Conflicts:
	Documentation/bpf/btf.rst
	kernel/bpf/btf.c
	tools/bpf/bpftool/btf.c
	tools/lib/bpf/libbpf.c
	tools/testing/selftests/bpf/README.rst
	tools/testing/selftests/bpf/btf_helpers.c
	tools/testing/selftests/bpf/prog_tests/btf.c
	tools/testing/selftests/bpf/prog_tests/btf_write.c
	tools/testing/selftests/bpf/progs/tag.c
	tools/testing/selftests/bpf/test_btf.h
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
上级 64dfed76
...@@ -84,6 +84,7 @@ sequentially and type id is assigned to each recognized type starting from id ...@@ -84,6 +84,7 @@ sequentially and type id is assigned to each recognized type starting from id
#define BTF_KIND_FUNC_PROTO 13 /* Function Proto */ #define BTF_KIND_FUNC_PROTO 13 /* Function Proto */
#define BTF_KIND_VAR 14 /* Variable */ #define BTF_KIND_VAR 14 /* Variable */
#define BTF_KIND_DATASEC 15 /* Section */ #define BTF_KIND_DATASEC 15 /* Section */
#define BTF_KIND_DECL_TAG 17 /* Decl Tag */
Note that the type section encodes debug info, not just pure types. Note that the type section encodes debug info, not just pure types.
``BTF_KIND_FUNC`` is not a type, and it represents a defined subprogram. ``BTF_KIND_FUNC`` is not a type, and it represents a defined subprogram.
...@@ -105,7 +106,7 @@ Each type contains the following common data:: ...@@ -105,7 +106,7 @@ Each type contains the following common data::
* "size" tells the size of the type it is describing. * "size" tells the size of the type it is describing.
* *
* "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT, * "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT,
* FUNC and FUNC_PROTO. * FUNC, FUNC_PROTO and DECL_TAG.
* "type" is a type_id referring to another type. * "type" is a type_id referring to another type.
*/ */
union { union {
......
...@@ -43,7 +43,7 @@ struct btf_type { ...@@ -43,7 +43,7 @@ struct btf_type {
* "size" tells the size of the type it is describing. * "size" tells the size of the type it is describing.
* *
* "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT, * "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT,
* FUNC, FUNC_PROTO, VAR and TAG. * FUNC, FUNC_PROTO, VAR and DECL_TAG.
* "type" is a type_id referring to another type. * "type" is a type_id referring to another type.
*/ */
union { union {
...@@ -74,7 +74,7 @@ enum { ...@@ -74,7 +74,7 @@ enum {
BTF_KIND_VAR = 14, /* Variable */ BTF_KIND_VAR = 14, /* Variable */
BTF_KIND_DATASEC = 15, /* Section */ BTF_KIND_DATASEC = 15, /* Section */
BTF_KIND_FLOAT = 16, /* Floating point */ BTF_KIND_FLOAT = 16, /* Floating point */
BTF_KIND_TAG = 17, /* Tag */ BTF_KIND_DECL_TAG = 17, /* Decl Tag */
NR_BTF_KINDS, NR_BTF_KINDS,
BTF_KIND_MAX = NR_BTF_KINDS - 1, BTF_KIND_MAX = NR_BTF_KINDS - 1,
...@@ -174,14 +174,14 @@ struct btf_var_secinfo { ...@@ -174,14 +174,14 @@ struct btf_var_secinfo {
__u32 size; __u32 size;
}; };
/* BTF_KIND_TAG is followed by a single "struct btf_tag" to describe /* BTF_KIND_DECL_TAG is followed by a single "struct btf_decl_tag" to describe
* additional information related to the tag applied location. * additional information related to the tag applied location.
* If component_idx == -1, the tag is applied to a struct, union, * If component_idx == -1, the tag is applied to a struct, union,
* variable or function. Otherwise, it is applied to a struct/union * variable or function. Otherwise, it is applied to a struct/union
* member or a func argument, and component_idx indicates which member * member or a func argument, and component_idx indicates which member
* or argument (0 ... vlen-1). * or argument (0 ... vlen-1).
*/ */
struct btf_tag { struct btf_decl_tag {
__s32 component_idx; __s32 component_idx;
}; };
......
...@@ -280,7 +280,7 @@ static const char * const btf_kind_str[NR_BTF_KINDS] = { ...@@ -280,7 +280,7 @@ static const char * const btf_kind_str[NR_BTF_KINDS] = {
[BTF_KIND_FUNC_PROTO] = "FUNC_PROTO", [BTF_KIND_FUNC_PROTO] = "FUNC_PROTO",
[BTF_KIND_VAR] = "VAR", [BTF_KIND_VAR] = "VAR",
[BTF_KIND_DATASEC] = "DATASEC", [BTF_KIND_DATASEC] = "DATASEC",
[BTF_KIND_TAG] = "TAG", [BTF_KIND_DECL_TAG] = "DECL_TAG",
}; };
const char *btf_type_str(const struct btf_type *t) const char *btf_type_str(const struct btf_type *t)
...@@ -459,12 +459,12 @@ static bool btf_type_is_datasec(const struct btf_type *t) ...@@ -459,12 +459,12 @@ static bool btf_type_is_datasec(const struct btf_type *t)
return BTF_INFO_KIND(t->info) == BTF_KIND_DATASEC; return BTF_INFO_KIND(t->info) == BTF_KIND_DATASEC;
} }
static bool btf_type_is_tag(const struct btf_type *t) static bool btf_type_is_decl_tag(const struct btf_type *t)
{ {
return BTF_INFO_KIND(t->info) == BTF_KIND_TAG; return BTF_INFO_KIND(t->info) == BTF_KIND_DECL_TAG;
} }
static bool btf_type_is_tag_target(const struct btf_type *t) static bool btf_type_is_decl_tag_target(const struct btf_type *t)
{ {
return btf_type_is_func(t) || btf_type_is_struct(t) || return btf_type_is_func(t) || btf_type_is_struct(t) ||
btf_type_is_var(t); btf_type_is_var(t);
...@@ -548,7 +548,7 @@ const struct btf_type *btf_type_resolve_func_ptr(const struct btf *btf, ...@@ -548,7 +548,7 @@ const struct btf_type *btf_type_resolve_func_ptr(const struct btf *btf,
static bool btf_type_is_resolve_source_only(const struct btf_type *t) static bool btf_type_is_resolve_source_only(const struct btf_type *t)
{ {
return btf_type_is_var(t) || return btf_type_is_var(t) ||
btf_type_is_tag(t) || btf_type_is_decl_tag(t) ||
btf_type_is_datasec(t); btf_type_is_datasec(t);
} }
...@@ -575,7 +575,7 @@ static bool btf_type_needs_resolve(const struct btf_type *t) ...@@ -575,7 +575,7 @@ static bool btf_type_needs_resolve(const struct btf_type *t)
btf_type_is_struct(t) || btf_type_is_struct(t) ||
btf_type_is_array(t) || btf_type_is_array(t) ||
btf_type_is_var(t) || btf_type_is_var(t) ||
btf_type_is_tag(t) || btf_type_is_decl_tag(t) ||
btf_type_is_datasec(t); btf_type_is_datasec(t);
} }
...@@ -628,9 +628,9 @@ static const struct btf_var *btf_type_var(const struct btf_type *t) ...@@ -628,9 +628,9 @@ static const struct btf_var *btf_type_var(const struct btf_type *t)
return (const struct btf_var *)(t + 1); return (const struct btf_var *)(t + 1);
} }
static const struct btf_tag *btf_type_tag(const struct btf_type *t) static const struct btf_decl_tag *btf_type_decl_tag(const struct btf_type *t)
{ {
return (const struct btf_tag *)(t + 1); return (const struct btf_decl_tag *)(t + 1);
} }
static const struct btf_kind_operations *btf_type_ops(const struct btf_type *t) static const struct btf_kind_operations *btf_type_ops(const struct btf_type *t)
...@@ -3694,11 +3694,11 @@ static const struct btf_kind_operations datasec_ops = { ...@@ -3694,11 +3694,11 @@ static const struct btf_kind_operations datasec_ops = {
.show = btf_datasec_show, .show = btf_datasec_show,
}; };
static s32 btf_tag_check_meta(struct btf_verifier_env *env, static s32 btf_decl_tag_check_meta(struct btf_verifier_env *env,
const struct btf_type *t, const struct btf_type *t,
u32 meta_left) u32 meta_left)
{ {
const struct btf_tag *tag; const struct btf_decl_tag *tag;
u32 meta_needed = sizeof(*tag); u32 meta_needed = sizeof(*tag);
s32 component_idx; s32 component_idx;
const char *value; const char *value;
...@@ -3726,7 +3726,7 @@ static s32 btf_tag_check_meta(struct btf_verifier_env *env, ...@@ -3726,7 +3726,7 @@ static s32 btf_tag_check_meta(struct btf_verifier_env *env,
return -EINVAL; return -EINVAL;
} }
component_idx = btf_type_tag(t)->component_idx; component_idx = btf_type_decl_tag(t)->component_idx;
if (component_idx < -1) { if (component_idx < -1) {
btf_verifier_log_type(env, t, "Invalid component_idx"); btf_verifier_log_type(env, t, "Invalid component_idx");
return -EINVAL; return -EINVAL;
...@@ -3737,7 +3737,7 @@ static s32 btf_tag_check_meta(struct btf_verifier_env *env, ...@@ -3737,7 +3737,7 @@ static s32 btf_tag_check_meta(struct btf_verifier_env *env,
return meta_needed; return meta_needed;
} }
static int btf_tag_resolve(struct btf_verifier_env *env, static int btf_decl_tag_resolve(struct btf_verifier_env *env,
const struct resolve_vertex *v) const struct resolve_vertex *v)
{ {
const struct btf_type *next_type; const struct btf_type *next_type;
...@@ -3748,7 +3748,7 @@ static int btf_tag_resolve(struct btf_verifier_env *env, ...@@ -3748,7 +3748,7 @@ static int btf_tag_resolve(struct btf_verifier_env *env,
u32 vlen; u32 vlen;
next_type = btf_type_by_id(btf, next_type_id); next_type = btf_type_by_id(btf, next_type_id);
if (!next_type || !btf_type_is_tag_target(next_type)) { if (!next_type || !btf_type_is_decl_tag_target(next_type)) {
btf_verifier_log_type(env, v->t, "Invalid type_id"); btf_verifier_log_type(env, v->t, "Invalid type_id");
return -EINVAL; return -EINVAL;
} }
...@@ -3757,7 +3757,7 @@ static int btf_tag_resolve(struct btf_verifier_env *env, ...@@ -3757,7 +3757,7 @@ static int btf_tag_resolve(struct btf_verifier_env *env,
!env_type_is_resolved(env, next_type_id)) !env_type_is_resolved(env, next_type_id))
return env_stack_push(env, next_type, next_type_id); return env_stack_push(env, next_type, next_type_id);
component_idx = btf_type_tag(t)->component_idx; component_idx = btf_type_decl_tag(t)->component_idx;
if (component_idx != -1) { if (component_idx != -1) {
if (btf_type_is_var(next_type)) { if (btf_type_is_var(next_type)) {
btf_verifier_log_type(env, v->t, "Invalid component_idx"); btf_verifier_log_type(env, v->t, "Invalid component_idx");
...@@ -3783,18 +3783,18 @@ static int btf_tag_resolve(struct btf_verifier_env *env, ...@@ -3783,18 +3783,18 @@ static int btf_tag_resolve(struct btf_verifier_env *env,
return 0; return 0;
} }
static void btf_tag_log(struct btf_verifier_env *env, const struct btf_type *t) static void btf_decl_tag_log(struct btf_verifier_env *env, const struct btf_type *t)
{ {
btf_verifier_log(env, "type=%u component_idx=%d", t->type, btf_verifier_log(env, "type=%u component_idx=%d", t->type,
btf_type_tag(t)->component_idx); btf_type_decl_tag(t)->component_idx);
} }
static const struct btf_kind_operations tag_ops = { static const struct btf_kind_operations decl_tag_ops = {
.check_meta = btf_tag_check_meta, .check_meta = btf_decl_tag_check_meta,
.resolve = btf_tag_resolve, .resolve = btf_decl_tag_resolve,
.check_member = btf_df_check_member, .check_member = btf_df_check_member,
.check_kflag_member = btf_df_check_kflag_member, .check_kflag_member = btf_df_check_kflag_member,
.log_details = btf_tag_log, .log_details = btf_decl_tag_log,
.show = btf_df_show, .show = btf_df_show,
}; };
...@@ -3931,7 +3931,7 @@ static const struct btf_kind_operations * const kind_ops[NR_BTF_KINDS] = { ...@@ -3931,7 +3931,7 @@ static const struct btf_kind_operations * const kind_ops[NR_BTF_KINDS] = {
[BTF_KIND_FUNC_PROTO] = &func_proto_ops, [BTF_KIND_FUNC_PROTO] = &func_proto_ops,
[BTF_KIND_VAR] = &var_ops, [BTF_KIND_VAR] = &var_ops,
[BTF_KIND_DATASEC] = &datasec_ops, [BTF_KIND_DATASEC] = &datasec_ops,
[BTF_KIND_TAG] = &tag_ops, [BTF_KIND_DECL_TAG] = &decl_tag_ops,
}; };
static s32 btf_check_meta(struct btf_verifier_env *env, static s32 btf_check_meta(struct btf_verifier_env *env,
...@@ -4016,7 +4016,7 @@ static bool btf_resolve_valid(struct btf_verifier_env *env, ...@@ -4016,7 +4016,7 @@ static bool btf_resolve_valid(struct btf_verifier_env *env,
return !btf_resolved_type_id(btf, type_id) && return !btf_resolved_type_id(btf, type_id) &&
!btf_resolved_type_size(btf, type_id); !btf_resolved_type_size(btf, type_id);
if (btf_type_is_tag(t)) if (btf_type_is_decl_tag(t))
return btf_resolved_type_id(btf, type_id) && return btf_resolved_type_id(btf, type_id) &&
!btf_resolved_type_size(btf, type_id); !btf_resolved_type_size(btf, type_id);
......
...@@ -36,7 +36,7 @@ static const char * const btf_kind_str[NR_BTF_KINDS] = { ...@@ -36,7 +36,7 @@ static const char * const btf_kind_str[NR_BTF_KINDS] = {
[BTF_KIND_FUNC_PROTO] = "FUNC_PROTO", [BTF_KIND_FUNC_PROTO] = "FUNC_PROTO",
[BTF_KIND_VAR] = "VAR", [BTF_KIND_VAR] = "VAR",
[BTF_KIND_DATASEC] = "DATASEC", [BTF_KIND_DATASEC] = "DATASEC",
[BTF_KIND_TAG] = "TAG", [BTF_KIND_DECL_TAG] = "DECL_TAG",
}; };
struct btf_attach_table { struct btf_attach_table {
...@@ -328,8 +328,8 @@ static int dump_btf_type(const struct btf *btf, __u32 id, ...@@ -328,8 +328,8 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
jsonw_end_array(w); jsonw_end_array(w);
break; break;
} }
case BTF_KIND_TAG: { case BTF_KIND_DECL_TAG: {
const struct btf_tag *tag = (const void *)(t + 1); const struct btf_decl_tag *tag = (const void *)(t + 1);
if (json_output) { if (json_output) {
jsonw_uint_field(w, "type_id", t->type); jsonw_uint_field(w, "type_id", t->type);
......
...@@ -43,7 +43,7 @@ struct btf_type { ...@@ -43,7 +43,7 @@ struct btf_type {
* "size" tells the size of the type it is describing. * "size" tells the size of the type it is describing.
* *
* "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT, * "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT,
* FUNC, FUNC_PROTO, VAR and TAG. * FUNC, FUNC_PROTO, VAR and DECL_TAG.
* "type" is a type_id referring to another type. * "type" is a type_id referring to another type.
*/ */
union { union {
...@@ -74,7 +74,7 @@ enum { ...@@ -74,7 +74,7 @@ enum {
BTF_KIND_VAR = 14, /* Variable */ BTF_KIND_VAR = 14, /* Variable */
BTF_KIND_DATASEC = 15, /* Section */ BTF_KIND_DATASEC = 15, /* Section */
BTF_KIND_FLOAT = 16, /* Floating point */ BTF_KIND_FLOAT = 16, /* Floating point */
BTF_KIND_TAG = 17, /* Tag */ BTF_KIND_DECL_TAG = 17, /* Decl Tag */
NR_BTF_KINDS, NR_BTF_KINDS,
BTF_KIND_MAX = NR_BTF_KINDS - 1, BTF_KIND_MAX = NR_BTF_KINDS - 1,
...@@ -174,14 +174,14 @@ struct btf_var_secinfo { ...@@ -174,14 +174,14 @@ struct btf_var_secinfo {
__u32 size; __u32 size;
}; };
/* BTF_KIND_TAG is followed by a single "struct btf_tag" to describe /* BTF_KIND_DECL_TAG is followed by a single "struct btf_decl_tag" to describe
* additional information related to the tag applied location. * additional information related to the tag applied location.
* If component_idx == -1, the tag is applied to a struct, union, * If component_idx == -1, the tag is applied to a struct, union,
* variable or function. Otherwise, it is applied to a struct/union * variable or function. Otherwise, it is applied to a struct/union
* member or a func argument, and component_idx indicates which member * member or a func argument, and component_idx indicates which member
* or argument (0 ... vlen-1). * or argument (0 ... vlen-1).
*/ */
struct btf_tag { struct btf_decl_tag {
__s32 component_idx; __s32 component_idx;
}; };
......
...@@ -315,8 +315,8 @@ static int btf_type_size(const struct btf_type *t) ...@@ -315,8 +315,8 @@ static int btf_type_size(const struct btf_type *t)
return base_size + sizeof(struct btf_var); return base_size + sizeof(struct btf_var);
case BTF_KIND_DATASEC: case BTF_KIND_DATASEC:
return base_size + vlen * sizeof(struct btf_var_secinfo); return base_size + vlen * sizeof(struct btf_var_secinfo);
case BTF_KIND_TAG: case BTF_KIND_DECL_TAG:
return base_size + sizeof(struct btf_tag); return base_size + sizeof(struct btf_decl_tag);
default: default:
pr_debug("Unsupported BTF_KIND:%u\n", btf_kind(t)); pr_debug("Unsupported BTF_KIND:%u\n", btf_kind(t));
return -EINVAL; return -EINVAL;
...@@ -389,8 +389,8 @@ static int btf_bswap_type_rest(struct btf_type *t) ...@@ -389,8 +389,8 @@ static int btf_bswap_type_rest(struct btf_type *t)
v->size = bswap_32(v->size); v->size = bswap_32(v->size);
} }
return 0; return 0;
case BTF_KIND_TAG: case BTF_KIND_DECL_TAG:
btf_tag(t)->component_idx = bswap_32(btf_tag(t)->component_idx); btf_decl_tag(t)->component_idx = bswap_32(btf_decl_tag(t)->component_idx);
return 0; return 0;
default: default:
pr_debug("Unsupported BTF_KIND:%u\n", btf_kind(t)); pr_debug("Unsupported BTF_KIND:%u\n", btf_kind(t));
...@@ -602,7 +602,7 @@ __s64 btf__resolve_size(const struct btf *btf, __u32 type_id) ...@@ -602,7 +602,7 @@ __s64 btf__resolve_size(const struct btf *btf, __u32 type_id)
case BTF_KIND_CONST: case BTF_KIND_CONST:
case BTF_KIND_RESTRICT: case BTF_KIND_RESTRICT:
case BTF_KIND_VAR: case BTF_KIND_VAR:
case BTF_KIND_TAG: case BTF_KIND_DECL_TAG:
type_id = t->type; type_id = t->type;
break; break;
case BTF_KIND_ARRAY: case BTF_KIND_ARRAY:
...@@ -2575,7 +2575,7 @@ int btf__add_datasec_var_info(struct btf *btf, int var_type_id, __u32 offset, __ ...@@ -2575,7 +2575,7 @@ int btf__add_datasec_var_info(struct btf *btf, int var_type_id, __u32 offset, __
} }
/* /*
* Append new BTF_KIND_TAG type with: * Append new BTF_KIND_DECL_TAG type with:
* - *value* - non-empty/non-NULL string; * - *value* - non-empty/non-NULL string;
* - *ref_type_id* - referenced type ID, it might not exist yet; * - *ref_type_id* - referenced type ID, it might not exist yet;
* - *component_idx* - -1 for tagging reference type, otherwise struct/union * - *component_idx* - -1 for tagging reference type, otherwise struct/union
...@@ -2584,7 +2584,7 @@ int btf__add_datasec_var_info(struct btf *btf, int var_type_id, __u32 offset, __ ...@@ -2584,7 +2584,7 @@ int btf__add_datasec_var_info(struct btf *btf, int var_type_id, __u32 offset, __
* - >0, type ID of newly added BTF type; * - >0, type ID of newly added BTF type;
* - <0, on error. * - <0, on error.
*/ */
int btf__add_tag(struct btf *btf, const char *value, int ref_type_id, int btf__add_decl_tag(struct btf *btf, const char *value, int ref_type_id,
int component_idx) int component_idx)
{ {
struct btf_type *t; struct btf_type *t;
...@@ -2599,7 +2599,7 @@ int btf__add_tag(struct btf *btf, const char *value, int ref_type_id, ...@@ -2599,7 +2599,7 @@ int btf__add_tag(struct btf *btf, const char *value, int ref_type_id,
if (btf_ensure_modifiable(btf)) if (btf_ensure_modifiable(btf))
return libbpf_err(-ENOMEM); return libbpf_err(-ENOMEM);
sz = sizeof(struct btf_type) + sizeof(struct btf_tag); sz = sizeof(struct btf_type) + sizeof(struct btf_decl_tag);
t = btf_add_type_mem(btf, sz); t = btf_add_type_mem(btf, sz);
if (!t) if (!t)
return libbpf_err(-ENOMEM); return libbpf_err(-ENOMEM);
...@@ -2609,9 +2609,9 @@ int btf__add_tag(struct btf *btf, const char *value, int ref_type_id, ...@@ -2609,9 +2609,9 @@ int btf__add_tag(struct btf *btf, const char *value, int ref_type_id,
return value_off; return value_off;
t->name_off = value_off; t->name_off = value_off;
t->info = btf_type_info(BTF_KIND_TAG, 0, false); t->info = btf_type_info(BTF_KIND_DECL_TAG, 0, false);
t->type = ref_type_id; t->type = ref_type_id;
btf_tag(t)->component_idx = component_idx; btf_decl_tag(t)->component_idx = component_idx;
return btf_commit_type(btf, sz); return btf_commit_type(btf, sz);
} }
...@@ -3433,7 +3433,7 @@ static bool btf_equal_common(struct btf_type *t1, struct btf_type *t2) ...@@ -3433,7 +3433,7 @@ static bool btf_equal_common(struct btf_type *t1, struct btf_type *t2)
} }
/* Calculate type signature hash of INT or TAG. */ /* Calculate type signature hash of INT or TAG. */
static long btf_hash_int_tag(struct btf_type *t) static long btf_hash_int_decl_tag(struct btf_type *t)
{ {
__u32 info = *(__u32 *)(t + 1); __u32 info = *(__u32 *)(t + 1);
long h; long h;
...@@ -3711,8 +3711,8 @@ static int btf_dedup_prep(struct btf_dedup *d) ...@@ -3711,8 +3711,8 @@ static int btf_dedup_prep(struct btf_dedup *d)
h = btf_hash_common(t); h = btf_hash_common(t);
break; break;
case BTF_KIND_INT: case BTF_KIND_INT:
case BTF_KIND_TAG: case BTF_KIND_DECL_TAG:
h = btf_hash_int_tag(t); h = btf_hash_int_decl_tag(t);
break; break;
case BTF_KIND_ENUM: case BTF_KIND_ENUM:
h = btf_hash_enum(t); h = btf_hash_enum(t);
...@@ -3767,11 +3767,11 @@ static int btf_dedup_prim_type(struct btf_dedup *d, __u32 type_id) ...@@ -3767,11 +3767,11 @@ static int btf_dedup_prim_type(struct btf_dedup *d, __u32 type_id)
case BTF_KIND_FUNC_PROTO: case BTF_KIND_FUNC_PROTO:
case BTF_KIND_VAR: case BTF_KIND_VAR:
case BTF_KIND_DATASEC: case BTF_KIND_DATASEC:
case BTF_KIND_TAG: case BTF_KIND_DECL_TAG:
return 0; return 0;
case BTF_KIND_INT: case BTF_KIND_INT:
h = btf_hash_int_tag(t); h = btf_hash_int_decl_tag(t);
for_each_dedup_cand(d, hash_entry, h) { for_each_dedup_cand(d, hash_entry, h) {
cand_id = (__u32)(long)hash_entry->value; cand_id = (__u32)(long)hash_entry->value;
cand = btf_type_by_id(d->btf, cand_id); cand = btf_type_by_id(d->btf, cand_id);
...@@ -4388,13 +4388,13 @@ static int btf_dedup_ref_type(struct btf_dedup *d, __u32 type_id) ...@@ -4388,13 +4388,13 @@ static int btf_dedup_ref_type(struct btf_dedup *d, __u32 type_id)
} }
break; break;
case BTF_KIND_TAG: case BTF_KIND_DECL_TAG:
ref_type_id = btf_dedup_ref_type(d, t->type); ref_type_id = btf_dedup_ref_type(d, t->type);
if (ref_type_id < 0) if (ref_type_id < 0)
return ref_type_id; return ref_type_id;
t->type = ref_type_id; t->type = ref_type_id;
h = btf_hash_int_tag(t); h = btf_hash_int_decl_tag(t);
for_each_dedup_cand(d, hash_entry, h) { for_each_dedup_cand(d, hash_entry, h) {
cand_id = (__u32)(long)hash_entry->value; cand_id = (__u32)(long)hash_entry->value;
cand = btf_type_by_id(d->btf, cand_id); cand = btf_type_by_id(d->btf, cand_id);
...@@ -4677,7 +4677,7 @@ int btf_type_visit_type_ids(struct btf_type *t, type_id_visit_fn visit, void *ct ...@@ -4677,7 +4677,7 @@ int btf_type_visit_type_ids(struct btf_type *t, type_id_visit_fn visit, void *ct
case BTF_KIND_TYPEDEF: case BTF_KIND_TYPEDEF:
case BTF_KIND_FUNC: case BTF_KIND_FUNC:
case BTF_KIND_VAR: case BTF_KIND_VAR:
case BTF_KIND_TAG: case BTF_KIND_DECL_TAG:
return visit(&t->type, ctx); return visit(&t->type, ctx);
case BTF_KIND_ARRAY: { case BTF_KIND_ARRAY: {
......
...@@ -166,7 +166,7 @@ LIBBPF_API int btf__add_datasec_var_info(struct btf *btf, int var_type_id, ...@@ -166,7 +166,7 @@ LIBBPF_API int btf__add_datasec_var_info(struct btf *btf, int var_type_id,
__u32 offset, __u32 byte_sz); __u32 offset, __u32 byte_sz);
/* tag construction API */ /* tag construction API */
LIBBPF_API int btf__add_tag(struct btf *btf, const char *value, int ref_type_id, LIBBPF_API int btf__add_decl_tag(struct btf *btf, const char *value, int ref_type_id,
int component_idx); int component_idx);
struct btf_dedup_opts { struct btf_dedup_opts {
...@@ -356,9 +356,9 @@ static inline bool btf_is_float(const struct btf_type *t) ...@@ -356,9 +356,9 @@ static inline bool btf_is_float(const struct btf_type *t)
return btf_kind(t) == BTF_KIND_FLOAT; return btf_kind(t) == BTF_KIND_FLOAT;
} }
static inline bool btf_is_tag(const struct btf_type *t) static inline bool btf_is_decl_tag(const struct btf_type *t)
{ {
return btf_kind(t) == BTF_KIND_TAG; return btf_kind(t) == BTF_KIND_DECL_TAG;
} }
static inline __u8 btf_int_encoding(const struct btf_type *t) static inline __u8 btf_int_encoding(const struct btf_type *t)
...@@ -429,10 +429,10 @@ btf_var_secinfos(const struct btf_type *t) ...@@ -429,10 +429,10 @@ btf_var_secinfos(const struct btf_type *t)
return (struct btf_var_secinfo *)(t + 1); return (struct btf_var_secinfo *)(t + 1);
} }
struct btf_tag; struct btf_decl_tag;
static inline struct btf_tag *btf_tag(const struct btf_type *t) static inline struct btf_decl_tag *btf_decl_tag(const struct btf_type *t)
{ {
return (struct btf_tag *)(t + 1); return (struct btf_decl_tag *)(t + 1);
} }
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -316,7 +316,7 @@ static int btf_dump_mark_referenced(struct btf_dump *d) ...@@ -316,7 +316,7 @@ static int btf_dump_mark_referenced(struct btf_dump *d)
case BTF_KIND_TYPEDEF: case BTF_KIND_TYPEDEF:
case BTF_KIND_FUNC: case BTF_KIND_FUNC:
case BTF_KIND_VAR: case BTF_KIND_VAR:
case BTF_KIND_TAG: case BTF_KIND_DECL_TAG:
d->type_states[t->type].referenced = 1; d->type_states[t->type].referenced = 1;
break; break;
...@@ -584,7 +584,7 @@ static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr) ...@@ -584,7 +584,7 @@ static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr)
case BTF_KIND_FUNC: case BTF_KIND_FUNC:
case BTF_KIND_VAR: case BTF_KIND_VAR:
case BTF_KIND_DATASEC: case BTF_KIND_DATASEC:
case BTF_KIND_TAG: case BTF_KIND_DECL_TAG:
d->type_states[id].order_state = ORDERED; d->type_states[id].order_state = ORDERED;
return 0; return 0;
...@@ -2222,7 +2222,7 @@ static int btf_dump_dump_type_data(struct btf_dump *d, ...@@ -2222,7 +2222,7 @@ static int btf_dump_dump_type_data(struct btf_dump *d,
case BTF_KIND_FWD: case BTF_KIND_FWD:
case BTF_KIND_FUNC: case BTF_KIND_FUNC:
case BTF_KIND_FUNC_PROTO: case BTF_KIND_FUNC_PROTO:
case BTF_KIND_TAG: case BTF_KIND_DECL_TAG:
err = btf_dump_unsupported_data(d, t, id); err = btf_dump_unsupported_data(d, t, id);
break; break;
case BTF_KIND_INT: case BTF_KIND_INT:
......
...@@ -193,8 +193,8 @@ enum kern_feature_id { ...@@ -193,8 +193,8 @@ enum kern_feature_id {
FEAT_MODULE_BTF, FEAT_MODULE_BTF,
/* BTF_KIND_FLOAT support */ /* BTF_KIND_FLOAT support */
FEAT_BTF_FLOAT, FEAT_BTF_FLOAT,
/* BTF_KIND_TAG support */ /* BTF_KIND_DECL_TAG support */
FEAT_BTF_TAG, FEAT_BTF_DECL_TAG,
__FEAT_CNT, __FEAT_CNT,
}; };
...@@ -2004,7 +2004,7 @@ static const char *__btf_kind_str(__u16 kind) ...@@ -2004,7 +2004,7 @@ static const char *__btf_kind_str(__u16 kind)
case BTF_KIND_VAR: return "var"; case BTF_KIND_VAR: return "var";
case BTF_KIND_DATASEC: return "datasec"; case BTF_KIND_DATASEC: return "datasec";
case BTF_KIND_FLOAT: return "float"; case BTF_KIND_FLOAT: return "float";
case BTF_KIND_TAG: return "tag"; case BTF_KIND_DECL_TAG: return "decl_tag";
default: return "unknown"; default: return "unknown";
} }
} }
...@@ -2504,9 +2504,9 @@ static bool btf_needs_sanitization(struct bpf_object *obj) ...@@ -2504,9 +2504,9 @@ static bool btf_needs_sanitization(struct bpf_object *obj)
bool has_datasec = kernel_supports(obj, FEAT_BTF_DATASEC); bool has_datasec = kernel_supports(obj, FEAT_BTF_DATASEC);
bool has_float = kernel_supports(obj, FEAT_BTF_FLOAT); bool has_float = kernel_supports(obj, FEAT_BTF_FLOAT);
bool has_func = kernel_supports(obj, FEAT_BTF_FUNC); bool has_func = kernel_supports(obj, FEAT_BTF_FUNC);
bool has_tag = kernel_supports(obj, FEAT_BTF_TAG); bool has_decl_tag = kernel_supports(obj, FEAT_BTF_DECL_TAG);
return !has_func || !has_datasec || !has_func_global || !has_float || !has_tag; return !has_func || !has_datasec || !has_func_global || !has_float || !has_decl_tag;
} }
static void bpf_object__sanitize_btf(struct bpf_object *obj, struct btf *btf) static void bpf_object__sanitize_btf(struct bpf_object *obj, struct btf *btf)
...@@ -2515,15 +2515,15 @@ static void bpf_object__sanitize_btf(struct bpf_object *obj, struct btf *btf) ...@@ -2515,15 +2515,15 @@ static void bpf_object__sanitize_btf(struct bpf_object *obj, struct btf *btf)
bool has_datasec = kernel_supports(obj, FEAT_BTF_DATASEC); bool has_datasec = kernel_supports(obj, FEAT_BTF_DATASEC);
bool has_float = kernel_supports(obj, FEAT_BTF_FLOAT); bool has_float = kernel_supports(obj, FEAT_BTF_FLOAT);
bool has_func = kernel_supports(obj, FEAT_BTF_FUNC); bool has_func = kernel_supports(obj, FEAT_BTF_FUNC);
bool has_tag = kernel_supports(obj, FEAT_BTF_TAG); bool has_decl_tag = kernel_supports(obj, FEAT_BTF_DECL_TAG);
struct btf_type *t; struct btf_type *t;
int i, j, vlen; int i, j, vlen;
for (i = 1; i <= btf__get_nr_types(btf); i++) { for (i = 1; i <= btf__get_nr_types(btf); i++) {
t = (struct btf_type *)btf__type_by_id(btf, i); t = (struct btf_type *)btf__type_by_id(btf, i);
if ((!has_datasec && btf_is_var(t)) || (!has_tag && btf_is_tag(t))) { if ((!has_datasec && btf_is_var(t)) || (!has_decl_tag && btf_is_decl_tag(t))) {
/* replace VAR/TAG with INT */ /* replace VAR/DECL_TAG with INT */
t->info = BTF_INFO_ENC(BTF_KIND_INT, 0, 0); t->info = BTF_INFO_ENC(BTF_KIND_INT, 0, 0);
/* /*
* using size = 1 is the safest choice, 4 will be too * using size = 1 is the safest choice, 4 will be too
...@@ -4229,7 +4229,7 @@ static int probe_kern_btf_float(void) ...@@ -4229,7 +4229,7 @@ static int probe_kern_btf_float(void)
strs, sizeof(strs))); strs, sizeof(strs)));
} }
static int probe_kern_btf_tag(void) static int probe_kern_btf_decl_tag(void)
{ {
static const char strs[] = "\0tag"; static const char strs[] = "\0tag";
__u32 types[] = { __u32 types[] = {
...@@ -4239,7 +4239,7 @@ static int probe_kern_btf_tag(void) ...@@ -4239,7 +4239,7 @@ static int probe_kern_btf_tag(void)
BTF_TYPE_ENC(1, BTF_INFO_ENC(BTF_KIND_VAR, 0, 0), 1), BTF_TYPE_ENC(1, BTF_INFO_ENC(BTF_KIND_VAR, 0, 0), 1),
BTF_VAR_STATIC, BTF_VAR_STATIC,
/* attr */ /* attr */
BTF_TYPE_TAG_ENC(1, 2, -1), BTF_TYPE_DECL_TAG_ENC(1, 2, -1),
}; };
return probe_fd(libbpf__load_raw_btf((char *)types, sizeof(types), return probe_fd(libbpf__load_raw_btf((char *)types, sizeof(types),
...@@ -4428,8 +4428,8 @@ static struct kern_feature_desc { ...@@ -4428,8 +4428,8 @@ static struct kern_feature_desc {
[FEAT_BTF_FLOAT] = { [FEAT_BTF_FLOAT] = {
"BTF_KIND_FLOAT support", probe_kern_btf_float, "BTF_KIND_FLOAT support", probe_kern_btf_float,
}, },
[FEAT_BTF_TAG] = { [FEAT_BTF_DECL_TAG] = {
"BTF_KIND_TAG support", probe_kern_btf_tag, "BTF_KIND_DECL_TAG support", probe_kern_btf_decl_tag,
}, },
}; };
......
...@@ -385,5 +385,5 @@ LIBBPF_0.5.0 { ...@@ -385,5 +385,5 @@ LIBBPF_0.5.0 {
LIBBPF_0.6.0 { LIBBPF_0.6.0 {
global: global:
btf__add_btf; btf__add_btf;
btf__add_tag; btf__add_decl_tag;
} LIBBPF_0.5.0; } LIBBPF_0.5.0;
...@@ -69,8 +69,8 @@ ...@@ -69,8 +69,8 @@
#define BTF_VAR_SECINFO_ENC(type, offset, size) (type), (offset), (size) #define BTF_VAR_SECINFO_ENC(type, offset, size) (type), (offset), (size)
#define BTF_TYPE_FLOAT_ENC(name, sz) \ #define BTF_TYPE_FLOAT_ENC(name, sz) \
BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_FLOAT, 0, 0), sz) BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_FLOAT, 0, 0), sz)
#define BTF_TYPE_TAG_ENC(value, type, component_idx) \ #define BTF_TYPE_DECL_TAG_ENC(value, type, component_idx) \
BTF_TYPE_ENC(value, BTF_INFO_ENC(BTF_KIND_TAG, 0, 0), type), (component_idx) BTF_TYPE_ENC(value, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 0, 0), type), (component_idx)
#ifndef likely #ifndef likely
#define likely(x) __builtin_expect(!!(x), 1) #define likely(x) __builtin_expect(!!(x), 1)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册