All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v4 0/3] libbpf: Resolve unambigous forward declarations
@ 2022-11-09 14:26 Eduard Zingerman
  2022-11-09 14:26 ` [PATCH bpf-next v4 1/3] libbpf: hashmap interface update to allow both long and void* keys/values Eduard Zingerman
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Eduard Zingerman @ 2022-11-09 14:26 UTC (permalink / raw)
  To: bpf, ast
  Cc: andrii, daniel, kernel-team, yhs, alan.maguire, acme, Eduard Zingerman

The patch-set is consists of the following parts:
- An update for libbpf's hashmap interface from void* -> void* to a
  polymorphic one, allowing to use both long and void* keys and values
  w/o additional casts. Interface functions are hidden behind
  auxiliary macro that add casts as necessary.
  
  This simplifies many use cases in libbpf as hashmaps there are
  mostly integer to integer and required awkward looking incantations
  like `(void *)(long)off` previously. Also includes updates for perf
  as it copies map implementation from libbpf.
  
- 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`.

The goal of the patch-set is to 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

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.

Changelog:
 v3 -> v4
 Changes suggested by Andrii:
 - hashmap interface rework to allow use of integer and pointer keys
   an values w/o casts as suggested in [1].
 v2 -> v3
 Changes suggested by Andrii:
 - perf's util/hashtable.{c,h} are synchronized with libbpf
   implementation, perf's source code updated accordingly;
 - changes to libbpf, bpf selftests and perf are combined in a single
   patch to simplify bisecting;
 - hashtable interface updated to be long -> long instead of
   uintptr_t -> uintptr_t;
 - btf_dedup_resolve_fwds updated to correctly use IS_ERR / PTR_ERR
   macro;
 - test cases for btf_dedup_resolve_fwds are updated for better
   clarity.
 v1 -> v2
 - Style fixes in btf_dedup_resolve_fwd and btf_dedup_resolve_fwds as
   suggested by Alan.

[v1] https://lore.kernel.org/bpf/20221102110905.2433622-1-eddyz87@gmail.com/
[v2] https://lore.kernel.org/bpf/20221103033430.2611623-1-eddyz87@gmail.com/
[v3] https://lore.kernel.org/bpf/20221106202910.4193104-1-eddyz87@gmail.com/

[1] https://lore.kernel.org/bpf/CAEf4BzZ8KFneEJxFAaNCCFPGqp20hSpS2aCj76uRk3-qZUH5xg@mail.gmail.com/

Eduard Zingerman (3):
  libbpf: hashmap interface update to allow both long and void*
    keys/values
  libbpf: Resolve unambigous forward declarations
  selftests/bpf: Tests for btf_dedup_resolve_fwds

 tools/bpf/bpftool/btf.c                       |  25 +--
 tools/bpf/bpftool/common.c                    |  10 +-
 tools/bpf/bpftool/gen.c                       |  19 +-
 tools/bpf/bpftool/link.c                      |   8 +-
 tools/bpf/bpftool/main.h                      |  14 +-
 tools/bpf/bpftool/map.c                       |   8 +-
 tools/bpf/bpftool/pids.c                      |  16 +-
 tools/bpf/bpftool/prog.c                      |   8 +-
 tools/lib/bpf/btf.c                           | 184 ++++++++++++++---
 tools/lib/bpf/btf_dump.c                      |  17 +-
 tools/lib/bpf/hashmap.c                       |  18 +-
 tools/lib/bpf/hashmap.h                       |  91 +++++----
 tools/lib/bpf/libbpf.c                        |  18 +-
 tools/lib/bpf/strset.c                        |  18 +-
 tools/lib/bpf/usdt.c                          |  29 ++-
 tools/perf/tests/expr.c                       |  28 +--
 tools/perf/tests/pmu-events.c                 |   6 +-
 tools/perf/util/bpf-loader.c                  |  11 +-
 tools/perf/util/evsel.c                       |   2 +-
 tools/perf/util/expr.c                        |  36 ++--
 tools/perf/util/hashmap.c                     |  18 +-
 tools/perf/util/hashmap.h                     |  91 +++++----
 tools/perf/util/metricgroup.c                 |  10 +-
 tools/perf/util/stat-shadow.c                 |   2 +-
 tools/perf/util/stat.c                        |   9 +-
 tools/testing/selftests/bpf/prog_tests/btf.c  | 176 ++++++++++++++++
 .../bpf/prog_tests/btf_dedup_split.c          |  45 +++--
 .../selftests/bpf/prog_tests/hashmap.c        | 190 +++++++++++++-----
 .../bpf/prog_tests/kprobe_multi_test.c        |   6 +-
 29 files changed, 756 insertions(+), 357 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-11-11 18:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-09 14:26 [PATCH bpf-next v4 0/3] libbpf: Resolve unambigous forward declarations Eduard Zingerman
2022-11-09 14:26 ` [PATCH bpf-next v4 1/3] libbpf: hashmap interface update to allow both long and void* keys/values Eduard Zingerman
2022-11-10  4:54   ` Andrii Nakryiko
2022-11-10 12:28     ` Eduard Zingerman
2022-11-11 18:20       ` Andrii Nakryiko
2022-11-09 14:26 ` [PATCH bpf-next v4 2/3] libbpf: Resolve unambigous forward declarations Eduard Zingerman
2022-11-09 14:26 ` [PATCH bpf-next v4 3/3] selftests/bpf: Tests for btf_dedup_resolve_fwds Eduard Zingerman
2022-11-10  5:00 ` [PATCH bpf-next v4 0/3] libbpf: Resolve unambigous forward declarations patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.