From: Heiko Stuebner Date: Sat, 28 Nov 2015 12:27:48 +0000 (+0100) Subject: crypto: rockchip - fix possible deadlock X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=ac7c8e6b6dc959d285382c7e9cdfe608205f0c68;p=linux-beck.git crypto: rockchip - fix possible deadlock Lockdep warns about a possible deadlock resulting from the use of regular spin_locks: ================================= [ INFO: inconsistent lock state ] 4.4.0-rc2+ #2724 Not tainted --------------------------------- inconsistent {SOFTIRQ-ON-W} -> {IN-SOFTIRQ-W} usage. ksoftirqd/0/3 [HC0[0]:SC1[1]:HE1:SE0] takes: (&(&crypto_info->lock)->rlock){+.?...}, at: [] rk_crypto_tasklet_cb+0x24/0xb4 [rk_crypto] {SOFTIRQ-ON-W} state was registered at: [] lock_acquire+0x178/0x218 [] _raw_spin_lock+0x54/0x64 [] rk_handle_req+0x7c/0xbc [rk_crypto] [] rk_des_ecb_encrypt+0x2c/0x30 [rk_crypto] [] rk_aes_ecb_encrypt+0x18/0x1c [rk_crypto] [] skcipher_encrypt_ablkcipher+0x64/0x68 [] __test_skcipher+0x2a8/0x8dc [] test_skcipher+0x38/0xc4 [] alg_test_skcipher+0x90/0xb0 [] alg_test+0x1e8/0x280 [] cryptomgr_test+0x34/0x54 [] kthread+0xf4/0x10c [] ret_from_fork+0x14/0x24 irq event stamp: 10672 hardirqs last enabled at (10672): [] tasklet_action+0x48/0x104 hardirqs last disabled at (10671): [] tasklet_action+0x20/0x104 softirqs last enabled at (10658): [] __do_softirq+0x358/0x49c softirqs last disabled at (10669): [] run_ksoftirqd+0x40/0x80 other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(&(&crypto_info->lock)->rlock); lock(&(&crypto_info->lock)->rlock); *** DEADLOCK *** Fix this by moving to irq-disabling spinlocks. Signed-off-by: Heiko Stuebner Signed-off-by: Herbert Xu --- diff --git a/drivers/crypto/rockchip/rk3288_crypto.c b/drivers/crypto/rockchip/rk3288_crypto.c index 6b72f8d2e643..da9c73dce4af 100644 --- a/drivers/crypto/rockchip/rk3288_crypto.c +++ b/drivers/crypto/rockchip/rk3288_crypto.c @@ -190,12 +190,13 @@ static void rk_crypto_tasklet_cb(unsigned long data) { struct rk_crypto_info *dev = (struct rk_crypto_info *)data; struct crypto_async_request *async_req, *backlog; + unsigned long flags; int err = 0; - spin_lock(&dev->lock); + spin_lock_irqsave(&dev->lock, flags); backlog = crypto_get_backlog(&dev->queue); async_req = crypto_dequeue_request(&dev->queue); - spin_unlock(&dev->lock); + spin_unlock_irqrestore(&dev->lock, flags); if (!async_req) { dev_err(dev->dev, "async_req is NULL !!\n"); return; diff --git a/drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c b/drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c index 4a8f9def0c8b..d98b681f6c06 100644 --- a/drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c +++ b/drivers/crypto/rockchip/rk3288_crypto_ablkcipher.c @@ -24,6 +24,7 @@ static void rk_crypto_complete(struct rk_crypto_info *dev, int err) static int rk_handle_req(struct rk_crypto_info *dev, struct ablkcipher_request *req) { + unsigned long flags; int err; if (!IS_ALIGNED(req->nbytes, dev->align_size)) @@ -38,9 +39,9 @@ static int rk_handle_req(struct rk_crypto_info *dev, dev->aligned = 1; dev->ablk_req = req; - spin_lock(&dev->lock); + spin_lock_irqsave(&dev->lock, flags); err = ablkcipher_enqueue_request(&dev->queue, req); - spin_unlock(&dev->lock); + spin_unlock_irqrestore(&dev->lock, flags); tasklet_schedule(&dev->crypto_tasklet); return err; } @@ -267,12 +268,13 @@ static int rk_set_data_start(struct rk_crypto_info *dev) static int rk_ablk_start(struct rk_crypto_info *dev) { + unsigned long flags; int err; - spin_lock(&dev->lock); + spin_lock_irqsave(&dev->lock, flags); rk_ablk_hw_init(dev); err = rk_set_data_start(dev); - spin_unlock(&dev->lock); + spin_unlock_irqrestore(&dev->lock, flags); return err; }