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

selftests/bpf: Add a BTF verification test for kflagged type_tag

Add a BTF verification test case for a type_tag with a kflag set.
Type tags with a kflag are now valid.

Add BTF_DECL_ATTR_ENC and BTF_TYPE_ATTR_ENC test helper macros,
corresponding to *_TAG_ENC.

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-7-ihor.solodrai@linux.dev

authored by

Ihor Solodrai and committed by
Andrii Nakryiko
770cdcf4 53ee0d66

+24 -1
+18 -1
tools/testing/selftests/bpf/prog_tests/btf.c
··· 3870 3870 .raw_types = { 3871 3871 BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */ 3872 3872 BTF_VAR_ENC(NAME_TBD, 1, 0), /* [2] */ 3873 - BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 1, 0), 2), (-1), 3873 + BTF_DECL_ATTR_ENC(NAME_TBD, 2, -1), 3874 3874 BTF_END_RAW, 3875 3875 }, 3876 3876 BTF_STR_SEC("\0local\0tag1"), ··· 4203 4203 .max_entries = 1, 4204 4204 .btf_load_err = true, 4205 4205 .err_str = "Type tags don't precede modifiers", 4206 + }, 4207 + { 4208 + .descr = "type_tag test #7, tag with kflag", 4209 + .raw_types = { 4210 + BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4), /* [1] */ 4211 + BTF_TYPE_ATTR_ENC(NAME_TBD, 1), /* [2] */ 4212 + BTF_PTR_ENC(2), /* [3] */ 4213 + BTF_END_RAW, 4214 + }, 4215 + BTF_STR_SEC("\0tag"), 4216 + .map_type = BPF_MAP_TYPE_ARRAY, 4217 + .map_name = "tag_type_check_btf", 4218 + .key_size = sizeof(int), 4219 + .value_size = 4, 4220 + .key_type_id = 1, 4221 + .value_type_id = 1, 4222 + .max_entries = 1, 4206 4223 }, 4207 4224 { 4208 4225 .descr = "enum64 test #1, unsigned, size 8",
+6
tools/testing/selftests/bpf/test_btf.h
··· 72 72 #define BTF_TYPE_FLOAT_ENC(name, sz) \ 73 73 BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_FLOAT, 0, 0), sz) 74 74 75 + #define BTF_DECL_ATTR_ENC(value, type, component_idx) \ 76 + BTF_TYPE_ENC(value, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 1, 0), type), (component_idx) 77 + 75 78 #define BTF_DECL_TAG_ENC(value, type, component_idx) \ 76 79 BTF_TYPE_ENC(value, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 0, 0), type), (component_idx) 80 + 81 + #define BTF_TYPE_ATTR_ENC(value, type) \ 82 + BTF_TYPE_ENC(value, BTF_INFO_ENC(BTF_KIND_TYPE_TAG, 1, 0), type) 77 83 78 84 #define BTF_TYPE_TAG_ENC(value, type) \ 79 85 BTF_TYPE_ENC(value, BTF_INFO_ENC(BTF_KIND_TYPE_TAG, 0, 0), type)