在 2025/7/21 22:24, Will Deacon 写道:
On Fri, Jul 18, 2025 at 03:10:32PM -0600, Shuah Khan wrote:
Can you take a look at this and let me know if this change looks good to you both.
I can take this through my tree after your reviews.
I never got to the point of fully understanding how the test was supposed to work, but it is true that arm64 requires a 16-byte aligned stack pointer and this patch appears to achieve that.
Will
Hi, Will,
In case you missed I reply in last version. I just paste the original reply, I hope it can help you understand the root cause.
From man page of clone():
The stack argument specifies the location of the stack used by the child process. Since the child and calling process may share memory, it is not possible for the child process to execute in the same stack as the calling process. *The calling process must therefore set up memory space for the child stack and pass a pointer to this space to clone()*. Stacks grow downward on all processors that run Linux (except the HP PA processors), so stack usually points to the topmost address of the memory space set up for the child stack. Note that clone() does not provide a means whereby the caller can inform the kernel of the size of the stack area.
The glibc will do the sanity check:
/* int clone(int (*fn)(void *arg), x0 void *child_stack, x1 int flags, x2 void *arg, x3 pid_t *ptid, x4 struct user_desc *tls, x5 pid_t *ctid); x6 */ .text ENTRY(__clone) PTR_ARG (0) PTR_ARG (1) PTR_ARG (3) PTR_ARG (4) PTR_ARG (5) PTR_ARG (6) /* Save args for the child. */ mov x10, x0 mov x11, x2 mov x12, x3
/* Sanity check args. */ mov x0, #-EINVAL cbz x10, .Lsyscall_error /* Align sp. */ and x1, x1, -16 cbz x1, .Lsyscall_error // this line
When the stack pointer is set to NULL, the aligned stack pointer remains zero, leading __clone to perform a syscall error, returning -EINVAL due to an invalid argument.
In summary, Whether or not CLONE_VM is used, an address-aligned child stack needs to be allocated.
Thanks. Shuai