Skip to content

Commit a8213a6

Browse files
mdouchapevik
authored andcommitted
cgroup_core02: Allocate child stack using mmap()
Some architectures like arm64 have strict requirements for stack alignment. Statically allocated buffer may result in one of the test processes getting killed by SIGBUS. Allocate child stack using mmap() to ensure the requirements are met. Link: https://lore.kernel.org/ltp/[email protected]/ Acked-by: Petr Vorel <[email protected]> Reviewed-by: Cyril Hrubis <[email protected]> Signed-off-by: Martin Doucha <[email protected]>
1 parent 02d5e99 commit a8213a6

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

testcases/kernel/controllers/cgroup/cgroup_core02.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "tst_safe_file_at.h"
3333
#include "lapi/sched.h"
3434

35+
#define STACK_SIZE 65536
36+
3537
static struct tst_cg_group *cg_child_a, *cg_child_b;
3638
static uid_t nobody_uid;
3739

@@ -51,7 +53,7 @@ static int lesser_ns_open_thread_fn(void *arg)
5153
static void test_lesser_ns_open(void)
5254
{
5355
int i;
54-
static char stack[65536];
56+
char *stack;
5557
pid_t pid;
5658
int status;
5759
struct lesser_ns_open_thread_arg targ = { .fds = {0}, .loops = -1};
@@ -63,14 +65,19 @@ static void test_lesser_ns_open(void)
6365
SAFE_CG_PRINT(cg_child_a, "cgroup.procs", "0");
6466
SAFE_CG_FCHOWN(cg_child_a, "cgroup.procs", nobody_uid, -1);
6567
SAFE_CG_FCHOWN(cg_child_b, "cgroup.procs", nobody_uid, -1);
68+
stack = SAFE_MMAP(NULL, STACK_SIZE, PROT_READ | PROT_WRITE,
69+
MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0);
6670
pid = ltp_clone(CLONE_NEWCGROUP | CLONE_FILES | CLONE_VM | SIGCHLD,
67-
lesser_ns_open_thread_fn, &targ, 65536, stack);
71+
lesser_ns_open_thread_fn, &targ, STACK_SIZE, stack);
72+
6873
if (pid < 0) {
6974
tst_res(TFAIL, "unexpected negative pid %d", pid);
7075
exit(1);
7176
}
7277

7378
SAFE_WAITPID(pid, &status, 0);
79+
SAFE_MUNMAP(stack, STACK_SIZE);
80+
7481
for (i = 0; i < targ.loops; i++) {
7582
if (targ.fds[i] < 1) {
7683
tst_res(TFAIL, "unexpected negative fd %d", targ.fds[i]);

0 commit comments

Comments
 (0)