Skip to content

Commit d3f1d2f

Browse files
Harsh Jainherbertx
authored andcommitted
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>
1 parent 854b06f commit d3f1d2f

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

drivers/crypto/chelsio/chcr_algo.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -899,26 +899,20 @@ static int chcr_update_tweak(struct ablkcipher_request *req, u8 *iv)
899899
u8 *key;
900900
unsigned int keylen;
901901

902-
cipher = crypto_alloc_cipher("aes-generic", 0, 0);
902+
cipher = ablkctx->aes_generic;
903903
memcpy(iv, req->info, AES_BLOCK_SIZE);
904904

905-
if (IS_ERR(cipher)) {
906-
ret = -ENOMEM;
907-
goto out;
908-
}
909905
keylen = ablkctx->enckey_len / 2;
910906
key = ablkctx->key + keylen;
911907
ret = crypto_cipher_setkey(cipher, key, keylen);
912908
if (ret)
913-
goto out1;
909+
goto out;
914910

915911
crypto_cipher_encrypt_one(cipher, iv, iv);
916912
for (i = 0; i < (reqctx->processed / AES_BLOCK_SIZE); i++)
917913
gf128mul_x_ble((le128 *)iv, (le128 *)iv);
918914

919915
crypto_cipher_decrypt_one(cipher, iv, iv);
920-
out1:
921-
crypto_free_cipher(cipher);
922916
out:
923917
return ret;
924918
}
@@ -1262,6 +1256,17 @@ static int chcr_cra_init(struct crypto_tfm *tfm)
12621256
pr_err("failed to allocate fallback for %s\n", alg->cra_name);
12631257
return PTR_ERR(ablkctx->sw_cipher);
12641258
}
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+
12651270
tfm->crt_ablkcipher.reqsize = sizeof(struct chcr_blkcipher_req_ctx);
12661271
return chcr_device_init(crypto_tfm_ctx(tfm));
12671272
}
@@ -1292,6 +1297,8 @@ static void chcr_cra_exit(struct crypto_tfm *tfm)
12921297
struct ablk_ctx *ablkctx = ABLK_CTX(ctx);
12931298

12941299
crypto_free_skcipher(ablkctx->sw_cipher);
1300+
if (ablkctx->aes_generic)
1301+
crypto_free_cipher(ablkctx->aes_generic);
12951302
}
12961303

12971304
static int get_alg_config(struct algo_param *params,

drivers/crypto/chelsio/chcr_crypto.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155

156156
struct ablk_ctx {
157157
struct crypto_skcipher *sw_cipher;
158+
struct crypto_cipher *aes_generic;
158159
__be32 key_ctx_hdr;
159160
unsigned int enckey_len;
160161
unsigned char ciph_mode;

0 commit comments

Comments
 (0)