From: YiFei Zhu <zhuyifei1999@gmail.com>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Stanislav Fomichev <sdf@google.com>,
Mahesh Bandewar <maheshb@google.com>,
YiFei Zhu <zhuyifei@google.com>
Subject: [RFC PATCH bpf-next 0/5] Allow storage of flexible metadata information for eBPF programs
Date: Fri, 14 Aug 2020 14:15:53 -0500 [thread overview]
Message-ID: <cover.1597427271.git.zhuyifei@google.com> (raw)
From: YiFei Zhu <zhuyifei@google.com>
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_ADD_MAP to attach a map
to a program's used_maps, even if the program instructions does not
reference the map. libbpf is extended to recognize the .metadata section
and load it as an internal map, and use the new syscall to ensure the
map is attached. bpftool is also extended to have a new flag to prog
subcommand, "--metadata" to dump the contents of the metadata section
without a separate map dump call.
An example use of this would be BPF C file declaring:
char commit_hash[] SEC(".metadata") = "abcdef123456";
and bpftool would emit:
$ bpftool prog --metadata
[...]
metadata:
commit_hash = "abcdef123456"
Patch 1 moves the used_maps array and count into an RCU-protected
struct.
Patch 2 implements the new syscall.
Patch 3 extends libbpf to have a wrapper around the syscall, probe the
kernel for support of this new syscall, and use it on .metadata section
if supported and the section exists.
Patch 4 extends bpftool so that it is able to dump metadata from prog
show.
Patch 5 adds a test to check the metadata loading and dumping.
YiFei Zhu (5):
bpf: RCU protect used_maps array and count
bpf: Add BPF_PROG_ADD_MAP syscall
libbpf: Add BPF_PROG_ADD_MAP syscall and use it on .metadata section
bpftool: support dumping metadata
selftests/bpf: Test bpftool loading and dumping metadata
.../net/ethernet/netronome/nfp/bpf/offload.c | 33 +++--
include/linux/bpf.h | 11 +-
include/uapi/linux/bpf.h | 7 +
kernel/bpf/core.c | 25 +++-
kernel/bpf/syscall.c | 102 +++++++++++++-
kernel/bpf/verifier.c | 37 +++--
net/core/dev.c | 12 +-
tools/bpf/bpftool/json_writer.c | 6 +
tools/bpf/bpftool/json_writer.h | 3 +
tools/bpf/bpftool/main.c | 10 ++
tools/bpf/bpftool/main.h | 1 +
tools/bpf/bpftool/prog.c | 132 ++++++++++++++++++
tools/include/uapi/linux/bpf.h | 7 +
tools/lib/bpf/bpf.c | 11 ++
tools/lib/bpf/bpf.h | 1 +
tools/lib/bpf/libbpf.c | 97 ++++++++++++-
tools/lib/bpf/libbpf.map | 1 +
tools/testing/selftests/bpf/Makefile | 3 +-
.../selftests/bpf/progs/metadata_unused.c | 15 ++
.../selftests/bpf/progs/metadata_used.c | 15 ++
.../selftests/bpf/test_bpftool_metadata.sh | 82 +++++++++++
21 files changed, 572 insertions(+), 39 deletions(-)
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
next reply other threads:[~2020-08-14 19:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-14 19:15 YiFei Zhu [this message]
2020-08-14 19:15 ` [RFC PATCH bpf-next 1/5] bpf: RCU protect used_maps array and count YiFei Zhu
2020-08-19 0:48 ` Alexei Starovoitov
2020-08-14 19:15 ` [RFC PATCH bpf-next 2/5] bpf: Add BPF_PROG_ADD_MAP syscall YiFei Zhu
2020-08-14 19:15 ` [RFC PATCH bpf-next 3/5] libbpf: Add BPF_PROG_ADD_MAP syscall and use it on .metadata section YiFei Zhu
2020-08-14 19:15 ` [RFC PATCH bpf-next 4/5] bpftool: support dumping metadata YiFei Zhu
2020-08-14 19:15 ` [RFC PATCH bpf-next 5/5] selftests/bpf: Test bpftool loading and " YiFei Zhu
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=cover.1597427271.git.zhuyifei@google.com \
--to=zhuyifei1999@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=maheshb@google.com \
--cc=sdf@google.com \
--cc=zhuyifei@google.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 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.