aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/tcrypt.c
diff options
context:
space:
mode:
authorGilad Ben-Yossef <gilad@benyossef.com>2017-10-18 03:00:48 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2017-11-03 10:11:22 -0400
commit646710419a978c6f82342a2ad5eb28adb5f47bc4 (patch)
tree8a8748f5ffc6383827e4bd1e3fb1c105e26fbd9e /crypto/tcrypt.c
parent46f1414c8a92d85b4391bc324dd58eace8c48837 (diff)
crypto: tcrypt - move to generic async completion
tcrypt starts several async crypto ops and waits for their completions. Move it over to generic code doing the same. Signed-off-by: Gilad Ben-Yossef <gilad@benyossef.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/tcrypt.c')
-rw-r--r--crypto/tcrypt.c84
1 files changed, 25 insertions, 59 deletions
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index 65d191b27ecc..9267cbdb14d2 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -79,34 +79,11 @@ static char *check[] = {
79 NULL 79 NULL
80}; 80};
81 81
82struct tcrypt_result {
83 struct completion completion;
84 int err;
85};
86
87static void tcrypt_complete(struct crypto_async_request *req, int err)
88{
89 struct tcrypt_result *res = req->data;
90
91 if (err == -EINPROGRESS)
92 return;
93
94 res->err = err;
95 complete(&res->completion);
96}
97
98static inline int do_one_aead_op(struct aead_request *req, int ret) 82static inline int do_one_aead_op(struct aead_request *req, int ret)
99{ 83{
100 if (ret == -EINPROGRESS || ret == -EBUSY) { 84 struct crypto_wait *wait = req->base.data;
101 struct tcrypt_result *tr = req->base.data;
102 85
103 ret = wait_for_completion_interruptible(&tr->completion); 86 return crypto_wait_req(ret, wait);
104 if (!ret)
105 ret = tr->err;
106 reinit_completion(&tr->completion);
107 }
108
109 return ret;
110} 87}
111 88
112static int test_aead_jiffies(struct aead_request *req, int enc, 89static int test_aead_jiffies(struct aead_request *req, int enc,
@@ -248,7 +225,7 @@ static void test_aead_speed(const char *algo, int enc, unsigned int secs,
248 char *axbuf[XBUFSIZE]; 225 char *axbuf[XBUFSIZE];
249 unsigned int *b_size; 226 unsigned int *b_size;
250 unsigned int iv_len; 227 unsigned int iv_len;
251 struct tcrypt_result result; 228 struct crypto_wait wait;
252 229
253 iv = kzalloc(MAX_IVLEN, GFP_KERNEL); 230 iv = kzalloc(MAX_IVLEN, GFP_KERNEL);
254 if (!iv) 231 if (!iv)
@@ -284,7 +261,7 @@ static void test_aead_speed(const char *algo, int enc, unsigned int secs,
284 goto out_notfm; 261 goto out_notfm;
285 } 262 }
286 263
287 init_completion(&result.completion); 264 crypto_init_wait(&wait);
288 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo, 265 printk(KERN_INFO "\ntesting speed of %s (%s) %s\n", algo,
289 get_driver_name(crypto_aead, tfm), e); 266 get_driver_name(crypto_aead, tfm), e);
290 267
@@ -296,7 +273,7 @@ static void test_aead_speed(const char *algo, int enc, unsigned int secs,
296 } 273 }
297 274
298 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 275 aead_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
299 tcrypt_complete, &result); 276 crypto_req_done, &wait);
300 277
301 i = 0; 278 i = 0;
302 do { 279 do {
@@ -398,21 +375,16 @@ static void test_hash_sg_init(struct scatterlist *sg)
398 375
399static inline int do_one_ahash_op(struct ahash_request *req, int ret) 376static inline int do_one_ahash_op(struct ahash_request *req, int ret)
400{ 377{
401 if (ret == -EINPROGRESS || ret == -EBUSY) { 378 struct crypto_wait *wait = req->base.data;
402 struct tcrypt_result *tr = req->base.data;
403 379
404 wait_for_completion(&tr->completion); 380 return crypto_wait_req(ret, wait);
405 reinit_completion(&tr->completion);
406 ret = tr->err;
407 }
408 return ret;
409} 381}
410 382
411struct test_mb_ahash_data { 383struct test_mb_ahash_data {
412 struct scatterlist sg[TVMEMSIZE]; 384 struct scatterlist sg[TVMEMSIZE];
413 char result[64]; 385 char result[64];
414 struct ahash_request *req; 386 struct ahash_request *req;
415 struct tcrypt_result tresult; 387 struct crypto_wait wait;
416 char *xbuf[XBUFSIZE]; 388 char *xbuf[XBUFSIZE];
417}; 389};
418 390
@@ -441,7 +413,7 @@ static void test_mb_ahash_speed(const char *algo, unsigned int sec,
441 if (testmgr_alloc_buf(data[i].xbuf)) 413 if (testmgr_alloc_buf(data[i].xbuf))
442 goto out; 414 goto out;
443 415
444 init_completion(&data[i].tresult.completion); 416 crypto_init_wait(&data[i].wait);
445 417
446 data[i].req = ahash_request_alloc(tfm, GFP_KERNEL); 418 data[i].req = ahash_request_alloc(tfm, GFP_KERNEL);
447 if (!data[i].req) { 419 if (!data[i].req) {
@@ -450,8 +422,8 @@ static void test_mb_ahash_speed(const char *algo, unsigned int sec,
450 goto out; 422 goto out;
451 } 423 }
452 424
453 ahash_request_set_callback(data[i].req, 0, 425 ahash_request_set_callback(data[i].req, 0, crypto_req_done,
454 tcrypt_complete, &data[i].tresult); 426 &data[i].wait);
455 test_hash_sg_init(data[i].sg); 427 test_hash_sg_init(data[i].sg);
456 } 428 }
457 429
@@ -493,16 +465,16 @@ static void test_mb_ahash_speed(const char *algo, unsigned int sec,
493 if (ret) 465 if (ret)
494 break; 466 break;
495 467
496 complete(&data[k].tresult.completion); 468 crypto_req_done(&data[k].req->base, 0);
497 data[k].tresult.err = 0;
498 } 469 }
499 470
500 for (j = 0; j < k; j++) { 471 for (j = 0; j < k; j++) {
501 struct tcrypt_result *tr = &data[j].tresult; 472 struct crypto_wait *wait = &data[j].wait;
473 int wait_ret;
502 474
503 wait_for_completion(&tr->completion); 475 wait_ret = crypto_wait_req(-EINPROGRESS, wait);
504 if (tr->err) 476 if (wait_ret)
505 ret = tr->err; 477 ret = wait_ret;
506 } 478 }
507 479
508 end = get_cycles(); 480 end = get_cycles();
@@ -680,7 +652,7 @@ static void test_ahash_speed_common(const char *algo, unsigned int secs,
680 struct hash_speed *speed, unsigned mask) 652 struct hash_speed *speed, unsigned mask)
681{ 653{
682 struct scatterlist sg[TVMEMSIZE]; 654 struct scatterlist sg[TVMEMSIZE];
683 struct tcrypt_result tresult; 655 struct crypto_wait wait;
684 struct ahash_request *req; 656 struct ahash_request *req;
685 struct crypto_ahash *tfm; 657 struct crypto_ahash *tfm;
686 char *output; 658 char *output;
@@ -709,9 +681,9 @@ static void test_ahash_speed_common(const char *algo, unsigned int secs,
709 goto out; 681 goto out;
710 } 682 }
711 683
712 init_completion(&tresult.completion); 684 crypto_init_wait(&wait);
713 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 685 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
714 tcrypt_complete, &tresult); 686 crypto_req_done, &wait);
715 687
716 output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL); 688 output = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
717 if (!output) 689 if (!output)
@@ -766,15 +738,9 @@ static void test_hash_speed(const char *algo, unsigned int secs,
766 738
767static inline int do_one_acipher_op(struct skcipher_request *req, int ret) 739static inline int do_one_acipher_op(struct skcipher_request *req, int ret)
768{ 740{
769 if (ret == -EINPROGRESS || ret == -EBUSY) { 741 struct crypto_wait *wait = req->base.data;
770 struct tcrypt_result *tr = req->base.data;
771
772 wait_for_completion(&tr->completion);
773 reinit_completion(&tr->completion);
774 ret = tr->err;
775 }
776 742
777 return ret; 743 return crypto_wait_req(ret, wait);
778} 744}
779 745
780static int test_acipher_jiffies(struct skcipher_request *req, int enc, 746static int test_acipher_jiffies(struct skcipher_request *req, int enc,
@@ -854,7 +820,7 @@ static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,
854 unsigned int tcount, u8 *keysize, bool async) 820 unsigned int tcount, u8 *keysize, bool async)
855{ 821{
856 unsigned int ret, i, j, k, iv_len; 822 unsigned int ret, i, j, k, iv_len;
857 struct tcrypt_result tresult; 823 struct crypto_wait wait;
858 const char *key; 824 const char *key;
859 char iv[128]; 825 char iv[128];
860 struct skcipher_request *req; 826 struct skcipher_request *req;
@@ -867,7 +833,7 @@ static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,
867 else 833 else
868 e = "decryption"; 834 e = "decryption";
869 835
870 init_completion(&tresult.completion); 836 crypto_init_wait(&wait);
871 837
872 tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC); 838 tfm = crypto_alloc_skcipher(algo, 0, async ? 0 : CRYPTO_ALG_ASYNC);
873 839
@@ -888,7 +854,7 @@ static void test_skcipher_speed(const char *algo, int enc, unsigned int secs,
888 } 854 }
889 855
890 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 856 skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
891 tcrypt_complete, &tresult); 857 crypto_req_done, &wait);
892 858
893 i = 0; 859 i = 0;
894 do { 860 do {