From: Yonghong Song <yhs@fb.com>
To: <bpf@vger.kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>, <kernel-team@fb.com>
Subject: [PATCH bpf-next v4 00/18] bpf: Add 64bit enum value support
Date: Thu, 2 Jun 2022 18:58:55 -0700 [thread overview]
Message-ID: <20220603015855.1187538-1-yhs@fb.com> (raw)
Currently, btf only supports upto 32bit enum value with BTF_KIND_ENUM.
But in kernel, some enum has 64bit values, e.g., in uapi bpf.h, we have
enum {
BPF_F_INDEX_MASK = 0xffffffffULL,
BPF_F_CURRENT_CPU = BPF_F_INDEX_MASK,
BPF_F_CTXLEN_MASK = (0xfffffULL << 32),
};
With BTF_KIND_ENUM, the value for BPF_F_CTXLEN_MASK will be encoded
as 0 which is incorrect.
To solve this problem, BTF_KIND_ENUM64 is proposed in this patch set
to support enum 64bit values. Also, since sometimes there is a need
to generate C code from btf, e.g., vmlinux.h, btf kflag support
is also added for BTF_KIND_ENUM and BTF_KIND_ENUM64 to indicate
signedness, helping proper value printout.
Changelog:
v3 -> v4:
- rename btf_type_is_any_enum() to btf_is_any_enum() to favor
consistency in libbpf.
- fix sign extension issue in btf_dump_get_enum_value().
- fix BPF_CORE_FIELD_SIGNED signedness issue in bpf_core_calc_field_relo().
v2 -> v3:
- Implement separate btf_equal_enum()/btf_equal_enum64() and
btf_compat_enum()/btf_compat_enum64().
- Add a new enum64 placeholder type dynamicly for enum64 sanitization.
- For bpftool output and unit selftest, printed out signed/unsigned
encoding as well.
- fix some issues with BTF_KIND_ENUM is doc and clarified sign extension
rules for enum values.
v1 -> v2:
- Changed kflag default from signed to unsigned
- Fixed sanitization issue
- Broke down libbpf related patches for easier review
- Added more tests
- More code refactorization
- Corresponding llvm patch (to support enum64) is also updated
Yonghong Song (18):
bpf: Add btf enum64 support
libbpf: Permit 64bit relocation value
libbpf: Fix an error in 64bit relocation value computation
libbpf: Refactor btf__add_enum() for future code sharing
libbpf: Add enum64 parsing and new enum64 public API
libbpf: Add enum64 deduplication support
libbpf: Add enum64 support for btf_dump
libbpf: Add enum64 sanitization
libbpf: Add enum64 support for bpf linking
libbpf: Add enum64 relocation support
bpftool: Add btf enum64 support
selftests/bpf: Fix selftests failure
selftests/bpf: Test new enum kflag and enum64 API functions
selftests/bpf: Add BTF_KIND_ENUM64 unit tests
selftests/bpf: Test BTF_KIND_ENUM64 for deduplication
selftests/bpf: Add a test for enum64 value relocations
selftests/bpf: Clarify llvm dependency with possible selftest failures
docs/bpf: Update documentation for BTF_KIND_ENUM64 support
Documentation/bpf/btf.rst | 43 +++-
include/linux/btf.h | 28 +++
include/uapi/linux/btf.h | 17 +-
kernel/bpf/btf.c | 142 +++++++++++--
kernel/bpf/verifier.c | 2 +-
tools/bpf/bpftool/btf.c | 57 ++++-
tools/bpf/bpftool/btf_dumper.c | 29 +++
tools/bpf/bpftool/gen.c | 1 +
tools/include/uapi/linux/btf.h | 17 +-
tools/lib/bpf/btf.c | 201 ++++++++++++++++--
tools/lib/bpf/btf.h | 32 ++-
tools/lib/bpf/btf_dump.c | 137 +++++++++---
tools/lib/bpf/libbpf.c | 63 +++++-
tools/lib/bpf/libbpf.map | 2 +
tools/lib/bpf/libbpf_internal.h | 2 +
tools/lib/bpf/linker.c | 2 +
tools/lib/bpf/relo_core.c | 105 +++++----
tools/lib/bpf/relo_core.h | 4 +-
tools/testing/selftests/bpf/README.rst | 18 ++
tools/testing/selftests/bpf/btf_helpers.c | 25 ++-
tools/testing/selftests/bpf/prog_tests/btf.c | 153 +++++++++++--
.../selftests/bpf/prog_tests/btf_write.c | 126 ++++++++---
.../selftests/bpf/prog_tests/core_reloc.c | 58 +++++
.../bpf/progs/btf__core_reloc_enum64val.c | 3 +
.../progs/btf__core_reloc_enum64val___diff.c | 3 +
.../btf__core_reloc_enum64val___err_missing.c | 3 +
...btf__core_reloc_enum64val___val3_missing.c | 3 +
.../selftests/bpf/progs/core_reloc_types.h | 78 +++++++
.../bpf/progs/test_core_reloc_enum64val.c | 70 ++++++
tools/testing/selftests/bpf/test_btf.h | 1 +
30 files changed, 1235 insertions(+), 190 deletions(-)
create mode 100644 tools/testing/selftests/bpf/progs/btf__core_reloc_enum64val.c
create mode 100644 tools/testing/selftests/bpf/progs/btf__core_reloc_enum64val___diff.c
create mode 100644 tools/testing/selftests/bpf/progs/btf__core_reloc_enum64val___err_missing.c
create mode 100644 tools/testing/selftests/bpf/progs/btf__core_reloc_enum64val___val3_missing.c
create mode 100644 tools/testing/selftests/bpf/progs/test_core_reloc_enum64val.c
--
2.30.2
next reply other threads:[~2022-06-03 1:59 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-03 1:58 Yonghong Song [this message]
2022-06-03 1:59 ` [PATCH bpf-next v4 01/18] bpf: Add btf enum64 support Yonghong Song
2022-06-03 1:59 ` [PATCH bpf-next v4 02/18] libbpf: Permit 64bit relocation value Yonghong Song
2022-06-03 1:59 ` [PATCH bpf-next v4 03/18] libbpf: Fix an error in 64bit relocation value computation Yonghong Song
2022-06-03 1:59 ` [PATCH bpf-next v4 04/18] libbpf: Refactor btf__add_enum() for future code sharing Yonghong Song
2022-06-03 1:59 ` [PATCH bpf-next v4 05/18] libbpf: Add enum64 parsing and new enum64 public API Yonghong Song
2022-06-03 1:59 ` [PATCH bpf-next v4 06/18] libbpf: Add enum64 deduplication support Yonghong Song
2022-06-03 21:44 ` Andrii Nakryiko
2022-06-03 1:59 ` [PATCH bpf-next v4 07/18] libbpf: Add enum64 support for btf_dump Yonghong Song
2022-06-03 21:46 ` Andrii Nakryiko
2022-06-03 1:59 ` [PATCH bpf-next v4 08/18] libbpf: Add enum64 sanitization Yonghong Song
2022-06-03 1:59 ` [PATCH bpf-next v4 09/18] libbpf: Add enum64 support for bpf linking Yonghong Song
2022-06-03 1:59 ` [PATCH bpf-next v4 10/18] libbpf: Add enum64 relocation support Yonghong Song
2022-06-03 21:49 ` Andrii Nakryiko
2022-06-03 1:59 ` [PATCH bpf-next v4 11/18] bpftool: Add btf enum64 support Yonghong Song
2022-06-03 1:59 ` [PATCH bpf-next v4 12/18] selftests/bpf: Fix selftests failure Yonghong Song
2022-06-03 2:00 ` [PATCH bpf-next v4 13/18] selftests/bpf: Test new enum kflag and enum64 API functions Yonghong Song
2022-06-03 2:00 ` [PATCH bpf-next v4 14/18] selftests/bpf: Add BTF_KIND_ENUM64 unit tests Yonghong Song
2022-06-03 2:00 ` [PATCH bpf-next v4 15/18] selftests/bpf: Test BTF_KIND_ENUM64 for deduplication Yonghong Song
2022-06-03 2:00 ` [PATCH bpf-next v4 16/18] selftests/bpf: Add a test for enum64 value relocations Yonghong Song
2022-06-03 15:14 ` Alexei Starovoitov
2022-06-03 20:22 ` Andrii Nakryiko
2022-06-03 20:24 ` Andrii Nakryiko
2022-06-04 2:51 ` Yonghong Song
2022-06-04 9:34 ` Alexei Starovoitov
2022-06-03 2:00 ` [PATCH bpf-next v4 17/18] selftests/bpf: Clarify llvm dependency with possible selftest failures Yonghong Song
2022-06-03 2:00 ` [PATCH bpf-next v4 18/18] docs/bpf: Update documentation for BTF_KIND_ENUM64 support Yonghong Song
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=20220603015855.1187538-1-yhs@fb.com \
--to=yhs@fb.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--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