linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cryptd: Use nested-BH locking for cryptd_cpu_queue
@ 2025-07-01  6:09 Sebastian Andrzej Siewior
  2025-07-18 10:57 ` Herbert Xu
  0 siblings, 1 reply; 2+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-07-01  6:09 UTC (permalink / raw)
  To: linux-crypto, linux-rt-devel
  Cc: Herbert Xu, David S. Miller, Clark Williams, Steven Rostedt,
	Thomas Gleinxer

cryptd_queue::cryptd_cpu_queue is a per-CPU variable and relies on
disabled BH for its locking. Without per-CPU locking in
local_bh_disable() on PREEMPT_RT this data structure requires explicit
locking.

Add a local_lock_t to the struct cryptd_cpu_queue and use
local_lock_nested_bh() for locking. This change adds only lockdep
coverage and does not alter the functional behaviour for !PREEMPT_RT.

Cc: "David S. Miller" <davem@davemloft.net>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: linux-crypto@vger.kernel.org
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---

This patch requires a prerequisite for __local_lock_nested_bh() which
has been made available at
   git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git local-lock-for-net

It can be pulled in so that the crypto bits are independent of the TIP
tree.

 crypto/cryptd.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/crypto/cryptd.c b/crypto/cryptd.c
index 5bb6f8d88cc2e..efff54e707cb5 100644
--- a/crypto/cryptd.c
+++ b/crypto/cryptd.c
@@ -34,6 +34,7 @@ MODULE_PARM_DESC(cryptd_max_cpu_qlen, "Set cryptd Max queue depth");
 static struct workqueue_struct *cryptd_wq;
 
 struct cryptd_cpu_queue {
+	local_lock_t bh_lock;
 	struct crypto_queue queue;
 	struct work_struct work;
 };
@@ -110,6 +111,7 @@ static int cryptd_init_queue(struct cryptd_queue *queue,
 		cpu_queue = per_cpu_ptr(queue->cpu_queue, cpu);
 		crypto_init_queue(&cpu_queue->queue, max_cpu_qlen);
 		INIT_WORK(&cpu_queue->work, cryptd_queue_worker);
+		local_lock_init(&cpu_queue->bh_lock);
 	}
 	pr_info("cryptd: max_cpu_qlen set to %d\n", max_cpu_qlen);
 	return 0;
@@ -135,6 +137,7 @@ static int cryptd_enqueue_request(struct cryptd_queue *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);
 
@@ -151,6 +154,7 @@ static int cryptd_enqueue_request(struct cryptd_queue *queue,
 	refcount_inc(refcnt);
 
 out:
+	local_unlock_nested_bh(&queue->cpu_queue->bh_lock);
 	local_bh_enable();
 
 	return err;
@@ -169,8 +173,10 @@ static void cryptd_queue_worker(struct work_struct *work)
 	 * Only handle one request at a time to avoid hogging crypto workqueue.
 	 */
 	local_bh_disable();
+	__local_lock_nested_bh(&cpu_queue->bh_lock);
 	backlog = crypto_get_backlog(&cpu_queue->queue);
 	req = crypto_dequeue_request(&cpu_queue->queue);
+	__local_unlock_nested_bh(&cpu_queue->bh_lock);
 	local_bh_enable();
 
 	if (!req)
-- 
2.50.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] cryptd: Use nested-BH locking for cryptd_cpu_queue
  2025-07-01  6:09 [PATCH] cryptd: Use nested-BH locking for cryptd_cpu_queue Sebastian Andrzej Siewior
@ 2025-07-18 10:57 ` Herbert Xu
  0 siblings, 0 replies; 2+ messages in thread
From: Herbert Xu @ 2025-07-18 10:57 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: linux-crypto, linux-rt-devel, David S. Miller, Clark Williams,
	Steven Rostedt, Thomas Gleinxer

On Tue, Jul 01, 2025 at 08:09:36AM +0200, Sebastian Andrzej Siewior wrote:
> cryptd_queue::cryptd_cpu_queue is a per-CPU variable and relies on
> disabled BH for its locking. Without per-CPU locking in
> local_bh_disable() on PREEMPT_RT this data structure requires explicit
> locking.
> 
> Add a local_lock_t to the struct cryptd_cpu_queue and use
> local_lock_nested_bh() for locking. This change adds only lockdep
> coverage and does not alter the functional behaviour for !PREEMPT_RT.
> 
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Herbert Xu <herbert@gondor.apana.org.au>
> Cc: linux-crypto@vger.kernel.org
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
> 
> This patch requires a prerequisite for __local_lock_nested_bh() which
> has been made available at
>    git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git local-lock-for-net
> 
> It can be pulled in so that the crypto bits are independent of the TIP
> tree.
> 
>  crypto/cryptd.c | 6 ++++++
>  1 file changed, 6 insertions(+)

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-07-18 10:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-01  6:09 [PATCH] cryptd: Use nested-BH locking for cryptd_cpu_queue Sebastian Andrzej Siewior
2025-07-18 10:57 ` Herbert Xu

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).