From 98162f190b8846b2f3f1c1e18d5d134705cb674d Mon Sep 17 00:00:00 2001 From: Yonghong Song Date: Wed, 24 Aug 2022 11:23:56 +0800 Subject: [PATCH] bpftool: Add support for BTF_KIND_TAG mainline inclusion from mainline-5.16-rc1 commit 5c07f2fec00361fb5e8cff8ba7fdede7b29f38bd category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I5EUVD CVE: NA Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5c07f2fec00361fb5e8cff8ba7fdede7b29f38bd ------------------------------------------------- Added bpftool support to dump BTF_KIND_TAG information. The new bpftool will be used in later patches to dump btf in the test bpf program object file. Currently, the tags are not emitted with bpftool btf dump file format c and they are silently ignored. The tag information is mostly used in the kernel for verification purpose and the kernel uses its own btf to check. With adding these tags to vmlinux.h, tags will be encoded in program's btf but they will not be used by the kernel, at least for now. So let us delay adding these tags to format C header files until there is a real need. Signed-off-by: Yonghong Song Signed-off-by: Alexei Starovoitov Acked-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20210914223031.246951-1-yhs@fb.com (cherry picked from commit 5c07f2fec00361fb5e8cff8ba7fdede7b29f38bd) Signed-off-by: Wang Yufen Conflicts: tools/bpf/bpftool/btf.c Signed-off-by: Wang Yufen --- tools/bpf/bpftool/btf.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c index 0ba562625b02..2228136c538a 100644 --- a/tools/bpf/bpftool/btf.c +++ b/tools/bpf/bpftool/btf.c @@ -36,6 +36,7 @@ static const char * const btf_kind_str[NR_BTF_KINDS] = { [BTF_KIND_FUNC_PROTO] = "FUNC_PROTO", [BTF_KIND_VAR] = "VAR", [BTF_KIND_DATASEC] = "DATASEC", + [BTF_KIND_TAG] = "TAG", }; struct btf_attach_table { @@ -327,6 +328,17 @@ static int dump_btf_type(const struct btf *btf, __u32 id, jsonw_end_array(w); break; } + case BTF_KIND_TAG: { + const struct btf_tag *tag = (const void *)(t + 1); + + if (json_output) { + jsonw_uint_field(w, "type_id", t->type); + jsonw_int_field(w, "component_idx", tag->component_idx); + } else { + printf(" type_id=%u component_idx=%d", t->type, tag->component_idx); + } + break; + } default: break; } -- GitLab