diff options
author | Andrii Nakryiko <andrii@kernel.org> | 2024-11-08 10:20:46 -0800 |
---|---|---|
committer | Andrii Nakryiko <andrii@kernel.org> | 2024-11-11 08:18:27 -0800 |
commit | 269e7c97cac8e19117518056e9f4bd3a1dfe9362 (patch) | |
tree | 42a01a04c808340b00c882ee1bb3bbf8165cc1a1 /tools/testing/selftests/bpf/progs/uprobe_multi_session_recursive.c | |
parent | dcf04676f347133a0c5944152e8d5110aa28d2dd (diff) | |
parent | abaec8341a86e556dff739d093aa30babc498ec5 (diff) | |
download | linux-269e7c97cac8e19117518056e9f4bd3a1dfe9362.tar.gz linux-269e7c97cac8e19117518056e9f4bd3a1dfe9362.tar.bz2 linux-269e7c97cac8e19117518056e9f4bd3a1dfe9362.zip |
Merge branch 'bpf-add-uprobe-session-support'
Jiri Olsa says:
====================
bpf: Add uprobe session support
hi,
this patchset is adding support for session uprobe attachment and
using it through bpf link for bpf programs.
The session means that the uprobe consumer is executed on entry
and return of probed function with additional control:
- entry callback can control execution of the return callback
- entry and return callbacks can share data/cookie
Uprobe changes (on top of perf/core [1] are posted in here [2].
This patchset is based on bpf-next/master and will be merged once
we pull [2] in bpf-next/master.
v9 changes:
- rebased on bpf-next/master with perf/core tag merged (thanks Peter!)
thanks,
jirka
[1] git://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git perf/core
[2] https://lore.kernel.org/bpf/20241018202252.693462-1-jolsa@kernel.org/T/#ma43c549c4bf684ca1b17fa638aa5e7cbb46893e9
---
====================
Link: https://lore.kernel.org/r/20241108134544.480660-1-jolsa@kernel.org
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Diffstat (limited to 'tools/testing/selftests/bpf/progs/uprobe_multi_session_recursive.c')
-rw-r--r-- | tools/testing/selftests/bpf/progs/uprobe_multi_session_recursive.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/uprobe_multi_session_recursive.c b/tools/testing/selftests/bpf/progs/uprobe_multi_session_recursive.c new file mode 100644 index 000000000000..8fbcd69fae22 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/uprobe_multi_session_recursive.c @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <linux/bpf.h> +#include <bpf/bpf_helpers.h> +#include <bpf/bpf_tracing.h> +#include <stdbool.h> +#include "bpf_kfuncs.h" +#include "bpf_misc.h" + +char _license[] SEC("license") = "GPL"; + +int pid = 0; + +int idx_entry = 0; +int idx_return = 0; + +__u64 test_uprobe_cookie_entry[6]; +__u64 test_uprobe_cookie_return[3]; + +static int check_cookie(void) +{ + __u64 *cookie = bpf_session_cookie(); + + if (bpf_session_is_return()) { + if (idx_return >= ARRAY_SIZE(test_uprobe_cookie_return)) + return 1; + test_uprobe_cookie_return[idx_return++] = *cookie; + return 0; + } + + if (idx_entry >= ARRAY_SIZE(test_uprobe_cookie_entry)) + return 1; + *cookie = test_uprobe_cookie_entry[idx_entry]; + return idx_entry++ % 2; +} + + +SEC("uprobe.session//proc/self/exe:uprobe_session_recursive") +int uprobe_recursive(struct pt_regs *ctx) +{ + if (bpf_get_current_pid_tgid() >> 32 != pid) + return 1; + + return check_cookie(); +} |