mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 06:44:00 -04:00
selftests/bpf: Fix flakiness of task_local_storage/sys_enter_exit
The test_sys_enter_exit test was setting target_pid before attaching the BPF programs, which causes syscalls made during the attach phase to be counted. This is flaky because, apparently, there is no guarantee that both on_enter and on_exit will trigger during the attachment. Move the target_pid assignment to after task_local_storage__attach() so that only explicit sys_gettid() calls are counted. Reported-by: BPF CI Bot (Claude Opus 4.6) <bot+bpf-ci@kernel.org> Closes: https://github.com/kernel-patches/vmtest/issues/448 Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev> Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com> Link: https://lore.kernel.org/r/20260224211202.214325-1-ihor.solodrai@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
committed by
Alexei Starovoitov
parent
e4094d56c5
commit
c89b50cc6b
@@ -25,24 +25,30 @@
|
||||
static void test_sys_enter_exit(void)
|
||||
{
|
||||
struct task_local_storage *skel;
|
||||
pid_t pid = sys_gettid();
|
||||
int err;
|
||||
|
||||
skel = task_local_storage__open_and_load();
|
||||
if (!ASSERT_OK_PTR(skel, "skel_open_and_load"))
|
||||
return;
|
||||
|
||||
skel->bss->target_pid = sys_gettid();
|
||||
|
||||
err = task_local_storage__attach(skel);
|
||||
if (!ASSERT_OK(err, "skel_attach"))
|
||||
goto out;
|
||||
|
||||
/* Set target_pid after attach so that syscalls made during
|
||||
* attach are not counted.
|
||||
*/
|
||||
skel->bss->target_pid = pid;
|
||||
|
||||
sys_gettid();
|
||||
sys_gettid();
|
||||
|
||||
/* 3x syscalls: 1x attach and 2x gettid */
|
||||
ASSERT_EQ(skel->bss->enter_cnt, 3, "enter_cnt");
|
||||
ASSERT_EQ(skel->bss->exit_cnt, 3, "exit_cnt");
|
||||
skel->bss->target_pid = 0;
|
||||
|
||||
/* 2x gettid syscalls */
|
||||
ASSERT_EQ(skel->bss->enter_cnt, 2, "enter_cnt");
|
||||
ASSERT_EQ(skel->bss->exit_cnt, 2, "exit_cnt");
|
||||
ASSERT_EQ(skel->bss->mismatch_cnt, 0, "mismatch_cnt");
|
||||
out:
|
||||
task_local_storage__destroy(skel);
|
||||
|
||||
Reference in New Issue
Block a user