From: Stanislav Fomichev <sdf@google.com>
To: netdev@vger.kernel.org, bpf@vger.kernel.org
Cc: davem@davemloft.net, ast@kernel.org, daniel@iogearbox.net,
Stanislav Fomichev <sdf@google.com>,
YiFei Zhu <zhuyifei1999@gmail.com>
Subject: [PATCH bpf-next v4 0/5] Allow storage of flexible metadata information for eBPF programs
Date: Wed, 9 Sep 2020 11:24:01 -0700 [thread overview]
Message-ID: <20200909182406.3147878-1-sdf@google.com> (raw)
Currently, if a user wants to store arbitrary metadata for an eBPF
program, for example, the program build commit hash or version, they
could store it in a map, and conveniently libbpf uses .data section to
populate an internal map. However, if the program does not actually
reference the map, then the map would be de-refcounted and freed.
This patch set introduces a new syscall BPF_PROG_BIND_MAP to add a map
to a program's used_maps, even if the program instructions does not
reference the map.
libbpf is extended to always BPF_PROG_BIND_MAP .rodata section so the
metadata is kept in place.
bpftool is also extended to print metadata in the 'bpftool prog' list.
The variable is considered metadata if it starts with the
magic 'bpf_metadata_' prefix; everything after the prefix is the
metadata name.
An example use of this would be BPF C file declaring:
const char bpf_metadata_commit_hash[] SEC(".rodata") = "abcdef123456";
and bpftool would emit:
$ bpftool prog
[...]
metadata:
commit_hash = "abcdef123456"
v4 changes:
* Don't return EEXIST from syscall if already bound (Andrii Nakryiko)
* Removed --metadata argument (Andrii Nakryiko)
* Removed custom .metadata section (Alexei Starovoitov)
* Addressed Andrii's suggestions about btf helpers and vsi (Andrii Nakryiko)
* Moved bpf_prog_find_metadata into bpftool (Alexei Starovoitov)
v3 changes:
* API changes for bpf_prog_find_metadata (Toke Høiland-Jørgensen)
v2 changes:
* Made struct bpf_prog_bind_opts in libbpf so flags is optional.
* Deduped probe_kern_global_data and probe_prog_bind_map into a common
helper.
* Added comment regarding why EEXIST is ignored in libbpf bind map.
* Froze all LIBBPF_MAP_METADATA internal maps.
* Moved bpf_prog_bind_map into new LIBBPF_0.1.1 in libbpf.map.
* Added p_err() calls on error cases in bpftool show_prog_metadata.
* Reverse christmas tree coding style in bpftool show_prog_metadata.
* Made bpftool gen skeleton recognize .metadata as an internal map and
generate datasec definition in skeleton.
* Added C test using skeleton to see asset that the metadata is what we
expect and rebinding causes EEXIST.
v1 changes:
* Fixed a few missing unlocks, and missing close while iterating map fds.
* Move mutex initialization to right after prog aux allocation, and mutex
destroy to right after prog aux free.
* s/ADD_MAP/BIND_MAP/
* Use mutex only instead of RCU to protect the used_map array & count.
Cc: YiFei Zhu <zhuyifei1999@gmail.com>
YiFei Zhu (5):
bpf: Mutex protect used_maps array and count
bpf: Add BPF_PROG_BIND_MAP syscall
libbpf: Add BPF_PROG_BIND_MAP syscall and use it on .metadata section
bpftool: support dumping metadata
selftests/bpf: Test load and dump metadata with btftool and skel
.../net/ethernet/netronome/nfp/bpf/offload.c | 18 +-
include/linux/bpf.h | 1 +
include/uapi/linux/bpf.h | 7 +
kernel/bpf/core.c | 15 +-
kernel/bpf/syscall.c | 79 ++++++-
net/core/dev.c | 11 +-
tools/bpf/bpftool/json_writer.c | 6 +
tools/bpf/bpftool/json_writer.h | 3 +
tools/bpf/bpftool/prog.c | 222 ++++++++++++++++++
tools/include/uapi/linux/bpf.h | 7 +
tools/lib/bpf/bpf.c | 13 +
tools/lib/bpf/bpf.h | 8 +
tools/lib/bpf/libbpf.c | 94 ++++++--
tools/lib/bpf/libbpf.map | 1 +
tools/testing/selftests/bpf/Makefile | 3 +-
.../selftests/bpf/prog_tests/metadata.c | 81 +++++++
.../selftests/bpf/progs/metadata_unused.c | 15 ++
.../selftests/bpf/progs/metadata_used.c | 15 ++
.../selftests/bpf/test_bpftool_metadata.sh | 82 +++++++
19 files changed, 645 insertions(+), 36 deletions(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/metadata.c
create mode 100644 tools/testing/selftests/bpf/progs/metadata_unused.c
create mode 100644 tools/testing/selftests/bpf/progs/metadata_used.c
create mode 100755 tools/testing/selftests/bpf/test_bpftool_metadata.sh
--
2.28.0.526.ge36021eeef-goog
next reply other threads:[~2020-09-09 18:24 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-09 18:24 Stanislav Fomichev [this message]
2020-09-09 18:24 ` [PATCH bpf-next v4 1/5] bpf: Mutex protect used_maps array and count Stanislav Fomichev
2020-09-10 19:23 ` Andrii Nakryiko
2020-09-09 18:24 ` [PATCH bpf-next v4 2/5] bpf: Add BPF_PROG_BIND_MAP syscall Stanislav Fomichev
2020-09-10 19:29 ` Andrii Nakryiko
2020-09-09 18:24 ` [PATCH bpf-next v4 3/5] libbpf: Add BPF_PROG_BIND_MAP syscall and use it on .metadata section Stanislav Fomichev
2020-09-10 19:40 ` Andrii Nakryiko
2020-09-11 15:49 ` Stanislav Fomichev
2020-09-09 18:24 ` [PATCH bpf-next v4 4/5] bpftool: support dumping metadata Stanislav Fomichev
2020-09-10 19:54 ` Andrii Nakryiko
2020-09-11 15:56 ` Stanislav Fomichev
2020-09-09 18:24 ` [PATCH bpf-next v4 5/5] selftests/bpf: Test load and dump metadata with btftool and skel Stanislav Fomichev
2020-09-10 19:59 ` Andrii Nakryiko
2020-09-11 15:57 ` Stanislav Fomichev
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=20200909182406.3147878-1-sdf@google.com \
--to=sdf@google.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=zhuyifei1999@gmail.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).