Skip to content

Commit fe1233c

Browse files
author
Eric Biggers
committed
lib/crypto: arm64/sha256: Remove obsolete chunking logic
Since commit aefbab8 ("arm64: fpsimd: Preserve/restore kernel mode NEON at context switch"), kernel-mode NEON sections have been preemptible on arm64. And since commit 7dadeaa ("sched: Further restrict the preemption modes"), voluntary preemption is no longer supported on arm64 either. Therefore, there's no longer any need to limit the length of kernel-mode NEON sections on arm64. Simplify the SHA-256 code accordingly. Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Link: https://lore.kernel.org/r/20260401000548.133151-7-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
1 parent fd50171 commit fe1233c

2 files changed

Lines changed: 13 additions & 30 deletions

File tree

lib/crypto/arm64/sha256-ce.S

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@
7979
.endm
8080

8181
/*
82-
* size_t __sha256_ce_transform(struct sha256_block_state *state,
83-
* const u8 *data, size_t nblocks);
82+
* void sha256_ce_transform(struct sha256_block_state *state,
83+
* const u8 *data, size_t nblocks);
8484
*/
8585
.text
86-
SYM_FUNC_START(__sha256_ce_transform)
86+
SYM_FUNC_START(sha256_ce_transform)
8787

8888
load_round_constants x8
8989

@@ -127,17 +127,13 @@ CPU_LE( rev32 v19.16b, v19.16b )
127127
add dgav.4s, dgav.4s, dg0v.4s
128128
add dgbv.4s, dgbv.4s, dg1v.4s
129129

130-
/* return early if voluntary preemption is needed */
131-
cond_yield 1f, x5, x6
132-
133130
/* handled all input blocks? */
134131
cbnz x2, 0b
135132

136133
/* store new state */
137-
1: st1 {dgav.4s, dgbv.4s}, [x0]
138-
mov x0, x2
134+
st1 {dgav.4s, dgbv.4s}, [x0]
139135
ret
140-
SYM_FUNC_END(__sha256_ce_transform)
136+
SYM_FUNC_END(sha256_ce_transform)
141137

142138
.unreq dga
143139
.unreq dgav

lib/crypto/arm64/sha256.h

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,17 @@ asmlinkage void sha256_block_data_order(struct sha256_block_state *state,
1414
const u8 *data, size_t nblocks);
1515
asmlinkage void sha256_block_neon(struct sha256_block_state *state,
1616
const u8 *data, size_t nblocks);
17-
asmlinkage size_t __sha256_ce_transform(struct sha256_block_state *state,
18-
const u8 *data, size_t nblocks);
17+
asmlinkage void sha256_ce_transform(struct sha256_block_state *state,
18+
const u8 *data, size_t nblocks);
1919

2020
static void sha256_blocks(struct sha256_block_state *state,
2121
const u8 *data, size_t nblocks)
2222
{
2323
if (static_branch_likely(&have_neon) && likely(may_use_simd())) {
24-
if (static_branch_likely(&have_ce)) {
25-
do {
26-
size_t rem;
27-
28-
scoped_ksimd()
29-
rem = __sha256_ce_transform(state, data,
30-
nblocks);
31-
32-
data += (nblocks - rem) * SHA256_BLOCK_SIZE;
33-
nblocks = rem;
34-
} while (nblocks);
35-
} else {
36-
scoped_ksimd()
24+
scoped_ksimd() {
25+
if (static_branch_likely(&have_ce))
26+
sha256_ce_transform(state, data, nblocks);
27+
else
3728
sha256_block_neon(state, data, nblocks);
3829
}
3930
} else {
@@ -55,13 +46,9 @@ static bool sha256_finup_2x_arch(const struct __sha256_ctx *ctx,
5546
u8 out1[SHA256_DIGEST_SIZE],
5647
u8 out2[SHA256_DIGEST_SIZE])
5748
{
58-
/*
59-
* The assembly requires len >= SHA256_BLOCK_SIZE && len <= INT_MAX.
60-
* Further limit len to 65536 to avoid spending too long with preemption
61-
* disabled. (Of course, in practice len is nearly always 4096 anyway.)
62-
*/
49+
/* The assembly requires len >= SHA256_BLOCK_SIZE && len <= INT_MAX. */
6350
if (static_branch_likely(&have_ce) && len >= SHA256_BLOCK_SIZE &&
64-
len <= 65536 && likely(may_use_simd())) {
51+
len <= INT_MAX && likely(may_use_simd())) {
6552
scoped_ksimd()
6653
sha256_ce_finup2x(ctx, data1, data2, len, out1, out2);
6754
kmsan_unpoison_memory(out1, SHA256_DIGEST_SIZE);

0 commit comments

Comments
 (0)