| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/09/30 22:52 | flow | patch-triage |
0mArgs:null Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"KMSANReasoning": "",
"NeedsKMSAN": false,
"Reasoning": "The patch only modifies user-space code within tools/lib/bpf (libbpf BTF dump functionality) and BPF selftests under tools/testing/selftests/bpf/. No kernel image (vmlinux) or kernel module code is altered, making it non-kernel code that is not applicable for syzkaller kernel fuzzing.",
"WorthFuzzing": false
} |
| 1/1 | 2026/09/30 22:52 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit df736aef1672d475d150a6f076f888051b6e6030\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Wed Sep 30 22:52:35 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c\nindex fa995c02a1705..996e61b5f11f0 100644\n--- a/tools/lib/bpf/btf_dump.c\n+++ b/tools/lib/bpf/btf_dump.c\n@@ -77,6 +77,11 @@ struct btf_dump_data {\n \tbool is_array_char;\n };\n \n+struct decl_tag_desc {\n+\t__u32 target_id;\n+\t__u32 tag_id;\n+};\n+\n struct btf_dump {\n \tconst struct btf *btf;\n \tbtf_dump_printf_fn_t printf_fn;\n@@ -93,6 +98,11 @@ struct btf_dump {\n \tconst char **cached_names;\n \tsize_t cached_names_cap;\n \n+\t/* decl tags, sorted by (target ID, tag ID) */\n+\tstruct decl_tag_desc *decl_tags;\n+\tsize_t decl_tag_cnt;\n+\tsize_t decl_tag_cap;\n+\n \t/* topo-sorted list of dependent type definitions */\n \t__u32 *emit_queue;\n \tint emit_queue_cap;\n@@ -143,7 +153,7 @@ static void btf_dump_printf(const struct btf_dump *d, const char *fmt, ...)\n \tva_end(args);\n }\n \n-static int btf_dump_mark_referenced(struct btf_dump *d);\n+static int btf_dump_mark_referenced(struct btf_dump *d, const struct btf_type *t);\n static int btf_dump_resize(struct btf_dump *d);\n \n struct btf_dump *btf_dump__new(const struct btf *btf,\n@@ -192,9 +202,36 @@ struct btf_dump *btf_dump__new(const struct btf *btf,\n \treturn libbpf_err_ptr(err);\n }\n \n+static int btf_dump_cmp_decl_tags(const void *a, const void *b)\n+{\n+\tconst struct decl_tag_desc *x = a, *y = b;\n+\n+\tif (x-\u003etarget_id != y-\u003etarget_id)\n+\t\treturn x-\u003etarget_id \u003c y-\u003etarget_id ? -1 : 1;\n+\tif (x-\u003etag_id != y-\u003etag_id)\n+\t\treturn x-\u003etag_id \u003c y-\u003etag_id ? -1 : 1;\n+\treturn 0;\n+}\n+\n+static int btf_dump_push_decl_tag(struct btf_dump *d, __u32 id, const struct btf_type *t)\n+{\n+\tif (libbpf_ensure_mem((void **)\u0026d-\u003edecl_tags, \u0026d-\u003edecl_tag_cap,\n+\t\t\t sizeof(*d-\u003edecl_tags), d-\u003edecl_tag_cnt + 1))\n+\t\treturn -ENOMEM;\n+\n+\td-\u003edecl_tags[d-\u003edecl_tag_cnt++] = (struct decl_tag_desc) {\n+\t\t.target_id = t-\u003etype,\n+\t\t.tag_id = id,\n+\t};\n+\treturn 0;\n+}\n+\n static int btf_dump_resize(struct btf_dump *d)\n {\n \tint err, last_id = btf__type_cnt(d-\u003ebtf) - 1;\n+\tsize_t cnt = d-\u003edecl_tag_cnt;\n+\tconst struct btf_type *t;\n+\t__u32 i;\n \n \tif (last_id \u003c= d-\u003elast_id)\n \t\treturn 0;\n@@ -212,13 +249,30 @@ static int btf_dump_resize(struct btf_dump *d)\n \t\td-\u003etype_states[0].emit_state = EMITTED;\n \t}\n \n-\t/* eagerly determine referenced types for anon enums */\n-\terr = btf_dump_mark_referenced(d);\n-\tif (err)\n-\t\treturn err;\n+\tfor (i = d-\u003elast_id + 1; i \u003c= last_id; i++) {\n+\t\tt = btf__type_by_id(d-\u003ebtf, i);\n+\n+\t\terr = btf_dump_mark_referenced(d, t);\n+\t\tif (err)\n+\t\t\tgoto out_err;\n+\n+\t\tif (btf_is_decl_tag(t)) {\n+\t\t\terr = btf_dump_push_decl_tag(d, i, t);\n+\t\t\tif (err)\n+\t\t\t\tgoto out_err;\n+\t\t}\n+\t}\n+\n+\tif (d-\u003edecl_tag_cnt != cnt)\n+\t\tqsort(d-\u003edecl_tags, d-\u003edecl_tag_cnt, sizeof(*d-\u003edecl_tags),\n+\t\t btf_dump_cmp_decl_tags);\n \n \td-\u003elast_id = last_id;\n \treturn 0;\n+\n+out_err:\n+\td-\u003edecl_tag_cnt = cnt;\n+\treturn err;\n }\n \n static void btf_dump_free_names(struct hashmap *map)\n@@ -251,6 +305,7 @@ void btf_dump__free(struct btf_dump *d)\n \t\t}\n \t}\n \tfree(d-\u003ecached_names);\n+\tfree(d-\u003edecl_tags);\n \tfree(d-\u003eemit_queue);\n \tfree(d-\u003edecl_stack);\n \tbtf_dump_free_names(d-\u003etype_names);\n@@ -312,71 +367,64 @@ int btf_dump__dump_type(struct btf_dump *d, __u32 id)\n * top-level anonymous enum won't be referenced by anything, while embedded\n * one will.\n */\n-static int btf_dump_mark_referenced(struct btf_dump *d)\n+static int btf_dump_mark_referenced(struct btf_dump *d, const struct btf_type *t)\n {\n-\tint i, j, n = btf__type_cnt(d-\u003ebtf);\n-\tconst struct btf_type *t;\n-\t__u32 vlen;\n-\n-\tfor (i = d-\u003elast_id + 1; i \u003c n; i++) {\n-\t\tt = btf__type_by_id(d-\u003ebtf, i);\n-\t\tvlen = btf_vlen(t);\n+\t__u32 j, vlen = btf_vlen(t);\n \n-\t\tswitch (btf_kind(t)) {\n-\t\tcase BTF_KIND_INT:\n-\t\tcase BTF_KIND_ENUM:\n-\t\tcase BTF_KIND_ENUM64:\n-\t\tcase BTF_KIND_FWD:\n-\t\tcase BTF_KIND_FLOAT:\n-\t\tcase BTF_KIND_LOC_PARAM:\n-\t\tcase BTF_KIND_LOC_PROTO:\n-\t\tcase BTF_KIND_LOCSEC:\n-\t\t\tbreak;\n+\tswitch (btf_kind(t)) {\n+\tcase BTF_KIND_INT:\n+\tcase BTF_KIND_ENUM:\n+\tcase BTF_KIND_ENUM64:\n+\tcase BTF_KIND_FWD:\n+\tcase BTF_KIND_FLOAT:\n+\tcase BTF_KIND_LOC_PARAM:\n+\tcase BTF_KIND_LOC_PROTO:\n+\tcase BTF_KIND_LOCSEC:\n+\t\tbreak;\n \n-\t\tcase BTF_KIND_VOLATILE:\n-\t\tcase BTF_KIND_CONST:\n-\t\tcase BTF_KIND_RESTRICT:\n-\t\tcase BTF_KIND_PTR:\n-\t\tcase BTF_KIND_TYPEDEF:\n-\t\tcase BTF_KIND_FUNC:\n-\t\tcase BTF_KIND_VAR:\n-\t\tcase BTF_KIND_DECL_TAG:\n-\t\tcase BTF_KIND_TYPE_TAG:\n-\t\t\td-\u003etype_states[t-\u003etype].referenced = 1;\n-\t\t\tbreak;\n+\tcase BTF_KIND_VOLATILE:\n+\tcase BTF_KIND_CONST:\n+\tcase BTF_KIND_RESTRICT:\n+\tcase BTF_KIND_PTR:\n+\tcase BTF_KIND_TYPEDEF:\n+\tcase BTF_KIND_FUNC:\n+\tcase BTF_KIND_VAR:\n+\tcase BTF_KIND_DECL_TAG:\n+\tcase BTF_KIND_TYPE_TAG:\n+\t\td-\u003etype_states[t-\u003etype].referenced = 1;\n+\t\tbreak;\n \n-\t\tcase BTF_KIND_ARRAY: {\n-\t\t\tconst struct btf_array *a = btf_array(t);\n+\tcase BTF_KIND_ARRAY: {\n+\t\tconst struct btf_array *a = btf_array(t);\n \n-\t\t\td-\u003etype_states[a-\u003eindex_type].referenced = 1;\n-\t\t\td-\u003etype_states[a-\u003etype].referenced = 1;\n-\t\t\tbreak;\n-\t\t}\n-\t\tcase BTF_KIND_STRUCT:\n-\t\tcase BTF_KIND_UNION: {\n-\t\t\tconst struct btf_member *m = btf_members(t);\n+\t\td-\u003etype_states[a-\u003eindex_type].referenced = 1;\n+\t\td-\u003etype_states[a-\u003etype].referenced = 1;\n+\t\tbreak;\n+\t}\n+\tcase BTF_KIND_STRUCT:\n+\tcase BTF_KIND_UNION: {\n+\t\tconst struct btf_member *m = btf_members(t);\n \n-\t\t\tfor (j = 0; j \u003c vlen; j++, m++)\n-\t\t\t\td-\u003etype_states[m-\u003etype].referenced = 1;\n-\t\t\tbreak;\n-\t\t}\n-\t\tcase BTF_KIND_FUNC_PROTO: {\n-\t\t\tconst struct btf_param *p = btf_params(t);\n+\t\tfor (j = 0; j \u003c vlen; j++, m++)\n+\t\t\td-\u003etype_states[m-\u003etype].referenced = 1;\n+\t\tbreak;\n+\t}\n+\tcase BTF_KIND_FUNC_PROTO: {\n+\t\tconst struct btf_param *p = btf_params(t);\n \n-\t\t\tfor (j = 0; j \u003c vlen; j++, p++)\n-\t\t\t\td-\u003etype_states[p-\u003etype].referenced = 1;\n-\t\t\tbreak;\n-\t\t}\n-\t\tcase BTF_KIND_DATASEC: {\n-\t\t\tconst struct btf_var_secinfo *v = btf_var_secinfos(t);\n+\t\tfor (j = 0; j \u003c vlen; j++, p++)\n+\t\t\td-\u003etype_states[p-\u003etype].referenced = 1;\n+\t\tbreak;\n+\t}\n+\tcase BTF_KIND_DATASEC: {\n+\t\tconst struct btf_var_secinfo *v = btf_var_secinfos(t);\n \n-\t\t\tfor (j = 0; j \u003c vlen; j++, v++)\n-\t\t\t\td-\u003etype_states[v-\u003etype].referenced = 1;\n-\t\t\tbreak;\n-\t\t}\n-\t\tdefault:\n-\t\t\treturn -EINVAL;\n-\t\t}\n+\t\tfor (j = 0; j \u003c vlen; j++, v++)\n+\t\t\td-\u003etype_states[v-\u003etype].referenced = 1;\n+\t\tbreak;\n+\t}\n+\tdefault:\n+\t\treturn -EINVAL;\n \t}\n \treturn 0;\n }\n@@ -970,6 +1018,44 @@ static void btf_dump_emit_struct_fwd(struct btf_dump *d, __u32 id,\n \t\t\tbtf_dump_type_name(d, id));\n }\n \n+static void btf_dump_emit_decl_tag(struct btf_dump *d, const struct btf_type *t)\n+{\n+\tconst char *name = btf_name_of(d, t-\u003ename_off);\n+\n+\tif (btf_kflag(t))\n+\t\tbtf_dump_printf(d, \" __attribute__((%s))\", name);\n+\telse\n+\t\tbtf_dump_printf(d, \" __attribute__((btf_decl_tag(\\\"%s\\\")))\", name);\n+}\n+\n+/*\n+ * btf_dump_resize() keeps d-\u003edecl_tags sorted by (target ID, tag ID), so the\n+ * tags of one type form a run that binary search finds the start of, in a\n+ * fixed order so that the same BTF always renders the same C.\n+ */\n+static void btf_dump_emit_decl_tags(struct btf_dump *d, __u32 id, int comp_idx)\n+{\n+\tsize_t i, lo = 0, hi = d-\u003edecl_tag_cnt, mid;\n+\tconst struct btf_type *t;\n+\n+\t/* lower bound on target_id */\n+\twhile (lo \u003c hi) {\n+\t\tmid = lo + (hi - lo) / 2;\n+\n+\t\tif (d-\u003edecl_tags[mid].target_id \u003c id)\n+\t\t\tlo = mid + 1;\n+\t\telse\n+\t\t\thi = mid;\n+\t}\n+\n+\tfor (i = lo; i \u003c d-\u003edecl_tag_cnt \u0026\u0026 d-\u003edecl_tags[i].target_id == id; i++) {\n+\t\tt = btf__type_by_id(d-\u003ebtf, d-\u003edecl_tags[i].tag_id);\n+\n+\t\tif (btf_decl_tag(t)-\u003ecomponent_idx == comp_idx)\n+\t\t\tbtf_dump_emit_decl_tag(d, t);\n+\t}\n+}\n+\n static void btf_dump_emit_struct_def(struct btf_dump *d,\n \t\t\t\t __u32 id,\n \t\t\t\t const struct btf_type *t,\n@@ -1015,6 +1101,8 @@ static void btf_dump_emit_struct_def(struct btf_dump *d,\n \t\t\tprev_bitfield = false;\n \t\t}\n \n+\t\t/* after the bit-field width */\n+\t\tbtf_dump_emit_decl_tags(d, id, i);\n \t\tbtf_dump_printf(d, \";\");\n \t}\n \n@@ -1034,6 +1122,7 @@ static void btf_dump_emit_struct_def(struct btf_dump *d,\n \t}\n \tif (packed)\n \t\tbtf_dump_printf(d, \" __attribute__((packed))\");\n+\tbtf_dump_emit_decl_tags(d, id, -1);\n }\n \n static const char *missing_base_types[][2] = {\n@@ -1211,6 +1300,7 @@ static void btf_dump_emit_typedef_def(struct btf_dump *d, __u32 id,\n \n \tbtf_dump_printf(d, \"typedef \");\n \tbtf_dump_emit_type_decl(d, t-\u003etype, name, lvl);\n+\tbtf_dump_emit_decl_tags(d, id, -1);\n }\n \n static int btf_dump_push_decl_stack_id(struct btf_dump *d, __u32 id)\ndiff --git a/tools/testing/selftests/bpf/btf_helpers.c b/tools/testing/selftests/bpf/btf_helpers.c\nindex 85a4d15d1dd1c..e04b61c08cd8e 100644\n--- a/tools/testing/selftests/bpf/btf_helpers.c\n+++ b/tools/testing/selftests/bpf/btf_helpers.c\n@@ -114,9 +114,12 @@ int fprintf_btf_type_raw(FILE *out, const struct btf *btf, __u32 id)\n \tcase BTF_KIND_VOLATILE:\n \tcase BTF_KIND_RESTRICT:\n \tcase BTF_KIND_TYPEDEF:\n-\tcase BTF_KIND_TYPE_TAG:\n \t\tfprintf(out, \" type_id=%u\", t-\u003etype);\n \t\tbreak;\n+\tcase BTF_KIND_TYPE_TAG:\n+\t\tfprintf(out, \" type_id=%u%s\", t-\u003etype,\n+\t\t\tbtf_kflag(t) ? \" kflag=1\" : \"\");\n+\t\tbreak;\n \tcase BTF_KIND_ARRAY: {\n \t\tconst struct btf_array *arr = btf_array(t);\n \n@@ -203,8 +206,9 @@ int fprintf_btf_type_raw(FILE *out, const struct btf *btf, __u32 id)\n \t\tfprintf(out, \" size=%u\", t-\u003esize);\n \t\tbreak;\n \tcase BTF_KIND_DECL_TAG:\n-\t\tfprintf(out, \" type_id=%u component_idx=%d\",\n-\t\t\tt-\u003etype, btf_decl_tag(t)-\u003ecomponent_idx);\n+\t\tfprintf(out, \" type_id=%u component_idx=%d%s\",\n+\t\t\tt-\u003etype, btf_decl_tag(t)-\u003ecomponent_idx,\n+\t\t\tbtf_kflag(t) ? \" kflag=1\" : \"\");\n \t\tbreak;\n \tcase BTF_KIND_LOC_PARAM: {\n \t\tstruct btf_loc_param *p = btf_loc_param(t);\ndiff --git a/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c b/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c\nindex abc62958b6ed2..534aa79a42785 100644\n--- a/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c\n+++ b/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c\n@@ -207,7 +207,6 @@ static void test_dump(const char *btf_path, bool sorted)\n {\n \tconst char *exp_path;\n \tchar *dump, *exp;\n-\tint err;\n \n \texp_path = sorted ? EXPECTED_SORTED : EXPECTED_UNSORTED;\n \n@@ -219,8 +218,7 @@ static void test_dump(const char *btf_path, bool sorted)\n \tif (!exp)\n \t\tgoto out_dump;\n \n-\terr = compare_text_to_expected(dump, exp);\n-\tASSERT_OK(err, sorted ? \"cmp_sorted\" : \"cmp_unsorted\");\n+\tASSERT_TEXT_EQ(dump, exp, sorted ? \"cmp_sorted\" : \"cmp_unsorted\");\n \n \tfree(exp);\n out_dump:\n@@ -260,7 +258,7 @@ static void test_loc_dump(const char *btf_path)\n \tif (!dump)\n \t\treturn;\n \n-\tASSERT_OK(compare_text_to_expected(dump, expected), \"cmp_loc_dump\");\n+\tASSERT_TEXT_EQ(dump, expected, \"cmp_loc_dump\");\n \tfree(dump);\n }\n \ndiff --git a/tools/testing/selftests/bpf/prog_tests/btf_dump.c b/tools/testing/selftests/bpf/prog_tests/btf_dump.c\nindex fe04a955d46cc..17fa44cb9c91f 100644\n--- a/tools/testing/selftests/bpf/prog_tests/btf_dump.c\n+++ b/tools/testing/selftests/bpf/prog_tests/btf_dump.c\n@@ -161,12 +161,7 @@ static int test_btf_dump_case(int n, struct btf_dump_test_case *t)\n \t\tgoto done;\n \t}\n \n-\t/*\n-\t * The mismatch has already been reported, so this only has to\n-\t * register the failure. ASSERT_OK() would append a stale errno to it.\n-\t */\n-\terr = compare_text_to_expected(dump, expected);\n-\tASSERT_EQ(err, 0, \"compare_text_to_expected\");\n+\tASSERT_TEXT_EQ(dump, expected, \"compare_text_to_expected\");\n \n done:\n \tfree(expected);\n@@ -224,7 +219,7 @@ static void test_ctx__dump_and_compare(struct test_ctx *t,\n \tfflush(t-\u003edump_buf_file);\n \tt-\u003edump_buf[t-\u003edump_buf_sz] = 0; /* some libc implementations don't do this */\n \n-\tASSERT_STREQ(t-\u003edump_buf, expected_output, message);\n+\tASSERT_TEXT_EQ(t-\u003edump_buf, expected_output, message);\n }\n \n static void test_btf_dump_incremental(void)\n@@ -315,6 +310,8 @@ static void test_btf_dump_incremental(void)\n \tASSERT_OK(err, \"field_ok\");\n \terr = btf__add_field(btf, \"s\", 6, 64, 0);\n \tASSERT_OK(err, \"field_ok\");\n+\t/* attribute on a type added after the first dump: the later walk indexes it */\n+\tASSERT_EQ(btf__add_decl_attr(btf, \"round2\", 7, -1), 8, \"round2_attr\");\n \n \ttest_ctx__dump_and_compare(\u0026t,\n \"struct s___2 {\\n\"\n@@ -323,7 +320,270 @@ static void test_btf_dump_incremental(void)\n \"\t\tY___2 = 1,\\n\"\n \"\t} y;\\n\"\n \"\tstruct s s;\\n\"\n-\"};\\n\\n\" , \"c_dump1\");\n+\"} __attribute__((round2));\\n\\n\", \"c_dump1\");\n+\n+\ttest_ctx__free(\u0026t);\n+}\n+\n+static void test_btf_dump_decl_tags(void)\n+{\n+\tstruct test_ctx t = {};\n+\tstruct btf *btf;\n+\tint id;\n+\n+\tif (test_ctx__init(\u0026t))\n+\t\treturn;\n+\n+\tbtf = t.btf;\n+\n+\t/*\n+\t * Generate BTF corresponding to the following C code:\n+\t *\n+\t * struct s1 { int f; } __attribute__((attr1))\n+\t * __attribute__((btf_decl_tag(\"plain_tag\")));\n+\t * typedef struct { int f; } __attribute__((a1)) __attribute__((a2)) t1;\n+\t * union u1 { int f; } __attribute__((uattr));\n+\t * struct p1 { char c; int i; } __attribute__((packed)) __attribute__((pattr));\n+\t * struct outer { struct { int g; } __attribute__((inner)) in; };\n+\t * struct s2 { int f; } __attribute__((on_s2));\n+\t * struct s3 { int f; } __attribute__((on_s3));\n+\t *\n+\t * plus attributes on a var and a func, which btf_dump does not declare.\n+\t */\n+\tid = btf__add_int(btf, \"int\", 4, BTF_INT_SIGNED);\n+\tASSERT_EQ(id, 1, \"int_id\");\n+\tid = btf__add_int(btf, \"char\", 1, BTF_INT_CHAR);\n+\tASSERT_EQ(id, 2, \"char_id\");\n+\n+\t/* a named record with one attribute of each form */\n+\tid = btf__add_struct(btf, \"s1\", 4);\n+\tASSERT_EQ(id, 3, \"s1_id\");\n+\tASSERT_OK(btf__add_field(btf, \"f\", 1, 0, 0), \"s1_field\");\n+\tASSERT_EQ(btf__add_decl_attr(btf, \"attr1\", 3, -1), 4, \"s1_attr\");\n+\t/* no kflag: rendered as a btf_decl_tag(), not as a bare attribute */\n+\tASSERT_EQ(btf__add_decl_tag(btf, \"plain_tag\", 3, -1), 5, \"s1_plain_tag\");\n+\n+\t/*\n+\t * an anonymous record behind a typedef, with two attributes. This is\n+\t * the case that cannot be expressed by a caller appending to the dump:\n+\t * the attribute has to go before the declarator.\n+\t */\n+\tid = btf__add_struct(btf, NULL, 4);\n+\tASSERT_EQ(id, 6, \"anon_id\");\n+\tASSERT_OK(btf__add_field(btf, \"f\", 1, 0, 0), \"anon_field\");\n+\tASSERT_EQ(btf__add_decl_attr(btf, \"a1\", 6, -1), 7, \"anon_attr1\");\n+\tASSERT_EQ(btf__add_decl_attr(btf, \"a2\", 6, -1), 8, \"anon_attr2\");\n+\tid = btf__add_typedef(btf, \"t1\", 6);\n+\tASSERT_EQ(id, 9, \"typedef_id\");\n+\n+\t/* unions are records too */\n+\tid = btf__add_union(btf, \"u1\", 4);\n+\tASSERT_EQ(id, 10, \"u1_id\");\n+\tASSERT_OK(btf__add_field(btf, \"f\", 1, 0, 0), \"u1_field\");\n+\tASSERT_EQ(btf__add_decl_attr(btf, \"uattr\", 10, -1), 11, \"u1_attr\");\n+\n+\t/* composes with the packed attribute, which is derived from layout */\n+\tid = btf__add_struct(btf, \"p1\", 5);\n+\tASSERT_EQ(id, 12, \"p1_id\");\n+\tASSERT_OK(btf__add_field(btf, \"c\", 2, 0, 0), \"p1_field_c\");\n+\tASSERT_OK(btf__add_field(btf, \"i\", 1, 8, 0), \"p1_field_i\");\n+\tASSERT_EQ(btf__add_decl_attr(btf, \"pattr\", 12, -1), 13, \"p1_attr\");\n+\n+\t/* an anonymous record inlined at a member, the third emission position */\n+\tid = btf__add_struct(btf, NULL, 4);\n+\tASSERT_EQ(id, 14, \"inner_id\");\n+\tASSERT_OK(btf__add_field(btf, \"g\", 1, 0, 0), \"inner_field\");\n+\tASSERT_EQ(btf__add_decl_attr(btf, \"inner\", 14, -1), 15, \"inner_attr\");\n+\tid = btf__add_struct(btf, \"outer\", 4);\n+\tASSERT_EQ(id, 16, \"outer_id\");\n+\tASSERT_OK(btf__add_field(btf, \"in\", 14, 0, 0), \"outer_field\");\n+\n+\t/* not rendered: a var has no declaration in the C output */\n+\tid = btf__add_var(btf, \"v\", BTF_VAR_GLOBAL_ALLOCATED, 3);\n+\tASSERT_EQ(id, 17, \"var_id\");\n+\tASSERT_EQ(btf__add_decl_attr(btf, \"var_attr\", 17, -1), 18, \"var_attr\");\n+\t/* not rendered: neither does a func */\n+\tid = btf__add_func_proto(btf, 1);\n+\tASSERT_EQ(id, 19, \"proto_id\");\n+\tid = btf__add_func(btf, \"fn\", BTF_FUNC_GLOBAL, 19);\n+\tASSERT_EQ(id, 20, \"func_id\");\n+\tASSERT_EQ(btf__add_decl_attr(btf, \"func_attr\", 20, -1), 21, \"func_attr\");\n+\n+\t/*\n+\t * Tags added in reverse target order: the tag with the lower type ID\n+\t * names the record with the higher one, so the index is in emission\n+\t * order only once btf_dump_resize() has sorted it. Without the sort\n+\t * the lookups land outside their runs and the records lose their\n+\t * attributes.\n+\t */\n+\tid = btf__add_struct(btf, \"s2\", 4);\n+\tASSERT_EQ(id, 22, \"s2_id\");\n+\tASSERT_OK(btf__add_field(btf, \"f\", 1, 0, 0), \"s2_field\");\n+\tid = btf__add_struct(btf, \"s3\", 4);\n+\tASSERT_EQ(id, 23, \"s3_id\");\n+\tASSERT_OK(btf__add_field(btf, \"f\", 1, 0, 0), \"s3_field\");\n+\tASSERT_EQ(btf__add_decl_attr(btf, \"on_s3\", 23, -1), 24, \"s3_attr\");\n+\tASSERT_EQ(btf__add_decl_attr(btf, \"on_s2\", 22, -1), 25, \"s2_attr\");\n+\n+\ttest_ctx__dump_and_compare(\u0026t,\n+\"struct s1 {\\n\"\n+\"\tint f;\\n\"\n+\"} __attribute__((attr1)) __attribute__((btf_decl_tag(\\\"plain_tag\\\")));\\n\"\n+\"\\n\"\n+\"typedef struct {\\n\"\n+\"\tint f;\\n\"\n+\"} __attribute__((a1)) __attribute__((a2)) t1;\\n\"\n+\"\\n\"\n+\"union u1 {\\n\"\n+\"\tint f;\\n\"\n+\"} __attribute__((uattr));\\n\"\n+\"\\n\"\n+\"struct p1 {\\n\"\n+\"\tchar c;\\n\"\n+\"\tint i;\\n\"\n+\"} __attribute__((packed)) __attribute__((pattr));\\n\"\n+\"\\n\"\n+\"struct outer {\\n\"\n+\"\tstruct {\\n\"\n+\"\t\tint g;\\n\"\n+\"\t} __attribute__((inner)) in;\\n\"\n+\"};\\n\"\n+\"\\n\"\n+\"struct s2 {\\n\"\n+\"\tint f;\\n\"\n+\"} __attribute__((on_s2));\\n\"\n+\"\\n\"\n+\"struct s3 {\\n\"\n+\"\tint f;\\n\"\n+\"} __attribute__((on_s3));\\n\"\n+\"\\n\", \"dump_and_compare\");\n+\n+\ttest_ctx__free(\u0026t);\n+}\n+\n+/*\n+ * An attribute on a member is emitted at the member declaration, and one on\n+ * the record at the closing brace. Both are keyed by the record in the index,\n+ * so this also checks that they do not leak into each other's position.\n+ */\n+static void test_btf_dump_decl_tags_members(void)\n+{\n+\tstruct test_ctx t = {};\n+\tstruct btf *btf;\n+\tint id;\n+\n+\tif (test_ctx__init(\u0026t))\n+\t\treturn;\n+\n+\tbtf = t.btf;\n+\n+\t/*\n+\t * Generate BTF corresponding to the following C code:\n+\t *\n+\t * struct m1 {\n+\t *\tint (*fp)(void) __attribute__((fp_attr));\n+\t *\tint a;\n+\t *\tint b __attribute__((b1)) __attribute__((b2));\n+\t *\tint arr[4] __attribute__((arr_attr));\n+\t * } __attribute__((rec));\n+\t * struct bits { int x : 3 __attribute__((x_attr)); int y : 29; };\n+\t */\n+\tid = btf__add_int(btf, \"int\", 4, BTF_INT_SIGNED);\n+\tASSERT_EQ(id, 1, \"int_id\");\n+\tid = btf__add_array(btf, 1, 1, 4);\n+\tASSERT_EQ(id, 2, \"array_id\");\n+\tid = btf__add_func_proto(btf, 1);\n+\tASSERT_EQ(id, 3, \"proto_id\");\n+\tid = btf__add_ptr(btf, 3);\n+\tASSERT_EQ(id, 4, \"ptr_id\");\n+\n+\tid = btf__add_struct(btf, \"m1\", 32);\n+\tASSERT_EQ(id, 5, \"m1_id\");\n+\tASSERT_OK(btf__add_field(btf, \"fp\", 4, 0, 0), \"m1_fp\");\n+\tASSERT_OK(btf__add_field(btf, \"a\", 1, 64, 0), \"m1_a\");\n+\tASSERT_OK(btf__add_field(btf, \"b\", 1, 96, 0), \"m1_b\");\n+\tASSERT_OK(btf__add_field(btf, \"arr\", 2, 128, 0), \"m1_arr\");\n+\tASSERT_EQ(btf__add_decl_attr(btf, \"rec\", 5, -1), 6, \"m1_rec_attr\");\n+\t/* the attribute follows the whole declarator, pointer and array alike */\n+\tASSERT_EQ(btf__add_decl_attr(btf, \"fp_attr\", 5, 0), 7, \"m1_fp_attr\");\n+\t/* two on one member, to pin the ordering */\n+\tASSERT_EQ(btf__add_decl_attr(btf, \"b1\", 5, 2), 8, \"m1_b1\");\n+\tASSERT_EQ(btf__add_decl_attr(btf, \"b2\", 5, 2), 9, \"m1_b2\");\n+\tASSERT_EQ(btf__add_decl_attr(btf, \"arr_attr\", 5, 3), 10, \"m1_arr_attr\");\n+\n+\t/* a bit-field: the attribute has to follow the width */\n+\tid = btf__add_struct(btf, \"bits\", 4);\n+\tASSERT_EQ(id, 11, \"bits_id\");\n+\tASSERT_OK(btf__add_field(btf, \"x\", 1, 0, 3), \"bits_x\");\n+\tASSERT_OK(btf__add_field(btf, \"y\", 1, 3, 29), \"bits_y\");\n+\tASSERT_EQ(btf__add_decl_attr(btf, \"x_attr\", 11, 0), 12, \"bits_x_attr\");\n+\n+\ttest_ctx__dump_and_compare(\u0026t,\n+\"struct m1 {\\n\"\n+\"\tint (*fp)(void) __attribute__((fp_attr));\\n\"\n+\"\tint a;\\n\"\n+\"\tint b __attribute__((b1)) __attribute__((b2));\\n\"\n+\"\tint arr[4] __attribute__((arr_attr));\\n\"\n+\"} __attribute__((rec));\\n\"\n+\"\\n\"\n+\"struct bits {\\n\"\n+\"\tint x: 3 __attribute__((x_attr));\\n\"\n+\"\tint y: 29;\\n\"\n+\"};\\n\"\n+\"\\n\", \"dump_and_compare\");\n+\n+\ttest_ctx__free(\u0026t);\n+}\n+\n+/*\n+ * A typedef is the third and last kind btf_dump declares. Its attributes go\n+ * after the declarator, so a typedef of an anonymous record can carry three\n+ * groups in one declaration, binding to three different entities.\n+ */\n+static void test_btf_dump_decl_tags_typedef(void)\n+{\n+\tstruct test_ctx t = {};\n+\tstruct btf *btf;\n+\tint id;\n+\n+\tif (test_ctx__init(\u0026t))\n+\t\treturn;\n+\n+\tbtf = t.btf;\n+\n+\t/*\n+\t * Generate BTF corresponding to the following C code:\n+\t *\n+\t * typedef int td __attribute__((t1))\n+\t * __attribute__((btf_decl_tag(\"t2\")));\n+\t * typedef struct {\n+\t *\tint f __attribute__((memb_attr));\n+\t * } __attribute__((rec_attr)) both __attribute__((both_attr));\n+\t */\n+\tid = btf__add_int(btf, \"int\", 4, BTF_INT_SIGNED);\n+\tASSERT_EQ(id, 1, \"int_id\");\n+\tid = btf__add_typedef(btf, \"td\", 1);\n+\tASSERT_EQ(id, 2, \"td_id\");\n+\tASSERT_EQ(btf__add_decl_attr(btf, \"t1\", 2, -1), 3, \"td_attr1\");\n+\t/* no kflag: rendered as a btf_decl_tag(), not as a bare attribute */\n+\tASSERT_EQ(btf__add_decl_tag(btf, \"t2\", 2, -1), 4, \"td_attr2\");\n+\n+\tid = btf__add_struct(btf, NULL, 4);\n+\tASSERT_EQ(id, 5, \"anon_id\");\n+\tASSERT_OK(btf__add_field(btf, \"f\", 1, 0, 0), \"anon_field\");\n+\tASSERT_EQ(btf__add_decl_attr(btf, \"rec_attr\", 5, -1), 6, \"anon_rec_attr\");\n+\tASSERT_EQ(btf__add_decl_attr(btf, \"memb_attr\", 5, 0), 7, \"anon_memb_attr\");\n+\tid = btf__add_typedef(btf, \"both\", 5);\n+\tASSERT_EQ(id, 8, \"both_id\");\n+\tASSERT_EQ(btf__add_decl_attr(btf, \"both_attr\", 8, -1), 9, \"both_attr\");\n+\n+\ttest_ctx__dump_and_compare(\u0026t,\n+\"typedef int td __attribute__((t1)) __attribute__((btf_decl_tag(\\\"t2\\\")));\\n\"\n+\"\\n\"\n+\"typedef struct {\\n\"\n+\"\tint f __attribute__((memb_attr));\\n\"\n+\"} __attribute__((rec_attr)) both __attribute__((both_attr));\\n\"\n+\"\\n\", \"dump_and_compare\");\n \n \ttest_ctx__free(\u0026t);\n }\n@@ -1109,6 +1369,15 @@ void test_btf_dump() {\n \tif (test__start_subtest(\"btf_dump: incremental\"))\n \t\ttest_btf_dump_incremental();\n \n+\tif (test__start_subtest(\"btf_dump: decl_tags\"))\n+\t\ttest_btf_dump_decl_tags();\n+\n+\tif (test__start_subtest(\"btf_dump: decl_tags_members\"))\n+\t\ttest_btf_dump_decl_tags_members();\n+\n+\tif (test__start_subtest(\"btf_dump: decl_tags_typedef\"))\n+\t\ttest_btf_dump_decl_tags_typedef();\n+\n \tif (test__start_subtest(\"btf_dump: type_tags\"))\n \t\ttest_btf_dump_type_tags();\n \ndiff --git a/tools/testing/selftests/bpf/prog_tests/btf_write.c b/tools/testing/selftests/bpf/prog_tests/btf_write.c\nindex 5c84723cf2540..3bed3a28c06a3 100644\n--- a/tools/testing/selftests/bpf/prog_tests/btf_write.c\n+++ b/tools/testing/selftests/bpf/prog_tests/btf_write.c\n@@ -606,6 +606,38 @@ static void test_btf_add_btf_split()\n \tbtf__free(base);\n }\n \n+static void test_btf_attrs(void)\n+{\n+\tstruct btf *btf;\n+\n+\tbtf = btf__new_empty();\n+\tif (!ASSERT_OK_PTR(btf, \"new_empty\"))\n+\t\treturn;\n+\n+\tbtf__add_int(btf, \"int\", 4, BTF_INT_SIGNED);\n+\tbtf__add_struct(btf, \"s\", 4);\n+\tbtf__add_field(btf, \"f\", 1, 0, 0);\n+\n+\tbtf__add_decl_tag(btf, \"tag\", 2, -1);\n+\tbtf__add_decl_attr(btf, \"tag\", 2, -1);\n+\tbtf__add_decl_attr(btf, \"member_attr\", 2, 0);\n+\tbtf__add_type_tag(btf, \"tag\", 1);\n+\tbtf__add_type_attr(btf, \"tag\", 1);\n+\n+\tVALIDATE_RAW_BTF(\n+\t\tbtf,\n+\t\t\"[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED\",\n+\t\t\"[2] STRUCT 's' size=4 vlen=1\\n\"\n+\t\t\"\\t'f' type_id=1 bits_offset=0\",\n+\t\t\"[3] DECL_TAG 'tag' type_id=2 component_idx=-1\",\n+\t\t\"[4] DECL_TAG 'tag' type_id=2 component_idx=-1 kflag=1\",\n+\t\t\"[5] DECL_TAG 'member_attr' type_id=2 component_idx=0 kflag=1\",\n+\t\t\"[6] TYPE_TAG 'tag' type_id=1\",\n+\t\t\"[7] TYPE_TAG 'tag' type_id=1 kflag=1\");\n+\n+\tbtf__free(btf);\n+}\n+\n void test_btf_write()\n {\n \tif (test__start_subtest(\"btf_add\"))\n@@ -614,4 +646,6 @@ void test_btf_write()\n \t\ttest_btf_add_btf();\n \tif (test__start_subtest(\"btf_add_btf_split\"))\n \t\ttest_btf_add_btf_split();\n+\tif (test__start_subtest(\"btf_attrs\"))\n+\t\ttest_btf_attrs();\n }\ndiff --git a/tools/testing/selftests/bpf/test_progs.h b/tools/testing/selftests/bpf/test_progs.h\nindex ea493c477fbde..adc18f5eceb65 100644\n--- a/tools/testing/selftests/bpf/test_progs.h\n+++ b/tools/testing/selftests/bpf/test_progs.h\n@@ -349,6 +349,9 @@ void hexdump(const char *prefix, const void *buf, size_t len);\n \t___ok;\t\t\t\t\t\t\t\t\\\n })\n \n+#define ASSERT_TEXT_EQ(actual, expected, name) \\\n+\tASSERT_TRUE(compare_text_to_expected(actual, expected) == 0, name)\n+\n #define ASSERT_MEMEQ(actual, expected, len, name) ({\t\t\t\\\n \tstatic int duration = 0;\t\t\t\t\t\\\n \tconst void *__act = actual;\t\t\t\t\t\\\n"
} |
| 2/1 | 2026/09/30 22:52 | agent | patch-evaluator |
0mModel:core Args: null Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"Reasoning": "The patch only modifies user-space code within tools/lib/bpf (libbpf BTF dump functionality) and BPF selftests under tools/testing/selftests/bpf/. No kernel image (vmlinux) or kernel module code is altered, making it non-kernel code that is not applicable for syzkaller kernel fuzzing.",
"WorthFuzzing": false
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit df736aef1672d475d150a6f076f888051b6e6030
Author: syz-cluster <triage@syzkaller.com>
Date: Wed Sep 30 22:52:35 2026 +0000
syz-cluster: applied patch under review
diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
index fa995c02a1705..996e61b5f11f0 100644
--- a/tools/lib/bpf/btf_dump.c
+++ b/tools/lib/bpf/btf_dump.c
@@ -77,6 +77,11 @@ struct btf_dump_data {
bool is_array_char;
};
+struct decl_tag_desc {
+ __u32 target_id;
+ __u32 tag_id;
+};
+
struct btf_dump {
const struct btf *btf;
btf_dump_printf_fn_t printf_fn;
@@ -93,6 +98,11 @@ struct btf_dump {
const char **cached_names;
size_t cached_names_cap;
+ /* decl tags, sorted by (target ID, tag ID) */
+ struct decl_tag_desc *decl_tags;
+ size_t decl_tag_cnt;
+ size_t decl_tag_cap;
+
/* topo-sorted list of dependent type definitions */
__u32 *emit_queue;
int emit_queue_cap;
@@ -143,7 +153,7 @@ static void btf_dump_printf(const struct btf_dump *d, const char *fmt, ...)
va_end(args);
}
-static int btf_dump_mark_referenced(struct btf_dump *d);
+static int btf_dump_mark_referenced(struct btf_dump *d, const struct btf_type *t);
static int btf_dump_resize(struct btf_dump *d);
struct btf_dump *btf_dump__new(const struct btf *btf,
@@ -192,9 +202,36 @@ struct btf_dump *btf_dump__new(const struct btf *btf,
return libbpf_err_ptr(err);
}
+static int btf_dump_cmp_decl_tags(const void *a, const void *b)
+{
+ const struct decl_tag_desc *x = a, *y = b;
+
+ if (x->target_id != y->target_id)
+ return x->target_id < y->target_id ? -1 : 1;
+ if (x->tag_id != y->tag_id)
+ return x->tag_id < y->tag_id ? -1 : 1;
+ return 0;
+}
+
+static int btf_dump_push_decl_tag(struct btf_dump *d, __u32 id, const struct btf_type *t)
+{
+ if (libbpf_ensure_mem((void **)&d->decl_tags, &d->decl_tag_cap,
+ sizeof(*d->decl_tags), d->decl_tag_cnt + 1))
+ return -ENOMEM;
+
+ d->decl_tags[d->decl_tag_cnt++] = (struct decl_tag_desc) {
+ .target_id = t->type,
+ .tag_id = id,
+ };
+ return 0;
+}
+
static int btf_dump_resize(struct btf_dump *d)
{
int err, last_id = btf__type_cnt(d->btf) - 1;
+ size_t cnt = d->decl_tag_cnt;
+ const struct btf_type *t;
+ __u32 i;
if (last_id <= d->last_id)
return 0;
@@ -212,13 +249,30 @@ static int btf_dump_resize(struct btf_dump *d)
d->type_states[0].emit_state = EMITTED;
}
- /* eagerly determine referenced types for anon enums */
- err = btf_dump_mark_referenced(d);
- if (err)
- return err;
+ for (i = d->last_id + 1; i <= last_id; i++) {
+ t = btf__type_by_id(d->btf, i);
+
+ err = btf_dump_mark_referenced(d, t);
+ if (err)
+ goto out_err;
+
+ if (btf_is_decl_tag(t)) {
+ err = btf_dump_push_decl_tag(d, i, t);
+ if (err)
+ goto out_err;
+ }
+ }
+
+ if (d->decl_tag_cnt != cnt)
+ qsort(d->decl_tags, d->decl_tag_cnt, sizeof(*d->decl_tags),
+ btf_dump_cmp_decl_tags);
d->last_id = last_id;
return 0;
+
+out_err:
+ d->decl_tag_cnt = cnt;
+ return err;
}
static void btf_dump_free_names(struct hashmap *map)
@@ -251,6 +305,7 @@ void btf_dump__free(struct btf_dump *d)
}
}
free(d->cached_names);
+ free(d->decl_tags);
free(d->emit_queue);
free(d->decl_stack);
btf_dump_free_names(d->type_names);
@@ -312,71 +367,64 @@ int btf_dump__dump_type(struct btf_dump *d, __u32 id)
* top-level anonymous enum won't be referenced by anything, while embedded
* one will.
*/
-static int btf_dump_mark_referenced(struct btf_dump *d)
+static int btf_dump_mark_referenced(struct btf_dump *d, const struct btf_type *t)
{
- int i, j, n = btf__type_cnt(d->btf);
- const struct btf_type *t;
- __u32 vlen;
-
- for (i = d->last_id + 1; i < n; i++) {
- t = btf__type_by_id(d->btf, i);
- vlen = btf_vlen(t);
+ __u32 j, vlen = btf_vlen(t);
- switch (btf_kind(t)) {
- case BTF_KIND_INT:
- case BTF_KIND_ENUM:
- case BTF_KIND_ENUM64:
- case BTF_KIND_FWD:
- case BTF_KIND_FLOAT:
- case BTF_KIND_LOC_PARAM:
- case BTF_KIND_LOC_PROTO:
- case BTF_KIND_LOCSEC:
- break;
+ switch (btf_kind(t)) {
+ case BTF_KIND_INT:
+ case BTF_KIND_ENUM:
+ case BTF_KIND_ENUM64:
+ case BTF_KIND_FWD:
+ case BTF_KIND_FLOAT:
+ case BTF_KIND_LOC_PARAM:
+ case BTF_KIND_LOC_PROTO:
+ case BTF_KIND_LOCSEC:
+ break;
- case BTF_KIND_VOLATILE:
- case BTF_KIND_CONST:
- case BTF_KIND_RESTRICT:
- case BTF_KIND_PTR:
- case BTF_KIND_TYPEDEF:
- case BTF_KIND_FUNC:
- case BTF_KIND_VAR:
- case BTF_KIND_DECL_TAG:
- case BTF_KIND_TYPE_TAG:
- d->type_states[t->type].referenced = 1;
- break;
+ case BTF_KIND_VOLATILE:
+ case BTF_KIND_CONST:
+ case BTF_KIND_RESTRICT:
+ case BTF_KIND_PTR:
+ case BTF_KIND_TYPEDEF:
+ case BTF_KIND_FUNC:
+ case BTF_KIND_VAR:
+ case BTF_KIND_DECL_TAG:
+ case BTF_KIND_TYPE_TAG:
+ d->type_states[t->type].referenced = 1;
+ break;
- case BTF_KIND_ARRAY: {
- const struct btf_array *a = btf_array(t);
+ case BTF_KIND_ARRAY: {
+ const struct btf_array *a = btf_array(t);
- d->type_states[a->index_type].referenced = 1;
- d->type_states[a->type].referenced = 1;
- break;
- }
- case BTF_KIND_STRUCT:
- case BTF_KIND_UNION: {
- const struct btf_member *m = btf_members(t);
+ d->type_states[a->index_type].referenced = 1;
+ d->type_states[a->type].referenced = 1;
+ break;
+ }
+ case BTF_KIND_STRUCT:
+ case BTF_KIND_UNION: {
+ const struct btf_member *m = btf_members(t);
- for (j = 0; j < vlen; j++, m++)
- d->type_states[m->type].referenced = 1;
- break;
- }
- case BTF_KIND_FUNC_PROTO: {
- const struct btf_param *p = btf_params(t);
+ for (j = 0; j < vlen; j++, m++)
+ d->type_states[m->type].referenced = 1;
+ break;
+ }
+ case BTF_KIND_FUNC_PROTO: {
+ const struct btf_param *p = btf_params(t);
- for (j = 0; j < vlen; j++, p++)
- d->type_states[p->type].referenced = 1;
- break;
- }
- case BTF_KIND_DATASEC: {
- const struct btf_var_secinfo *v = btf_var_secinfos(t);
+ for (j = 0; j < vlen; j++, p++)
+ d->type_states[p->type].referenced = 1;
+ break;
+ }
+ case BTF_KIND_DATASEC: {
+ const struct btf_var_secinfo *v = btf_var_secinfos(t);
- for (j = 0; j < vlen; j++, v++)
- d->type_states[v->type].referenced = 1;
- break;
- }
- default:
- return -EINVAL;
- }
+ for (j = 0; j < vlen; j++, v++)
+ d->type_states[v->type].referenced = 1;
+ break;
+ }
+ default:
+ return -EINVAL;
}
return 0;
}
@@ -970,6 +1018,44 @@ static void btf_dump_emit_struct_fwd(struct btf_dump *d, __u32 id,
btf_dump_type_name(d, id));
}
+static void btf_dump_emit_decl_tag(struct btf_dump *d, const struct btf_type *t)
+{
+ const char *name = btf_name_of(d, t->name_off);
+
+ if (btf_kflag(t))
+ btf_dump_printf(d, " __attribute__((%s))", name);
+ else
+ btf_dump_printf(d, " __attribute__((btf_decl_tag(\"%s\")))", name);
+}
+
+/*
+ * btf_dump_resize() keeps d->decl_tags sorted by (target ID, tag ID), so the
+ * tags of one type form a run that binary search finds the start of, in a
+ * fixed order so that the same BTF always renders the same C.
+ */
+static void btf_dump_emit_decl_tags(struct btf_dump *d, __u32 id, int comp_idx)
+{
+ size_t i, lo = 0, hi = d->decl_tag_cnt, mid;
+ const struct btf_type *t;
+
+ /* lower bound on target_id */
+ while (lo < hi) {
+ mid = lo + (hi - lo) / 2;
+
+ if (d->decl_tags[mid].target_id < id)
+ lo = mid + 1;
+ else
+ hi = mid;
+ }
+
+ for (i = lo; i < d->decl_tag_cnt && d->decl_tags[i].target_id == id; i++) {
+ t = btf__type_by_id(d->btf, d->decl_tags[i].tag_id);
+
+ if (btf_decl_tag(t)->component_idx == comp_idx)
+ btf_dump_emit_decl_tag(d, t);
+ }
+}
+
static void btf_dump_emit_struct_def(struct btf_dump *d,
__u32 id,
const struct btf_type *t,
@@ -1015,6 +1101,8 @@ static void btf_dump_emit_struct_def(struct btf_dump *d,
prev_bitfield = false;
}
+ /* after the bit-field width */
+ btf_dump_emit_decl_tags(d, id, i);
btf_dump_printf(d, ";");
}
@@ -1034,6 +1122,7 @@ static void btf_dump_emit_struct_def(struct btf_dump *d,
}
if (packed)
btf_dump_printf(d, " __attribute__((packed))");
+ btf_dump_emit_decl_tags(d, id, -1);
}
static const char *missing_base_types[][2] = {
@@ -1211,6 +1300,7 @@ static void btf_dump_emit_typedef_def(struct btf_dump *d, __u32 id,
btf_dump_printf(d, "typedef ");
btf_dump_emit_type_decl(d, t->type, name, lvl);
+ btf_dump_emit_decl_tags(d, id, -1);
}
static int btf_dump_push_decl_stack_id(struct btf_dump *d, __u32 id)
diff --git a/tools/testing/selftests/bpf/btf_helpers.c b/tools/testing/selftests/bpf/btf_helpers.c
index 85a4d15d1dd1c..e04b61c08cd8e 100644
--- a/tools/testing/selftests/bpf/btf_helpers.c
+++ b/tools/testing/selftests/bpf/btf_helpers.c
@@ -114,9 +114,12 @@ int fprintf_btf_type_raw(FILE *out, const struct btf *btf, __u32 id)
case BTF_KIND_VOLATILE:
case BTF_KIND_RESTRICT:
case BTF_KIND_TYPEDEF:
- case BTF_KIND_TYPE_TAG:
fprintf(out, " type_id=%u", t->type);
break;
+ case BTF_KIND_TYPE_TAG:
+ fprintf(out, " type_id=%u%s", t->type,
+ btf_kflag(t) ? " kflag=1" : "");
+ break;
case BTF_KIND_ARRAY: {
const struct btf_array *arr = btf_array(t);
@@ -203,8 +206,9 @@ int fprintf_btf_type_raw(FILE *out, const struct btf *btf, __u32 id)
fprintf(out, " size=%u", t->size);
break;
case BTF_KIND_DECL_TAG:
- fprintf(out, " type_id=%u component_idx=%d",
- t->type, btf_decl_tag(t)->component_idx);
+ fprintf(out, " type_id=%u component_idx=%d%s",
+ t->type, btf_decl_tag(t)->component_idx,
+ btf_kflag(t) ? " kflag=1" : "");
break;
case BTF_KIND_LOC_PARAM: {
struct btf_loc_param *p = btf_loc_param(t);
diff --git a/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c b/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c
index abc62958b6ed2..534aa79a42785 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpftool_btf_dump.c
@@ -207,7 +207,6 @@ static void test_dump(const char *btf_path, bool sorted)
{
const char *exp_path;
char *dump, *exp;
- int err;
exp_path = sorted ? EXPECTED_SORTED : EXPECTED_UNSORTED;
@@ -219,8 +218,7 @@ static void test_dump(const char *btf_path, bool sorted)
if (!exp)
goto out_dump;
- err = compare_text_to_expected(dump, exp);
- ASSERT_OK(err, sorted ? "cmp_sorted" : "cmp_unsorted");
+ ASSERT_TEXT_EQ(dump, exp, sorted ? "cmp_sorted" : "cmp_unsorted");
free(exp);
out_dump:
@@ -260,7 +258,7 @@ static void test_loc_dump(const char *btf_path)
if (!dump)
return;
- ASSERT_OK(compare_text_to_expected(dump, expected), "cmp_loc_dump");
+ ASSERT_TEXT_EQ(dump, expected, "cmp_loc_dump");
free(dump);
}
diff --git a/tools/testing/selftests/bpf/prog_tests/btf_dump.c b/tools/testing/selftests/bpf/prog_tests/btf_dump.c
index fe04a955d46cc..17fa44cb9c91f 100644
--- a/tools/testing/selftests/bpf/prog_tests/btf_dump.c
+++ b/tools/testing/selftests/bpf/prog_tests/btf_dump.c
@@ -161,12 +161,7 @@ static int test_btf_dump_case(int n, struct btf_dump_test_case *t)
goto done;
}
- /*
- * The mismatch has already been reported, so this only has to
- * register the failure. ASSERT_OK() would append a stale errno to it.
- */
- err = compare_text_to_expected(dump, expected);
- ASSERT_EQ(err, 0, "compare_text_to_expected");
+ ASSERT_TEXT_EQ(dump, expected, "compare_text_to_expected");
done:
free(expected);
@@ -224,7 +219,7 @@ static void test_ctx__dump_and_compare(struct test_ctx *t,
fflush(t->dump_buf_file);
t->dump_buf[t->dump_buf_sz] = 0; /* some libc implementations don't do this */
- ASSERT_STREQ(t->dump_buf, expected_output, message);
+ ASSERT_TEXT_EQ(t->dump_buf, expected_output, message);
}
static void test_btf_dump_incremental(void)
@@ -315,6 +310,8 @@ static void test_btf_dump_incremental(void)
ASSERT_OK(err, "field_ok");
err = btf__add_field(btf, "s", 6, 64, 0);
ASSERT_OK(err, "field_ok");
+ /* attribute on a type added after the first dump: the later walk indexes it */
+ ASSERT_EQ(btf__add_decl_attr(btf, "round2", 7, -1), 8, "round2_attr");
test_ctx__dump_and_compare(&t,
"struct s___2 {\n"
@@ -323,7 +320,270 @@ static void test_btf_dump_incremental(void)
" Y___2 = 1,\n"
" } y;\n"
" struct s s;\n"
-"};\n\n" , "c_dump1");
+"} __attribute__((round2));\n\n", "c_dump1");
+
+ test_ctx__free(&t);
+}
+
+static void test_btf_dump_decl_tags(void)
+{
+ struct test_ctx t = {};
+ struct btf *btf;
+ int id;
+
+ if (test_ctx__init(&t))
+ return;
+
+ btf = t.btf;
+
+ /*
+ * Generate BTF corresponding to the following C code:
+ *
+ * struct s1 { int f; } __attribute__((attr1))
+ * __attribute__((btf_decl_tag("plain_tag")));
+ * typedef struct { int f; } __attribute__((a1)) __attribute__((a2)) t1;
+ * union u1 { int f; } __attribute__((uattr));
+ * struct p1 { char c; int i; } __attribute__((packed)) __attribute__((pattr));
+ * struct outer { struct { int g; } __attribute__((inner)) in; };
+ * struct s2 { int f; } __attribute__((on_s2));
+ * struct s3 { int f; } __attribute__((on_s3));
+ *
+ * plus attributes on a var and a func, which btf_dump does not declare.
+ */
+ id = btf__add_int(btf, "int", 4, BTF_INT_SIGNED);
+ ASSERT_EQ(id, 1, "int_id");
+ id = btf__add_int(btf, "char", 1, BTF_INT_CHAR);
+ ASSERT_EQ(id, 2, "char_id");
+
+ /* a named record with one attribute of each form */
+ id = btf__add_struct(btf, "s1", 4);
+ ASSERT_EQ(id, 3, "s1_id");
+ ASSERT_OK(btf__add_field(btf, "f", 1, 0, 0), "s1_field");
+ ASSERT_EQ(btf__add_decl_attr(btf, "attr1", 3, -1), 4, "s1_attr");
+ /* no kflag: rendered as a btf_decl_tag(), not as a bare attribute */
+ ASSERT_EQ(btf__add_decl_tag(btf, "plain_tag", 3, -1), 5, "s1_plain_tag");
+
+ /*
+ * an anonymous record behind a typedef, with two attributes. This is
+ * the case that cannot be expressed by a caller appending to the dump:
+ * the attribute has to go before the declarator.
+ */
+ id = btf__add_struct(btf, NULL, 4);
+ ASSERT_EQ(id, 6, "anon_id");
+ ASSERT_OK(btf__add_field(btf, "f", 1, 0, 0), "anon_field");
+ ASSERT_EQ(btf__add_decl_attr(btf, "a1", 6, -1), 7, "anon_attr1");
+ ASSERT_EQ(btf__add_decl_attr(btf, "a2", 6, -1), 8, "anon_attr2");
+ id = btf__add_typedef(btf, "t1", 6);
+ ASSERT_EQ(id, 9, "typedef_id");
+
+ /* unions are records too */
+ id = btf__add_union(btf, "u1", 4);
+ ASSERT_EQ(id, 10, "u1_id");
+ ASSERT_OK(btf__add_field(btf, "f", 1, 0, 0), "u1_field");
+ ASSERT_EQ(btf__add_decl_attr(btf, "uattr", 10, -1), 11, "u1_attr");
+
+ /* composes with the packed attribute, which is derived from layout */
+ id = btf__add_struct(btf, "p1", 5);
+ ASSERT_EQ(id, 12, "p1_id");
+ ASSERT_OK(btf__add_field(btf, "c", 2, 0, 0), "p1_field_c");
+ ASSERT_OK(btf__add_field(btf, "i", 1, 8, 0), "p1_field_i");
+ ASSERT_EQ(btf__add_decl_attr(btf, "pattr", 12, -1), 13, "p1_attr");
+
+ /* an anonymous record inlined at a member, the third emission position */
+ id = btf__add_struct(btf, NULL, 4);
+ ASSERT_EQ(id, 14, "inner_id");
+ ASSERT_OK(btf__add_field(btf, "g", 1, 0, 0), "inner_field");
+ ASSERT_EQ(btf__add_decl_attr(btf, "inner", 14, -1), 15, "inner_attr");
+ id = btf__add_struct(btf, "outer", 4);
+ ASSERT_EQ(id, 16, "outer_id");
+ ASSERT_OK(btf__add_field(btf, "in", 14, 0, 0), "outer_field");
+
+ /* not rendered: a var has no declaration in the C output */
+ id = btf__add_var(btf, "v", BTF_VAR_GLOBAL_ALLOCATED, 3);
+ ASSERT_EQ(id, 17, "var_id");
+ ASSERT_EQ(btf__add_decl_attr(btf, "var_attr", 17, -1), 18, "var_attr");
+ /* not rendered: neither does a func */
+ id = btf__add_func_proto(btf, 1);
+ ASSERT_EQ(id, 19, "proto_id");
+ id = btf__add_func(btf, "fn", BTF_FUNC_GLOBAL, 19);
+ ASSERT_EQ(id, 20, "func_id");
+ ASSERT_EQ(btf__add_decl_attr(btf, "func_attr", 20, -1), 21, "func_attr");
+
+ /*
+ * Tags added in reverse target order: the tag with the lower type ID
+ * names the record with the higher one, so the index is in emission
+ * order only once btf_dump_resize() has sorted it. Without the sort
+ * the lookups land outside their runs and the records lose their
+ * attributes.
+ */
+ id = btf__add_struct(btf, "s2", 4);
+ ASSERT_EQ(id, 22, "s2_id");
+ ASSERT_OK(btf__add_field(btf, "f", 1, 0, 0), "s2_field");
+ id = btf__add_struct(btf, "s3", 4);
+ ASSERT_EQ(id, 23, "s3_id");
+ ASSERT_OK(btf__add_field(btf, "f", 1, 0, 0), "s3_field");
+ ASSERT_EQ(btf__add_decl_attr(btf, "on_s3", 23, -1), 24, "s3_attr");
+ ASSERT_EQ(btf__add_decl_attr(btf, "on_s2", 22, -1), 25, "s2_attr");
+
+ test_ctx__dump_and_compare(&t,
+"struct s1 {\n"
+" int f;\n"
+"} __attribute__((attr1)) __attribute__((btf_decl_tag(\"plain_tag\")));\n"
+"\n"
+"typedef struct {\n"
+" int f;\n"
+"} __attribute__((a1)) __attribute__((a2)) t1;\n"
+"\n"
+"union u1 {\n"
+" int f;\n"
+"} __attribute__((uattr));\n"
+"\n"
+"struct p1 {\n"
+" char c;\n"
+" int i;\n"
+"} __attribute__((packed)) __attribute__((pattr));\n"
+"\n"
+"struct outer {\n"
+" struct {\n"
+" int g;\n"
+" } __attribute__((inner)) in;\n"
+"};\n"
+"\n"
+"struct s2 {\n"
+" int f;\n"
+"} __attribute__((on_s2));\n"
+"\n"
+"struct s3 {\n"
+" int f;\n"
+"} __attribute__((on_s3));\n"
+"\n", "dump_and_compare");
+
+ test_ctx__free(&t);
+}
+
+/*
+ * An attribute on a member is emitted at the member declaration, and one on
+ * the record at the closing brace. Both are keyed by the record in the index,
+ * so this also checks that they do not leak into each other's position.
+ */
+static void test_btf_dump_decl_tags_members(void)
+{
+ struct test_ctx t = {};
+ struct btf *btf;
+ int id;
+
+ if (test_ctx__init(&t))
+ return;
+
+ btf = t.btf;
+
+ /*
+ * Generate BTF corresponding to the following C code:
+ *
+ * struct m1 {
+ * int (*fp)(void) __attribute__((fp_attr));
+ * int a;
+ * int b __attribute__((b1)) __attribute__((b2));
+ * int arr[4] __attribute__((arr_attr));
+ * } __attribute__((rec));
+ * struct bits { int x : 3 __attribute__((x_attr)); int y : 29; };
+ */
+ id = btf__add_int(btf, "int", 4, BTF_INT_SIGNED);
+ ASSERT_EQ(id, 1, "int_id");
+ id = btf__add_array(btf, 1, 1, 4);
+ ASSERT_EQ(id, 2, "array_id");
+ id = btf__add_func_proto(btf, 1);
+ ASSERT_EQ(id, 3, "proto_id");
+ id = btf__add_ptr(btf, 3);
+ ASSERT_EQ(id, 4, "ptr_id");
+
+ id = btf__add_struct(btf, "m1", 32);
+ ASSERT_EQ(id, 5, "m1_id");
+ ASSERT_OK(btf__add_field(btf, "fp", 4, 0, 0), "m1_fp");
+ ASSERT_OK(btf__add_field(btf, "a", 1, 64, 0), "m1_a");
+ ASSERT_OK(btf__add_field(btf, "b", 1, 96, 0), "m1_b");
+ ASSERT_OK(btf__add_field(btf, "arr", 2, 128, 0), "m1_arr");
+ ASSERT_EQ(btf__add_decl_attr(btf, "rec", 5, -1), 6, "m1_rec_attr");
+ /* the attribute follows the whole declarator, pointer and array alike */
+ ASSERT_EQ(btf__add_decl_attr(btf, "fp_attr", 5, 0), 7, "m1_fp_attr");
+ /* two on one member, to pin the ordering */
+ ASSERT_EQ(btf__add_decl_attr(btf, "b1", 5, 2), 8, "m1_b1");
+ ASSERT_EQ(btf__add_decl_attr(btf, "b2", 5, 2), 9, "m1_b2");
+ ASSERT_EQ(btf__add_decl_attr(btf, "arr_attr", 5, 3), 10, "m1_arr_attr");
+
+ /* a bit-field: the attribute has to follow the width */
+ id = btf__add_struct(btf, "bits", 4);
+ ASSERT_EQ(id, 11, "bits_id");
+ ASSERT_OK(btf__add_field(btf, "x", 1, 0, 3), "bits_x");
+ ASSERT_OK(btf__add_field(btf, "y", 1, 3, 29), "bits_y");
+ ASSERT_EQ(btf__add_decl_attr(btf, "x_attr", 11, 0), 12, "bits_x_attr");
+
+ test_ctx__dump_and_compare(&t,
+"struct m1 {\n"
+" int (*fp)(void) __attribute__((fp_attr));\n"
+" int a;\n"
+" int b __attribute__((b1)) __attribute__((b2));\n"
+" int arr[4] __attribute__((arr_attr));\n"
+"} __attribute__((rec));\n"
+"\n"
+"struct bits {\n"
+" int x: 3 __attribute__((x_attr));\n"
+" int y: 29;\n"
+"};\n"
+"\n", "dump_and_compare");
+
+ test_ctx__free(&t);
+}
+
+/*
+ * A typedef is the third and last kind btf_dump declares. Its attributes go
+ * after the declarator, so a typedef of an anonymous record can carry three
+ * groups in one declaration, binding to three different entities.
+ */
+static void test_btf_dump_decl_tags_typedef(void)
+{
+ struct test_ctx t = {};
+ struct btf *btf;
+ int id;
+
+ if (test_ctx__init(&t))
+ return;
+
+ btf = t.btf;
+
+ /*
+ * Generate BTF corresponding to the following C code:
+ *
+ * typedef int td __attribute__((t1))
+ * __attribute__((btf_decl_tag("t2")));
+ * typedef struct {
+ * int f __attribute__((memb_attr));
+ * } __attribute__((rec_attr)) both __attribute__((both_attr));
+ */
+ id = btf__add_int(btf, "int", 4, BTF_INT_SIGNED);
+ ASSERT_EQ(id, 1, "int_id");
+ id = btf__add_typedef(btf, "td", 1);
+ ASSERT_EQ(id, 2, "td_id");
+ ASSERT_EQ(btf__add_decl_attr(btf, "t1", 2, -1), 3, "td_attr1");
+ /* no kflag: rendered as a btf_decl_tag(), not as a bare attribute */
+ ASSERT_EQ(btf__add_decl_tag(btf, "t2", 2, -1), 4, "td_attr2");
+
+ id = btf__add_struct(btf, NULL, 4);
+ ASSERT_EQ(id, 5, "anon_id");
+ ASSERT_OK(btf__add_field(btf, "f", 1, 0, 0), "anon_field");
+ ASSERT_EQ(btf__add_decl_attr(btf, "rec_attr", 5, -1), 6, "anon_rec_attr");
+ ASSERT_EQ(btf__add_decl_attr(btf, "memb_attr", 5, 0), 7, "anon_memb_attr");
+ id = btf__add_typedef(btf, "both", 5);
+ ASSERT_EQ(id, 8, "both_id");
+ ASSERT_EQ(btf__add_decl_attr(btf, "both_attr", 8, -1), 9, "both_attr");
+
+ test_ctx__dump_and_compare(&t,
+"typedef int td __attribute__((t1)) __attribute__((btf_decl_tag(\"t2\")));\n"
+"\n"
+"typedef struct {\n"
+" int f __attribute__((memb_attr));\n"
+"} __attribute__((rec_attr)) both __attribute__((both_attr));\n"
+"\n", "dump_and_compare");
test_ctx__free(&t);
}
@@ -1109,6 +1369,15 @@ void test_btf_dump() {
if (test__start_subtest("btf_dump: incremental"))
test_btf_dump_incremental();
+ if (test__start_subtest("btf_dump: decl_tags"))
+ test_btf_dump_decl_tags();
+
+ if (test__start_subtest("btf_dump: decl_tags_members"))
+ test_btf_dump_decl_tags_members();
+
+ if (test__start_subtest("btf_dump: decl_tags_typedef"))
+ test_btf_dump_decl_tags_typedef();
+
if (test__start_subtest("btf_dump: type_tags"))
test_btf_dump_type_tags();
diff --git a/tools/testing/selftests/bpf/prog_tests/btf_write.c b/tools/testing/selftests/bpf/prog_tests/btf_write.c
index 5c84723cf2540..3bed3a28c06a3 100644
--- a/tools/testing/selftests/bpf/prog_tests/btf_write.c
+++ b/tools/testing/selftests/bpf/prog_tests/btf_write.c
@@ -606,6 +606,38 @@ static void test_btf_add_btf_split()
btf__free(base);
}
+static void test_btf_attrs(void)
+{
+ struct btf *btf;
+
+ btf = btf__new_empty();
+ if (!ASSERT_OK_PTR(btf, "new_empty"))
+ return;
+
+ btf__add_int(btf, "int", 4, BTF_INT_SIGNED);
+ btf__add_struct(btf, "s", 4);
+ btf__add_field(btf, "f", 1, 0, 0);
+
+ btf__add_decl_tag(btf, "tag", 2, -1);
+ btf__add_decl_attr(btf, "tag", 2, -1);
+ btf__add_decl_attr(btf, "member_attr", 2, 0);
+ btf__add_type_tag(btf, "tag", 1);
+ btf__add_type_attr(btf, "tag", 1);
+
+ VALIDATE_RAW_BTF(
+ btf,
+ "[1] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED",
+ "[2] STRUCT 's' size=4 vlen=1\n"
+ "\t'f' type_id=1 bits_offset=0",
+ "[3] DECL_TAG 'tag' type_id=2 component_idx=-1",
+ "[4] DECL_TAG 'tag' type_id=2 component_idx=-1 kflag=1",
+ "[5] DECL_TAG 'member_attr' type_id=2 component_idx=0 kflag=1",
+ "[6] TYPE_TAG 'tag' type_id=1",
+ "[7] TYPE_TAG 'tag' type_id=1 kflag=1");
+
+ btf__free(btf);
+}
+
void test_btf_write()
{
if (test__start_subtest("btf_add"))
@@ -614,4 +646,6 @@ void test_btf_write()
test_btf_add_btf();
if (test__start_subtest("btf_add_btf_split"))
test_btf_add_btf_split();
+ if (test__start_subtest("btf_attrs"))
+ test_btf_attrs();
}
diff --git a/tools/testing/selftests/bpf/test_progs.h b/tools/testing/selftests/bpf/test_progs.h
index ea493c477fbde..adc18f5eceb65 100644
--- a/tools/testing/selftests/bpf/test_progs.h
+++ b/tools/testing/selftests/bpf/test_progs.h
@@ -349,6 +349,9 @@ void hexdump(const char *prefix, const void *buf, size_t len);
___ok; \
})
+#define ASSERT_TEXT_EQ(actual, expected, name) \
+ ASSERT_TRUE(compare_text_to_expected(actual, expected) == 0, name)
+
#define ASSERT_MEMEQ(actual, expected, len, name) ({ \
static int duration = 0; \
const void *__act = actual; \
|
| 3/2 | 2026/09/30 22:52 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 13759 output: 24 thoughts: 578 Thoughts: **Analyzing the Patch: WorthFuzzing Evaluation** Okay, let's break this down. My initial assessment is based on the files touched in this diff. I see changes in `tools/lib/bpf/btf_dump.c` and several files within `tools/testing/selftests/bpf/`. My immediate thought is, "all these files are in the `tools/` directory, which typically indicates user-space code or test infrastructure." This makes me think about the criteria for determining if a patch is *WorthFuzzing*. Now, let me explicitly check the negative criteria, specifically Section 2 of the guidelines. The critical point is: "Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories". Specifically, I'm focusing on "User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/) that do not affect the compiled kernel image (vmlinux) or kernel modules." That is, strictly `tools/` directory. I need to confirm that no changes exist outside of `tools/`. So, I'll go back to my initial file list: `tools/lib/bpf/btf_dump.c` and the selftests are the only changes. I'm not seeing any modifications in `kernel/bpf/`, `include/`, `net/`, `drivers/`, or anywhere else that would suggest kernel code is being modified. Just to be absolutely certain, I'll run a quick `git log` or `git show` to get a definitive confirmation. This is just a sanity check to eliminate any potential surprises, but my initial assessment is that this patch is *not* worth fuzzing. The patch is strictly contained within `tools/` and does not affect the kernel image or modules. Therefore, by the negative criteria, I believe this is `WorthFuzzing=false`. |
| 4/2 | 2026/09/30 22:52 | tool | grepper |
0mArgs:{
"Expression": "btf_dump_cmp_decl_tags"
}Results: {
"Output": "tools/lib/bpf/btf_dump.c=159=struct btf_dump *btf_dump__new(const struct btf *btf,\n--\ntools/lib/bpf/btf_dump.c-204-\ntools/lib/bpf/btf_dump.c:205:static int btf_dump_cmp_decl_tags(const void *a, const void *b)\ntools/lib/bpf/btf_dump.c-206-{\n--\ntools/lib/bpf/btf_dump.c=229=static int btf_dump_resize(struct btf_dump *d)\n--\ntools/lib/bpf/btf_dump.c-267-\t\tqsort(d-\u003edecl_tags, d-\u003edecl_tag_cnt, sizeof(*d-\u003edecl_tags),\ntools/lib/bpf/btf_dump.c:268:\t\t btf_dump_cmp_decl_tags);\ntools/lib/bpf/btf_dump.c-269-\n"
} |
| 5/2 | 2026/09/30 22:52 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 15046 output: 106 thoughts: 299 Thoughts: **My Assessment: No Fuzzing Required** Okay, so I've taken a look at this commit. Everything here is strictly within `tools/lib/bpf` and `tools/testing/selftests/bpf`. That's important. These are userspace libraries and self-tests, completely separate from the kernel image and kernel modules. My negative criteria kicks in here: specifically, anything that doesn't impact the kernel image or modules. This clearly falls under "user-space directories, self-tests, samples, or scripts... that do not affect the compiled kernel image (vmlinux) or kernel modules". Hence, **`WorthFuzzing` is `false`**. Now, let me double-check the arguments for the `set-results` call. We have: * **`WorthFuzzing`**: *false* - as expected. * **`Reasoning`**: "The patch only modifies user-space code within tools/ (libbpf BTF dump functionality) and selftests under tools/testing/selftests/bpf/. No kernel-space code (vmlinux or modules) is modified, so these changes cannot be fuzzed via syzkaller." This is a solid explanation. * **`EnableConfigs`**: An empty list or null, which is fine. * **`FocusSymbols`**: Also an empty list or null. Alright, the data schema for `set-results` checks out: `EnableConfigs` and `FocusSymbols` are lists of strings and can be null; `Reasoning` is a string; and `WorthFuzzing` is a boolean. All the requirements are perfectly met. We're good to go. Time to call `set-results`. |
| 6/2 | 2026/09/30 22:52 | tool | set-results |
0mArgs:{
"EnableConfigs": [],
"FocusSymbols": [],
"Reasoning": "The patch only modifies user-space code within tools/lib/bpf (libbpf BTF dump functionality) and BPF selftests under tools/testing/selftests/bpf/. No kernel image (vmlinux) or kernel module code is altered, making it non-kernel code that is not applicable for syzkaller kernel fuzzing.",
"WorthFuzzing": false
}Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"Reasoning": "The patch only modifies user-space code within tools/lib/bpf (libbpf BTF dump functionality) and BPF selftests under tools/testing/selftests/bpf/. No kernel image (vmlinux) or kernel module code is altered, making it non-kernel code that is not applicable for syzkaller kernel fuzzing.",
"WorthFuzzing": false
} |
| 7/1 | 2026/09/30 22:52 | action | If |
0mArgs:{
"WorthFuzzing": false
}Results: null |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|