Skip to content

Commit d82f37a

Browse files
Ard Biesheuvelherbertx
authored andcommitted
crypto: arm64/sha2-ce - yield NEON after every block of input
Avoid excessive scheduling delays under a preemptible kernel by yielding the NEON after every block of input. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 7df8d16 commit d82f37a

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

arch/arm64/crypto/sha2-ce-core.S

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,30 +79,36 @@
7979
*/
8080
.text
8181
ENTRY(sha2_ce_transform)
82+
frame_push 3
83+
84+
mov x19, x0
85+
mov x20, x1
86+
mov x21, x2
87+
8288
/* load round constants */
83-
adr_l x8, .Lsha2_rcon
89+
0: adr_l x8, .Lsha2_rcon
8490
ld1 { v0.4s- v3.4s}, [x8], #64
8591
ld1 { v4.4s- v7.4s}, [x8], #64
8692
ld1 { v8.4s-v11.4s}, [x8], #64
8793
ld1 {v12.4s-v15.4s}, [x8]
8894

8995
/* load state */
90-
ld1 {dgav.4s, dgbv.4s}, [x0]
96+
ld1 {dgav.4s, dgbv.4s}, [x19]
9197

9298
/* load sha256_ce_state::finalize */
9399
ldr_l w4, sha256_ce_offsetof_finalize, x4
94-
ldr w4, [x0, x4]
100+
ldr w4, [x19, x4]
95101

96102
/* load input */
97-
0: ld1 {v16.4s-v19.4s}, [x1], #64
98-
sub w2, w2, #1
103+
1: ld1 {v16.4s-v19.4s}, [x20], #64
104+
sub w21, w21, #1
99105

100106
CPU_LE( rev32 v16.16b, v16.16b )
101107
CPU_LE( rev32 v17.16b, v17.16b )
102108
CPU_LE( rev32 v18.16b, v18.16b )
103109
CPU_LE( rev32 v19.16b, v19.16b )
104110

105-
1: add t0.4s, v16.4s, v0.4s
111+
2: add t0.4s, v16.4s, v0.4s
106112
mov dg0v.16b, dgav.16b
107113
mov dg1v.16b, dgbv.16b
108114

@@ -131,16 +137,24 @@ CPU_LE( rev32 v19.16b, v19.16b )
131137
add dgbv.4s, dgbv.4s, dg1v.4s
132138

133139
/* handled all input blocks? */
134-
cbnz w2, 0b
140+
cbz w21, 3f
141+
142+
if_will_cond_yield_neon
143+
st1 {dgav.4s, dgbv.4s}, [x19]
144+
do_cond_yield_neon
145+
b 0b
146+
endif_yield_neon
147+
148+
b 1b
135149

136150
/*
137151
* Final block: add padding and total bit count.
138152
* Skip if the input size was not a round multiple of the block size,
139153
* the padding is handled by the C code in that case.
140154
*/
141-
cbz x4, 3f
155+
3: cbz x4, 4f
142156
ldr_l w4, sha256_ce_offsetof_count, x4
143-
ldr x4, [x0, x4]
157+
ldr x4, [x19, x4]
144158
movi v17.2d, #0
145159
mov x8, #0x80000000
146160
movi v18.2d, #0
@@ -149,9 +163,10 @@ CPU_LE( rev32 v19.16b, v19.16b )
149163
mov x4, #0
150164
mov v19.d[0], xzr
151165
mov v19.d[1], x7
152-
b 1b
166+
b 2b
153167

154168
/* store new state */
155-
3: st1 {dgav.4s, dgbv.4s}, [x0]
169+
4: st1 {dgav.4s, dgbv.4s}, [x19]
170+
frame_pop
156171
ret
157172
ENDPROC(sha2_ce_transform)

0 commit comments

Comments
 (0)