Skip to content

Commit e1ef78d

Browse files
puranjaymohanborkmann
authored andcommitted
selftests/bpf: fexit_sleep: Fix stack allocation for arm64
On ARM64 the stack pointer should be aligned at a 16 byte boundary or the SPAlignmentFault can occur. The fexit_sleep selftest allocates the stack for the child process as a character array, this is not guaranteed to be aligned at 16 bytes. Because of the SPAlignmentFault, the child process is killed before it can do the nanosleep call and hence fentry_cnt remains as 0. This causes the main thread to hang on the following line: while (READ_ONCE(fexit_skel->bss->fentry_cnt) != 2); Fix this by allocating the stack using mmap() as described in the example in the man page of clone(). Remove the fexit_sleep test from the DENYLIST of arm64. Fixes: eddbe8e ("selftest/bpf: Add a test to check trampoline freeing logic.") Signed-off-by: Puranjay Mohan <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 0e03c64 commit e1ef78d

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

tools/testing/selftests/bpf/DENYLIST.aarch64

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
bpf_cookie/multi_kprobe_attach_api # kprobe_multi_link_api_subtest:FAIL:fentry_raw_skel_load unexpected error: -3
22
bpf_cookie/multi_kprobe_link_api # kprobe_multi_link_api_subtest:FAIL:fentry_raw_skel_load unexpected error: -3
3-
fexit_sleep # The test never returns. The remaining tests cannot start.
43
kprobe_multi_bench_attach # needs CONFIG_FPROBE
54
kprobe_multi_test # needs CONFIG_FPROBE
65
module_attach # prog 'kprobe_multi': failed to auto-attach: -95

tools/testing/selftests/bpf/prog_tests/fexit_sleep.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ static int do_sleep(void *skel)
2121
}
2222

2323
#define STACK_SIZE (1024 * 1024)
24-
static char child_stack[STACK_SIZE];
2524

2625
void test_fexit_sleep(void)
2726
{
2827
struct fexit_sleep_lskel *fexit_skel = NULL;
2928
int wstatus, duration = 0;
3029
pid_t cpid;
30+
char *child_stack = NULL;
3131
int err, fexit_cnt;
3232

3333
fexit_skel = fexit_sleep_lskel__open_and_load();
@@ -38,6 +38,11 @@ void test_fexit_sleep(void)
3838
if (CHECK(err, "fexit_attach", "fexit attach failed: %d\n", err))
3939
goto cleanup;
4040

41+
child_stack = mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE |
42+
MAP_ANONYMOUS | MAP_STACK, -1, 0);
43+
if (!ASSERT_NEQ(child_stack, MAP_FAILED, "mmap"))
44+
goto cleanup;
45+
4146
cpid = clone(do_sleep, child_stack + STACK_SIZE, CLONE_FILES | SIGCHLD, fexit_skel);
4247
if (CHECK(cpid == -1, "clone", "%s\n", strerror(errno)))
4348
goto cleanup;
@@ -78,5 +83,6 @@ void test_fexit_sleep(void)
7883
goto cleanup;
7984

8085
cleanup:
86+
munmap(child_stack, STACK_SIZE);
8187
fexit_sleep_lskel__destroy(fexit_skel);
8288
}

0 commit comments

Comments
 (0)