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

Commits on Nov 12, 2021

  1. adding ci files

    Nobody committed Nov 12, 2021
    Configuration menu
    Copy the full SHA
    002eb4b View commit details
    Browse the repository at this point in the history
  2. bpf: Support BTF_KIND_TYPE_TAG for btf_type_tag attributes

    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>
    yonghong-song authored and Nobody committed Nov 12, 2021
    Configuration menu
    Copy the full SHA
    a2559a1 View commit details
    Browse the repository at this point in the history
  3. libbpf: Support BTF_KIND_TYPE_TAG

    Add libbpf support for BTF_KIND_TYPE_TAG.
    
    Acked-by: Andrii Nakryiko <andrii@kernel.org>
    Signed-off-by: Yonghong Song <yhs@fb.com>
    yonghong-song authored and Nobody committed Nov 12, 2021
    Configuration menu
    Copy the full SHA
    f2dc7d1 View commit details
    Browse the repository at this point in the history
  4. bpftool: Support BTF_KIND_TYPE_TAG

    Add bpftool support for BTF_KIND_TYPE_TAG.
    
    Acked-by: Andrii Nakryiko <andrii@kernel.org>
    Signed-off-by: Yonghong Song <yhs@fb.com>
    yonghong-song authored and Nobody committed Nov 12, 2021
    Configuration menu
    Copy the full SHA
    b7b1016 View commit details
    Browse the repository at this point in the history
  5. selftests/bpf: Test libbpf API function btf__add_type_tag()

    Add unit tests for btf__add_type_tag().
    
    Acked-by: Andrii Nakryiko <andrii@kernel.org>
    Signed-off-by: Yonghong Song <yhs@fb.com>
    yonghong-song authored and Nobody committed Nov 12, 2021
    Configuration menu
    Copy the full SHA
    3529294 View commit details
    Browse the repository at this point in the history
  6. selftests/bpf: Add BTF_KIND_TYPE_TAG unit tests

    Add BTF_KIND_TYPE_TAG unit tests.
    
    Acked-by: Andrii Nakryiko <andrii@kernel.org>
    Signed-off-by: Yonghong Song <yhs@fb.com>
    yonghong-song authored and Nobody committed Nov 12, 2021
    Configuration menu
    Copy the full SHA
    ce2f0b9 View commit details
    Browse the repository at this point in the history
  7. selftests/bpf: Test BTF_KIND_DECL_TAG for deduplication

    Add BTF_KIND_TYPE_TAG duplication unit tests.
    
    Signed-off-by: Yonghong Song <yhs@fb.com>
    yonghong-song authored and Nobody committed Nov 12, 2021
    Configuration menu
    Copy the full SHA
    665c5ff View commit details
    Browse the repository at this point in the history
  8. selftests/bpf: Rename progs/tag.c to progs/btf_decl_tag.c

    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>
    yonghong-song authored and Nobody committed Nov 12, 2021
    Configuration menu
    Copy the full SHA
    9740fae View commit details
    Browse the repository at this point in the history
  9. selftests/bpf: Add a C test for btf_type_tag

    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>
    yonghong-song authored and Nobody committed Nov 12, 2021
    Configuration menu
    Copy the full SHA
    41fa67c View commit details
    Browse the repository at this point in the history
  10. selftests/bpf: Clarify llvm dependency with btf_tag selftest

    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>
    yonghong-song authored and Nobody committed Nov 12, 2021
    Configuration menu
    Copy the full SHA
    0b9f7e7 View commit details
    Browse the repository at this point in the history
  11. docs/bpf: Update documentation for BTF_KIND_TYPE_TAG support

    Add BTF_KIND_TYPE_TAG documentation in btf.rst.
    
    Acked-by: Andrii Nakryiko <andrii@kernel.org>
    Signed-off-by: Yonghong Song <yhs@fb.com>
    yonghong-song authored and Nobody committed Nov 12, 2021
    Configuration menu
    Copy the full SHA
    602c269 View commit details
    Browse the repository at this point in the history