mirror of
https://github.com/torvalds/linux.git
synced 2026-06-04 12:35:52 +02:00
selftests/bpf: Add uprobe session cookie test
Adding uprobe session test that verifies the cookie value get properly propagated from entry to return program. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20241108134544.480660-8-jolsa@kernel.org
This commit is contained in:
parent
4856ecb115
commit
f6b45e352f
|
|
@ -9,6 +9,7 @@
|
|||
#include "uprobe_multi_consumers.skel.h"
|
||||
#include "uprobe_multi_pid_filter.skel.h"
|
||||
#include "uprobe_multi_session.skel.h"
|
||||
#include "uprobe_multi_session_cookie.skel.h"
|
||||
#include "bpf/libbpf_internal.h"
|
||||
#include "testing_helpers.h"
|
||||
#include "../sdt.h"
|
||||
|
|
@ -1062,6 +1063,34 @@ static void test_session_skel_api(void)
|
|||
uprobe_multi_session__destroy(skel);
|
||||
}
|
||||
|
||||
static void test_session_cookie_skel_api(void)
|
||||
{
|
||||
struct uprobe_multi_session_cookie *skel = NULL;
|
||||
int err;
|
||||
|
||||
skel = uprobe_multi_session_cookie__open_and_load();
|
||||
if (!ASSERT_OK_PTR(skel, "uprobe_multi_session_cookie__open_and_load"))
|
||||
goto cleanup;
|
||||
|
||||
skel->bss->pid = getpid();
|
||||
|
||||
err = uprobe_multi_session_cookie__attach(skel);
|
||||
if (!ASSERT_OK(err, "uprobe_multi_session_cookie__attach"))
|
||||
goto cleanup;
|
||||
|
||||
/* trigger all probes */
|
||||
uprobe_multi_func_1();
|
||||
uprobe_multi_func_2();
|
||||
uprobe_multi_func_3();
|
||||
|
||||
ASSERT_EQ(skel->bss->test_uprobe_1_result, 1, "test_uprobe_1_result");
|
||||
ASSERT_EQ(skel->bss->test_uprobe_2_result, 2, "test_uprobe_2_result");
|
||||
ASSERT_EQ(skel->bss->test_uprobe_3_result, 3, "test_uprobe_3_result");
|
||||
|
||||
cleanup:
|
||||
uprobe_multi_session_cookie__destroy(skel);
|
||||
}
|
||||
|
||||
static void test_bench_attach_uprobe(void)
|
||||
{
|
||||
long attach_start_ns = 0, attach_end_ns = 0;
|
||||
|
|
@ -1160,4 +1189,6 @@ void test_uprobe_multi_test(void)
|
|||
test_pid_filter_process(true);
|
||||
if (test__start_subtest("session"))
|
||||
test_session_skel_api();
|
||||
if (test__start_subtest("session_cookie"))
|
||||
test_session_cookie_skel_api();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
// 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"
|
||||
|
||||
char _license[] SEC("license") = "GPL";
|
||||
|
||||
int pid = 0;
|
||||
|
||||
__u64 test_uprobe_1_result = 0;
|
||||
__u64 test_uprobe_2_result = 0;
|
||||
__u64 test_uprobe_3_result = 0;
|
||||
|
||||
static int check_cookie(__u64 val, __u64 *result)
|
||||
{
|
||||
__u64 *cookie;
|
||||
|
||||
if (bpf_get_current_pid_tgid() >> 32 != pid)
|
||||
return 1;
|
||||
|
||||
cookie = bpf_session_cookie();
|
||||
|
||||
if (bpf_session_is_return())
|
||||
*result = *cookie == val ? val : 0;
|
||||
else
|
||||
*cookie = val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
SEC("uprobe.session//proc/self/exe:uprobe_multi_func_1")
|
||||
int uprobe_1(struct pt_regs *ctx)
|
||||
{
|
||||
return check_cookie(1, &test_uprobe_1_result);
|
||||
}
|
||||
|
||||
SEC("uprobe.session//proc/self/exe:uprobe_multi_func_2")
|
||||
int uprobe_2(struct pt_regs *ctx)
|
||||
{
|
||||
return check_cookie(2, &test_uprobe_2_result);
|
||||
}
|
||||
|
||||
SEC("uprobe.session//proc/self/exe:uprobe_multi_func_3")
|
||||
int uprobe_3(struct pt_regs *ctx)
|
||||
{
|
||||
return check_cookie(3, &test_uprobe_3_result);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user