From: "Herbert Xu" <herbert@gondor.apana.org.au>
To: Linux Crypto Mailing List <linux-crypto@vger.kernel.org>,
Tudor Ambarus <tudor.ambarus@microchip.com>,
Jesper Nilsson <jesper.nilsson@axis.com>,
Lars Persson <lars.persson@axis.com>,
linux-arm-kernel@axis.com,
Raveendra Padasalagi <raveendra.padasalagi@broadcom.com>,
George Cherian <gcherian@marvell.com>,
Tom Lendacky <thomas.lendacky@amd.com>,
John Allen <john.allen@amd.com>,
Ayush Sawal <ayush.sawal@chelsio.com>,
Kai Ye <yekai13@huawei.com>,
Longfang Liu <liulongfang@huawei.com>,
Antoine Tenart <atenart@kernel.org>,
Corentin Labbe <clabbe@baylibre.com>,
Boris Brezillon <bbrezillon@kernel.org>,
Arnaud Ebalard <arno@natisbad.org>,
Srujana Challa <schalla@marvell.com>,
Giovanni Cabiddu <giovanni.cabiddu@intel.com>,
qat-linux@intel.com, Thara Gopinath <thara.gopinath@gmail.com>,
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>,
Vladimir Zapolskiy <vz@mleia.com>
Subject: [PATCH 11/32] crypto: cryptd - Use request_complete helpers
Date: Tue, 31 Jan 2023 16:02:06 +0800 [thread overview]
Message-ID: <E1pMlag-005viF-F5@formenos.hmeau.com> (raw)
In-Reply-To: Y9jKmRsdHsIwfFLo@gondor.apana.org.au
Use the request_complete helpers instead of calling the completion
function directly.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---
crypto/cryptd.c | 228 +++++++++++++++++++++++++++++---------------------------
1 file changed, 120 insertions(+), 108 deletions(-)
diff --git a/crypto/cryptd.c b/crypto/cryptd.c
index c0c416eda8e8..06ef3fcbe4ae 100644
--- a/crypto/cryptd.c
+++ b/crypto/cryptd.c
@@ -72,7 +72,6 @@ struct cryptd_skcipher_ctx {
};
struct cryptd_skcipher_request_ctx {
- crypto_completion_t complete;
struct skcipher_request req;
};
@@ -83,6 +82,7 @@ struct cryptd_hash_ctx {
struct cryptd_hash_request_ctx {
crypto_completion_t complete;
+ void *data;
struct shash_desc desc;
};
@@ -92,7 +92,6 @@ struct cryptd_aead_ctx {
};
struct cryptd_aead_request_ctx {
- crypto_completion_t complete;
struct aead_request req;
};
@@ -178,8 +177,8 @@ static void cryptd_queue_worker(struct work_struct *work)
return;
if (backlog)
- backlog->complete(backlog, -EINPROGRESS);
- req->complete(req, 0);
+ crypto_request_complete(backlog, -EINPROGRESS);
+ crypto_request_complete(req, 0);
if (cpu_queue->queue.qlen)
queue_work(cryptd_wq, &cpu_queue->work);
@@ -238,18 +237,47 @@ static int cryptd_skcipher_setkey(struct crypto_skcipher *parent,
return crypto_skcipher_setkey(child, key, keylen);
}
-static void cryptd_skcipher_complete(struct skcipher_request *req, int err)
+static struct skcipher_request *cryptd_skcipher_prepare(
+ struct skcipher_request *req, int err)
+{
+ struct cryptd_skcipher_request_ctx *rctx = skcipher_request_ctx(req);
+ struct skcipher_request *subreq = &rctx->req;
+ struct cryptd_skcipher_ctx *ctx;
+ struct crypto_skcipher *child;
+
+ req->base.complete = subreq->base.complete;
+ req->base.data = subreq->base.data;
+
+ if (unlikely(err == -EINPROGRESS))
+ return NULL;
+
+ ctx = crypto_skcipher_ctx(crypto_skcipher_reqtfm(req));
+ child = ctx->child;
+
+ skcipher_request_set_tfm(subreq, child);
+ skcipher_request_set_callback(subreq, CRYPTO_TFM_REQ_MAY_SLEEP,
+ NULL, NULL);
+ skcipher_request_set_crypt(subreq, req->src, req->dst, req->cryptlen,
+ req->iv);
+
+ return subreq;
+}
+
+static void cryptd_skcipher_complete(struct skcipher_request *req, int err,
+ crypto_completion_t complete)
{
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
struct cryptd_skcipher_ctx *ctx = crypto_skcipher_ctx(tfm);
- struct cryptd_skcipher_request_ctx *rctx = skcipher_request_ctx(req);
int refcnt = refcount_read(&ctx->refcnt);
local_bh_disable();
- rctx->complete(&req->base, err);
+ skcipher_request_complete(req, err);
local_bh_enable();
- if (err != -EINPROGRESS && refcnt && refcount_dec_and_test(&ctx->refcnt))
+ if (unlikely(err == -EINPROGRESS)) {
+ req->base.complete = complete;
+ req->base.data = req;
+ } else if (refcnt && refcount_dec_and_test(&ctx->refcnt))
crypto_free_skcipher(tfm);
}
@@ -257,54 +285,26 @@ static void cryptd_skcipher_encrypt(struct crypto_async_request *base,
int err)
{
struct skcipher_request *req = skcipher_request_cast(base);
- struct cryptd_skcipher_request_ctx *rctx = skcipher_request_ctx(req);
- struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
- struct cryptd_skcipher_ctx *ctx = crypto_skcipher_ctx(tfm);
- struct skcipher_request *subreq = &rctx->req;
- struct crypto_skcipher *child = ctx->child;
-
- if (unlikely(err == -EINPROGRESS))
- goto out;
-
- skcipher_request_set_tfm(subreq, child);
- skcipher_request_set_callback(subreq, CRYPTO_TFM_REQ_MAY_SLEEP,
- NULL, NULL);
- skcipher_request_set_crypt(subreq, req->src, req->dst, req->cryptlen,
- req->iv);
-
- err = crypto_skcipher_encrypt(subreq);
+ struct skcipher_request *subreq;
- req->base.complete = rctx->complete;
+ subreq = cryptd_skcipher_prepare(req, err);
+ if (likely(subreq))
+ err = crypto_skcipher_encrypt(subreq);
-out:
- cryptd_skcipher_complete(req, err);
+ cryptd_skcipher_complete(req, err, cryptd_skcipher_encrypt);
}
static void cryptd_skcipher_decrypt(struct crypto_async_request *base,
int err)
{
struct skcipher_request *req = skcipher_request_cast(base);
- struct cryptd_skcipher_request_ctx *rctx = skcipher_request_ctx(req);
- struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
- struct cryptd_skcipher_ctx *ctx = crypto_skcipher_ctx(tfm);
- struct skcipher_request *subreq = &rctx->req;
- struct crypto_skcipher *child = ctx->child;
+ struct skcipher_request *subreq;
- if (unlikely(err == -EINPROGRESS))
- goto out;
-
- skcipher_request_set_tfm(subreq, child);
- skcipher_request_set_callback(subreq, CRYPTO_TFM_REQ_MAY_SLEEP,
- NULL, NULL);
- skcipher_request_set_crypt(subreq, req->src, req->dst, req->cryptlen,
- req->iv);
-
- err = crypto_skcipher_decrypt(subreq);
-
- req->base.complete = rctx->complete;
+ subreq = cryptd_skcipher_prepare(req, err);
+ if (likely(subreq))
+ err = crypto_skcipher_decrypt(subreq);
-out:
- cryptd_skcipher_complete(req, err);
+ cryptd_skcipher_complete(req, err, cryptd_skcipher_decrypt);
}
static int cryptd_skcipher_enqueue(struct skcipher_request *req,
@@ -312,11 +312,14 @@ static int cryptd_skcipher_enqueue(struct skcipher_request *req,
{
struct cryptd_skcipher_request_ctx *rctx = skcipher_request_ctx(req);
struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
+ struct skcipher_request *subreq = &rctx->req;
struct cryptd_queue *queue;
queue = cryptd_get_queue(crypto_skcipher_tfm(tfm));
- rctx->complete = req->base.complete;
+ subreq->base.complete = req->base.complete;
+ subreq->base.data = req->base.data;
req->base.complete = compl;
+ req->base.data = req;
return cryptd_enqueue_request(queue, &req->base);
}
@@ -469,45 +472,63 @@ static int cryptd_hash_enqueue(struct ahash_request *req,
cryptd_get_queue(crypto_ahash_tfm(tfm));
rctx->complete = req->base.complete;
+ rctx->data = req->base.data;
req->base.complete = compl;
+ req->base.data = req;
return cryptd_enqueue_request(queue, &req->base);
}
-static void cryptd_hash_complete(struct ahash_request *req, int err)
+static struct shash_desc *cryptd_hash_prepare(struct ahash_request *req,
+ int err)
+{
+ struct cryptd_hash_request_ctx *rctx = ahash_request_ctx(req);
+
+ req->base.complete = rctx->complete;
+ req->base.data = rctx->data;
+
+ if (unlikely(err == -EINPROGRESS))
+ return NULL;
+
+ return &rctx->desc;
+}
+
+static void cryptd_hash_complete(struct ahash_request *req, int err,
+ crypto_completion_t complete)
{
struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
struct cryptd_hash_ctx *ctx = crypto_ahash_ctx(tfm);
- struct cryptd_hash_request_ctx *rctx = ahash_request_ctx(req);
int refcnt = refcount_read(&ctx->refcnt);
local_bh_disable();
- rctx->complete(&req->base, err);
+ ahash_request_complete(req, err);
local_bh_enable();
- if (err != -EINPROGRESS && refcnt && refcount_dec_and_test(&ctx->refcnt))
+ if (err == -EINPROGRESS) {
+ req->base.complete = complete;
+ req->base.data = req;
+ } else if (refcnt && refcount_dec_and_test(&ctx->refcnt))
crypto_free_ahash(tfm);
}
static void cryptd_hash_init(struct crypto_async_request *req_async, int err)
{
- struct cryptd_hash_ctx *ctx = crypto_tfm_ctx(req_async->tfm);
- struct crypto_shash *child = ctx->child;
struct ahash_request *req = ahash_request_cast(req_async);
- struct cryptd_hash_request_ctx *rctx = ahash_request_ctx(req);
- struct shash_desc *desc = &rctx->desc;
+ struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
+ struct cryptd_hash_ctx *ctx = crypto_ahash_ctx(tfm);
+ struct crypto_shash *child = ctx->child;
+ struct shash_desc *desc;
- if (unlikely(err == -EINPROGRESS))
+ desc = cryptd_hash_prepare(req, err);
+ if (unlikely(!desc))
goto out;
desc->tfm = child;
err = crypto_shash_init(desc);
- req->base.complete = rctx->complete;
-
out:
- cryptd_hash_complete(req, err);
+ cryptd_hash_complete(req, err, cryptd_hash_init);
}
static int cryptd_hash_init_enqueue(struct ahash_request *req)
@@ -518,19 +539,13 @@ static int cryptd_hash_init_enqueue(struct ahash_request *req)
static void cryptd_hash_update(struct crypto_async_request *req_async, int err)
{
struct ahash_request *req = ahash_request_cast(req_async);
- struct cryptd_hash_request_ctx *rctx;
-
- rctx = ahash_request_ctx(req);
-
- if (unlikely(err == -EINPROGRESS))
- goto out;
-
- err = shash_ahash_update(req, &rctx->desc);
+ struct shash_desc *desc;
- req->base.complete = rctx->complete;
+ desc = cryptd_hash_prepare(req, err);
+ if (likely(desc))
+ err = shash_ahash_update(req, desc);
-out:
- cryptd_hash_complete(req, err);
+ cryptd_hash_complete(req, err, cryptd_hash_update);
}
static int cryptd_hash_update_enqueue(struct ahash_request *req)
@@ -541,17 +556,13 @@ static int cryptd_hash_update_enqueue(struct ahash_request *req)
static void cryptd_hash_final(struct crypto_async_request *req_async, int err)
{
struct ahash_request *req = ahash_request_cast(req_async);
- struct cryptd_hash_request_ctx *rctx = ahash_request_ctx(req);
-
- if (unlikely(err == -EINPROGRESS))
- goto out;
-
- err = crypto_shash_final(&rctx->desc, req->result);
+ struct shash_desc *desc;
- req->base.complete = rctx->complete;
+ desc = cryptd_hash_prepare(req, err);
+ if (likely(desc))
+ err = crypto_shash_final(desc, req->result);
-out:
- cryptd_hash_complete(req, err);
+ cryptd_hash_complete(req, err, cryptd_hash_final);
}
static int cryptd_hash_final_enqueue(struct ahash_request *req)
@@ -562,17 +573,13 @@ static int cryptd_hash_final_enqueue(struct ahash_request *req)
static void cryptd_hash_finup(struct crypto_async_request *req_async, int err)
{
struct ahash_request *req = ahash_request_cast(req_async);
- struct cryptd_hash_request_ctx *rctx = ahash_request_ctx(req);
+ struct shash_desc *desc;
- if (unlikely(err == -EINPROGRESS))
- goto out;
-
- err = shash_ahash_finup(req, &rctx->desc);
+ desc = cryptd_hash_prepare(req, err);
+ if (likely(desc))
+ err = shash_ahash_finup(req, desc);
- req->base.complete = rctx->complete;
-
-out:
- cryptd_hash_complete(req, err);
+ cryptd_hash_complete(req, err, cryptd_hash_finup);
}
static int cryptd_hash_finup_enqueue(struct ahash_request *req)
@@ -582,23 +589,22 @@ static int cryptd_hash_finup_enqueue(struct ahash_request *req)
static void cryptd_hash_digest(struct crypto_async_request *req_async, int err)
{
- struct cryptd_hash_ctx *ctx = crypto_tfm_ctx(req_async->tfm);
- struct crypto_shash *child = ctx->child;
struct ahash_request *req = ahash_request_cast(req_async);
- struct cryptd_hash_request_ctx *rctx = ahash_request_ctx(req);
- struct shash_desc *desc = &rctx->desc;
+ struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
+ struct cryptd_hash_ctx *ctx = crypto_ahash_ctx(tfm);
+ struct crypto_shash *child = ctx->child;
+ struct shash_desc *desc;
- if (unlikely(err == -EINPROGRESS))
+ desc = cryptd_hash_prepare(req, err);
+ if (unlikely(!desc))
goto out;
desc->tfm = child;
err = shash_ahash_digest(req, desc);
- req->base.complete = rctx->complete;
-
out:
- cryptd_hash_complete(req, err);
+ cryptd_hash_complete(req, err, cryptd_hash_digest);
}
static int cryptd_hash_digest_enqueue(struct ahash_request *req)
@@ -711,20 +717,20 @@ static int cryptd_aead_setauthsize(struct crypto_aead *parent,
}
static void cryptd_aead_crypt(struct aead_request *req,
- struct crypto_aead *child,
- int err,
- int (*crypt)(struct aead_request *req))
+ struct crypto_aead *child, int err,
+ int (*crypt)(struct aead_request *req),
+ crypto_completion_t compl)
{
struct cryptd_aead_request_ctx *rctx;
struct aead_request *subreq;
struct cryptd_aead_ctx *ctx;
- crypto_completion_t compl;
struct crypto_aead *tfm;
int refcnt;
rctx = aead_request_ctx(req);
- compl = rctx->complete;
subreq = &rctx->req;
+ req->base.complete = subreq->base.complete;
+ req->base.data = subreq->base.data;
tfm = crypto_aead_reqtfm(req);
@@ -740,17 +746,18 @@ static void cryptd_aead_crypt(struct aead_request *req,
err = crypt( req );
- req->base.complete = compl;
-
out:
ctx = crypto_aead_ctx(tfm);
refcnt = refcount_read(&ctx->refcnt);
local_bh_disable();
- compl(&req->base, err);
+ aead_request_complete(req, err);
local_bh_enable();
- if (err != -EINPROGRESS && refcnt && refcount_dec_and_test(&ctx->refcnt))
+ if (err == -EINPROGRESS) {
+ req->base.complete = compl;
+ req->base.data = req;
+ } else if (refcnt && refcount_dec_and_test(&ctx->refcnt))
crypto_free_aead(tfm);
}
@@ -761,7 +768,8 @@ static void cryptd_aead_encrypt(struct crypto_async_request *areq, int err)
struct aead_request *req;
req = container_of(areq, struct aead_request, base);
- cryptd_aead_crypt(req, child, err, crypto_aead_alg(child)->encrypt);
+ cryptd_aead_crypt(req, child, err, crypto_aead_alg(child)->encrypt,
+ cryptd_aead_encrypt);
}
static void cryptd_aead_decrypt(struct crypto_async_request *areq, int err)
@@ -771,7 +779,8 @@ static void cryptd_aead_decrypt(struct crypto_async_request *areq, int err)
struct aead_request *req;
req = container_of(areq, struct aead_request, base);
- cryptd_aead_crypt(req, child, err, crypto_aead_alg(child)->decrypt);
+ cryptd_aead_crypt(req, child, err, crypto_aead_alg(child)->decrypt,
+ cryptd_aead_decrypt);
}
static int cryptd_aead_enqueue(struct aead_request *req,
@@ -780,9 +789,12 @@ static int cryptd_aead_enqueue(struct aead_request *req,
struct cryptd_aead_request_ctx *rctx = aead_request_ctx(req);
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
struct cryptd_queue *queue = cryptd_get_queue(crypto_aead_tfm(tfm));
+ struct aead_request *subreq = &rctx->req;
- rctx->complete = req->base.complete;
+ subreq->base.complete = req->base.complete;
+ subreq->base.data = req->base.data;
req->base.complete = compl;
+ req->base.data = req;
return cryptd_enqueue_request(queue, &req->base);
}
next prev parent reply other threads:[~2023-01-31 8:02 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-31 8:00 [PATCH 0/32] crypto: api - Prepare to change callback argument to void star Herbert Xu
2023-01-31 8:01 ` [PATCH 1/32] crypto: api - Add scaffolding to change completion function signature Herbert Xu
2023-02-01 16:41 ` Giovanni Cabiddu
2023-01-31 8:01 ` [PATCH 2/32] crypto: cryptd - Use subreq for AEAD Herbert Xu
2023-02-08 5:53 ` [v2 PATCH " Herbert Xu
2023-01-31 8:01 ` [PATCH 3/32] crypto: acompress - Use crypto_request_complete Herbert Xu
2023-02-01 16:45 ` Giovanni Cabiddu
2023-01-31 8:01 ` [PATCH 4/32] crypto: aead " Herbert Xu
2023-01-31 8:01 ` [PATCH 5/32] crypto: akcipher " Herbert Xu
2023-01-31 8:01 ` [PATCH 6/32] crypto: hash " Herbert Xu
2023-02-10 12:20 ` [v2 PATCH " Herbert Xu
2023-01-31 8:01 ` [PATCH 7/32] crypto: kpp " Herbert Xu
2023-01-31 8:02 ` [PATCH 8/32] crypto: skcipher " Herbert Xu
2023-01-31 8:02 ` [PATCH 9/32] crypto: engine " Herbert Xu
2023-01-31 8:02 ` [PATCH 10/32] crypto: rsa-pkcs1pad - Use akcipher_request_complete Herbert Xu
2023-01-31 8:02 ` Herbert Xu [this message]
2023-02-08 5:56 ` [v2 PATCH 11/32] crypto: cryptd - Use request_complete helpers Herbert Xu
2023-01-31 8:02 ` [PATCH 12/32] crypto: atmel " Herbert Xu
2023-01-31 8:02 ` [PATCH 13/32] crypto: artpec6 " Herbert Xu
2023-02-08 7:20 ` Jesper Nilsson
2023-01-31 8:02 ` [PATCH 14/32] crypto: bcm " Herbert Xu
2023-01-31 8:02 ` [PATCH 15/32] crypto: cpt " Herbert Xu
2023-01-31 8:02 ` [PATCH 16/32] crypto: nitrox " Herbert Xu
2023-01-31 8:02 ` [PATCH 17/32] crypto: ccp " Herbert Xu
2023-01-31 15:21 ` Tom Lendacky
2023-01-31 8:02 ` [PATCH 18/32] crypto: chelsio " Herbert Xu
2023-01-31 8:02 ` [PATCH 19/32] crypto: hifn_795x " Herbert Xu
2023-01-31 8:02 ` [PATCH 20/32] crypto: hisilicon " Herbert Xu
2023-01-31 8:02 ` [PATCH 21/32] crypto: img-hash " Herbert Xu
2023-01-31 8:02 ` [PATCH 22/32] crypto: safexcel " Herbert Xu
2023-01-31 8:02 ` [PATCH 23/32] crypto: ixp4xx " Herbert Xu
2023-01-31 8:02 ` [PATCH 24/32] crypto: marvell/cesa " Herbert Xu
2023-01-31 8:02 ` [PATCH 25/32] crypto: octeontx " Herbert Xu
2023-01-31 8:02 ` [PATCH 26/32] crypto: octeontx2 " Herbert Xu
2023-01-31 8:02 ` [PATCH 27/32] crypto: mxs-dcp " Herbert Xu
2023-01-31 8:02 ` [PATCH 28/32] crypto: qat " Herbert Xu
2023-02-01 16:57 ` Giovanni Cabiddu
2023-01-31 8:02 ` [PATCH 29/32] crypto: qce " Herbert Xu
2023-01-31 8:02 ` [PATCH 30/32] crypto: s5p-sss " Herbert Xu
2023-01-31 8:02 ` [PATCH 31/32] crypto: sahara " Herbert Xu
2023-01-31 8:02 ` [PATCH 32/32] crypto: talitos " Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E1pMlag-005viF-F5@formenos.hmeau.com \
--to=herbert@gondor.apana.org.au \
--cc=arno@natisbad.org \
--cc=atenart@kernel.org \
--cc=ayush.sawal@chelsio.com \
--cc=bbrezillon@kernel.org \
--cc=clabbe@baylibre.com \
--cc=gcherian@marvell.com \
--cc=giovanni.cabiddu@intel.com \
--cc=jesper.nilsson@axis.com \
--cc=john.allen@amd.com \
--cc=krzysztof.kozlowski@linaro.org \
--cc=lars.persson@axis.com \
--cc=linux-arm-kernel@axis.com \
--cc=linux-crypto@vger.kernel.org \
--cc=liulongfang@huawei.com \
--cc=qat-linux@intel.com \
--cc=raveendra.padasalagi@broadcom.com \
--cc=schalla@marvell.com \
--cc=thara.gopinath@gmail.com \
--cc=thomas.lendacky@amd.com \
--cc=tudor.ambarus@microchip.com \
--cc=vz@mleia.com \
--cc=yekai13@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).