linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Add kto and kfrom to input operands list.
@ 2010-06-01  8:06 Khem Raj
  2010-06-02 12:08 ` Mikael Pettersson
  0 siblings, 1 reply; 3+ messages in thread
From: Khem Raj @ 2010-06-01  8:06 UTC (permalink / raw)
  To: linux-arm-kernel

When functions incoming parameters are not in input operands list gcc 4.5 does not
load the parameters into registers before calling this function but the
inline assembly assumes valid addresses inside this function. This
breaks the code because r0 and r1 are invalid when execution enters
v4wb_copy_user_page ()

Also the constant needs to be used as third input operand so account for that
as well.

Tested on qemu arm.

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 arch/arm/mm/copypage-feroceon.c |    4 ++--
 arch/arm/mm/copypage-v4wb.c     |    4 ++--
 arch/arm/mm/copypage-v4wt.c     |    4 ++--
 arch/arm/mm/copypage-xsc3.c     |    4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/arch/arm/mm/copypage-feroceon.c b/arch/arm/mm/copypage-feroceon.c
index 5eb4fd9..ac163de 100644
--- a/arch/arm/mm/copypage-feroceon.c
+++ b/arch/arm/mm/copypage-feroceon.c
@@ -18,7 +18,7 @@ feroceon_copy_user_page(void *kto, const void *kfrom)
 {
 	asm("\
 	stmfd	sp!, {r4-r9, lr}		\n\
-	mov	ip, %0				\n\
+	mov	ip, %2				\n\
 1:	mov	lr, r1				\n\
 	ldmia	r1!, {r2 - r9}			\n\
 	pld	[lr, #32]			\n\
@@ -64,7 +64,7 @@ feroceon_copy_user_page(void *kto, const void *kfrom)
 	mcr	p15, 0, ip, c7, c10, 4		@ drain WB\n\
 	ldmfd	sp!, {r4-r9, pc}"
 	:
-	: "I" (PAGE_SIZE));
+	: "r" (kto), "r" (kfrom), "I" (PAGE_SIZE));
 }
 
 void feroceon_copy_user_highpage(struct page *to, struct page *from,
diff --git a/arch/arm/mm/copypage-v4wb.c b/arch/arm/mm/copypage-v4wb.c
index 7c2eb55..cb589cb 100644
--- a/arch/arm/mm/copypage-v4wb.c
+++ b/arch/arm/mm/copypage-v4wb.c
@@ -27,7 +27,7 @@ v4wb_copy_user_page(void *kto, const void *kfrom)
 {
 	asm("\
 	stmfd	sp!, {r4, lr}			@ 2\n\
-	mov	r2, %0				@ 1\n\
+	mov	r2, %2				@ 1\n\
 	ldmia	r1!, {r3, r4, ip, lr}		@ 4\n\
 1:	mcr	p15, 0, r0, c7, c6, 1		@ 1   invalidate D line\n\
 	stmia	r0!, {r3, r4, ip, lr}		@ 4\n\
@@ -44,7 +44,7 @@ v4wb_copy_user_page(void *kto, const void *kfrom)
 	mcr	p15, 0, r1, c7, c10, 4		@ 1   drain WB\n\
 	ldmfd	 sp!, {r4, pc}			@ 3"
 	:
-	: "I" (PAGE_SIZE / 64));
+	: "r" (kto), "r" (kfrom), "I" (PAGE_SIZE / 64));
 }
 
 void v4wb_copy_user_highpage(struct page *to, struct page *from,
diff --git a/arch/arm/mm/copypage-v4wt.c b/arch/arm/mm/copypage-v4wt.c
index 172e6a5..30c7d04 100644
--- a/arch/arm/mm/copypage-v4wt.c
+++ b/arch/arm/mm/copypage-v4wt.c
@@ -25,7 +25,7 @@ v4wt_copy_user_page(void *kto, const void *kfrom)
 {
 	asm("\
 	stmfd	sp!, {r4, lr}			@ 2\n\
-	mov	r2, %0				@ 1\n\
+	mov	r2, %2				@ 1\n\
 	ldmia	r1!, {r3, r4, ip, lr}		@ 4\n\
 1:	stmia	r0!, {r3, r4, ip, lr}		@ 4\n\
 	ldmia	r1!, {r3, r4, ip, lr}		@ 4+1\n\
@@ -40,7 +40,7 @@ v4wt_copy_user_page(void *kto, const void *kfrom)
 	mcr	p15, 0, r2, c7, c7, 0		@ flush ID cache\n\
 	ldmfd	sp!, {r4, pc}			@ 3"
 	:
-	: "I" (PAGE_SIZE / 64));
+	: "r" (kto), "r" (kfrom), "I" (PAGE_SIZE / 64));
 }
 
 void v4wt_copy_user_highpage(struct page *to, struct page *from,
diff --git a/arch/arm/mm/copypage-xsc3.c b/arch/arm/mm/copypage-xsc3.c
index 747ad41..f9cde07 100644
--- a/arch/arm/mm/copypage-xsc3.c
+++ b/arch/arm/mm/copypage-xsc3.c
@@ -34,7 +34,7 @@ xsc3_mc_copy_user_page(void *kto, const void *kfrom)
 {
 	asm("\
 	stmfd	sp!, {r4, r5, lr}		\n\
-	mov	lr, %0				\n\
+	mov	lr, %2				\n\
 						\n\
 	pld	[r1, #0]			\n\
 	pld	[r1, #32]			\n\
@@ -67,7 +67,7 @@ xsc3_mc_copy_user_page(void *kto, const void *kfrom)
 						\n\
 	ldmfd	sp!, {r4, r5, pc}"
 	:
-	: "I" (PAGE_SIZE / 64 - 1));
+	: "r" (kto), "r" (kfrom), "I" (PAGE_SIZE / 64 - 1));
 }
 
 void xsc3_mc_copy_user_highpage(struct page *to, struct page *from,
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] Add kto and kfrom to input operands list.
  2010-06-01  8:06 [PATCH] Add kto and kfrom to input operands list Khem Raj
@ 2010-06-02 12:08 ` Mikael Pettersson
  2010-06-02 16:00   ` Russell King - ARM Linux
  0 siblings, 1 reply; 3+ messages in thread
From: Mikael Pettersson @ 2010-06-02 12:08 UTC (permalink / raw)
  To: linux-arm-kernel

Khem Raj writes:
 > When functions incoming parameters are not in input operands list gcc 4.5 does not
 > load the parameters into registers before calling this function but the
 > inline assembly assumes valid addresses inside this function. This
 > breaks the code because r0 and r1 are invalid when execution enters
 > v4wb_copy_user_page ()
 > 
 > Also the constant needs to be used as third input operand so account for that
 > as well.
 > 
 > Tested on qemu arm.
 > 
 > Signed-off-by: Khem Raj <raj.khem@gmail.com>
 > ---
 >  arch/arm/mm/copypage-feroceon.c |    4 ++--

I've tested and verified that this bit enables a gcc-4.5 compiled kernel
to boot on TS-119 (Kirkwood) when combined with my fix for __naked.
With neither or only one of the patches applied, the kernel oopses hard
in copy_user_page() as it tries to start /sbin/init.

So for the copypage-feroceon.c change:
Tested-by: Mikael Pettersson <mikpe@it.uu.se>

To elaborate, the copy_user_page() functions in these copypage-*.c files
break in two ways with gcc-4.5:
- they are static __naked functions, and gcc-4.5 erroneously clones
  them and changes their calling conventions in ways that don't match
  the expectations of their asm() bodies, causing runtime crashes;
  my patch to make __naked imply noinline and noclone fixes that
- the asm() bodies of these __naked functions have inadequate input
  parameter constraints, in particular they fail to declare any
  dependencies on the functions' formal parameters; gcc-4.5 sees this
  and skips the parameter setup before calling these functions, causing
  runtime crashes; Khem's patch (this one) fixes that
  (copypage-xscale.c already had correct asm() constraints so it works
  with only the __naked fix, these other copypage-*.c files need both
  patches to work)

These patches are no-ops for earlier compilers since they merely
formalise the parameter passing behaviour that the kernel has been
expecting all along.

/Mikael

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] Add kto and kfrom to input operands list.
  2010-06-02 12:08 ` Mikael Pettersson
