Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Ihor Solodrai and committed by
Alexei Starovoitov
c89b50cc e4094d56

+11 -5
+11 -5
tools/testing/selftests/bpf/prog_tests/task_local_storage.c
··· 25 25 static void test_sys_enter_exit(void) 26 26 { 27 27 struct task_local_storage *skel; 28 + pid_t pid = sys_gettid(); 28 29 int err; 29 30 30 31 skel = task_local_storage__open_and_load(); 31 32 if (!ASSERT_OK_PTR(skel, "skel_open_and_load")) 32 33 return; 33 34 34 - skel->bss->target_pid = sys_gettid(); 35 - 36 35 err = task_local_storage__attach(skel); 37 36 if (!ASSERT_OK(err, "skel_attach")) 38 37 goto out; 39 38 39 + /* Set target_pid after attach so that syscalls made during 40 + * attach are not counted. 41 + */ 42 + skel->bss->target_pid = pid; 43 + 40 44 sys_gettid(); 41 45 sys_gettid(); 42 46 43 - /* 3x syscalls: 1x attach and 2x gettid */ 44 - ASSERT_EQ(skel->bss->enter_cnt, 3, "enter_cnt"); 45 - ASSERT_EQ(skel->bss->exit_cnt, 3, "exit_cnt"); 47 + skel->bss->target_pid = 0; 48 + 49 + /* 2x gettid syscalls */ 50 + ASSERT_EQ(skel->bss->enter_cnt, 2, "enter_cnt"); 51 + ASSERT_EQ(skel->bss->exit_cnt, 2, "exit_cnt"); 46 52 ASSERT_EQ(skel->bss->mismatch_cnt, 0, "mismatch_cnt"); 47 53 out: 48 54 task_local_storage__destroy(skel);