diff mbox series

[bpf-next,1/2] libbpf: fix a couple of missed btf_type_tag handling in btf.c

Message ID 20211115163937.3922235-1-yhs@fb.com (mailing list archive)
State Accepted
Commit 69a055d546156adc6f7727ec981f721d5ba9231a
Delegated to: BPF
Headers show
Series bpf: fix a couple of missed btf_type_tag handling in libbpf | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 5 maintainers not CCed: kafai@fb.com songliubraving@fb.com john.fastabend@gmail.com netdev@vger.kernel.org kpsingh@kernel.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 14 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next fail VM_Test

Commit Message

Yonghong Song Nov. 15, 2021, 4:39 p.m. UTC
Commit 2dc1e488e5cd ("libbpf: Support BTF_KIND_TYPE_TAG") added
BTF_KIND_TYPE_TAG support. But to test vmlinux build with
  #define __user __attribute__((btf_type_tag("user")))
I need to sync libbpf repo and manually copy libbpf sources
to pahole. To simplify process, I used BTF_KIND_RESTRICT to
simulate BTF_KIND_TYPE_TAG with vmlinux build as "restrict"
modifier is barely used in kernel. But this approach missed
one case in dedup with structures where BTF_KIND_RESTRICT is
handled and BTF_KIND_TYPE_TAG is not handled in
btf_dedup_is_equiv(), and this will result in pahole dedup
failure. This patch fixed this issue and a selftest is added in
the subsequent patch to test this scenario.

The other missed handling is in btf__resolve_size().
Currently the compiler always emit like PTR->TYPE_TAG->...
so in practice we don't hit the missing BTF_KIND_TYPE_TAG handling
issue with compiler generated code. But let us added
case BTF_KIND_TYPE_TAG in the switch statement
to be future proof.

Fixes: 2dc1e488e5cd ("libbpf: Support BTF_KIND_TYPE_TAG")
Signed-off-by: Yonghong Song <yhs@fb.com>
---
 tools/lib/bpf/btf.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index fadf089ae8fe..b6be579e0dc6 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -610,6 +610,7 @@  __s64 btf__resolve_size(const struct btf *btf, __u32 type_id)
 		case BTF_KIND_RESTRICT:
 		case BTF_KIND_VAR:
 		case BTF_KIND_DECL_TAG:
+		case BTF_KIND_TYPE_TAG:
 			type_id = t->type;
 			break;
 		case BTF_KIND_ARRAY:
@@ -4023,6 +4024,7 @@  static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id,
 	case BTF_KIND_PTR:
 	case BTF_KIND_TYPEDEF:
 	case BTF_KIND_FUNC:
+	case BTF_KIND_TYPE_TAG:
 		if (cand_type->info != canon_type->info)
 			return 0;
 		return btf_dedup_is_equiv(d, cand_type->type, canon_type->type);