aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarsh Jain <harsh@chelsio.com>2017-06-23 10:15:11 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2017-07-12 06:38:08 -0400
commitd3f1d2f7863137c5d71e64041b48968db29b149e (patch)
treee355670658068522a14a1d71698c9d036c0b6869
parent854b06f768794cd664886ec3ba3a5b1c58d42167 (diff)
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>
-rw-r--r--drivers/crypto/chelsio/chcr_algo.c23
-rw-r--r--drivers/crypto/chelsio/chcr_crypto.h1
2 files changed, 16 insertions, 8 deletions
diff --git a/drivers/crypto/chelsio/chcr_algo.c b/drivers/crypto/chelsio/chcr_algo.c
index aa4e5b88483d..508cbc79e508 100644
--- a/drivers/crypto/chelsio/chcr_algo.c
+++ b/drivers/crypto/chelsio/chcr_algo.c
@@ -899,26 +899,20 @@ static int chcr_update_tweak(struct ablkcipher_request *req, u8 *iv)
899 u8 *key; 899 u8 *key;
900 unsigned int keylen; 900 unsigned int keylen;
901 901
902 cipher = crypto_alloc_cipher("aes-generic", 0, 0); 902 cipher = ablkctx->aes_generic;
903 memcpy(iv, req->info, AES_BLOCK_SIZE); 903 memcpy(iv, req->info, AES_BLOCK_SIZE);
904 904
905 if (IS_ERR(cipher)) {
906 ret = -ENOMEM;
907 goto out;
908 }
909 keylen = ablkctx->enckey_len / 2; 905 keylen = ablkctx->enckey_len / 2;
910 key = ablkctx->key + keylen; 906 key = ablkctx->key + keylen;
911 ret = crypto_cipher_setkey(cipher, key, keylen); 907 ret = crypto_cipher_setkey(cipher, key, keylen);
912 if (ret) 908 if (ret)
913 goto out1; 909 goto out;
914 910
915 crypto_cipher_encrypt_one(cipher, iv, iv); 911 crypto_cipher_encrypt_one(cipher, iv, iv);
916 for (i = 0; i < (reqctx->processed / AES_BLOCK_SIZE); i++) 912 for (i = 0; i < (reqctx->processed / AES_BLOCK_SIZE); i++)
917 gf128mul_x_ble((le128 *)iv, (le128 *)iv); 913 gf128mul_x_ble((le128 *)iv, (le128 *)iv);
918 914
919 crypto_cipher_decrypt_one(cipher, iv, iv); 915 crypto_cipher_decrypt_one(cipher, iv, iv);
920out1:
921 crypto_free_cipher(cipher);
922out: 916out:
923 return ret; 917 return ret;
924} 918}
@@ -1262,6 +1256,17 @@ static int chcr_cra_init(struct crypto_tfm *tfm)
1262 pr_err("failed to allocate fallback for %s\n", alg->cra_name); 1256 pr_err("failed to allocate fallback for %s\n", alg->cra_name);
1263 return PTR_ERR(ablkctx->sw_cipher); 1257 return PTR_ERR(ablkctx->sw_cipher);
1264 } 1258 }
1259
1260 if (get_cryptoalg_subtype(tfm) == CRYPTO_ALG_SUB_TYPE_XTS) {
1261 /* To update tweak*/
1262 ablkctx->aes_generic = crypto_alloc_cipher("aes-generic", 0, 0);
1263 if (IS_ERR(ablkctx->aes_generic)) {
1264 pr_err("failed to allocate aes cipher for tweak\n");
1265 return PTR_ERR(ablkctx->aes_generic);
1266 }
1267 } else
1268 ablkctx->aes_generic = NULL;
1269
1265 tfm->crt_ablkcipher.reqsize = sizeof(struct chcr_blkcipher_req_ctx); 1270 tfm->crt_ablkcipher.reqsize = sizeof(struct chcr_blkcipher_req_ctx);
1266 return chcr_device_init(crypto_tfm_ctx(tfm)); 1271 return chcr_device_init(crypto_tfm_ctx(tfm));
1267} 1272}
@@ -1292,6 +1297,8 @@ static void chcr_cra_exit(struct crypto_tfm *tfm)
1292 struct ablk_ctx *ablkctx = ABLK_CTX(ctx); 1297 struct ablk_ctx *ablkctx = ABLK_CTX(ctx);
1293 1298
1294 crypto_free_skcipher(ablkctx->sw_cipher); 1299 crypto_free_skcipher(ablkctx->sw_cipher);
1300 if (ablkctx->aes_generic)
1301 crypto_free_cipher(ablkctx->aes_generic);
1295} 1302}
1296 1303
1297static int get_alg_config(struct algo_param *params, 1304static int get_alg_config(struct algo_param *params,
diff --git a/drivers/crypto/chelsio/chcr_crypto.h b/drivers/crypto/chelsio/chcr_crypto.h
index a4f95b014b46..30af1ee17b87 100644
--- a/drivers/crypto/chelsio/chcr_crypto.h
+++ b/drivers/crypto/chelsio/chcr_crypto.h
@@ -155,6 +155,7 @@
155 155
156struct ablk_ctx { 156struct ablk_ctx {
157 struct crypto_skcipher *sw_cipher; 157 struct crypto_skcipher *sw_cipher;
158 struct crypto_cipher *aes_generic;
158 __be32 key_ctx_hdr; 159 __be32 key_ctx_hdr;
159 unsigned int enckey_len; 160 unsigned int enckey_len;
160 unsigned char ciph_mode; 161 unsigned char ciph_mode;