]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/bpf: Add a BTF verification test for kflagged type_tag
authorIhor Solodrai <ihor.solodrai@linux.dev>
Thu, 30 Jan 2025 20:12:39 +0000 (12:12 -0800)
committerAndrii Nakryiko <andrii@kernel.org>
Thu, 6 Feb 2025 00:18:00 +0000 (16:18 -0800)
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
tools/testing/selftests/bpf/prog_tests/btf.c
tools/testing/selftests/bpf/test_btf.h

index aab9ad88c8453b48782d1a1509407c7a677fc1ca..8a9ba42921092c4e9af0eb3f6ec9b88debf05c72 100644 (file)
@@ -3870,7 +3870,7 @@ static struct btf_raw_test raw_tests[] = {
        .raw_types = {
                BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),  /* [1] */
                BTF_VAR_ENC(NAME_TBD, 1, 0),                    /* [2] */
-               BTF_TYPE_ENC(NAME_TBD, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 1, 0), 2), (-1),
+               BTF_DECL_ATTR_ENC(NAME_TBD, 2, -1),
                BTF_END_RAW,
        },
        BTF_STR_SEC("\0local\0tag1"),
@@ -4204,6 +4204,23 @@ static struct btf_raw_test raw_tests[] = {
        .btf_load_err = true,
        .err_str = "Type tags don't precede modifiers",
 },
+{
+       .descr = "type_tag test #7, tag with kflag",
+       .raw_types = {
+               BTF_TYPE_INT_ENC(0, BTF_INT_SIGNED, 0, 32, 4),  /* [1] */
+               BTF_TYPE_ATTR_ENC(NAME_TBD, 1),                 /* [2] */
+               BTF_PTR_ENC(2),                                 /* [3] */
+               BTF_END_RAW,
+       },
+       BTF_STR_SEC("\0tag"),
+       .map_type = BPF_MAP_TYPE_ARRAY,
+       .map_name = "tag_type_check_btf",
+       .key_size = sizeof(int),
+       .value_size = 4,
+       .key_type_id = 1,
+       .value_type_id = 1,
+       .max_entries = 1,
+},
 {
        .descr = "enum64 test #1, unsigned, size 8",
        .raw_types = {
index fb4f4714eeb41d82023ed863a3bc38e3d544937d..e65889ab4adf9d5e9083594c2aa4b21e08097a43 100644 (file)
 #define BTF_TYPE_FLOAT_ENC(name, sz) \
        BTF_TYPE_ENC(name, BTF_INFO_ENC(BTF_KIND_FLOAT, 0, 0), sz)
 
+#define BTF_DECL_ATTR_ENC(value, type, component_idx)  \
+       BTF_TYPE_ENC(value, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 1, 0), type), (component_idx)
+
 #define BTF_DECL_TAG_ENC(value, type, component_idx)   \
        BTF_TYPE_ENC(value, BTF_INFO_ENC(BTF_KIND_DECL_TAG, 0, 0), type), (component_idx)
 
+#define BTF_TYPE_ATTR_ENC(value, type) \
+       BTF_TYPE_ENC(value, BTF_INFO_ENC(BTF_KIND_TYPE_TAG, 1, 0), type)
+
 #define BTF_TYPE_TAG_ENC(value, type)  \
        BTF_TYPE_ENC(value, BTF_INFO_ENC(BTF_KIND_TYPE_TAG, 0, 0), type)