diff options
author | Andrii Nakryiko <andrii@kernel.org> | 2021-10-08 13:22:57 -0700 |
---|---|---|
committer | Andrii Nakryiko <andrii@kernel.org> | 2021-10-08 13:22:58 -0700 |
commit | a1852ce0e54251c977e92ca55476ef37bd08fb0e (patch) | |
tree | e2abd0f4d04594fc4204db299cb5b74be0d222f8 /tools/testing/selftests/bpf/prog_tests/module_attach.c | |
parent | 1c8dab7da1d27a474721a789777af82edf2085c1 (diff) | |
parent | fa7f17d066bd0996b930b664aa0ed1f213fc1828 (diff) |
Merge branch 'add support for writable bare tracepoint'
Hou Tao says:
====================
From: Hou Tao <houtao1@huawei.com>
Hi,
The patchset series supports writable context for bare tracepoint.
The main idea comes from patchset "writable contexts for bpf raw
tracepoints" [1], but it only supports normal tracepoint with
associated trace event under tracefs. Now we have one use case
in which we add bare tracepoint in VFS layer, and update
file::f_mode for specific files. The reason using bare tracepoint
is that it doesn't form a ABI and we can change it freely. So
add support for it in BPF.
Comments are always welcome.
[1]: https://lore.kernel.org/lkml/20190426184951.21812-1-mmullins@fb.com
Change log:
v5:
* rebased on bpf-next
* patch 1: add Acked-by tag
* patch 2: handle invalid section name, make prefixes array being const
v4: https://www.spinics.net/lists/bpf/msg47021.html
* rebased on bpf-next
* update patch 2 to add support for writable raw tracepoint attachment
in attach_raw_tp().
* update patch 3 to add Acked-by tag
v3: https://www.spinics.net/lists/bpf/msg46824.html
* use raw_tp.w instead of raw_tp_writable as section
name of writable tp
* use ASSERT_XXX() instead of CHECK()
* define a common macro for "/sys/kernel/bpf_testmod"
v2: https://www.spinics.net/lists/bpf/msg46356.html
* rebase on bpf-next tree
* address comments from Yonghong Song
* rename bpf_testmode_test_writable_ctx::ret as early_ret to reflect
its purpose better.
v1: https://www.spinics.net/lists/bpf/msg46221.html
====================
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Diffstat (limited to 'tools/testing/selftests/bpf/prog_tests/module_attach.c')
-rw-r--r-- | tools/testing/selftests/bpf/prog_tests/module_attach.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/module_attach.c b/tools/testing/selftests/bpf/prog_tests/module_attach.c index 1797a6e4d6d8..6d0e50dcf47c 100644 --- a/tools/testing/selftests/bpf/prog_tests/module_attach.c +++ b/tools/testing/selftests/bpf/prog_tests/module_attach.c @@ -2,10 +2,36 @@ /* Copyright (c) 2020 Facebook */ #include <test_progs.h> +#include <stdbool.h> #include "test_module_attach.skel.h" static int duration; +static int trigger_module_test_writable(int *val) +{ + int fd, err; + char buf[65]; + ssize_t rd; + + fd = open(BPF_TESTMOD_TEST_FILE, O_RDONLY); + err = -errno; + if (!ASSERT_GE(fd, 0, "testmode_file_open")) + return err; + + rd = read(fd, buf, sizeof(buf) - 1); + err = -errno; + if (!ASSERT_GT(rd, 0, "testmod_file_rd_val")) { + close(fd); + return err; + } + + buf[rd] = '\0'; + *val = strtol(buf, NULL, 0); + close(fd); + + return 0; +} + static int delete_module(const char *name, int flags) { return syscall(__NR_delete_module, name, flags); @@ -19,6 +45,7 @@ void test_module_attach(void) struct test_module_attach__bss *bss; struct bpf_link *link; int err; + int writable_val = 0; skel = test_module_attach__open(); if (CHECK(!skel, "skel_open", "failed to open skeleton\n")) @@ -51,6 +78,14 @@ void test_module_attach(void) ASSERT_EQ(bss->fexit_ret, -EIO, "fexit_tet"); ASSERT_EQ(bss->fmod_ret_read_sz, READ_SZ, "fmod_ret"); + bss->raw_tp_writable_bare_early_ret = true; + bss->raw_tp_writable_bare_out_val = 0xf1f2f3f4; + ASSERT_OK(trigger_module_test_writable(&writable_val), + "trigger_writable"); + ASSERT_EQ(bss->raw_tp_writable_bare_in_val, 1024, "writable_test_in"); + ASSERT_EQ(bss->raw_tp_writable_bare_out_val, writable_val, + "writable_test_out"); + test_module_attach__detach(skel); /* attach fentry/fexit and make sure it get's module reference */ |