Skip to content

Commit 6f7d948

Browse files
ardbiesheuvelEric Biggers
authored andcommitted
crypto/arm64: sm4/xts - Merge ksimd scopes to reduce stack bloat
Merge the two ksimd scopes in the implementation of SM4-XTS to prevent stack bloat in cases where the compiler fails to combine the stack slots for the kernel mode FP/SIMD buffers. Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Tested-by: Arnd Bergmann <arnd@arndb.de> Link: https://lore.kernel.org/r/20251203163803.157541-6-ardb@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
1 parent a9a8b1a commit 6f7d948

1 file changed

Lines changed: 20 additions & 22 deletions

File tree

arch/arm64/crypto/sm4-ce-glue.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,11 @@ static int sm4_xts_crypt(struct skcipher_request *req, bool encrypt)
346346
tail = 0;
347347
}
348348

349-
while ((nbytes = walk.nbytes) >= SM4_BLOCK_SIZE) {
350-
if (nbytes < walk.total)
351-
nbytes &= ~(SM4_BLOCK_SIZE - 1);
349+
scoped_ksimd() {
350+
while ((nbytes = walk.nbytes) >= SM4_BLOCK_SIZE) {
351+
if (nbytes < walk.total)
352+
nbytes &= ~(SM4_BLOCK_SIZE - 1);
352353

353-
scoped_ksimd() {
354354
if (encrypt)
355355
sm4_ce_xts_enc(ctx->key1.rkey_enc, walk.dst.virt.addr,
356356
walk.src.virt.addr, walk.iv, nbytes,
@@ -359,32 +359,30 @@ static int sm4_xts_crypt(struct skcipher_request *req, bool encrypt)
359359
sm4_ce_xts_dec(ctx->key1.rkey_dec, walk.dst.virt.addr,
360360
walk.src.virt.addr, walk.iv, nbytes,
361361
rkey2_enc);
362-
}
363362

364-
rkey2_enc = NULL;
363+
rkey2_enc = NULL;
365364

366-
err = skcipher_walk_done(&walk, walk.nbytes - nbytes);
367-
if (err)
368-
return err;
369-
}
365+
err = skcipher_walk_done(&walk, walk.nbytes - nbytes);
366+
if (err)
367+
return err;
368+
}
370369

371-
if (likely(tail == 0))
372-
return 0;
370+
if (likely(tail == 0))
371+
return 0;
373372

374-
/* handle ciphertext stealing */
373+
/* handle ciphertext stealing */
375374

376-
dst = src = scatterwalk_ffwd(sg_src, req->src, subreq.cryptlen);
377-
if (req->dst != req->src)
378-
dst = scatterwalk_ffwd(sg_dst, req->dst, subreq.cryptlen);
375+
dst = src = scatterwalk_ffwd(sg_src, req->src, subreq.cryptlen);
376+
if (req->dst != req->src)
377+
dst = scatterwalk_ffwd(sg_dst, req->dst, subreq.cryptlen);
379378

380-
skcipher_request_set_crypt(&subreq, src, dst, SM4_BLOCK_SIZE + tail,
381-
req->iv);
379+
skcipher_request_set_crypt(&subreq, src, dst,
380+
SM4_BLOCK_SIZE + tail, req->iv);
382381

383-
err = skcipher_walk_virt(&walk, &subreq, false);
384-
if (err)
385-
return err;
382+
err = skcipher_walk_virt(&walk, &subreq, false);
383+
if (err)
384+
return err;
386385

387-
scoped_ksimd() {
388386
if (encrypt)
389387
sm4_ce_xts_enc(ctx->key1.rkey_enc, walk.dst.virt.addr,
390388
walk.src.virt.addr, walk.iv, walk.nbytes,

0 commit comments

Comments
 (0)