From: Yonghong Song <yhs@fb.com>
To: "Jose E. Marchesi" <jose.marchesi@oracle.com>
Cc: <bpf@vger.kernel.org>, Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>, <kernel-team@fb.com>
Subject: Re: [PATCH bpf-next v2 00/11] bpf: add support for new btf kind BTF_KIND_TAG
Date: Thu, 16 Dec 2021 13:52:25 -0800 [thread overview]
Message-ID: <fc6e80ec-a823-bee4-7451-2b4d497a64af@fb.com> (raw)
In-Reply-To: <87sfy82zvd.fsf@oracle.com>
On 9/13/21 9:40 AM, Jose E. Marchesi wrote:
>
>> cc Jose E. Marchesi
>>
>> Hi, Jose, just let you know that the BTF format for BTF_KIND_TAG is
>> changed since v1 as the new format can simplify kernel/libbpf
>> implementation. Thanks!
>
> Noted. Thanks for the update.
Hi, Jose,
This is just another update on btf_tag development.
Now, btf_tag is divided into btf_decl_tag and btf_type_tag
for tagging declarations and types as clang compiler prefers
not to mix them with each other. All compiler works in llvm
has done and you can check upstream llvm-project "main" branch
for implementation.
The patch set below (under review)
https://lore.kernel.org/bpf/20211209173537.1525283-1-yhs@fb.com/
actually tried to use btf_type_tag for linux kernel __user
annotation so bpf verifier can use it.
Another question from Omar (open source drgn maintainer)
https://developers.facebook.com/blog/post/2021/12/09/drgn-how-linux-kernel-team-meta-debugs-kernel-scale/
mentioned that btf_tag information will also help drgn since it
can then especially distinguish between __percpu pointer from
other pointers. Currently drgn is using dwarf, clang compiled
kernel puts btf_tag information in dwarf. Based on our earlier
discussion, gcc intends to generate btf tags for BTF only. Maybe
we could discuss to also generate for dwarf? Do we need a flag?
Please let me know if you have any questions.
Happy to help in whatever way to get gcc also implementing btf tag
support.
Thanks!
Yonghong
>
>>
>> On 9/13/21 8:51 AM, Yonghong Song wrote:
>>> LLVM14 added support for a new C attribute ([1])
>>> __attribute__((btf_tag("arbitrary_str")))
>>> This attribute will be emitted to dwarf ([2]) and pahole
>>> will convert it to BTF. Or for bpf target, this
>>> attribute will be emitted to BTF directly ([3], [4]).
>>> The attribute is intended to provide additional
>>> information for
>>> - struct/union type or struct/union member
>>> - static/global variables
>>> - static/global function or function parameter.
>>> This new attribute can be used to add attributes
>>> to kernel codes, e.g., pre- or post- conditions,
>>> allow/deny info, or any other info in which only
>>> the kernel is interested. Such attributes will
>>> be processed by clang frontend and emitted to
>>> dwarf, converting to BTF by pahole. Ultimiately
>>> the verifier can use these information for
>>> verification purpose.
>>> The new attribute can also be used for bpf
>>> programs, e.g., tagging with __user attributes
>>> for function parameters, specifying global
>>> function preconditions, etc. Such information
>>> may help verifier to detect user program
>>> bugs.
>>> After this series, pahole dwarf->btf converter
>>> will be enhanced to support new llvm tag
>>> for btf_tag attribute. With pahole support,
>>> we will then try to add a few real use case,
>>> e.g., __user/__rcu tagging, allow/deny list,
>>> some kernel function precondition, etc,
>>> in the kernel.
>>> In the rest of the series, Patches 1-2 had
>>> kernel support. Patches 3-4 added
>>> libbpf support. Patch 5 added bpftool
>>> support. Patches 6-10 added various selftests.
>>> Patch 11 added documentation for the new kind.
>>> [1] https://reviews.llvm.org/D106614
>>> [2] https://reviews.llvm.org/D106621
>>> [3] https://reviews.llvm.org/D106622
>>> [4] https://reviews.llvm.org/D109560
>>> Changelog:
>>> v1 -> v2:
>>> - BTF ELF format changed in llvm ([4] above),
>>> so cross-board change to use the new format.
>>> - Clarified in commit message that BTF_KIND_TAG
>>> is not emitted by bpftool btf dump format c.
>>> - Fix various comments from Andrii.
>>> Yonghong Song (11):
>>> btf: change BTF_KIND_* macros to enums
>>> bpf: support for new btf kind BTF_KIND_TAG
>>> libbpf: rename btf_{hash,equal}_int to btf_{hash,equal}_int_tag
>>> libbpf: add support for BTF_KIND_TAG
>>> bpftool: add support for BTF_KIND_TAG
>>> selftests/bpf: test libbpf API function btf__add_tag()
>>> selftests/bpf: change NAME_NTH/IS_NAME_NTH for BTF_KIND_TAG format
>>> selftests/bpf: add BTF_KIND_TAG unit tests
>>> selftests/bpf: test BTF_KIND_TAG for deduplication
>>> selftests/bpf: add a test with a bpf program with btf_tag attributes
>>> docs/bpf: add documentation for BTF_KIND_TAG
>>> Documentation/bpf/btf.rst | 27 +-
>>> include/uapi/linux/btf.h | 52 +--
>>> kernel/bpf/btf.c | 120 +++++++
>>> tools/bpf/bpftool/btf.c | 12 +
>>> tools/include/uapi/linux/btf.h | 52 +--
>>> tools/lib/bpf/btf.c | 85 ++++-
>>> tools/lib/bpf/btf.h | 15 +
>>> tools/lib/bpf/btf_dump.c | 3 +
>>> tools/lib/bpf/libbpf.c | 31 +-
>>> tools/lib/bpf/libbpf.map | 5 +
>>> tools/lib/bpf/libbpf_internal.h | 2 +
>>> tools/testing/selftests/bpf/btf_helpers.c | 7 +-
>>> tools/testing/selftests/bpf/prog_tests/btf.c | 318 ++++++++++++++++--
>>> .../selftests/bpf/prog_tests/btf_tag.c | 14 +
>>> .../selftests/bpf/prog_tests/btf_write.c | 21 ++
>>> tools/testing/selftests/bpf/progs/tag.c | 39 +++
>>> tools/testing/selftests/bpf/test_btf.h | 3 +
>>> 17 files changed, 736 insertions(+), 70 deletions(-)
>>> create mode 100644 tools/testing/selftests/bpf/prog_tests/btf_tag.c
>>> create mode 100644 tools/testing/selftests/bpf/progs/tag.c
>>>
next prev parent reply other threads:[~2021-12-16 21:52 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-13 15:51 [PATCH bpf-next v2 00/11] bpf: add support for new btf kind BTF_KIND_TAG Yonghong Song
2021-09-13 15:51 ` [PATCH bpf-next v2 01/11] btf: change BTF_KIND_* macros to enums Yonghong Song
2021-09-14 4:59 ` Andrii Nakryiko
2021-09-14 15:53 ` Yonghong Song
2021-09-13 15:51 ` [PATCH bpf-next v2 02/11] bpf: support for new btf kind BTF_KIND_TAG Yonghong Song
2021-09-14 5:08 ` Andrii Nakryiko
2021-09-14 15:59 ` Yonghong Song
2021-09-14 23:30 ` Andrii Nakryiko
2021-09-13 15:51 ` [PATCH bpf-next v2 03/11] libbpf: rename btf_{hash,equal}_int to btf_{hash,equal}_int_tag Yonghong Song
2021-09-13 15:51 ` [PATCH bpf-next v2 04/11] libbpf: add support for BTF_KIND_TAG Yonghong Song
2021-09-14 5:15 ` Andrii Nakryiko
2021-09-14 16:42 ` Yonghong Song
2021-09-13 15:51 ` [PATCH bpf-next v2 05/11] bpftool: " Yonghong Song
2021-09-14 5:16 ` Andrii Nakryiko
2021-09-13 15:51 ` [PATCH bpf-next v2 06/11] selftests/bpf: test libbpf API function btf__add_tag() Yonghong Song
2021-09-14 5:18 ` Andrii Nakryiko
2021-09-13 15:52 ` [PATCH bpf-next v2 07/11] selftests/bpf: change NAME_NTH/IS_NAME_NTH for BTF_KIND_TAG format Yonghong Song
2021-09-14 5:23 ` Andrii Nakryiko
2021-09-13 15:52 ` [PATCH bpf-next v2 08/11] selftests/bpf: add BTF_KIND_TAG unit tests Yonghong Song
2021-09-14 5:31 ` Andrii Nakryiko
2021-09-14 17:00 ` Yonghong Song
2021-09-13 15:52 ` [PATCH bpf-next v2 09/11] selftests/bpf: test BTF_KIND_TAG for deduplication Yonghong Song
2021-09-14 5:38 ` Andrii Nakryiko
2021-09-14 17:15 ` Yonghong Song
2021-09-14 19:39 ` Yonghong Song
2021-09-14 23:31 ` Andrii Nakryiko
2021-09-13 15:52 ` [PATCH bpf-next v2 10/11] selftests/bpf: add a test with a bpf program with btf_tag attributes Yonghong Song
2021-09-13 15:52 ` [PATCH bpf-next v2 11/11] docs/bpf: add documentation for BTF_KIND_TAG Yonghong Song
2021-09-14 5:40 ` Andrii Nakryiko
2021-09-13 16:08 ` [PATCH bpf-next v2 00/11] bpf: add support for new btf kind BTF_KIND_TAG Yonghong Song
2021-09-13 16:40 ` Jose E. Marchesi
2021-12-16 21:52 ` Yonghong Song [this message]
2021-12-17 10:40 ` Jose E. Marchesi
2021-12-18 1:44 ` Alexei Starovoitov
2021-12-18 20:15 ` Yonghong Song
2021-12-20 9:49 ` Jose E. Marchesi
2021-12-20 15:52 ` Yonghong Song
2022-01-25 3:58 ` Yonghong Song
2022-01-27 15:38 ` Jose E. Marchesi
2022-01-27 16:42 ` Yonghong Song
2022-02-17 13:20 ` Jose E. Marchesi
2022-02-17 15:28 ` Alexei Starovoitov
2022-02-17 16:41 ` Jose E. Marchesi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fc6e80ec-a823-bee4-7451-2b4d497a64af@fb.com \
--to=yhs@fb.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=jose.marchesi@oracle.com \
--cc=kernel-team@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).