From: Oskar Schirmer <[email protected]>
The flat loader uses an architecture's flat_stack_align() to align the
stack but assumes word-alignment is enough for the data sections.
However, on the Xtensa S6000 we need an alignment of more than
wordsize for data that is loaded to 128bit wide registers.
This patch replaces the specific flat_stack_align() with a more
generic flat_data_align() that is then used for both stack, the data
and bss section.
It also fixes m32r which was obviously kaput, aligning an
uninitialized stack entry instead of the stack pointer.
Signed-off-by: Oskar Schirmer <[email protected]>
Cc: David Howells <[email protected]>
Cc: Russell King <[email protected]>
Cc: Bryan Wu <[email protected]>
Cc: Geert Uytterhoeven <[email protected]>
Cc: Paul Mundt <[email protected]>
Signed-off-by: Johannes Weiner <[email protected]>
---
arch/arm/include/asm/flat.h | 4 +---
arch/blackfin/include/asm/flat.h | 2 +-
arch/h8300/include/asm/flat.h | 2 +-
arch/m68k/include/asm/flat.h | 2 +-
arch/sh/include/asm/flat.h | 2 +-
fs/binfmt_flat.c | 28 ++++++++++++++--------------
include/asm-m32r/flat.h | 2 +-
7 files changed, 20 insertions(+), 22 deletions(-)
We tried to verify brain-wise that all the alignments on other archs
are still correct but please note that we have only one xtensa-based
box to test this patch on. It works here with a required data
alignment of 16 bytes.
--- a/fs/binfmt_flat.c
+++ b/fs/binfmt_flat.c
@@ -115,19 +115,17 @@ static unsigned long create_flat_tables(
char uninitialized_var(dummy);
sp = (unsigned long *) ((-(unsigned long)sizeof(char *))&(unsigned long) p);
+ sp -= (envc + argc + 2) + 1 + (flat_argvp_envp_on_stack() ? 2 : 0);
+ sp = (unsigned long *) ((-(unsigned long)flat_data_align())&(unsigned long) sp);
+ argv = sp + 1 + (flat_argvp_envp_on_stack() ? 2 : 0);
+ envp = argv + (argc + 1);
- sp -= envc+1;
- envp = sp;
- sp -= argc+1;
- argv = sp;
-
- flat_stack_align(sp);
if (flat_argvp_envp_on_stack()) {
- --sp; put_user((unsigned long) envp, sp);
- --sp; put_user((unsigned long) argv, sp);
+ put_user((unsigned long) envp, sp + 2);
+ put_user((unsigned long) argv, sp + 1);
}
- put_user(argc,--sp);
+ put_user(argc,sp);
current->mm->arg_start = (unsigned long) p;
while (argc-->0) {
put_user((unsigned long) p, argv++);
@@ -558,7 +556,8 @@ static int load_flat_file(struct linux_b
ret = realdatastart;
goto err;
}
- datapos = realdatastart + MAX_SHARED_LIBS * sizeof(unsigned long);
+ datapos = ALIGN(realdatastart + MAX_SHARED_LIBS * sizeof(unsigned long),
+ flat_data_align());
DBG_FLT("BINFMT_FLAT: Allocated data+bss+stack (%d bytes): %x\n",
(int)(data_len + bss_len + stack_len), (int)datapos);
@@ -604,9 +603,10 @@ static int load_flat_file(struct linux_b
}
realdatastart = textpos + ntohl(hdr->data_start);
- datapos = realdatastart + MAX_SHARED_LIBS * sizeof(unsigned long);
- reloc = (unsigned long *) (textpos + ntohl(hdr->reloc_start) +
- MAX_SHARED_LIBS * sizeof(unsigned long));
+ datapos = ALIGN(realdatastart + MAX_SHARED_LIBS * sizeof(unsigned long),
+ flat_data_align());
+
+ reloc = (unsigned long *) (datapos+(ntohl(hdr->reloc_start)-text_len));
memp = textpos;
memp_size = len;
#ifdef CONFIG_BINFMT_ZFLAT
@@ -854,7 +854,7 @@ static int load_flat_binary(struct linux
stack_len = TOP_OF_ARGS - bprm->p; /* the strings */
stack_len += (bprm->argc + 1) * sizeof(char *); /* the argv array */
stack_len += (bprm->envc + 1) * sizeof(char *); /* the envp array */
-
+ stack_len += flat_data_align();
res = load_flat_file(bprm, &libinfo, 0, &stack_len);
if (res > (unsigned long)-4096)
--- a/arch/arm/include/asm/flat.h
+++ b/arch/arm/include/asm/flat.h
@@ -5,9 +5,7 @@
#ifndef __ARM_FLAT_H__
#define __ARM_FLAT_H__
-/* An odd number of words will be pushed after this alignment, so
- deliberately misalign the value. */
-#define flat_stack_align(sp) sp = (void *)(((unsigned long)(sp) - 4) | 4)
+#define flat_data_align() 8
#define flat_argvp_envp_on_stack() 1
#define flat_old_ram_flag(flags) (flags)
#define flat_reloc_valid(reloc, size) ((reloc) <= (size))
--- a/arch/blackfin/include/asm/flat.h
+++ b/arch/blackfin/include/asm/flat.h
@@ -10,7 +10,7 @@
#include <asm/unaligned.h>
-#define flat_stack_align(sp) /* nothing needed */
+#define flat_data_align() sizeof(void *)
#define flat_argvp_envp_on_stack() 0
#define flat_old_ram_flag(flags) (flags)
--- a/arch/h8300/include/asm/flat.h
+++ b/arch/h8300/include/asm/flat.h
@@ -5,7 +5,7 @@
#ifndef __H8300_FLAT_H__
#define __H8300_FLAT_H__
-#define flat_stack_align(sp) /* nothing needed */
+#define flat_data_align() sizeof(void *)
#define flat_argvp_envp_on_stack() 1
#define flat_old_ram_flag(flags) 1
#define flat_reloc_valid(reloc, size) ((reloc) <= (size))
--- a/arch/m68k/include/asm/flat.h
+++ b/arch/m68k/include/asm/flat.h
@@ -5,7 +5,7 @@
#ifndef __M68KNOMMU_FLAT_H__
#define __M68KNOMMU_FLAT_H__
-#define flat_stack_align(sp) /* nothing needed */
+#define flat_data_align(sp) sizeof(void *)
#define flat_argvp_envp_on_stack() 1
#define flat_old_ram_flag(flags) (flags)
#define flat_reloc_valid(reloc, size) ((reloc) <= (size))
--- a/arch/sh/include/asm/flat.h
+++ b/arch/sh/include/asm/flat.h
@@ -12,7 +12,7 @@
#ifndef __ASM_SH_FLAT_H
#define __ASM_SH_FLAT_H
-#define flat_stack_align(sp) /* nothing needed */
+#define flat_data_align(sp) sizeof(void *)
#define flat_argvp_envp_on_stack() 0
#define flat_old_ram_flag(flags) (flags)
#define flat_reloc_valid(reloc, size) ((reloc) <= (size))
--- a/include/asm-m32r/flat.h
+++ b/include/asm-m32r/flat.h
@@ -12,7 +12,7 @@
#ifndef __ASM_M32R_FLAT_H
#define __ASM_M32R_FLAT_H
-#define flat_stack_align(sp) (*sp += (*sp & 3 ? (4 - (*sp & 3)): 0))
+#define flat_data_align() sizeof(void *)
#define flat_argvp_envp_on_stack() 0
#define flat_old_ram_flag(flags) (flags)
#define flat_set_persistent(relval, p) 0
On Tue, Mar 03, 2009 at 05:33:13PM +0100, Johannes Weiner wrote:
> From: Oskar Schirmer <[email protected]>
>
> The flat loader uses an architecture's flat_stack_align() to align the
> stack but assumes word-alignment is enough for the data sections.
I think you're missing Greg Ungerer. Also, Hyok Choi used to look after
ARM uclinux, but vanished mid-merging with mainline.
I've no idea about the flat binfmt, so I won't be acking this change.
Moreover, I don't know who to pass it to in the ARM community to get an
ack.
--
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of:
On Tue, Mar 03, 2009 at 05:33:13PM +0100, Johannes Weiner wrote:
> The flat loader uses an architecture's flat_stack_align() to align the
> stack but assumes word-alignment is enough for the data sections.
>
> However, on the Xtensa S6000 we need an alignment of more than
> wordsize for data that is loaded to 128bit wide registers.
>
> This patch replaces the specific flat_stack_align() with a more
> generic flat_data_align() that is then used for both stack, the data
> and bss section.
>
> It also fixes m32r which was obviously kaput, aligning an
> uninitialized stack entry instead of the stack pointer.
>
Can you provide a bit more information about this for your platform? I
note that while this patch is aimed to generalize things for your
platform, there is no Xtensa patch included here, making it difficult to
Ack without having more context to go on.
Based on your description, it looks like you need register size alignment
in the case where your registers are greater than BYTES_PER_WORD, or the
pointer size. If this is the case, then you are going to have the same
issues with the slab caches and need to set ARCH_SLAB_MINALIGN
accordingly. This is presently a situation that exists for certain ARM
and SH platforms already today, but none that are actively used in nommu
configurations. It would be preferable to generalize this, rather than
duplicating the special-cased alignment.
On Wed, Mar 04, 2009 at 03:28:02 +0900, Paul Mundt wrote:
> On Tue, Mar 03, 2009 at 05:33:13PM +0100, Johannes Weiner wrote:
> > The flat loader uses an architecture's flat_stack_align() to align the
> > stack but assumes word-alignment is enough for the data sections.
> >
> > However, on the Xtensa S6000 we need an alignment of more than
> > wordsize for data that is loaded to 128bit wide registers.
> >
> > This patch replaces the specific flat_stack_align() with a more
> > generic flat_data_align() that is then used for both stack, the data
> > and bss section.
> >
> > It also fixes m32r which was obviously kaput, aligning an
> > uninitialized stack entry instead of the stack pointer.
> >
> Can you provide a bit more information about this for your platform? I
> note that while this patch is aimed to generalize things for your
> platform, there is no Xtensa patch included here, making it difficult to
> Ack without having more context to go on.
You are right, currently there is no variant which
really needs these fixes. But the Xtensa noMMU port
(will follow as soon as possible) wont work without
these.
> Based on your description, it looks like you need register size alignment
> in the case where your registers are greater than BYTES_PER_WORD, or the
This is right. Xtensa S6000 provides an additional set of
wide registers (128 bit), and load/store instructions to
fill them. These load/store cycles need to be 16 byte aligned.
> pointer size. If this is the case, then you are going to have the same
> issues with the slab caches and need to set ARCH_SLAB_MINALIGN
> accordingly. This is presently a situation that exists for certain ARM
> and SH platforms already today, but none that are actively used in nommu
> configurations. It would be preferable to generalize this, rather than
> duplicating the special-cased alignment.
This sounds like a good proposal.
We will rewrite the patch to use the more generic
ARCH_SLAB_MINALIGN and send it soon.
Oskar
--
oskar schirmer, emlix gmbh, http://www.emlix.com
fon +49 551 30664-0, fax -11, bahnhofsallee 1b, 37081 göttingen, germany
geschäftsführung: dr. uwe kracke, dr. cord seele, ust-idnr.: de 205 198 055
sitz der gesellschaft: göttingen, amtsgericht göttingen hr b 3160
emlix - your embedded linux partner