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

crypto: chcr - Avoid algo allocation in softirq.

Thsi patch fixes calling "crypto_alloc_cipher" call in bottom halves.
Pre allocate aes cipher required to update Tweak value for XTS.

Signed-off-by: Harsh Jain <harsh@chelsio.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Harsh Jain and committed by
Herbert Xu
d3f1d2f7 854b06f7

+16 -8
+15 -8
drivers/crypto/chelsio/chcr_algo.c
··· 899 899 u8 *key; 900 900 unsigned int keylen; 901 901 902 - cipher = crypto_alloc_cipher("aes-generic", 0, 0); 902 + cipher = ablkctx->aes_generic; 903 903 memcpy(iv, req->info, AES_BLOCK_SIZE); 904 904 905 - if (IS_ERR(cipher)) { 906 - ret = -ENOMEM; 907 - goto out; 908 - } 909 905 keylen = ablkctx->enckey_len / 2; 910 906 key = ablkctx->key + keylen; 911 907 ret = crypto_cipher_setkey(cipher, key, keylen); 912 908 if (ret) 913 - goto out1; 909 + goto out; 914 910 915 911 crypto_cipher_encrypt_one(cipher, iv, iv); 916 912 for (i = 0; i < (reqctx->processed / AES_BLOCK_SIZE); i++) 917 913 gf128mul_x_ble((le128 *)iv, (le128 *)iv); 918 914 919 915 crypto_cipher_decrypt_one(cipher, iv, iv); 920 - out1: 921 - crypto_free_cipher(cipher); 922 916 out: 923 917 return ret; 924 918 } ··· 1256 1262 pr_err("failed to allocate fallback for %s\n", alg->cra_name); 1257 1263 return PTR_ERR(ablkctx->sw_cipher); 1258 1264 } 1265 + 1266 + if (get_cryptoalg_subtype(tfm) == CRYPTO_ALG_SUB_TYPE_XTS) { 1267 + /* To update tweak*/ 1268 + ablkctx->aes_generic = crypto_alloc_cipher("aes-generic", 0, 0); 1269 + if (IS_ERR(ablkctx->aes_generic)) { 1270 + pr_err("failed to allocate aes cipher for tweak\n"); 1271 + return PTR_ERR(ablkctx->aes_generic); 1272 + } 1273 + } else 1274 + ablkctx->aes_generic = NULL; 1275 + 1259 1276 tfm->crt_ablkcipher.reqsize = sizeof(struct chcr_blkcipher_req_ctx); 1260 1277 return chcr_device_init(crypto_tfm_ctx(tfm)); 1261 1278 } ··· 1297 1292 struct ablk_ctx *ablkctx = ABLK_CTX(ctx); 1298 1293 1299 1294 crypto_free_skcipher(ablkctx->sw_cipher); 1295 + if (ablkctx->aes_generic) 1296 + crypto_free_cipher(ablkctx->aes_generic); 1300 1297 } 1301 1298 1302 1299 static int get_alg_config(struct algo_param *params,
+1
drivers/crypto/chelsio/chcr_crypto.h
··· 155 155 156 156 struct ablk_ctx { 157 157 struct crypto_skcipher *sw_cipher; 158 + struct crypto_cipher *aes_generic; 158 159 __be32 key_ctx_hdr; 159 160 unsigned int enckey_len; 160 161 unsigned char ciph_mode;