Skip to content

Commit 223f903

Browse files
yonghong-songAlexei Starovoitov
authored and
Alexei Starovoitov
committed
bpf: Rename BTF_KIND_TAG to BTF_KIND_DECL_TAG
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/[email protected]/ [2] https://reviews.llvm.org/D111588 [3] https://reviews.llvm.org/D111199 Fixes: b5ea834 ("bpf: Support for new btf kind BTF_KIND_TAG") Fixes: 5b84bd1 ("libbpf: Add support for BTF_KIND_TAG") Fixes: 5c07f2f ("bpftool: Add support for BTF_KIND_TAG") Signed-off-by: Yonghong Song <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 431bfb9 commit 223f903

File tree

17 files changed

+193
-193
lines changed

17 files changed

+193
-193
lines changed

Documentation/bpf/btf.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ sequentially and type id is assigned to each recognized type starting from id
8585
#define BTF_KIND_VAR 14 /* Variable */
8686
#define BTF_KIND_DATASEC 15 /* Section */
8787
#define BTF_KIND_FLOAT 16 /* Floating point */
88-
#define BTF_KIND_TAG 17 /* Tag */
88+
#define BTF_KIND_DECL_TAG 17 /* Decl Tag */
8989

9090
Note that the type section encodes debug info, not just pure types.
9191
``BTF_KIND_FUNC`` is not a type, and it represents a defined subprogram.
@@ -107,7 +107,7 @@ Each type contains the following common data::
107107
* "size" tells the size of the type it is describing.
108108
*
109109
* "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT,
110-
* FUNC, FUNC_PROTO and TAG.
110+
* FUNC, FUNC_PROTO and DECL_TAG.
111111
* "type" is a type_id referring to another type.
112112
*/
113113
union {
@@ -466,30 +466,30 @@ map definition.
466466

467467
No additional type data follow ``btf_type``.
468468

469-
2.2.17 BTF_KIND_TAG
470-
~~~~~~~~~~~~~~~~~~~
469+
2.2.17 BTF_KIND_DECL_TAG
470+
~~~~~~~~~~~~~~~~~~~~~~~~
471471

472472
``struct btf_type`` encoding requirement:
473473
* ``name_off``: offset to a non-empty string
474474
* ``info.kind_flag``: 0
475-
* ``info.kind``: BTF_KIND_TAG
475+
* ``info.kind``: BTF_KIND_DECL_TAG
476476
* ``info.vlen``: 0
477477
* ``type``: ``struct``, ``union``, ``func`` or ``var``
478478

479-
``btf_type`` is followed by ``struct btf_tag``.::
479+
``btf_type`` is followed by ``struct btf_decl_tag``.::
480480

481-
struct btf_tag {
481+
struct btf_decl_tag {
482482
__u32 component_idx;
483483
};
484484

485-
The ``name_off`` encodes btf_tag attribute string.
485+
The ``name_off`` encodes btf_decl_tag attribute string.
486486
The ``type`` should be ``struct``, ``union``, ``func`` or ``var``.
487-
For ``var`` type, ``btf_tag.component_idx`` must be ``-1``.
488-
For the other three types, if the btf_tag attribute is
487+
For ``var`` type, ``btf_decl_tag.component_idx`` must be ``-1``.
488+
For the other three types, if the btf_decl_tag attribute is
489489
applied to the ``struct``, ``union`` or ``func`` itself,
490-
``btf_tag.component_idx`` must be ``-1``. Otherwise,
490+
``btf_decl_tag.component_idx`` must be ``-1``. Otherwise,
491491
the attribute is applied to a ``struct``/``union`` member or
492-
a ``func`` argument, and ``btf_tag.component_idx`` should be a
492+
a ``func`` argument, and ``btf_decl_tag.component_idx`` should be a
493493
valid index (starting from 0) pointing to a member or an argument.
494494

495495
3. BTF Kernel API

include/uapi/linux/btf.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct btf_type {
4343
* "size" tells the size of the type it is describing.
4444
*
4545
* "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT,
46-
* FUNC, FUNC_PROTO, VAR and TAG.
46+
* FUNC, FUNC_PROTO, VAR and DECL_TAG.
4747
* "type" is a type_id referring to another type.
4848
*/
4949
union {
@@ -74,7 +74,7 @@ enum {
7474
BTF_KIND_VAR = 14, /* Variable */
7575
BTF_KIND_DATASEC = 15, /* Section */
7676
BTF_KIND_FLOAT = 16, /* Floating point */
77-
BTF_KIND_TAG = 17, /* Tag */
77+
BTF_KIND_DECL_TAG = 17, /* Decl Tag */
7878

7979
NR_BTF_KINDS,
8080
BTF_KIND_MAX = NR_BTF_KINDS - 1,
@@ -174,14 +174,14 @@ struct btf_var_secinfo {
174174
__u32 size;
175175
};
176176

177-
/* BTF_KIND_TAG is followed by a single "struct btf_tag" to describe
177+
/* BTF_KIND_DECL_TAG is followed by a single "struct btf_decl_tag" to describe
178178
* additional information related to the tag applied location.
179179
* If component_idx == -1, the tag is applied to a struct, union,
180180
* variable or function. Otherwise, it is applied to a struct/union
181181
* member or a func argument, and component_idx indicates which member
182182
* or argument (0 ... vlen-1).
183183
*/
184-
struct btf_tag {
184+
struct btf_decl_tag {
185185
__s32 component_idx;
186186
};
187187

kernel/bpf/btf.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ static const char * const btf_kind_str[NR_BTF_KINDS] = {
281281
[BTF_KIND_VAR] = "VAR",
282282
[BTF_KIND_DATASEC] = "DATASEC",
283283
[BTF_KIND_FLOAT] = "FLOAT",
284-
[BTF_KIND_TAG] = "TAG",
284+
[BTF_KIND_DECL_TAG] = "DECL_TAG",
285285
};
286286

287287
const char *btf_type_str(const struct btf_type *t)
@@ -460,12 +460,12 @@ static bool btf_type_is_datasec(const struct btf_type *t)
460460
return BTF_INFO_KIND(t->info) == BTF_KIND_DATASEC;
461461
}
462462

463-
static bool btf_type_is_tag(const struct btf_type *t)
463+
static bool btf_type_is_decl_tag(const struct btf_type *t)
464464
{
465-
return BTF_INFO_KIND(t->info) == BTF_KIND_TAG;
465+
return BTF_INFO_KIND(t->info) == BTF_KIND_DECL_TAG;
466466
}
467467

468-
static bool btf_type_is_tag_target(const struct btf_type *t)
468+
static bool btf_type_is_decl_tag_target(const struct btf_type *t)
469469
{
470470
return btf_type_is_func(t) || btf_type_is_struct(t) ||
471471
btf_type_is_var(t);
@@ -549,7 +549,7 @@ const struct btf_type *btf_type_resolve_func_ptr(const struct btf *btf,
549549
static bool btf_type_is_resolve_source_only(const struct btf_type *t)
550550
{
551551
return btf_type_is_var(t) ||
552-
btf_type_is_tag(t) ||
552+
btf_type_is_decl_tag(t) ||
553553
btf_type_is_datasec(t);
554554
}
555555

@@ -576,7 +576,7 @@ static bool btf_type_needs_resolve(const struct btf_type *t)
576576
btf_type_is_struct(t) ||
577577
btf_type_is_array(t) ||
578578
btf_type_is_var(t) ||
579-
btf_type_is_tag(t) ||
579+
btf_type_is_decl_tag(t) ||
580580
btf_type_is_datasec(t);
581581
}
582582

@@ -630,9 +630,9 @@ static const struct btf_var *btf_type_var(const struct btf_type *t)
630630
return (const struct btf_var *)(t + 1);
631631
}
632632

633-
static const struct btf_tag *btf_type_tag(const struct btf_type *t)
633+
static const struct btf_decl_tag *btf_type_decl_tag(const struct btf_type *t)
634634
{
635-
return (const struct btf_tag *)(t + 1);
635+
return (const struct btf_decl_tag *)(t + 1);
636636
}
637637

638638
static const struct btf_kind_operations *btf_type_ops(const struct btf_type *t)
@@ -3820,11 +3820,11 @@ static const struct btf_kind_operations float_ops = {
38203820
.show = btf_df_show,
38213821
};
38223822

3823-
static s32 btf_tag_check_meta(struct btf_verifier_env *env,
3823+
static s32 btf_decl_tag_check_meta(struct btf_verifier_env *env,
38243824
const struct btf_type *t,
38253825
u32 meta_left)
38263826
{
3827-
const struct btf_tag *tag;
3827+
const struct btf_decl_tag *tag;
38283828
u32 meta_needed = sizeof(*tag);
38293829
s32 component_idx;
38303830
const char *value;
@@ -3852,7 +3852,7 @@ static s32 btf_tag_check_meta(struct btf_verifier_env *env,
38523852
return -EINVAL;
38533853
}
38543854

3855-
component_idx = btf_type_tag(t)->component_idx;
3855+
component_idx = btf_type_decl_tag(t)->component_idx;
38563856
if (component_idx < -1) {
38573857
btf_verifier_log_type(env, t, "Invalid component_idx");
38583858
return -EINVAL;
@@ -3863,7 +3863,7 @@ static s32 btf_tag_check_meta(struct btf_verifier_env *env,
38633863
return meta_needed;
38643864
}
38653865

3866-
static int btf_tag_resolve(struct btf_verifier_env *env,
3866+
static int btf_decl_tag_resolve(struct btf_verifier_env *env,
38673867
const struct resolve_vertex *v)
38683868
{
38693869
const struct btf_type *next_type;
@@ -3874,7 +3874,7 @@ static int btf_tag_resolve(struct btf_verifier_env *env,
38743874
u32 vlen;
38753875

38763876
next_type = btf_type_by_id(btf, next_type_id);
3877-
if (!next_type || !btf_type_is_tag_target(next_type)) {
3877+
if (!next_type || !btf_type_is_decl_tag_target(next_type)) {
38783878
btf_verifier_log_type(env, v->t, "Invalid type_id");
38793879
return -EINVAL;
38803880
}
@@ -3883,7 +3883,7 @@ static int btf_tag_resolve(struct btf_verifier_env *env,
38833883
!env_type_is_resolved(env, next_type_id))
38843884
return env_stack_push(env, next_type, next_type_id);
38853885

3886-
component_idx = btf_type_tag(t)->component_idx;
3886+
component_idx = btf_type_decl_tag(t)->component_idx;
38873887
if (component_idx != -1) {
38883888
if (btf_type_is_var(next_type)) {
38893889
btf_verifier_log_type(env, v->t, "Invalid component_idx");
@@ -3909,18 +3909,18 @@ static int btf_tag_resolve(struct btf_verifier_env *env,
39093909
return 0;
39103910
}
39113911

3912-
static void btf_tag_log(struct btf_verifier_env *env, const struct btf_type *t)
3912+
static void btf_decl_tag_log(struct btf_verifier_env *env, const struct btf_type *t)
39133913
{
39143914
btf_verifier_log(env, "type=%u component_idx=%d", t->type,
3915-
btf_type_tag(t)->component_idx);
3915+
btf_type_decl_tag(t)->component_idx);
39163916
}
39173917

3918-
static const struct btf_kind_operations tag_ops = {
3919-
.check_meta = btf_tag_check_meta,
3920-
.resolve = btf_tag_resolve,
3918+
static const struct btf_kind_operations decl_tag_ops = {
3919+
.check_meta = btf_decl_tag_check_meta,
3920+
.resolve = btf_decl_tag_resolve,
39213921
.check_member = btf_df_check_member,
39223922
.check_kflag_member = btf_df_check_kflag_member,
3923-
.log_details = btf_tag_log,
3923+
.log_details = btf_decl_tag_log,
39243924
.show = btf_df_show,
39253925
};
39263926

@@ -4058,7 +4058,7 @@ static const struct btf_kind_operations * const kind_ops[NR_BTF_KINDS] = {
40584058
[BTF_KIND_VAR] = &var_ops,
40594059
[BTF_KIND_DATASEC] = &datasec_ops,
40604060
[BTF_KIND_FLOAT] = &float_ops,
4061-
[BTF_KIND_TAG] = &tag_ops,
4061+
[BTF_KIND_DECL_TAG] = &decl_tag_ops,
40624062
};
40634063

40644064
static s32 btf_check_meta(struct btf_verifier_env *env,
@@ -4143,7 +4143,7 @@ static bool btf_resolve_valid(struct btf_verifier_env *env,
41434143
return !btf_resolved_type_id(btf, type_id) &&
41444144
!btf_resolved_type_size(btf, type_id);
41454145

4146-
if (btf_type_is_tag(t))
4146+
if (btf_type_is_decl_tag(t))
41474147
return btf_resolved_type_id(btf, type_id) &&
41484148
!btf_resolved_type_size(btf, type_id);
41494149

tools/bpf/bpftool/btf.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static const char * const btf_kind_str[NR_BTF_KINDS] = {
3737
[BTF_KIND_VAR] = "VAR",
3838
[BTF_KIND_DATASEC] = "DATASEC",
3939
[BTF_KIND_FLOAT] = "FLOAT",
40-
[BTF_KIND_TAG] = "TAG",
40+
[BTF_KIND_DECL_TAG] = "DECL_TAG",
4141
};
4242

4343
struct btf_attach_table {
@@ -348,8 +348,8 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
348348
printf(" size=%u", t->size);
349349
break;
350350
}
351-
case BTF_KIND_TAG: {
352-
const struct btf_tag *tag = (const void *)(t + 1);
351+
case BTF_KIND_DECL_TAG: {
352+
const struct btf_decl_tag *tag = (const void *)(t + 1);
353353

354354
if (json_output) {
355355
jsonw_uint_field(w, "type_id", t->type);

tools/include/uapi/linux/btf.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct btf_type {
4343
* "size" tells the size of the type it is describing.
4444
*
4545
* "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT,
46-
* FUNC, FUNC_PROTO, VAR and TAG.
46+
* FUNC, FUNC_PROTO, VAR and DECL_TAG.
4747
* "type" is a type_id referring to another type.
4848
*/
4949
union {
@@ -74,7 +74,7 @@ enum {
7474
BTF_KIND_VAR = 14, /* Variable */
7575
BTF_KIND_DATASEC = 15, /* Section */
7676
BTF_KIND_FLOAT = 16, /* Floating point */
77-
BTF_KIND_TAG = 17, /* Tag */
77+
BTF_KIND_DECL_TAG = 17, /* Decl Tag */
7878

7979
NR_BTF_KINDS,
8080
BTF_KIND_MAX = NR_BTF_KINDS - 1,
@@ -174,14 +174,14 @@ struct btf_var_secinfo {
174174
__u32 size;
175175
};
176176

177-
/* BTF_KIND_TAG is followed by a single "struct btf_tag" to describe
177+
/* BTF_KIND_DECL_TAG is followed by a single "struct btf_decl_tag" to describe
178178
* additional information related to the tag applied location.
179179
* If component_idx == -1, the tag is applied to a struct, union,
180180
* variable or function. Otherwise, it is applied to a struct/union
181181
* member or a func argument, and component_idx indicates which member
182182
* or argument (0 ... vlen-1).
183183
*/
184-
struct btf_tag {
184+
struct btf_decl_tag {
185185
__s32 component_idx;
186186
};
187187

0 commit comments

Comments
 (0)