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

crypto/arm64: sm4-ce-ccm - Avoid pointless yield of the NEON unit

Kernel mode NEON sections are now preemptible on arm64, and so there is
no need to yield it when calling APIs that may sleep.

Also, move the calls to kernel_neon_end() to the same scope as
kernel_neon_begin(). This is needed for a subsequent change where a
stack buffer is allocated transparently and passed to
kernel_neon_begin().

Reviewed-by: Eric Biggers <ebiggers@kernel.org>
Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>

+6 -19
+6 -19
arch/arm64/crypto/sm4-ce-ccm-glue.c
··· 172 172 if (req->assoclen) 173 173 ccm_calculate_auth_mac(req, mac); 174 174 175 - while (walk->nbytes && walk->nbytes != walk->total) { 175 + while (walk->nbytes) { 176 176 unsigned int tail = walk->nbytes % SM4_BLOCK_SIZE; 177 + 178 + if (walk->nbytes == walk->total) 179 + tail = 0; 177 180 178 181 sm4_ce_ccm_crypt(rkey_enc, walk->dst.virt.addr, 179 182 walk->src.virt.addr, walk->iv, 180 183 walk->nbytes - tail, mac); 181 184 182 - kernel_neon_end(); 183 - 184 185 err = skcipher_walk_done(walk, tail); 185 - 186 - kernel_neon_begin(); 187 186 } 188 187 189 - if (walk->nbytes) { 190 - sm4_ce_ccm_crypt(rkey_enc, walk->dst.virt.addr, 191 - walk->src.virt.addr, walk->iv, 192 - walk->nbytes, mac); 188 + sm4_ce_ccm_final(rkey_enc, ctr0, mac); 193 189 194 - sm4_ce_ccm_final(rkey_enc, ctr0, mac); 195 - 196 - kernel_neon_end(); 197 - 198 - err = skcipher_walk_done(walk, 0); 199 - } else { 200 - sm4_ce_ccm_final(rkey_enc, ctr0, mac); 201 - 202 - kernel_neon_end(); 203 - } 190 + kernel_neon_end(); 204 191 205 192 return err; 206 193 }