-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'bpf: Fixes for kprobe multi on kernel modules'
Jiri Olsa says: ==================== hi, Martynas reported kprobe _multi link does not resolve symbols from kernel modules, which attach by address works. In addition while fixing that I realized we do not take module reference if the module has kprobe_multi link on top of it and can be removed. There's mo crash related to this, it will silently disappear from ftrace tables, while kprobe_multi link stays up with no data. This patchset has fixes for both issues. v3 changes: - reorder fields in struct bpf_kprobe_multi_link [Andrii] - added ack [Andrii] v2 changes: - added acks (Song) - added comment to kallsyms_callback (Song) - change module_callback realloc logic (Andrii) - get rid of macros in tests (Andrii) thanks, jirka ==================== Signed-off-by: Alexei Starovoitov <ast@kernel.org>
- Loading branch information
Showing
11 changed files
with
306 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
tools/testing/selftests/bpf/prog_tests/kprobe_multi_testmod_test.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
#include <test_progs.h> | ||
#include "kprobe_multi.skel.h" | ||
#include "trace_helpers.h" | ||
#include "bpf/libbpf_internal.h" | ||
|
||
static void kprobe_multi_testmod_check(struct kprobe_multi *skel) | ||
{ | ||
ASSERT_EQ(skel->bss->kprobe_testmod_test1_result, 1, "kprobe_test1_result"); | ||
ASSERT_EQ(skel->bss->kprobe_testmod_test2_result, 1, "kprobe_test2_result"); | ||
ASSERT_EQ(skel->bss->kprobe_testmod_test3_result, 1, "kprobe_test3_result"); | ||
|
||
ASSERT_EQ(skel->bss->kretprobe_testmod_test1_result, 1, "kretprobe_test1_result"); | ||
ASSERT_EQ(skel->bss->kretprobe_testmod_test2_result, 1, "kretprobe_test2_result"); | ||
ASSERT_EQ(skel->bss->kretprobe_testmod_test3_result, 1, "kretprobe_test3_result"); | ||
} | ||
|
||
static void test_testmod_attach_api(struct bpf_kprobe_multi_opts *opts) | ||
{ | ||
struct kprobe_multi *skel = NULL; | ||
|
||
skel = kprobe_multi__open_and_load(); | ||
if (!ASSERT_OK_PTR(skel, "fentry_raw_skel_load")) | ||
return; | ||
|
||
skel->bss->pid = getpid(); | ||
|
||
skel->links.test_kprobe_testmod = bpf_program__attach_kprobe_multi_opts( | ||
skel->progs.test_kprobe_testmod, | ||
NULL, opts); | ||
if (!skel->links.test_kprobe_testmod) | ||
goto cleanup; | ||
|
||
opts->retprobe = true; | ||
skel->links.test_kretprobe_testmod = bpf_program__attach_kprobe_multi_opts( | ||
skel->progs.test_kretprobe_testmod, | ||
NULL, opts); | ||
if (!skel->links.test_kretprobe_testmod) | ||
goto cleanup; | ||
|
||
ASSERT_OK(trigger_module_test_read(1), "trigger_read"); | ||
kprobe_multi_testmod_check(skel); | ||
|
||
cleanup: | ||
kprobe_multi__destroy(skel); | ||
} | ||
|
||
static void test_testmod_attach_api_addrs(void) | ||
{ | ||
LIBBPF_OPTS(bpf_kprobe_multi_opts, opts); | ||
unsigned long long addrs[3]; | ||
|
||
addrs[0] = ksym_get_addr("bpf_testmod_fentry_test1"); | ||
ASSERT_NEQ(addrs[0], 0, "ksym_get_addr"); | ||
addrs[1] = ksym_get_addr("bpf_testmod_fentry_test2"); | ||
ASSERT_NEQ(addrs[1], 0, "ksym_get_addr"); | ||
addrs[2] = ksym_get_addr("bpf_testmod_fentry_test3"); | ||
ASSERT_NEQ(addrs[2], 0, "ksym_get_addr"); | ||
|
||
opts.addrs = (const unsigned long *) addrs; | ||
opts.cnt = ARRAY_SIZE(addrs); | ||
|
||
test_testmod_attach_api(&opts); | ||
} | ||
|
||
static void test_testmod_attach_api_syms(void) | ||
{ | ||
LIBBPF_OPTS(bpf_kprobe_multi_opts, opts); | ||
const char *syms[3] = { | ||
"bpf_testmod_fentry_test1", | ||
"bpf_testmod_fentry_test2", | ||
"bpf_testmod_fentry_test3", | ||
}; | ||
|
||
opts.syms = syms; | ||
opts.cnt = ARRAY_SIZE(syms); | ||
test_testmod_attach_api(&opts); | ||
} | ||
|
||
void serial_test_kprobe_multi_testmod_test(void) | ||
{ | ||
if (!ASSERT_OK(load_kallsyms_refresh(), "load_kallsyms_refresh")) | ||
return; | ||
|
||
if (test__start_subtest("testmod_attach_api_syms")) | ||
test_testmod_attach_api_syms(); | ||
if (test__start_subtest("testmod_attach_api_addrs")) | ||
test_testmod_attach_api_addrs(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.