[PATCH] powerpc/32: fix csum_partial_copy_generic()

Subsystems: linux for powerpc (32-bit and 64-bit), the rest

STALE3655d

4 messages, 2 authors, 2016-08-01 · open the first message on its own page

[PATCH] powerpc/32: fix csum_partial_copy_generic()

From: Christophe Leroy <hidden>
Date: 2016-08-01 12:57:12

commit 7aef4136566b0 ("powerpc32: rewrite csum_partial_copy_generic()
based on copy_tofrom_user()") introduced a bug when destination
address is odd and initial csum is not null

In that (rare) case the initial csum value has to be rotated one byte
as well as the resulting value is

Fixes: 7aef4136566b0 ("powerpc32: rewrite csum_partial_copy_generic()
based on copy_tofrom_user()")
Cc: stable@vger.kernel.org

Signed-off-by: Christophe Leroy <redacted>
---
 arch/powerpc/lib/checksum_32.S | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/lib/checksum_32.S b/arch/powerpc/lib/checksum_32.S
index d90870a..ad0870a 100644
--- a/arch/powerpc/lib/checksum_32.S
+++ b/arch/powerpc/lib/checksum_32.S
@@ -127,7 +127,8 @@ _GLOBAL(csum_partial_copy_generic)
 	stw	r7,12(r1)
 	stw	r8,8(r1)
 
-	andi.	r0,r4,1			/* is destination address even ? */
+	rlwinm	r0,r4,3,0x8		/* is destination address even ? */
+	rlwnm	r6,r6,r0,0,31		/* swap bytes for odd destination */
 	cmplwi	cr7,r0,0
 	addic	r12,r6,0
 	addi	r6,r4,-4
-- 
2.1.0

Re: [PATCH] powerpc/32: fix csum_partial_copy_generic()

From: Christophe Leroy <hidden>
Date: 2016-08-01 13:46:51


Le 01/08/2016 à 15:15, Segher Boessenkool a écrit :
On Mon, Aug 01, 2016 at 02:56:05PM +0200, Christophe Leroy wrote:
quoted
--- a/arch/powerpc/lib/checksum_32.S
+++ b/arch/powerpc/lib/checksum_32.S
@@ -127,7 +127,8 @@ _GLOBAL(csum_partial_copy_generic)
 	stw	r7,12(r1)
 	stw	r8,8(r1)

-	andi.	r0,r4,1			/* is destination address even ? */
+	rlwinm	r0,r4,3,0x8		/* is destination address even ? */
+	rlwnm	r6,r6,r0,0,31		/* swap bytes for odd destination */
 	cmplwi	cr7,r0,0
 	addic	r12,r6,0
 	addi	r6,r4,-4
That does not "swap bytes"; it shifts the word up by 8 bits, instead.
That may or may not do what is intended.
Indeed it does what is intended, similar to what is done at the end of 
the function:

	...
	beqlr+	cr7
	rlwinm	r3,r3,8,0,31	/* swap bytes for odd destination */
  	blr

Should I fix the (both) comment(s) ?

Christophe

Re: [PATCH] powerpc/32: fix csum_partial_copy_generic()

From: Segher Boessenkool <hidden>
Date: 2016-08-01 14:32:50

On Mon, Aug 01, 2016 at 03:45:59PM +0200, Christophe Leroy wrote:
quoted
quoted
--- a/arch/powerpc/lib/checksum_32.S
+++ b/arch/powerpc/lib/checksum_32.S
@@ -127,7 +127,8 @@ _GLOBAL(csum_partial_copy_generic)
	stw	r7,12(r1)
	stw	r8,8(r1)

-	andi.	r0,r4,1			/* is destination address even ? */
+	rlwinm	r0,r4,3,0x8		/* is destination address even ? */
+	rlwnm	r6,r6,r0,0,31		/* swap bytes for odd destination */
	cmplwi	cr7,r0,0
	addic	r12,r6,0
	addi	r6,r4,-4
That does not "swap bytes"; it shifts the word up by 8 bits, instead.
That may or may not do what is intended.
Indeed it does what is intended, similar to what is done at the end of 
the function:

	...
	beqlr+	cr7
	rlwinm	r3,r3,8,0,31	/* swap bytes for odd destination */
 	blr

Should I fix the (both) comment(s) ?
It's quite confusing comment, so yes please.  The code is hard enough to
understand as is!


Segher

Re: [PATCH] powerpc/32: fix csum_partial_copy_generic()

From: Segher Boessenkool <hidden>
Date: 2016-08-01 19:35:17

On Mon, Aug 01, 2016 at 02:56:05PM +0200, Christophe Leroy wrote:
quoted hunk
--- a/arch/powerpc/lib/checksum_32.S
+++ b/arch/powerpc/lib/checksum_32.S
@@ -127,7 +127,8 @@ _GLOBAL(csum_partial_copy_generic)
 	stw	r7,12(r1)
 	stw	r8,8(r1)
 
-	andi.	r0,r4,1			/* is destination address even ? */
+	rlwinm	r0,r4,3,0x8		/* is destination address even ? */
+	rlwnm	r6,r6,r0,0,31		/* swap bytes for odd destination */
 	cmplwi	cr7,r0,0
 	addic	r12,r6,0
 	addi	r6,r4,-4
That does not "swap bytes"; it shifts the word up by 8 bits, instead.
That may or may not do what is intended.


Segher
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help