Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

docs/bpf: Document the semantics of BTF tags with kind_flag

Explain the meaning of kind_flag in BTF type_tags and decl_tags.
Update uapi btf.h kind_flag comment to reflect the changes.

Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20250130201239.1429648-3-ihor.solodrai@linux.dev

authored by

Ihor Solodrai and committed by
Andrii Nakryiko
ea70faa1 51d1b1d4

+25 -6
+21 -4
Documentation/bpf/btf.rst
··· 102 102 * bits 24-28: kind (e.g. int, ptr, array...etc) 103 103 * bits 29-30: unused 104 104 * bit 31: kind_flag, currently used by 105 - * struct, union, fwd, enum and enum64. 105 + * struct, union, enum, fwd, enum64, 106 + * decl_tag and type_tag 106 107 */ 107 108 __u32 info; 108 109 /* "size" is used by INT, ENUM, STRUCT, UNION and ENUM64. ··· 479 478 480 479 ``struct btf_type`` encoding requirement: 481 480 * ``name_off``: offset to a non-empty string 482 - * ``info.kind_flag``: 0 481 + * ``info.kind_flag``: 0 or 1 483 482 * ``info.kind``: BTF_KIND_DECL_TAG 484 483 * ``info.vlen``: 0 485 484 * ``type``: ``struct``, ``union``, ``func``, ``var`` or ``typedef`` ··· 490 489 __u32 component_idx; 491 490 }; 492 491 493 - The ``name_off`` encodes btf_decl_tag attribute string. 494 492 The ``type`` should be ``struct``, ``union``, ``func``, ``var`` or ``typedef``. 495 493 For ``var`` or ``typedef`` type, ``btf_decl_tag.component_idx`` must be ``-1``. 496 494 For the other three types, if the btf_decl_tag attribute is ··· 499 499 a ``func`` argument, and ``btf_decl_tag.component_idx`` should be a 500 500 valid index (starting from 0) pointing to a member or an argument. 501 501 502 + If ``info.kind_flag`` is 0, then this is a normal decl tag, and the 503 + ``name_off`` encodes btf_decl_tag attribute string. 504 + 505 + If ``info.kind_flag`` is 1, then the decl tag represents an arbitrary 506 + __attribute__. In this case, ``name_off`` encodes a string 507 + representing the attribute-list of the attribute specifier. For 508 + example, for an ``__attribute__((aligned(4)))`` the string's contents 509 + is ``aligned(4)``. 510 + 502 511 2.2.18 BTF_KIND_TYPE_TAG 503 512 ~~~~~~~~~~~~~~~~~~~~~~~~ 504 513 505 514 ``struct btf_type`` encoding requirement: 506 515 * ``name_off``: offset to a non-empty string 507 - * ``info.kind_flag``: 0 516 + * ``info.kind_flag``: 0 or 1 508 517 * ``info.kind``: BTF_KIND_TYPE_TAG 509 518 * ``info.vlen``: 0 510 519 * ``type``: the type with ``btf_type_tag`` attribute ··· 530 521 type_tag, then zero or more const/volatile/restrict/typedef 531 522 and finally the base type. The base type is one of 532 523 int, ptr, array, struct, union, enum, func_proto and float types. 524 + 525 + Similarly to decl tags, if the ``info.kind_flag`` is 0, then this is a 526 + normal type tag, and the ``name_off`` encodes btf_type_tag attribute 527 + string. 528 + 529 + If ``info.kind_flag`` is 1, then the type tag represents an arbitrary 530 + __attribute__, and the ``name_off`` encodes a string representing the 531 + attribute-list of the attribute specifier. 533 532 534 533 2.2.19 BTF_KIND_ENUM64 535 534 ~~~~~~~~~~~~~~~~~~~~~~
+2 -1
include/uapi/linux/btf.h
··· 36 36 * bits 24-28: kind (e.g. int, ptr, array...etc) 37 37 * bits 29-30: unused 38 38 * bit 31: kind_flag, currently used by 39 - * struct, union, enum, fwd and enum64 39 + * struct, union, enum, fwd, enum64, 40 + * decl_tag and type_tag 40 41 */ 41 42 __u32 info; 42 43 /* "size" is used by INT, ENUM, STRUCT, UNION, DATASEC and ENUM64.
+2 -1
tools/include/uapi/linux/btf.h
··· 36 36 * bits 24-28: kind (e.g. int, ptr, array...etc) 37 37 * bits 29-30: unused 38 38 * bit 31: kind_flag, currently used by 39 - * struct, union, enum, fwd and enum64 39 + * struct, union, enum, fwd, enum64, 40 + * decl_tag and type_tag 40 41 */ 41 42 __u32 info; 42 43 /* "size" is used by INT, ENUM, STRUCT, UNION, DATASEC and ENUM64.