@ 2010-06-02 16:00   ` Russell King - ARM Linux
  0 siblings, 0 replies; 3+ messages in thread
From: Russell King - ARM Linux @ 2010-06-02 16:00 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, Jun 02, 2010 at 02:08:44PM +0200, Mikael Pettersson wrote:
> Khem Raj writes:
>  > When functions incoming parameters are not in input operands list gcc 4.5 does not
>  > load the parameters into registers before calling this function but the
>  > inline assembly assumes valid addresses inside this function. This
>  > breaks the code because r0 and r1 are invalid when execution enters
>  > v4wb_copy_user_page ()
>  > 
>  > Also the constant needs to be used as third input operand so account for that
>  > as well.
>  > 
>  > Tested on qemu arm.
>  > 
>  > Signed-off-by: Khem Raj <raj.khem@gmail.com>
>  > ---
>  >  arch/arm/mm/copypage-feroceon.c |    4 ++--
> 
> I've tested and verified that this bit enables a gcc-4.5 compiled kernel
> to boot on TS-119 (Kirkwood) when combined with my fix for __naked.
> With neither or only one of the patches applied, the kernel oopses hard
> in copy_user_page() as it tries to start /sbin/init.
> 
> So for the copypage-feroceon.c change:
> Tested-by: Mikael Pettersson <mikpe@it.uu.se>

Ok.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-06-02 16:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-01  8:06 [PATCH] Add kto and kfrom to input operands list Khem Raj
2010-06-02 12:08 ` Mikael Pettersson
2010-06-02 16:00   ` Russell King - ARM Linux

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 NNTP newsgroup(s).