diff options
author | Gilad Ben-Yossef <gilad@benyossef.com> | 2017-10-18 03:00:39 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2017-11-03 10:11:18 -0400 |
commit | 2c3f8b162106a7d12097d02eb22459f57fab8247 (patch) | |
tree | b36a46ee96b9f7060317e869060ac0dafd792f7e /crypto | |
parent | ada69a1639eca54ff74d839a6513c43db8d57d70 (diff) |
crypto: algif - move to generic async completion
algif starts several async crypto ops and waits for their completion.
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')
-rw-r--r-- | crypto/af_alg.c | 27 | ||||
-rw-r--r-- | crypto/algif_aead.c | 8 | ||||
-rw-r--r-- | crypto/algif_hash.c | 30 | ||||
-rw-r--r-- | crypto/algif_skcipher.c | 9 |
4 files changed, 22 insertions, 52 deletions
diff --git a/crypto/af_alg.c b/crypto/af_alg.c index 337cf382718e..85cea9de324a 100644 --- a/crypto/af_alg.c +++ b/crypto/af_alg.c | |||
@@ -481,33 +481,6 @@ int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con) | |||
481 | } | 481 | } |
482 | EXPORT_SYMBOL_GPL(af_alg_cmsg_send); | 482 | EXPORT_SYMBOL_GPL(af_alg_cmsg_send); |
483 | 483 | ||
484 | int af_alg_wait_for_completion(int err, struct af_alg_completion *completion) | ||
485 | { | ||
486 | switch (err) { | ||
487 | case -EINPROGRESS: | ||
488 | case -EBUSY: | ||
489 | wait_for_completion(&completion->completion); | ||
490 | reinit_completion(&completion->completion); | ||
491 | err = completion->err; | ||
492 | break; | ||
493 | }; | ||
494 | |||
495 | return err; | ||
496 | } | ||
497 | EXPORT_SYMBOL_GPL(af_alg_wait_for_completion); | ||
498 | |||
499 | void af_alg_complete(struct crypto_async_request *req, int err) | ||
500 | { | ||
501 | struct af_alg_completion *completion = req->data; | ||
502 | |||
503 | if (err == -EINPROGRESS) | ||
504 | return; | ||
505 | |||
506 | completion->err = err; | ||
507 | complete(&completion->completion); | ||
508 | } | ||
509 | EXPORT_SYMBOL_GPL(af_alg_complete); | ||
510 | |||
511 | /** | 484 | /** |
512 | * af_alg_alloc_tsgl - allocate the TX SGL | 485 | * af_alg_alloc_tsgl - allocate the TX SGL |
513 | * | 486 | * |
diff --git a/crypto/algif_aead.c b/crypto/algif_aead.c index 516b38c3a169..aacae0837aff 100644 --- a/crypto/algif_aead.c +++ b/crypto/algif_aead.c | |||
@@ -278,11 +278,11 @@ static int _aead_recvmsg(struct socket *sock, struct msghdr *msg, | |||
278 | /* Synchronous operation */ | 278 | /* Synchronous operation */ |
279 | aead_request_set_callback(&areq->cra_u.aead_req, | 279 | aead_request_set_callback(&areq->cra_u.aead_req, |
280 | CRYPTO_TFM_REQ_MAY_BACKLOG, | 280 | CRYPTO_TFM_REQ_MAY_BACKLOG, |
281 | af_alg_complete, &ctx->completion); | 281 | crypto_req_done, &ctx->wait); |
282 | err = af_alg_wait_for_completion(ctx->enc ? | 282 | err = crypto_wait_req(ctx->enc ? |
283 | crypto_aead_encrypt(&areq->cra_u.aead_req) : | 283 | crypto_aead_encrypt(&areq->cra_u.aead_req) : |
284 | crypto_aead_decrypt(&areq->cra_u.aead_req), | 284 | crypto_aead_decrypt(&areq->cra_u.aead_req), |
285 | &ctx->completion); | 285 | &ctx->wait); |
286 | } | 286 | } |
287 | 287 | ||
288 | /* AIO operation in progress */ | 288 | /* AIO operation in progress */ |
@@ -554,7 +554,7 @@ static int aead_accept_parent_nokey(void *private, struct sock *sk) | |||
554 | ctx->merge = 0; | 554 | ctx->merge = 0; |
555 | ctx->enc = 0; | 555 | ctx->enc = 0; |
556 | ctx->aead_assoclen = 0; | 556 | ctx->aead_assoclen = 0; |
557 | af_alg_init_completion(&ctx->completion); | 557 | crypto_init_wait(&ctx->wait); |
558 | 558 | ||
559 | ask->private = ctx; | 559 | ask->private = ctx; |
560 | 560 | ||
diff --git a/crypto/algif_hash.c b/crypto/algif_hash.c index 5e92bd275ef3..76d2e716c792 100644 --- a/crypto/algif_hash.c +++ b/crypto/algif_hash.c | |||
@@ -26,7 +26,7 @@ struct hash_ctx { | |||
26 | 26 | ||
27 | u8 *result; | 27 | u8 *result; |
28 | 28 | ||
29 | struct af_alg_completion completion; | 29 | struct crypto_wait wait; |
30 | 30 | ||
31 | unsigned int len; | 31 | unsigned int len; |
32 | bool more; | 32 | bool more; |
@@ -88,8 +88,7 @@ static int hash_sendmsg(struct socket *sock, struct msghdr *msg, | |||
88 | if ((msg->msg_flags & MSG_MORE)) | 88 | if ((msg->msg_flags & MSG_MORE)) |
89 | hash_free_result(sk, ctx); | 89 | hash_free_result(sk, ctx); |
90 | 90 | ||
91 | err = af_alg_wait_for_completion(crypto_ahash_init(&ctx->req), | 91 | err = crypto_wait_req(crypto_ahash_init(&ctx->req), &ctx->wait); |
92 | &ctx->completion); | ||
93 | if (err) | 92 | if (err) |
94 | goto unlock; | 93 | goto unlock; |
95 | } | 94 | } |
@@ -110,8 +109,8 @@ static int hash_sendmsg(struct socket *sock, struct msghdr *msg, | |||
110 | 109 | ||
111 | ahash_request_set_crypt(&ctx->req, ctx->sgl.sg, NULL, len); | 110 | ahash_request_set_crypt(&ctx->req, ctx->sgl.sg, NULL, len); |
112 | 111 | ||
113 | err = af_alg_wait_for_completion(crypto_ahash_update(&ctx->req), | 112 | err = crypto_wait_req(crypto_ahash_update(&ctx->req), |
114 | &ctx->completion); | 113 | &ctx->wait); |
115 | af_alg_free_sg(&ctx->sgl); | 114 | af_alg_free_sg(&ctx->sgl); |
116 | if (err) | 115 | if (err) |
117 | goto unlock; | 116 | goto unlock; |
@@ -129,8 +128,8 @@ static int hash_sendmsg(struct socket *sock, struct msghdr *msg, | |||
129 | goto unlock; | 128 | goto unlock; |
130 | 129 | ||
131 | ahash_request_set_crypt(&ctx->req, NULL, ctx->result, 0); | 130 | ahash_request_set_crypt(&ctx->req, NULL, ctx->result, 0); |
132 | err = af_alg_wait_for_completion(crypto_ahash_final(&ctx->req), | 131 | err = crypto_wait_req(crypto_ahash_final(&ctx->req), |
133 | &ctx->completion); | 132 | &ctx->wait); |
134 | } | 133 | } |
135 | 134 | ||
136 | unlock: | 135 | unlock: |
@@ -171,7 +170,7 @@ static ssize_t hash_sendpage(struct socket *sock, struct page *page, | |||
171 | } else { | 170 | } else { |
172 | if (!ctx->more) { | 171 | if (!ctx->more) { |
173 | err = crypto_ahash_init(&ctx->req); | 172 | err = crypto_ahash_init(&ctx->req); |
174 | err = af_alg_wait_for_completion(err, &ctx->completion); | 173 | err = crypto_wait_req(err, &ctx->wait); |
175 | if (err) | 174 | if (err) |
176 | goto unlock; | 175 | goto unlock; |
177 | } | 176 | } |
@@ -179,7 +178,7 @@ static ssize_t hash_sendpage(struct socket *sock, struct page *page, | |||
179 | err = crypto_ahash_update(&ctx->req); | 178 | err = crypto_ahash_update(&ctx->req); |
180 | } | 179 | } |
181 | 180 | ||
182 | err = af_alg_wait_for_completion(err, &ctx->completion); | 181 | err = crypto_wait_req(err, &ctx->wait); |
183 | if (err) | 182 | if (err) |
184 | goto unlock; | 183 | goto unlock; |
185 | 184 | ||
@@ -215,17 +214,16 @@ static int hash_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, | |||
215 | ahash_request_set_crypt(&ctx->req, NULL, ctx->result, 0); | 214 | ahash_request_set_crypt(&ctx->req, NULL, ctx->result, 0); |
216 | 215 | ||
217 | if (!result && !ctx->more) { | 216 | if (!result && !ctx->more) { |
218 | err = af_alg_wait_for_completion( | 217 | err = crypto_wait_req(crypto_ahash_init(&ctx->req), |
219 | crypto_ahash_init(&ctx->req), | 218 | &ctx->wait); |
220 | &ctx->completion); | ||
221 | if (err) | 219 | if (err) |
222 | goto unlock; | 220 | goto unlock; |
223 | } | 221 | } |
224 | 222 | ||
225 | if (!result || ctx->more) { | 223 | if (!result || ctx->more) { |
226 | ctx->more = 0; | 224 | ctx->more = 0; |
227 | err = af_alg_wait_for_completion(crypto_ahash_final(&ctx->req), | 225 | err = crypto_wait_req(crypto_ahash_final(&ctx->req), |
228 | &ctx->completion); | 226 | &ctx->wait); |
229 | if (err) | 227 | if (err) |
230 | goto unlock; | 228 | goto unlock; |
231 | } | 229 | } |
@@ -476,13 +474,13 @@ static int hash_accept_parent_nokey(void *private, struct sock *sk) | |||
476 | ctx->result = NULL; | 474 | ctx->result = NULL; |
477 | ctx->len = len; | 475 | ctx->len = len; |
478 | ctx->more = 0; | 476 | ctx->more = 0; |
479 | af_alg_init_completion(&ctx->completion); | 477 | crypto_init_wait(&ctx->wait); |
480 | 478 | ||
481 | ask->private = ctx; | 479 | ask->private = ctx; |
482 | 480 | ||
483 | ahash_request_set_tfm(&ctx->req, hash); | 481 | ahash_request_set_tfm(&ctx->req, hash); |
484 | ahash_request_set_callback(&ctx->req, CRYPTO_TFM_REQ_MAY_BACKLOG, | 482 | ahash_request_set_callback(&ctx->req, CRYPTO_TFM_REQ_MAY_BACKLOG, |
485 | af_alg_complete, &ctx->completion); | 483 | crypto_req_done, &ctx->wait); |
486 | 484 | ||
487 | sk->sk_destruct = hash_sock_destruct; | 485 | sk->sk_destruct = hash_sock_destruct; |
488 | 486 | ||
diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c index 8ae4170aaeb4..9954b078f0b9 100644 --- a/crypto/algif_skcipher.c +++ b/crypto/algif_skcipher.c | |||
@@ -129,12 +129,11 @@ static int _skcipher_recvmsg(struct socket *sock, struct msghdr *msg, | |||
129 | skcipher_request_set_callback(&areq->cra_u.skcipher_req, | 129 | skcipher_request_set_callback(&areq->cra_u.skcipher_req, |
130 | CRYPTO_TFM_REQ_MAY_SLEEP | | 130 | CRYPTO_TFM_REQ_MAY_SLEEP | |
131 | CRYPTO_TFM_REQ_MAY_BACKLOG, | 131 | CRYPTO_TFM_REQ_MAY_BACKLOG, |
132 | af_alg_complete, | 132 | crypto_req_done, &ctx->wait); |
133 | &ctx->completion); | 133 | err = crypto_wait_req(ctx->enc ? |
134 | err = af_alg_wait_for_completion(ctx->enc ? | ||
135 | crypto_skcipher_encrypt(&areq->cra_u.skcipher_req) : | 134 | crypto_skcipher_encrypt(&areq->cra_u.skcipher_req) : |
136 | crypto_skcipher_decrypt(&areq->cra_u.skcipher_req), | 135 | crypto_skcipher_decrypt(&areq->cra_u.skcipher_req), |
137 | &ctx->completion); | 136 | &ctx->wait); |
138 | } | 137 | } |
139 | 138 | ||
140 | /* AIO operation in progress */ | 139 | /* AIO operation in progress */ |
@@ -388,7 +387,7 @@ static int skcipher_accept_parent_nokey(void *private, struct sock *sk) | |||
388 | ctx->more = 0; | 387 | ctx->more = 0; |
389 | ctx->merge = 0; | 388 | ctx->merge = 0; |
390 | ctx->enc = 0; | 389 | ctx->enc = 0; |
391 | af_alg_init_completion(&ctx->completion); | 390 | crypto_init_wait(&ctx->wait); |
392 | 391 | ||
393 | ask->private = ctx; | 392 | ask->private = ctx; |
394 | 393 | ||