Skip to content

Commit

Permalink
cgroup_core02: Allocate child stack using mmap()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
mdoucha authored and pevik committed Jan 20, 2025
1 parent 02d5e99 commit a8213a6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions testcases/kernel/controllers/cgroup/cgroup_core02.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "tst_safe_file_at.h"
#include "lapi/sched.h"

#define STACK_SIZE 65536

static struct tst_cg_group *cg_child_a, *cg_child_b;
static uid_t nobody_uid;

Expand All @@ -51,7 +53,7 @@ static int lesser_ns_open_thread_fn(void *arg)
static void test_lesser_ns_open(void)
{
int i;
static char stack[65536];
char *stack;
pid_t pid;
int status;
struct lesser_ns_open_thread_arg targ = { .fds = {0}, .loops = -1};
Expand All @@ -63,14 +65,19 @@ static void test_lesser_ns_open(void)
SAFE_CG_PRINT(cg_child_a, "cgroup.procs", "0");
SAFE_CG_FCHOWN(cg_child_a, "cgroup.procs", nobody_uid, -1);
SAFE_CG_FCHOWN(cg_child_b, "cgroup.procs", nobody_uid, -1);
stack = SAFE_MMAP(NULL, STACK_SIZE, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, -1, 0);
pid = ltp_clone(CLONE_NEWCGROUP | CLONE_FILES | CLONE_VM | SIGCHLD,
lesser_ns_open_thread_fn, &targ, 65536, stack);
lesser_ns_open_thread_fn, &targ, STACK_SIZE, stack);

if (pid < 0) {
tst_res(TFAIL, "unexpected negative pid %d", pid);
exit(1);
}

SAFE_WAITPID(pid, &status, 0);
SAFE_MUNMAP(stack, STACK_SIZE);

for (i = 0; i < targ.loops; i++) {
if (targ.fds[i] < 1) {
tst_res(TFAIL, "unexpected negative fd %d", targ.fds[i]);
Expand Down

0 comments on commit a8213a6

Please sign in to comment.