Commit 2c3f8b16 authored by Gilad Ben-Yossef's avatar Gilad Ben-Yossef Committed by Herbert Xu

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: default avatarGilad Ben-Yossef <gilad@benyossef.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent ada69a16
...@@ -481,33 +481,6 @@ int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con) ...@@ -481,33 +481,6 @@ int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con)
} }
EXPORT_SYMBOL_GPL(af_alg_cmsg_send); EXPORT_SYMBOL_GPL(af_alg_cmsg_send);
int af_alg_wait_for_completion(int err, struct af_alg_completion *completion)
{
switch (err) {
case -EINPROGRESS:
case -EBUSY:
wait_for_completion(&completion->completion);
reinit_completion(&completion->completion);
err = completion->err;
break;
};
return err;
}
EXPORT_SYMBOL_GPL(af_alg_wait_for_completion);
void af_alg_complete(struct crypto_async_request *req, int err)
{
struct af_alg_completion *completion = req->data;
if (err == -EINPROGRESS)
return;
completion->err = err;
complete(&completion->completion);
}
EXPORT_SYMBOL_GPL(af_alg_complete);
/** /**
* af_alg_alloc_tsgl - allocate the TX SGL * af_alg_alloc_tsgl - allocate the TX SGL
* *
......
...@@ -278,11 +278,11 @@ static int _aead_recvmsg(struct socket *sock, struct msghdr *msg, ...@@ -278,11 +278,11 @@ static int _aead_recvmsg(struct socket *sock, struct msghdr *msg,
/* Synchronous operation */ /* Synchronous operation */
aead_request_set_callback(&areq->cra_u.aead_req, aead_request_set_callback(&areq->cra_u.aead_req,
CRYPTO_TFM_REQ_MAY_BACKLOG, CRYPTO_TFM_REQ_MAY_BACKLOG,
af_alg_complete, &ctx->completion); crypto_req_done, &ctx->wait);
err = af_alg_wait_for_completion(ctx->enc ? err = crypto_wait_req(ctx->enc ?
crypto_aead_encrypt(&areq->cra_u.aead_req) : crypto_aead_encrypt(&areq->cra_u.aead_req) :
crypto_aead_decrypt(&areq->cra_u.aead_req), crypto_aead_decrypt(&areq->cra_u.aead_req),
&ctx->completion); &ctx->wait);
} }
/* AIO operation in progress */ /* AIO operation in progress */
...@@ -554,7 +554,7 @@ static int aead_accept_parent_nokey(void *private, struct sock *sk) ...@@ -554,7 +554,7 @@ static int aead_accept_parent_nokey(void *private, struct sock *sk)
ctx->merge = 0; ctx->merge = 0;
ctx->enc = 0; ctx->enc = 0;
ctx->aead_assoclen = 0; ctx->aead_assoclen = 0;
af_alg_init_completion(&ctx->completion); crypto_init_wait(&ctx->wait);
ask->private = ctx; ask->private = ctx;
......
...@@ -26,7 +26,7 @@ struct hash_ctx { ...@@ -26,7 +26,7 @@ struct hash_ctx {
u8 *result; u8 *result;
struct af_alg_completion completion; struct crypto_wait wait;
unsigned int len; unsigned int len;
bool more; bool more;
...@@ -88,8 +88,7 @@ static int hash_sendmsg(struct socket *sock, struct msghdr *msg, ...@@ -88,8 +88,7 @@ static int hash_sendmsg(struct socket *sock, struct msghdr *msg,
if ((msg->msg_flags & MSG_MORE)) if ((msg->msg_flags & MSG_MORE))
hash_free_result(sk, ctx); hash_free_result(sk, ctx);
err = af_alg_wait_for_completion(crypto_ahash_init(&ctx->req), err = crypto_wait_req(crypto_ahash_init(&ctx->req), &ctx->wait);
&ctx->completion);
if (err) if (err)
goto unlock; goto unlock;
} }
...@@ -110,8 +109,8 @@ static int hash_sendmsg(struct socket *sock, struct msghdr *msg, ...@@ -110,8 +109,8 @@ static int hash_sendmsg(struct socket *sock, struct msghdr *msg,
ahash_request_set_crypt(&ctx->req, ctx->sgl.sg, NULL, len); ahash_request_set_crypt(&ctx->req, ctx->sgl.sg, NULL, len);
err = af_alg_wait_for_completion(crypto_ahash_update(&ctx->req), err = crypto_wait_req(crypto_ahash_update(&ctx->req),
&ctx->completion); &ctx->wait);
af_alg_free_sg(&ctx->sgl); af_alg_free_sg(&ctx->sgl);
if (err) if (err)
goto unlock; goto unlock;
...@@ -129,8 +128,8 @@ static int hash_sendmsg(struct socket *sock, struct msghdr *msg, ...@@ -129,8 +128,8 @@ static int hash_sendmsg(struct socket *sock, struct msghdr *msg,
goto unlock; goto unlock;
ahash_request_set_crypt(&ctx->req, NULL, ctx->result, 0); ahash_request_set_crypt(&ctx->req, NULL, ctx->result, 0);
err = af_alg_wait_for_completion(crypto_ahash_final(&ctx->req), err = crypto_wait_req(crypto_ahash_final(&ctx->req),
&ctx->completion); &ctx->wait);
} }
unlock: unlock:
...@@ -171,7 +170,7 @@ static ssize_t hash_sendpage(struct socket *sock, struct page *page, ...@@ -171,7 +170,7 @@ static ssize_t hash_sendpage(struct socket *sock, struct page *page,
} else { } else {
if (!ctx->more) { if (!ctx->more) {
err = crypto_ahash_init(&ctx->req); err = crypto_ahash_init(&ctx->req);
err = af_alg_wait_for_completion(err, &ctx->completion); err = crypto_wait_req(err, &ctx->wait);
if (err) if (err)
goto unlock; goto unlock;
} }
...@@ -179,7 +178,7 @@ static ssize_t hash_sendpage(struct socket *sock, struct page *page, ...@@ -179,7 +178,7 @@ static ssize_t hash_sendpage(struct socket *sock, struct page *page,
err = crypto_ahash_update(&ctx->req); err = crypto_ahash_update(&ctx->req);
} }
err = af_alg_wait_for_completion(err, &ctx->completion); err = crypto_wait_req(err, &ctx->wait);
if (err) if (err)
goto unlock; goto unlock;
...@@ -215,17 +214,16 @@ static int hash_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, ...@@ -215,17 +214,16 @@ static int hash_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
ahash_request_set_crypt(&ctx->req, NULL, ctx->result, 0); ahash_request_set_crypt(&ctx->req, NULL, ctx->result, 0);
if (!result && !ctx->more) { if (!result && !ctx->more) {
err = af_alg_wait_for_completion( err = crypto_wait_req(crypto_ahash_init(&ctx->req),
crypto_ahash_init(&ctx->req), &ctx->wait);
&ctx->completion);
if (err) if (err)
goto unlock; goto unlock;
} }
if (!result || ctx->more) { if (!result || ctx->more) {
ctx->more = 0; ctx->more = 0;
err = af_alg_wait_for_completion(crypto_ahash_final(&ctx->req), err = crypto_wait_req(crypto_ahash_final(&ctx->req),
&ctx->completion); &ctx->wait);
if (err) if (err)
goto unlock; goto unlock;
} }
...@@ -476,13 +474,13 @@ static int hash_accept_parent_nokey(void *private, struct sock *sk) ...@@ -476,13 +474,13 @@ static int hash_accept_parent_nokey(void *private, struct sock *sk)
ctx->result = NULL; ctx->result = NULL;
ctx->len = len; ctx->len = len;
ctx->more = 0; ctx->more = 0;
af_alg_init_completion(&ctx->completion); crypto_init_wait(&ctx->wait);
ask->private = ctx; ask->private = ctx;
ahash_request_set_tfm(&ctx->req, hash); ahash_request_set_tfm(&ctx->req, hash);
ahash_request_set_callback(&ctx->req, CRYPTO_TFM_REQ_MAY_BACKLOG, ahash_request_set_callback(&ctx->req, CRYPTO_TFM_REQ_MAY_BACKLOG,
af_alg_complete, &ctx->completion); crypto_req_done, &ctx->wait);
sk->sk_destruct = hash_sock_destruct; sk->sk_destruct = hash_sock_destruct;
......
...@@ -129,12 +129,11 @@ static int _skcipher_recvmsg(struct socket *sock, struct msghdr *msg, ...@@ -129,12 +129,11 @@ static int _skcipher_recvmsg(struct socket *sock, struct msghdr *msg,
skcipher_request_set_callback(&areq->cra_u.skcipher_req, skcipher_request_set_callback(&areq->cra_u.skcipher_req,
CRYPTO_TFM_REQ_MAY_SLEEP | CRYPTO_TFM_REQ_MAY_SLEEP |
CRYPTO_TFM_REQ_MAY_BACKLOG, CRYPTO_TFM_REQ_MAY_BACKLOG,
af_alg_complete, crypto_req_done, &ctx->wait);
&ctx->completion); err = crypto_wait_req(ctx->enc ?
err = af_alg_wait_for_completion(ctx->enc ?
crypto_skcipher_encrypt(&areq->cra_u.skcipher_req) : crypto_skcipher_encrypt(&areq->cra_u.skcipher_req) :
crypto_skcipher_decrypt(&areq->cra_u.skcipher_req), crypto_skcipher_decrypt(&areq->cra_u.skcipher_req),
&ctx->completion); &ctx->wait);
} }
/* AIO operation in progress */ /* AIO operation in progress */
...@@ -388,7 +387,7 @@ static int skcipher_accept_parent_nokey(void *private, struct sock *sk) ...@@ -388,7 +387,7 @@ static int skcipher_accept_parent_nokey(void *private, struct sock *sk)
ctx->more = 0; ctx->more = 0;
ctx->merge = 0; ctx->merge = 0;
ctx->enc = 0; ctx->enc = 0;
af_alg_init_completion(&ctx->completion); crypto_init_wait(&ctx->wait);
ask->private = ctx; ask->private = ctx;
......
...@@ -40,11 +40,6 @@ struct alg_sock { ...@@ -40,11 +40,6 @@ struct alg_sock {
void *private; void *private;
}; };
struct af_alg_completion {
struct completion completion;
int err;
};
struct af_alg_control { struct af_alg_control {
struct af_alg_iv *iv; struct af_alg_iv *iv;
int op; int op;
...@@ -152,7 +147,7 @@ struct af_alg_ctx { ...@@ -152,7 +147,7 @@ struct af_alg_ctx {
void *iv; void *iv;
size_t aead_assoclen; size_t aead_assoclen;
struct af_alg_completion completion; struct crypto_wait wait;
size_t used; size_t used;
size_t rcvused; size_t rcvused;
...@@ -177,19 +172,11 @@ void af_alg_link_sg(struct af_alg_sgl *sgl_prev, struct af_alg_sgl *sgl_new); ...@@ -177,19 +172,11 @@ void af_alg_link_sg(struct af_alg_sgl *sgl_prev, struct af_alg_sgl *sgl_new);
int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con); int af_alg_cmsg_send(struct msghdr *msg, struct af_alg_control *con);
int af_alg_wait_for_completion(int err, struct af_alg_completion *completion);
void af_alg_complete(struct crypto_async_request *req, int err);
static inline struct alg_sock *alg_sk(struct sock *sk) static inline struct alg_sock *alg_sk(struct sock *sk)
{ {
return (struct alg_sock *)sk; return (struct alg_sock *)sk;
} }
static inline void af_alg_init_completion(struct af_alg_completion *completion)
{
init_completion(&completion->completion);
}
/** /**
* Size of available buffer for sending data from user space to kernel. * Size of available buffer for sending data from user space to kernel.
* *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment