From: Andrii Nakryiko <andrii@kernel.org>
To: <bpf@vger.kernel.org>, <netdev@vger.kernel.org>, <ast@fb.com>,
<daniel@iogearbox.net>
Cc: <andrii@kernel.org>, <kernel-team@fb.com>
Subject: [PATCH RFC bpf-next 0/4] Support kernel module ksym variables
Date: Thu, 10 Dec 2020 20:27:30 -0800 [thread overview]
Message-ID: <20201211042734.730147-1-andrii@kernel.org> (raw)
This RFC is sent to show how ksym variable access in BPF program can be
supported for kernel modules and gather some feedback while necessary fixes
for pahole ([0]) are reviewed and hopefully will make it into 1.20 version.
This work builds on all the previous kernel and libbpf changes to support
kernel module BTFs. On top of that, BPF verifier will now support ldimm64 with
src_reg=BPF_PSEUDO_BTF_ID and non-zero insn[1].imm field, which contains BTF
FD for kernel module. In such case, used module BTF, similarly to used BPF
map, will be recorded and refcnt will be increased for both BTF object itself
and its kernel module. This makes sure kernel module won't be unloaded from
under active attached BPF program.
New selftest validates all this is working as intended. bpf_testmod.ko is
extended with per-CPU variable.
[0] https://patchwork.kernel.org/project/netdevbpf/list/?series=400229&state=*
Andrii Nakryiko (4):
selftests/bpf: sync RCU before unloading bpf_testmod
bpf: support BPF ksym variables in kernel modules
libbpf: support kernel module ksym externs
selftests/bpf: test kernel module ksym externs
include/linux/bpf.h | 9 ++
include/linux/bpf_verifier.h | 3 +
include/linux/btf.h | 3 +
kernel/bpf/btf.c | 31 +++-
kernel/bpf/core.c | 23 +++
kernel/bpf/verifier.c | 149 ++++++++++++++----
tools/lib/bpf/libbpf.c | 47 ++++--
.../selftests/bpf/bpf_testmod/bpf_testmod.c | 3 +
.../selftests/bpf/prog_tests/btf_map_in_map.c | 33 ----
.../selftests/bpf/prog_tests/ksyms_module.c | 33 ++++
.../selftests/bpf/progs/test_ksyms_module.c | 26 +++
tools/testing/selftests/bpf/test_progs.c | 40 +++++
tools/testing/selftests/bpf/test_progs.h | 1 +
13 files changed, 321 insertions(+), 80 deletions(-)
create mode 100644 tools/testing/selftests/bpf/prog_tests/ksyms_module.c
create mode 100644 tools/testing/selftests/bpf/progs/test_ksyms_module.c
--
2.24.1
next reply other threads:[~2020-12-11 4:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-11 4:27 Andrii Nakryiko [this message]
2020-12-11 4:27 ` [PATCH RFC bpf-next 1/4] selftests/bpf: sync RCU before unloading bpf_testmod Andrii Nakryiko
2020-12-11 4:27 ` [PATCH RFC bpf-next 2/4] bpf: support BPF ksym variables in kernel modules Andrii Nakryiko
2020-12-11 21:27 ` Alexei Starovoitov
2020-12-11 22:15 ` Andrii Nakryiko
2020-12-12 1:52 ` Alexei Starovoitov
2020-12-12 5:23 ` Andrii Nakryiko
2020-12-11 4:27 ` [PATCH RFC bpf-next 3/4] libbpf: support kernel module ksym externs Andrii Nakryiko
2020-12-11 4:27 ` [PATCH RFC bpf-next 4/4] selftests/bpf: test " Andrii Nakryiko
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=20201211042734.730147-1-andrii@kernel.org \
--to=andrii@kernel.org \
--cc=ast@fb.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.org \
/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).