From: Eduard Zingerman <eddyz87@gmail.com>
To: bpf@vger.kernel.org, ast@kernel.org
Cc: andrii@kernel.org, daniel@iogearbox.net, kernel-team@fb.com,
yhs@fb.com, alan.maguire@oracle.com,
Eduard Zingerman <eddyz87@gmail.com>
Subject: [PATCH bpf-next 0/4] libbpf: Resolve unambigous forward declarations
Date: Wed, 2 Nov 2022 13:09:01 +0200 [thread overview]
Message-ID: <20221102110905.2433622-1-eddyz87@gmail.com> (raw)
Resolve forward declarations that don't take part in type graphs
comparisons if declaration name is unambiguous.
Example:
CU #1:
struct foo; // standalone forward declaration
struct foo *some_global;
CU #2:
struct foo { int x; };
struct foo *another_global;
Currently the de-duplicated BTF for this example looks as follows:
[1] STRUCT 'foo' size=4 vlen=1 ...
[2] INT 'int' size=4 ...
[3] PTR '(anon)' type_id=1
[4] FWD 'foo' fwd_kind=struct
[5] PTR '(anon)' type_id=4
The goal of this patch-set is to simplify it as follows:
[1] STRUCT 'foo' size=4 vlen=1
'x' type_id=2 bits_offset=0
[2] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
[3] PTR '(anon)' type_id=1
The patch-set is consists of the following parts:
- A refactoring of the libbpf's hashmap interface to use `uintptr_t`
instead of `void*` for keys and values. The reasoning behind the
refactoring is that integer keys / values are used in libbpf more
often then pointer keys / values. Thus the refactoring reduces the
number of awkward looking casts like "(void *)(long)off".
`uintptr_t` is used to avoid necessity for temporary variables when
pointer keys / values are used on platforms with 32-bit pointers.
- A change to `lib/bpf/btf.c:btf__dedup` that adds a new pass named
"Resolve unambiguous forward declaration". This pass builds a
hashmap `name_off -> uniquely named struct or union` and uses it to
replace FWD types by structs or unions. This is necessary for corner
cases when FWD is not used as a part of some struct or union
definition de-duplicated by `btf_dedup_struct_types`.
For defconfig kernel with BTF enabled this removes 63 forward
declarations.
For allmodconfig kernel with BTF enabled this removes ~5K out of ~21K
forward declarations in ko objects. This unlocks some additional
de-duplication in ko objects, but impact is tiny: ~13K less BTF ids
out of ~2M.
Eduard Zingerman (4):
libbpf: hashmap interface update to uintptr_t -> uintptr_t
selftests/bpf: hashmap test cases updated for uintptr_t -> uintptr_t
interface
libbpf: Resolve unambigous forward declarations
selftests/bpf: Tests for btf_dedup_resolve_fwds
tools/bpf/bpftool/btf.c | 23 +--
tools/bpf/bpftool/common.c | 10 +-
tools/bpf/bpftool/gen.c | 19 +-
tools/bpf/bpftool/link.c | 8 +-
tools/bpf/bpftool/main.h | 4 +-
tools/bpf/bpftool/map.c | 8 +-
tools/bpf/bpftool/pids.c | 16 +-
tools/bpf/bpftool/prog.c | 8 +-
tools/lib/bpf/btf.c | 183 +++++++++++++++---
tools/lib/bpf/btf_dump.c | 16 +-
tools/lib/bpf/hashmap.c | 16 +-
tools/lib/bpf/hashmap.h | 35 ++--
tools/lib/bpf/libbpf.c | 18 +-
tools/lib/bpf/strset.c | 24 +--
tools/lib/bpf/usdt.c | 31 ++-
tools/testing/selftests/bpf/prog_tests/btf.c | 152 +++++++++++++++
.../bpf/prog_tests/btf_dedup_split.c | 45 +++--
.../selftests/bpf/prog_tests/hashmap.c | 68 +++----
.../bpf/prog_tests/kprobe_multi_test.c | 6 +-
19 files changed, 482 insertions(+), 208 deletions(-)
--
2.34.1
next reply other threads:[~2022-11-02 11:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-02 11:09 Eduard Zingerman [this message]
2022-11-02 11:09 ` [PATCH bpf-next 1/4] libbpf: hashmap interface update to uintptr_t -> uintptr_t Eduard Zingerman
2022-11-02 11:09 ` [PATCH bpf-next 2/4] selftests/bpf: hashmap test cases updated for uintptr_t -> uintptr_t interface Eduard Zingerman
2022-11-02 11:09 ` [PATCH bpf-next 3/4] libbpf: Resolve unambigous forward declarations Eduard Zingerman
2022-11-02 16:36 ` Alan Maguire
2022-11-02 16:46 ` Eduard Zingerman
2022-11-02 11:09 ` [PATCH bpf-next 4/4] selftests/bpf: Tests for btf_dedup_resolve_fwds Eduard Zingerman
2022-11-02 16:47 ` Alan Maguire
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=20221102110905.2433622-1-eddyz87@gmail.com \
--to=eddyz87@gmail.com \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=yhs@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