Skip to contentSkip to conversation

src/nsexec: fix stack pointer alignment exception

PATCH Superseded Zorro Lang 3 participants 4 messages Sep 27, 2017 – Sep 29, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Zorro Lang

author
#0 lore raw

PATCH 1/1 src/nsexec: fix stack pointer alignment exception

When test g/317 or g/318 on ARM server, we got a kernel exception:

kernel: nsexec[8203]: SP Alignment exception: pc=00000000004010a0 sp=00000000005200e8

nsexec gives an unaligned child stack address to clone() system call sometimes. For making sure it's always aligned, use "__attribute__((aligned))" extension of GCC (Thanks this suggestion from Eric sandeen).

---
 src/nsexec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
src/nsexec.c +2 -1
index f033b1a4..205dd081 100644
@@ -138,7 +138,8 @@ childFunc(void *arg)
 
 #define STACK_SIZE (1024 * 1024)
 
-static char child_stack[STACK_SIZE];    /* Space for child's stack */
+/* Space for child's stack */
+static char __attribute__((aligned)) child_stack[STACK_SIZE];
 
 int
 main(int argc, char *argv[])
Signature · 1 line
2.13.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 19 lines · Zorro Lang

When test g/317 or g/318 on ARM server, we got a kernel exception:

kernel: nsexec[8203]: SP Alignment exception: pc=00000000004010a0 sp=00000000005200e8

nsexec gives an unaligned child stack address to clone() system call sometimes. For making sure it's always aligned, use "__attribute__((aligned))" extension of GCC (Thanks this suggestion from Eric sandeen).

---
 src/nsexec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
src/nsexec.c +0 -0
index f033b1a4..205dd081 100644

src/nsexec.c childFunc(void *arg) · line 142

Quoted 6 lines
src/nsexec.c +2 -1
@@ -138,7 +138,8 @@ childFunc(void *arg)
 
 #define STACK_SIZE (1024 * 1024)
 
-static char child_stack[STACK_SIZE];    /* Space for child's stack */
+/* Space for child's stack */
+static char __attribute__((aligned)) child_stack[STACK_SIZE];

I don't really think the comment is necessary, other than that:

Quoted 10 lines
src/nsexec.c +0 -0
 int
 main(int argc, char *argv[])
Signature · 6 lines
2.13.5

--
To unsubscribe from this list: send the line "unsubscribe fstests" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 1 line
Carlos
#2 lore raw
In reply to Zorro Lang
Quoted 19 lines · Zorro Lang

When test g/317 or g/318 on ARM server, we got a kernel exception:

kernel: nsexec[8203]: SP Alignment exception: pc=00000000004010a0 sp=00000000005200e8

nsexec gives an unaligned child stack address to clone() system call sometimes. For making sure it's always aligned, use "__attribute__((aligned))" extension of GCC (Thanks this suggestion from Eric sandeen).

---
 src/nsexec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
src/nsexec.c +0 -0
index f033b1a4..205dd081 100644

src/nsexec.c childFunc(void *arg) · line 142

Quoted 6 lines
src/nsexec.c +2 -1
@@ -138,7 +138,8 @@ childFunc(void *arg)
 
 #define STACK_SIZE (1024 * 1024)
 
-static char child_stack[STACK_SIZE];    /* Space for child's stack */
+/* Space for child's stack */
+static char __attribute__((aligned)) child_stack[STACK_SIZE];

Does it matter if the __attribute__ goes before or after
the array name (child_stack[])? I can't quite tell from reading i.e.
https://gcc.gnu.org/onlinedocs/gcc-3.1/gcc/Variable-Attributes.html#Variable%20Attributes
if it does, though most examples I see have the __attribute__ after the variable name, i.e.

src/nsexec.c childFunc(void *arg) · line 143

Quoted 1 line
src/nsexec.c +0 -0
 short array[3] __attribute__ ((aligned));

in the URL above.

-Eric

Quoted 4 lines
src/nsexec.c +0 -0
 int
 main(int argc, char *argv[])
author
#3 lore raw
Quoted 23 lines · Eric Sandeen
Quoted 22 lines · Zorro Lang

When test g/317 or g/318 on ARM server, we got a kernel exception:

kernel: nsexec[8203]: SP Alignment exception: pc=00000000004010a0 sp=00000000005200e8

nsexec gives an unaligned child stack address to clone() system call sometimes. For making sure it's always aligned, use "__attribute__((aligned))" extension of GCC (Thanks this suggestion from Eric sandeen).

---
 src/nsexec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
src/nsexec.c +0 -0
index f033b1a4..205dd081 100644
@@ -138,7 +138,8 @@ childFunc(void *arg)
 
 #define STACK_SIZE (1024 * 1024)
 
Quoted 9 lines

src/nsexec.c childFunc(void *arg) · line 142

Quoted 3 lines
src/nsexec.c +2 -1
-static char child_stack[STACK_SIZE];    /* Space for child's stack */
+/* Space for child's stack */
+static char __attribute__((aligned)) child_stack[STACK_SIZE];

Does it matter if the __attribute__ goes before or after
the array name (child_stack[])? I can't quite tell from reading i.e.
https://gcc.gnu.org/onlinedocs/gcc-3.1/gcc/Variable-Attributes.html#Variable%20Attributes
if it does, though most examples I see have the __attribute__ after the variable name, i.e.

Sorry, I didn't notice this "before/after" problem. Yes, you're right, everyone use "__attribute__" at the end. I'll change that.

BTW, using it in the middle works (compile and run) fine from my side.

Thanks,
Zorro

Quoted 11 lines

src/nsexec.c childFunc(void *arg) · line 143

Quoted 2 lines
src/nsexec.c +0 -0
 short array[3] __attribute__ ((aligned));

in the URL above.

-Eric

Quoted 4 lines
src/nsexec.c +0 -0
 int
 main(int argc, char *argv[])