diff options
author | Alexei Starovoitov <ast@kernel.org> | 2021-01-12 15:00:01 -0800 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2021-01-12 17:24:30 -0800 |
commit | 7c7a80ea5e3f91a93f17070f0b071cc34a474e3c (patch) | |
tree | 348ac2808f0006934b49aa2f472b7d069af710ba /tools/testing/selftests/bpf/test_progs.c | |
parent | 3218231dbb16cd85d94831759b6c78e6feb54b58 (diff) | |
parent | 430d97a8a7bf1500c081ce756ff2ead73d2303c5 (diff) |
Merge branch 'Support kernel module ksym variables'
Andrii Nakryiko says:
====================
Add support for using kernel module global variables (__ksym externs in BPF
program). BPF verifier will now support ldimm64 with src_reg=BPF_PSEUDO_BTF_ID
and non-zero insn[1].imm field, specifying module BTF's FD. In such case,
module BTF object, similarly to BPF maps referenced from ldimm64 with
src_reg=BPF_PSEUDO_MAP_FD, will be recorded in bpf_progran's auxiliary data
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. These refcounts will be dropped when BPF program is unloaded.
New selftest validates all this is working as intended. bpf_testmod.ko is
extended with per-CPU variable. Selftests expects the latest pahole changes
(soon to be released as v1.20) to generate per-CPU variable BTF info for
kernel module.
v2->v3:
- added comments, addressed feedack (Yonghong, Hao);
v1->v2:
- fixed few compiler warnings, posted as separate pre-patches;
rfc->v1:
- use sys_membarrier(MEMBARRIER_CMD_GLOBAL) (Alexei).
Cc: Hao Luo <haoluo@google.com>
====================
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/testing/selftests/bpf/test_progs.c')
-rw-r--r-- | tools/testing/selftests/bpf/test_progs.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c index 7d077d48cadd..213628ee721c 100644 --- a/tools/testing/selftests/bpf/test_progs.c +++ b/tools/testing/selftests/bpf/test_progs.c @@ -11,6 +11,7 @@ #include <signal.h> #include <string.h> #include <execinfo.h> /* backtrace */ +#include <linux/membarrier.h> #define EXIT_NO_TEST 2 #define EXIT_ERR_SETUP_INFRA 3 @@ -370,8 +371,18 @@ static int delete_module(const char *name, int flags) return syscall(__NR_delete_module, name, flags); } +/* + * Trigger synchronize_rcu() in kernel. + */ +int kern_sync_rcu(void) +{ + return syscall(__NR_membarrier, MEMBARRIER_CMD_SHARED, 0, 0); +} + static void unload_bpf_testmod(void) { + if (kern_sync_rcu()) + fprintf(env.stderr, "Failed to trigger kernel-side RCU sync!\n"); if (delete_module("bpf_testmod", 0)) { if (errno == ENOENT) { if (env.verbosity > VERBOSE_NONE) |