* [PATCH] mips: align stack in clone [BZ #28223]
@ 2021-08-12 16:58 Xi Ruoyao
2021-08-12 17:20 ` Joseph Myers
0 siblings, 1 reply; 7+ messages in thread
From: Xi Ruoyao @ 2021-08-12 16:58 UTC (permalink / raw)
To: libc-alpha
The MIPS O32 ABI requires 4 byte aligned stack, and the MIPS N64 and N32
ABI require 8 byte aligned stack. Previously if the caller passed an
unaligned stack to clone the the child misbehaved.
Fixes bug 28223.
---
sysdeps/unix/sysv/linux/mips/clone.S | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/sysdeps/unix/sysv/linux/mips/clone.S b/sysdeps/unix/sysv/linux/mips/clone.S
index 71d9dba8bd..9e5826aeba 100644
--- a/sysdeps/unix/sysv/linux/mips/clone.S
+++ b/sysdeps/unix/sysv/linux/mips/clone.S
@@ -55,6 +55,13 @@ NESTED(__clone,4*SZREG,sp)
.set at
#endif
+ /* Align stack to 4/8 bytes per the ABI */
+#if _MIPS_SIM == _ABIO32
+ li t0,-4
+#else
+ li t0,-8
+#endif
+ and a1,a1,t0
/* Sanity check arguments. */
li v0,EINVAL
--
2.32.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mips: align stack in clone [BZ #28223]
2021-08-12 16:58 [PATCH] mips: align stack in clone [BZ #28223] Xi Ruoyao
@ 2021-08-12 17:20 ` Joseph Myers
2021-08-12 17:27 ` Xi Ruoyao
0 siblings, 1 reply; 7+ messages in thread
From: Joseph Myers @ 2021-08-12 17:20 UTC (permalink / raw)
To: Xi Ruoyao; +Cc: libc-alpha
On Fri, 13 Aug 2021, Xi Ruoyao via Libc-alpha wrote:
> The MIPS O32 ABI requires 4 byte aligned stack, and the MIPS N64 and N32
> ABI require 8 byte aligned stack. Previously if the caller passed an
> unaligned stack to clone the the child misbehaved.
>
> Fixes bug 28223.
This patch is OK.
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mips: align stack in clone [BZ #28223]
2021-08-12 17:20 ` Joseph Myers
@ 2021-08-12 17:27 ` Xi Ruoyao
2021-08-12 20:32 ` Joseph Myers
0 siblings, 1 reply; 7+ messages in thread
From: Xi Ruoyao @ 2021-08-12 17:27 UTC (permalink / raw)
To: Joseph Myers; +Cc: libc-alpha
On Thu, 2021-08-12 at 17:20 +0000, Joseph Myers wrote:
> On Fri, 13 Aug 2021, Xi Ruoyao via Libc-alpha wrote:
>
> > The MIPS O32 ABI requires 4 byte aligned stack, and the MIPS N64 and
> > N32
> > ABI require 8 byte aligned stack. Previously if the caller passed
> > an
> > unaligned stack to clone the the child misbehaved.
> >
> > Fixes bug 28223.
>
> This patch is OK.
>
I don't have git write access, waiting for a maintainer to push it.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mips: align stack in clone [BZ #28223]
2021-08-12 17:27 ` Xi Ruoyao
@ 2021-08-12 20:32 ` Joseph Myers
2021-08-13 10:43 ` [PATCH] mips: increase stack alignment in clone to match the ABI Xi Ruoyao
0 siblings, 1 reply; 7+ messages in thread
From: Joseph Myers @ 2021-08-12 20:32 UTC (permalink / raw)
To: Xi Ruoyao; +Cc: libc-alpha
On Fri, 13 Aug 2021, Xi Ruoyao via Libc-alpha wrote:
> On Thu, 2021-08-12 at 17:20 +0000, Joseph Myers wrote:
> > On Fri, 13 Aug 2021, Xi Ruoyao via Libc-alpha wrote:
> >
> > > The MIPS O32 ABI requires 4 byte aligned stack, and the MIPS N64 and
> > > N32
> > > ABI require 8 byte aligned stack. Previously if the caller passed
> > > an
> > > unaligned stack to clone the the child misbehaved.
> > >
> > > Fixes bug 28223.
> >
> > This patch is OK.
>
> I don't have git write access, waiting for a maintainer to push it.
Now pushed.
--
Joseph S. Myers
joseph@codesourcery.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] mips: increase stack alignment in clone to match the ABI
2021-08-12 20:32 ` Joseph Myers
@ 2021-08-13 10:43 ` Xi Ruoyao
2021-08-13 12:04 ` [PATCH v2] " Xi Ruoyao
0 siblings, 1 reply; 7+ messages in thread
From: Xi Ruoyao @ 2021-08-13 10:43 UTC (permalink / raw)
To: Joseph Myers; +Cc: libc-alpha
Hi Joseph,
Sorry for this, but I have to admit I've made an error in the previous
patch. In MIPS documentations one "word" is defined 32-bit (4-byte), so
a "doubleword" is 8-byte and a "quadword" is 16-byte. I misinterpreted
"doubleword" as a "dword" we normally uses for 4-byte, so the alignment
is actually insufficient.
I'm not sure why "tst-misaligned-stack" passed with the previous
problematic patch on my board. Maybe it was pure luck, or my CPU used
to test the patch supports some non-standard unaligned access.
The following patch should fix this:
In "mips: align stack in clone [BZ #28223]"
(commit 1f51cd9a860ee45eee8a56fb2ba925267a2a7bfe) I made a mistake: I
misbelieved one "word" was 2-byte and "doubleword" should be 4-byte.
But in MIPS ABI one "word" is defined 32-bit (4-byte), so "doubleword" is
8-byte [1], and "quadword" is 16-byte [2].
[1]: "System V Application Binary Interface: MIPS(R) RISC Processor
Supplement, 3rd edition", page 3-31
[2]: "MIPSpro(TM) 64-Bit Porting and Transition Guide", page 23
---
sysdeps/unix/sysv/linux/mips/clone.S | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sysdeps/unix/sysv/linux/mips/clone.S b/sysdeps/unix/sysv/linux/mips/clone.S
index 43a5ad3a40..81d814ba4d 100644
--- a/sysdeps/unix/sysv/linux/mips/clone.S
+++ b/sysdeps/unix/sysv/linux/mips/clone.S
@@ -57,9 +57,9 @@ NESTED(__clone,4*SZREG,sp)
/* Align stack to 4/8 bytes per the ABI. */
#if _MIPS_SIM == _ABIO32
- li t0,-4
-#else
li t0,-8
+#else
+ li t0,-16
#endif
and a1,a1,t0
--
2.32.0
Sorry again for the error.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2] mips: increase stack alignment in clone to match the ABI
2021-08-13 10:43 ` [PATCH] mips: increase stack alignment in clone to match the ABI Xi Ruoyao
@ 2021-08-13 12:04 ` Xi Ruoyao
2021-08-13 16:02 ` Joseph Myers
0 siblings, 1 reply; 7+ messages in thread
From: Xi Ruoyao @ 2021-08-13 12:04 UTC (permalink / raw)
To: Joseph Myers; +Cc: libc-alpha
v2: change the comment along with the code
I must have been too sleepy in recent two days...
--
In "mips: align stack in clone [BZ #28223]"
(commit 1f51cd9a860ee45eee8a56fb2ba925267a2a7bfe) I made a mistake: I
misbelieved one "word" was 2-byte and "doubleword" should be 4-byte.
But in MIPS ABI one "word" is defined 32-bit (4-byte), so "doubleword" is
8-byte [1], and "quadword" is 16-byte [2].
[1]: "System V Application Binary Interface: MIPS(R) RISC Processor
Supplement, 3rd edition", page 3-31
[2]: "MIPSpro(TM) 64-Bit Porting and Transition Guide", page 23
---
sysdeps/unix/sysv/linux/mips/clone.S | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/sysdeps/unix/sysv/linux/mips/clone.S b/sysdeps/unix/sysv/linux/mips/clone.S
index 43a5ad3a40..fd71b5ca2e 100644
--- a/sysdeps/unix/sysv/linux/mips/clone.S
+++ b/sysdeps/unix/sysv/linux/mips/clone.S
@@ -55,11 +55,11 @@ NESTED(__clone,4*SZREG,sp)
.set at
#endif
- /* Align stack to 4/8 bytes per the ABI. */
+ /* Align stack to 8/16 bytes per the ABI. */
#if _MIPS_SIM == _ABIO32
- li t0,-4
-#else
li t0,-8
+#else
+ li t0,-16
#endif
and a1,a1,t0
--
2.32.0
On Fri, 2021-08-13 at 18:43 +0800, Xi Ruoyao wrote:
> Hi Joseph,
>
> Sorry for this, but I have to admit I've made an error in the previous
> patch. In MIPS documentations one "word" is defined 32-bit (4-byte), so
> a "doubleword" is 8-byte and a "quadword" is 16-byte. I misinterpreted
> "doubleword" as a "dword" we normally uses for 4-byte, so the alignment
> is actually insufficient.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-08-13 16:02 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-12 16:58 [PATCH] mips: align stack in clone [BZ #28223] Xi Ruoyao
2021-08-12 17:20 ` Joseph Myers
2021-08-12 17:27 ` Xi Ruoyao
2021-08-12 20:32 ` Joseph Myers
2021-08-13 10:43 ` [PATCH] mips: increase stack alignment in clone to match the ABI Xi Ruoyao
2021-08-13 12:04 ` [PATCH v2] " Xi Ruoyao
2021-08-13 16:02 ` Joseph Myers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).