Skip to content

Commit b5319c9

Browse files
groeckglaubitz
authored andcommitted
Revert "sh: Handle calling csum_partial with misaligned data"
This reverts commit cadc4e1. Commit cadc4e1 ("sh: Handle calling csum_partial with misaligned data") causes bad checksum calculations on unaligned data. Reverting it fixes the problem. # Subtest: checksum # module: checksum_kunit 1..5 # test_csum_fixed_random_inputs: ASSERTION FAILED at lib/checksum_kunit.c:500 Expected ( u64)result == ( u64)expec, but ( u64)result == 53378 (0xd082) ( u64)expec == 33488 (0x82d0) # test_csum_fixed_random_inputs: pass:0 fail:1 skip:0 total:1 not ok 1 test_csum_fixed_random_inputs # test_csum_all_carry_inputs: ASSERTION FAILED at lib/checksum_kunit.c:525 Expected ( u64)result == ( u64)expec, but ( u64)result == 65281 (0xff01) ( u64)expec == 65280 (0xff00) # test_csum_all_carry_inputs: pass:0 fail:1 skip:0 total:1 not ok 2 test_csum_all_carry_inputs # test_csum_no_carry_inputs: ASSERTION FAILED at lib/checksum_kunit.c:573 Expected ( u64)result == ( u64)expec, but ( u64)result == 65535 (0xffff) ( u64)expec == 65534 (0xfffe) # test_csum_no_carry_inputs: pass:0 fail:1 skip:0 total:1 not ok 3 test_csum_no_carry_inputs # test_ip_fast_csum: pass:1 fail:0 skip:0 total:1 ok 4 test_ip_fast_csum # test_csum_ipv6_magic: pass:1 fail:0 skip:0 total:1 ok 5 test_csum_ipv6_magic # checksum: pass:2 fail:3 skip:0 total:5 # Totals: pass:2 fail:3 skip:0 total:5 not ok 22 checksum Fixes: cadc4e1 ("sh: Handle calling csum_partial with misaligned data") Signed-off-by: Guenter Roeck <[email protected]> Tested-by: Geert Uytterhoeven <[email protected]> Reviewed-by: John Paul Adrian Glaubitz <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: John Paul Adrian Glaubitz <[email protected]>
1 parent 6516f19 commit b5319c9

File tree

1 file changed

+18
-49
lines changed

1 file changed

+18
-49
lines changed

arch/sh/lib/checksum.S

Lines changed: 18 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
*/
3434

3535
/*
36-
* asmlinkage __wsum csum_partial(const void *buf, int len, __wsum sum);
36+
* unsigned int csum_partial(const unsigned char *buf, int len,
37+
* unsigned int sum);
3738
*/
3839

3940
.text
@@ -45,49 +46,28 @@ ENTRY(csum_partial)
4546
* Fortunately, it is easy to convert 2-byte alignment to 4-byte
4647
* alignment for the unrolled loop.
4748
*/
49+
mov r5, r1
4850
mov r4, r0
49-
tst #3, r0 ! Check alignment.
50-
bt/s 2f ! Jump if alignment is ok.
51-
mov r4, r7 ! Keep a copy to check for alignment
51+
tst #2, r0 ! Check alignment.
52+
bt 2f ! Jump if alignment is ok.
5253
!
53-
tst #1, r0 ! Check alignment.
54-
bt 21f ! Jump if alignment is boundary of 2bytes.
55-
56-
! buf is odd
57-
tst r5, r5
58-
add #-1, r5
59-
bt 9f
60-
mov.b @r4+, r0
61-
extu.b r0, r0
62-
addc r0, r6 ! t=0 from previous tst
63-
mov r6, r0
64-
shll8 r6
65-
shlr16 r0
66-
shlr8 r0
67-
or r0, r6
68-
mov r4, r0
69-
tst #2, r0
70-
bt 2f
71-
21:
72-
! buf is 2 byte aligned (len could be 0)
7354
add #-2, r5 ! Alignment uses up two bytes.
7455
cmp/pz r5 !
7556
bt/s 1f ! Jump if we had at least two bytes.
7657
clrt
7758
bra 6f
7859
add #2, r5 ! r5 was < 2. Deal with it.
7960
1:
61+
mov r5, r1 ! Save new len for later use.
8062
mov.w @r4+, r0
8163
extu.w r0, r0
8264
addc r0, r6
8365
bf 2f
8466
add #1, r6
8567
2:
86-
! buf is 4 byte aligned (len could be 0)
87-
mov r5, r1
8868
mov #-5, r0
89-
shld r0, r1
90-
tst r1, r1
69+
shld r0, r5
70+
tst r5, r5
9171
bt/s 4f ! if it's =0, go to 4f
9272
clrt
9373
.align 2
@@ -109,31 +89,30 @@ ENTRY(csum_partial)
10989
addc r0, r6
11090
addc r2, r6
11191
movt r0
112-
dt r1
92+
dt r5
11393
bf/s 3b
11494
cmp/eq #1, r0
115-
! here, we know r1==0
116-
addc r1, r6 ! add carry to r6
95+
! here, we know r5==0
96+
addc r5, r6 ! add carry to r6
11797
4:
118-
mov r5, r0
98+
mov r1, r0
11999
and #0x1c, r0
120100
tst r0, r0
121-
bt 6f
122-
! 4 bytes or more remaining
123-
mov r0, r1
124-
shlr2 r1
101+
bt/s 6f
102+
mov r0, r5
103+
shlr2 r5
125104
mov #0, r2
126105
5:
127106
addc r2, r6
128107
mov.l @r4+, r2
129108
movt r0
130-
dt r1
109+
dt r5
131110
bf/s 5b
132111
cmp/eq #1, r0
133112
addc r2, r6
134-
addc r1, r6 ! r1==0 here, so it means add carry-bit
113+
addc r5, r6 ! r5==0 here, so it means add carry-bit
135114
6:
136-
! 3 bytes or less remaining
115+
mov r1, r5
137116
mov #3, r0
138117
and r0, r5
139118
tst r5, r5
@@ -159,16 +138,6 @@ ENTRY(csum_partial)
159138
mov #0, r0
160139
addc r0, r6
161140
9:
162-
! Check if the buffer was misaligned, if so realign sum
163-
mov r7, r0
164-
tst #1, r0
165-
bt 10f
166-
mov r6, r0
167-
shll8 r6
168-
shlr16 r0
169-
shlr8 r0
170-
or r0, r6
171-
10:
172141
rts
173142
mov r6, r0
174143

0 commit comments

Comments
 (0)