Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support BTF_KIND_TYPE_TAG for btf_type_tag attributes #2100

Closed
wants to merge 11 commits into from

Conversation

kernel-patches-bot
Copy link

Pull request for series with
subject: Support BTF_KIND_TYPE_TAG for btf_type_tag attributes
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=577773

@kernel-patches-bot
Copy link
Author

Master branch: 3a74ac2
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=577773
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 3a74ac2
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=577773
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 1a8b597
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=577773
version: 1

@kernel-patches-bot
Copy link
Author

Master branch: 04f8cb6
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=577773
version: 1

@kernel-patches-bot
Copy link
Author

At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=577773 expired. Closing PR.

@kernel-patches-bot
Copy link
Author

Master branch: 04f8cb6
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=578993
version: 2

@kernel-patches-bot
Copy link
Author

Master branch: 3a75111
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=578993
version: 2

Pull request is NOT updated. Failed to apply https://patchwork.kernel.org/project/netdevbpf/list/?series=578993
error message:

Cmd('git') failed due to: exit code(128)
  cmdline: git am -3
  stdout: 'Applying: bpf: Support BTF_KIND_TYPE_TAG for btf_type_tag attributes
Applying: libbpf: Support BTF_KIND_TYPE_TAG
Patch failed at 0002 libbpf: Support BTF_KIND_TYPE_TAG
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".'
  stderr: 'error: sha1 information is lacking or useless (tools/lib/bpf/libbpf_internal.h).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch'

conflict:


@kernel-patches-bot
Copy link
Author

At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=578993 expired. Closing PR.

Nobody and others added 2 commits November 11, 2021 17:38
LLVM patches ([1] for clang, [2] and [3] for BPF backend)
added support for btf_type_tag attributes. This patch
added support for the kernel.

The main motivation for btf_type_tag is to bring kernel
annotations __user, __rcu etc. to btf. With such information
available in btf, bpf verifier can detect mis-usages
and reject the program. For example, for __user tagged pointer,
developers can then use proper helper like bpf_probe_read_user()
etc. to read the data.

BTF_KIND_TYPE_TAG may also useful for other tracing
facility where instead of to require user to specify
kernel/user address type, the kernel can detect it
by itself with btf.

  [1] https://reviews.llvm.org/D111199
  [2] https://reviews.llvm.org/D113222
  [3] https://reviews.llvm.org/D113496

Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Yonghong Song <yhs@fb.com>
Add libbpf support for BTF_KIND_TYPE_TAG.

Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Yonghong Song <yhs@fb.com>
Add bpftool support for BTF_KIND_TYPE_TAG.

Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Yonghong Song <yhs@fb.com>
Add unit tests for btf__add_type_tag().

Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Yonghong Song <yhs@fb.com>
Add BTF_KIND_TYPE_TAG unit tests.

Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Yonghong Song <yhs@fb.com>
Add BTF_KIND_TYPE_TAG duplication unit tests.

Signed-off-by: Yonghong Song <yhs@fb.com>
Rename progs/tag.c to progs/btf_decl_tag.c so we can introduce
progs/btf_type_tag.c in the next patch.

Also create a subtest for btf_decl_tag in prog_tests/btf_tag.c
so we can introduce btf_type_tag subtest in the next patch.

I also took opportunity to remove the check whether __has_attribute
is defined or not in progs/btf_decl_tag.c since all recent
clangs should already support this macro.

Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Yonghong Song <yhs@fb.com>
The following is the main btf_type_tag usage in the
C test:
  #define __tag1 __attribute__((btf_type_tag("tag1")))
  #define __tag2 __attribute__((btf_type_tag("tag2")))
  struct btf_type_tag_test {
       int __tag1 * __tag1 __tag2 *p;
  } g;

The bpftool raw dump with related types:
  [4] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
  [11] STRUCT 'btf_type_tag_test' size=8 vlen=1
          'p' type_id=14 bits_offset=0
  [12] TYPE_TAG 'tag1' type_id=16
  [13] TYPE_TAG 'tag2' type_id=12
  [14] PTR '(anon)' type_id=13
  [15] TYPE_TAG 'tag1' type_id=4
  [16] PTR '(anon)' type_id=15
  [17] VAR 'g' type_id=11, linkage=global

With format C dump, we have
  struct btf_type_tag_test {
        int __attribute__((btf_type_tag("tag1"))) * __attribute__((btf_type_tag("tag1"))) __attribute__((btf_type_tag("tag2"))) *p;
  };
The result C code is identical to the original definition except macro's are gone.

Signed-off-by: Yonghong Song <yhs@fb.com>
btf_tag selftest needs certain llvm versions (>= llvm14).
Make it clear in the selftests README.rst file.

Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Yonghong Song <yhs@fb.com>
Add BTF_KIND_TYPE_TAG documentation in btf.rst.

Acked-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Yonghong Song <yhs@fb.com>
@kernel-patches-bot
Copy link
Author

Master branch: 2326ff8
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=579013
version: 3

@kernel-patches-bot
Copy link
Author

At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=579013 irrelevant now. Closing PR.

@kernel-patches-bot kernel-patches-bot deleted the series/577773=>bpf-next branch November 12, 2021 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants