From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796285044; b=F1DvSwM+YwyQYqNCY2OGee977Et1hA3ZwfnHgi69yqk84FTZXcXEw4IgwzLGBM+bn0Ht OoWnUzOstGE7H13ddlGZ0a5S/A6OpTYHn0SbNG0onrQ6S6RW0e0yFlUjWtd+cQauwsBYq dfYduSOChTSdvZwCjjYaCd3BBdy3IPFUDxguYpsvi1rNC3VT0jGnBveCgzja8L9UKGO7A 2ALW1MbPGZvHehdVGKmI7CqW9L0vWDObBqfKhVbvK8v7ASQ5GuPLLpoPJ6jpfqDoU15R9 t8iGSn5r2aGh16XRO4aFNAd/uYQPmOHfI4UF66Ys87/gultGWWU6fUCfXXBSUBU/nCQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796285044; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=xvmIybO9kLekG2h+pqhaEcPTttwYow8M8GSIdsTdKi0=; b=ARF4Z7o/9zBRvtj7LQHyyJRIgRCwZtWxgvpk62xSfkYVLpiV5svwtzUAr2zrpSBe5gPK L1NwqFFNIjAbgU4wqvOtbOY7Kcz0XQDh2KkHNZ9JXmLU2HzAmOWO7rCZPgZiWXfRnNzrG rnaByZiUP9e43Jguz/nqB+xxHNXhk1EG9VZnyKG7rm724I/WmqG/0gttQ58VAiQyM81Jm 4xi0okhaQqHQf05YnbE0bzlfnAazx/qHW3FFclB1SiTlFCrwI30aj0DRU2UcGlM2Kl/+s LNTz/sRmPRVoxC5tmhsl5aesISkSQNlCFEy/0gz9x78ioPtyHI+L3L0HV05EQGfEKDw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=J6kmObvX; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9458A606A333 for ; Thu, 3 Dec 2026 08:04:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=J6kmObvX Received: by smtp.kernel.org (Postfix) with ESMTPSA id 343771F00896; Thu, 3 Dec 2026 08:04:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796285044; bh=xvmIybO9kLekG2h+pqhaEcPTttwYow8M8GSIdsTdKi0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=J6kmObvXHCsF2oMHz6OMHvl9yLRpPJaO1+AYCEnYHkjqZRkYlvd+VglfiDjuv2RNL 7MP3zi1RJsSGeJDGqER8qXlbcvsWf5QTaSV7LT26WOqg1ua1UWExBwWTR+aZ4h1+mc JeGfNEQttGf8R5BzLltN3TOj+G4VS847R3LSodOQOpQCCphfe91OvTjY+bOT9X1NqZ G0YRAEX/mZZXpbA4iJE+hUuB6mXHYu3SVvC9XFQeSxpOT2yRtquweMWkHAsRpnq3ZD TxxG46SWm7lzktyBgF+RDD5l6ZKTKRlBDrFkewXrBTSDgfA/ZwG9Tj2BxtQdpGUrq4 7gssc2ID0CuqA== From: Eric Biggers To: Herbert Xu , linux-crypto@vger.kernel.org Cc: Danny Tsen , Eric Biggers Subject: [PATCH 3/5] crypto: cryptd - Remove pointless reference count Date: Thu, 3 Dec 2026 00:03:31 -0800 Message-ID: <20261203080333.145409-4-ebiggers@kernel.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261203080333.145409-1-ebiggers@kernel.org> References: <20261203080333.145409-1-ebiggers@kernel.org> X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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 #include #include -#include #include #include #include @@ -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