From: Eric Biggers <ebiggers@kernel.org>
To: Herbert Xu <herbert@gondor.apana.org.au>, linux-crypto@vger.kernel.org
Cc: Danny Tsen <dtsen@linux.ibm.com>, Eric Biggers <ebiggers@kernel.org>
Subject: [PATCH 3/5] crypto: cryptd - Remove pointless reference count
Date: Thu, 3 Dec 2026 00:03:31 -0800 [thread overview]
Message-ID: <20261203080333.145409-4-ebiggers@kernel.org> (raw)
In-Reply-To: <20261203080333.145409-1-ebiggers@kernel.org>
The per-tfm refcnt in cryptd was originally added to allow crypto_simd
(originally ablk_helper) to check whether a cryptd tfm had any requests
queued so that synchronous softirq execution wouldn't reorder ahead of
queued requests. To support this, cryptd_alloc_*() initialized refcnt
to 1, cryptd_enqueue_request() incremented it, request completion
decremented it, and cryptd_free_*() dropped the initial reference so the
tfm would be freed once all queued requests completed.
However, with the last remaining cryptd_{alloc,queued,free}_*() helpers
now removed, refcnt is never initialized to a non-zero value, and all of
the refcnt handling is dead code. Remove it.
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
crypto/cryptd.c | 43 +++++--------------------------------------
1 file changed, 5 insertions(+), 38 deletions(-)
diff --git a/crypto/cryptd.c b/crypto/cryptd.c
index 9c6a7c14f0e43..29dde50f93603 100644
--- a/crypto/cryptd.c
+++ b/crypto/cryptd.c
@@ -15,7 +15,6 @@
#include <crypto/internal/hash.h>
#include <crypto/internal/aead.h>
#include <crypto/internal/skcipher.h>
-#include <linux/refcount.h>
#include <linux/err.h>
#include <linux/init.h>
#include <linux/kernel.h>
@@ -67,7 +66,6 @@ struct aead_instance_ctx {
};
struct cryptd_skcipher_ctx {
- refcount_t refcnt;
struct crypto_skcipher *child;
};
@@ -76,7 +74,6 @@ struct cryptd_skcipher_request_ctx {
};
struct cryptd_hash_ctx {
- refcount_t refcnt;
struct crypto_shash *child;
};
@@ -87,7 +84,6 @@ struct cryptd_hash_request_ctx {
};
struct cryptd_aead_ctx {
- refcount_t refcnt;
struct crypto_aead *child;
};
@@ -133,26 +129,15 @@ static int cryptd_enqueue_request(struct cryptd_queue *queue,
{
int err;
struct cryptd_cpu_queue *cpu_queue;
- refcount_t *refcnt;
local_bh_disable();
local_lock_nested_bh(&queue->cpu_queue->bh_lock);
cpu_queue = this_cpu_ptr(queue->cpu_queue);
err = crypto_enqueue_request(&cpu_queue->queue, request);
- refcnt = crypto_tfm_ctx(request->tfm);
+ if (err != -ENOSPC)
+ queue_work_on(smp_processor_id(), cryptd_wq, &cpu_queue->work);
- if (err == -ENOSPC)
- goto out;
-
- queue_work_on(smp_processor_id(), cryptd_wq, &cpu_queue->work);
-
- if (!refcount_read(refcnt))
- goto out;
-
- refcount_inc(refcnt);
-
-out:
local_unlock_nested_bh(&queue->cpu_queue->bh_lock);
local_bh_enable();
@@ -272,10 +257,7 @@ static void cryptd_skcipher_complete(struct skcipher_request *req, int err,
crypto_completion_t complete)
{
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;
- int refcnt = refcount_read(&ctx->refcnt);
local_bh_disable();
skcipher_request_complete(req, err);
@@ -286,8 +268,7 @@ static void cryptd_skcipher_complete(struct skcipher_request *req, int err,
subreq->base.data = req->base.data;
req->base.complete = complete;
req->base.data = req;
- } else if (refcnt && refcount_dec_and_test(&ctx->refcnt))
- crypto_free_skcipher(tfm);
+ }
}
static void cryptd_skcipher_encrypt(void *data, int err)
@@ -503,10 +484,6 @@ static struct shash_desc *cryptd_hash_prepare(struct ahash_request *req,
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);
- int refcnt = refcount_read(&ctx->refcnt);
-
local_bh_disable();
ahash_request_complete(req, err);
local_bh_enable();
@@ -514,8 +491,7 @@ static void cryptd_hash_complete(struct ahash_request *req, int err,
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(void *data, int err)
@@ -731,17 +707,12 @@ static void cryptd_aead_crypt(struct aead_request *req,
{
struct cryptd_aead_request_ctx *rctx;
struct aead_request *subreq;
- struct cryptd_aead_ctx *ctx;
- struct crypto_aead *tfm;
- int refcnt;
rctx = aead_request_ctx(req);
subreq = &rctx->req;
req->base.complete = subreq->base.complete;
req->base.data = subreq->base.data;
- tfm = crypto_aead_reqtfm(req);
-
if (unlikely(err == -EINPROGRESS))
goto out;
@@ -755,9 +726,6 @@ static void cryptd_aead_crypt(struct aead_request *req,
err = crypt(subreq);
out:
- ctx = crypto_aead_ctx(tfm);
- refcnt = refcount_read(&ctx->refcnt);
-
local_bh_disable();
aead_request_complete(req, err);
local_bh_enable();
@@ -767,8 +735,7 @@ static void cryptd_aead_crypt(struct aead_request *req,
subreq->base.data = req->base.data;
req->base.complete = compl;
req->base.data = req;
- } else if (refcnt && refcount_dec_and_test(&ctx->refcnt))
- crypto_free_aead(tfm);
+ }
}
static void cryptd_aead_encrypt(void *data, int err)
--
2.56.1
next prev parent reply other threads:[~2026-12-03 8:04 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 8:03 [PATCH 0/5] crypto: Remove crypto_simd and clean up cryptd Eric Biggers
2026-12-03 8:03 ` [PATCH 1/5] crypto: simd - Remove unused crypto_simd module Eric Biggers
2026-12-03 8:03 ` [PATCH 2/5] crypto: cryptd - Remove unused AEAD functions Eric Biggers
2026-12-03 8:03 ` Eric Biggers [this message]
2026-12-03 8:03 ` [PATCH 4/5] crypto: cryptd - Remove unused CRYPTO_ALG_INTERNAL support Eric Biggers
2026-12-03 8:03 ` [PATCH 5/5] crypto: cryptd - Remove pointless per-instance queue pointer Eric Biggers
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=20261203080333.145409-4-ebiggers@kernel.org \
--to=ebiggers@kernel.org \
--cc=dtsen@linux.ibm.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.