From: Shuai Xue <xueshuai@linux.alibaba.com>
To: Will Deacon <will@kernel.org>, Shuah Khan <skhan@linuxfoundation.org>
Cc: brauner@kernel.org, shuah@kernel.org,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
baolin.wang@linux.alibaba.com, tianruidong@linux.alibaba.com,
catalin.marinas@arm.com, mark.rutland@arm.com
Subject: Re: [RESEND PATCH] selftests/pidfd: align stack to fix SP alignment exception
Date: Tue, 22 Jul 2025 09:37:08 +0800 [thread overview]
Message-ID: <87ed033c-f2b1-4858-8438-f9935c4f12cf@linux.alibaba.com> (raw)
In-Reply-To: <aH5NiFDmnLwh7J_w@willie-the-truck>
在 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
prev parent reply other threads:[~2025-07-22 1:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-16 5:06 Shuai Xue
2025-06-18 21:36 ` Shuah Khan
2025-06-19 2:26 ` Shuai Xue
2025-07-16 7:00 ` Shuai Xue
2025-07-18 21:10 ` Shuah Khan
2025-07-21 14:24 ` Will Deacon
2025-07-22 1:37 ` Shuai Xue [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ed033c-f2b1-4858-8438-f9935c4f12cf@linux.alibaba.com \
--to=xueshuai@linux.alibaba.com \
--cc=baolin.wang@linux.alibaba.com \
--cc=brauner@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=shuah@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=tianruidong@linux.alibaba.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®