public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 0/4] Introduce bpf_object__prepare
@ 2025-03-03 13:57 Mykyta Yatsenko
  2025-03-03 13:57 ` [PATCH bpf-next v2 1/4] libbpf: use map_is_created helper in map setters Mykyta Yatsenko
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Mykyta Yatsenko @ 2025-03-03 13:57 UTC (permalink / raw)
  To: bpf, ast, andrii, daniel, kafai, kernel-team, eddyz87; +Cc: Mykyta Yatsenko

From: Mykyta Yatsenko <yatsenko@meta.com>

We are introducing a new function in the libbpf API, bpf_object__prepare,
which provides more granular control over the process of loading a
bpf_object. bpf_object__prepare performs ELF processing, relocations,
prepares final state of BPF program instructions (accessible with
bpf_program__insns()), creates and potentially pins maps, and stops short
of loading BPF programs.

There are couple of anticipated usecases for this API:
* Use BPF token for freplace programs that might need to lookup BTF of
other programs (BPF token creation can't be moved to open step, as open
step is "no privilege assumption" step so that tools like bpftool can
generate skeleton, discover the structure of BPF object, etc).
* Stopping at prepare gives users finalized BPF program
instructions (with subprogs appended, everything relocated and
finalized, etc). And that property can be taken advantage of by
veristat (and similar tools) that might want to process one program at
a time, but would like to avoid relatively slow ELF parsing and
processing; and even BPF selftests itself (RUN_TESTS part of it at
least) would benefit from this by eliminating waste of re-processing
ELF many times.

Mykyta Yatsenko (4):
  libbpf: use map_is_created helper in map setters
  libbpf: introduce more granular state for bpf_object
  libbpf: split bpf object load into prepare/load
  selftests/bpf: add tests for bpf_object__prepare

 tools/lib/bpf/libbpf.c                        | 197 ++++++++++++------
 tools/lib/bpf/libbpf.h                        |  13 ++
 tools/lib/bpf/libbpf.map                      |   1 +
 .../selftests/bpf/prog_tests/prepare.c        |  99 +++++++++
 tools/testing/selftests/bpf/progs/prepare.c   |  28 +++
 5 files changed, 271 insertions(+), 67 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/prepare.c
 create mode 100644 tools/testing/selftests/bpf/progs/prepare.c

-- 
2.48.1


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

end of thread, other threads:[~2025-03-03 23:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-03 13:57 [PATCH bpf-next v2 0/4] Introduce bpf_object__prepare Mykyta Yatsenko
2025-03-03 13:57 ` [PATCH bpf-next v2 1/4] libbpf: use map_is_created helper in map setters Mykyta Yatsenko
2025-03-03 13:57 ` [PATCH bpf-next v2 2/4] libbpf: introduce more granular state for bpf_object Mykyta Yatsenko
2025-03-03 13:57 ` [PATCH bpf-next v2 3/4] libbpf: split bpf object load into prepare/load Mykyta Yatsenko
2025-03-03 23:23   ` Andrii Nakryiko
2025-03-03 13:57 ` [PATCH bpf-next v2 4/4] selftests/bpf: add tests for bpf_object__prepare Mykyta Yatsenko
2025-03-03 23:36 ` [PATCH bpf-next v2 0/4] Introduce bpf_object__prepare patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox