Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Revert "sh: Handle calling csum_partial with misaligned data"

This reverts commit cadc4e1a2b4d20d0cc0e81f2c6ba0588775e54e5.

Commit cadc4e1a2b4d ("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: cadc4e1a2b4d ("sh: Handle calling csum_partial with misaligned data")
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Link: https://lore.kernel.org/r/20240324231804.841099-1-linux@roeck-us.net
Signed-off-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>

authored by

Guenter Roeck and committed by
John Paul Adrian Glaubitz
b5319c96 6516f191

+18 -49
+18 -49
arch/sh/lib/checksum.S
··· 33 33 */ 34 34 35 35 /* 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); 37 38 */ 38 39 39 40 .text ··· 46 45 * Fortunately, it is easy to convert 2-byte alignment to 4-byte 47 46 * alignment for the unrolled loop. 48 47 */ 48 + mov r5, r1 49 49 mov r4, r0 50 - tst #3, r0 ! Check alignment. 51 - bt/s 2f ! Jump if alignment is ok. 52 - mov r4, r7 ! Keep a copy to check for alignment 50 + tst #2, r0 ! Check alignment. 51 + bt 2f ! Jump if alignment is ok. 53 52 ! 54 - tst #1, r0 ! Check alignment. 55 - bt 21f ! Jump if alignment is boundary of 2bytes. 56 - 57 - ! buf is odd 58 - tst r5, r5 59 - add #-1, r5 60 - bt 9f 61 - mov.b @r4+, r0 62 - extu.b r0, r0 63 - addc r0, r6 ! t=0 from previous tst 64 - mov r6, r0 65 - shll8 r6 66 - shlr16 r0 67 - shlr8 r0 68 - or r0, r6 69 - mov r4, r0 70 - tst #2, r0 71 - bt 2f 72 - 21: 73 - ! buf is 2 byte aligned (len could be 0) 74 53 add #-2, r5 ! Alignment uses up two bytes. 75 54 cmp/pz r5 ! 76 55 bt/s 1f ! Jump if we had at least two bytes. ··· 58 77 bra 6f 59 78 add #2, r5 ! r5 was < 2. Deal with it. 60 79 1: 80 + mov r5, r1 ! Save new len for later use. 61 81 mov.w @r4+, r0 62 82 extu.w r0, r0 63 83 addc r0, r6 64 84 bf 2f 65 85 add #1, r6 66 86 2: 67 - ! buf is 4 byte aligned (len could be 0) 68 - mov r5, r1 69 87 mov #-5, r0 70 - shld r0, r1 71 - tst r1, r1 88 + shld r0, r5 89 + tst r5, r5 72 90 bt/s 4f ! if it's =0, go to 4f 73 91 clrt 74 92 .align 2 ··· 89 109 addc r0, r6 90 110 addc r2, r6 91 111 movt r0 92 - dt r1 112 + dt r5 93 113 bf/s 3b 94 114 cmp/eq #1, r0 95 - ! here, we know r1==0 96 - addc r1, r6 ! add carry to r6 115 + ! here, we know r5==0 116 + addc r5, r6 ! add carry to r6 97 117 4: 98 - mov r5, r0 118 + mov r1, r0 99 119 and #0x1c, r0 100 120 tst r0, r0 101 - bt 6f 102 - ! 4 bytes or more remaining 103 - mov r0, r1 104 - shlr2 r1 121 + bt/s 6f 122 + mov r0, r5 123 + shlr2 r5 105 124 mov #0, r2 106 125 5: 107 126 addc r2, r6 108 127 mov.l @r4+, r2 109 128 movt r0 110 - dt r1 129 + dt r5 111 130 bf/s 5b 112 131 cmp/eq #1, r0 113 132 addc r2, r6 114 - addc r1, r6 ! r1==0 here, so it means add carry-bit 133 + addc r5, r6 ! r5==0 here, so it means add carry-bit 115 134 6: 116 - ! 3 bytes or less remaining 135 + mov r1, r5 117 136 mov #3, r0 118 137 and r0, r5 119 138 tst r5, r5 ··· 138 159 mov #0, r0 139 160 addc r0, r6 140 161 9: 141 - ! Check if the buffer was misaligned, if so realign sum 142 - mov r7, r0 143 - tst #1, r0 144 - bt 10f 145 - mov r6, r0 146 - shll8 r6 147 - shlr16 r0 148 - shlr8 r0 149 - or r0, r6 150 - 10: 151 162 rts 152 163 mov r6, r0 153 164