From 21c890363a204f37f3190707bc341b892ae8045e Mon Sep 17 00:00:00 2001
From: Sebastian Andrzej Siewior <>
Date: Thu, 26 Jul 2018 18:52:00 +0200
Subject: [PATCH 095/166] crypto: cryptd - add a lock instead

cryptd has a per-CPU lock which protected with local_bh_disable() and
Add an explicit spin_lock to make the locking context more obvious and
visible to lockdep. Since it is a per-CPU lock, there should be no lock
contention on the actual spinlock.
There is a small race-window where we could be migrated to another CPU
after the cpu_queue has been obtain. This is not a problem because the
actual ressource is protected by the spinlock.

Signed-off-by: Sebastian Andrzej Siewior <>
Signed-off-by: Thomas Gleixner <>
 crypto/cryptd.c |    2 ++
 1 file changed, 2 insertions(+)

Index: linux-5.15.13-rt26/crypto/cryptd.c
@ linux-5.15.13-rt26/crypto/cryptd.c:39 @ static struct workqueue_struct *cryptd_w
 struct cryptd_cpu_queue {
 	struct crypto_queue queue;
 	struct work_struct work;
+	spinlock_t qlock;
 struct cryptd_queue {
@ linux-5.15.13-rt26/crypto/cryptd.c:113 @ static int cryptd_init_queue(struct cryp
 		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);
+		spin_lock_init(&cpu_queue->qlock);
 	pr_info("cryptd: max_cpu_qlen set to %d\n", max_cpu_qlen);
 	return 0;