All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next] blk-ioc: fix recursive spin_lock/unlock_irq() in ioc_clear_queue()
@ 2023-06-06  1:14 Yu Kuai
  2023-06-07  5:33 ` Christoph Hellwig
  2023-06-07 13:52 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Yu Kuai @ 2023-06-06  1:14 UTC (permalink / raw)
  To: hch, axboe, yukuai3
  Cc: linux-block, linux-kernel, yukuai1, yi.zhang, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

Recursive spin_lock/unlock_irq() is not safe, because spin_unlock_irq()
will enable irq unconditionally:

spin_lock_irq	queue_lock	-> disable irq
spin_lock_irq	ioc->lock
spin_unlock_irq ioc->lock	-> enable irq
/*
 * AA dead lock will be triggered if current context is preempted by irq,
 * and irq try to hold queue_lock again.
 */
spin_unlock_irq queue_lock

Fix this problem by using spin_lock/unlock() directly for 'ioc->lock'.

Fixes: 5a0ac57c48aa ("blk-ioc: protect ioc_destroy_icq() by 'queue_lock'")
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 block/blk-ioc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/blk-ioc.c b/block/blk-ioc.c
index d5db92e62c43..25dd4db11121 100644
--- a/block/blk-ioc.c
+++ b/block/blk-ioc.c
@@ -179,9 +179,9 @@ void ioc_clear_queue(struct request_queue *q)
 		 * Other context won't hold ioc lock to wait for queue_lock, see
 		 * details in ioc_release_fn().
 		 */
-		spin_lock_irq(&icq->ioc->lock);
+		spin_lock(&icq->ioc->lock);
 		ioc_destroy_icq(icq);
-		spin_unlock_irq(&icq->ioc->lock);
+		spin_unlock(&icq->ioc->lock);
 	}
 	spin_unlock_irq(&q->queue_lock);
 }
-- 
2.39.2


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

* Re: [PATCH -next] blk-ioc: fix recursive spin_lock/unlock_irq() in ioc_clear_queue()
  2023-06-06  1:14 [PATCH -next] blk-ioc: fix recursive spin_lock/unlock_irq() in ioc_clear_queue() Yu Kuai
@ 2023-06-07  5:33 ` Christoph Hellwig
  2023-06-07 13:52 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2023-06-07  5:33 UTC (permalink / raw)
  To: Yu Kuai
  Cc: hch, axboe, yukuai3, linux-block, linux-kernel, yi.zhang, yangerkun

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH -next] blk-ioc: fix recursive spin_lock/unlock_irq() in ioc_clear_queue()
  2023-06-06  1:14 [PATCH -next] blk-ioc: fix recursive spin_lock/unlock_irq() in ioc_clear_queue() Yu Kuai
  2023-06-07  5:33 ` Christoph Hellwig
@ 2023-06-07 13:52 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2023-06-07 13:52 UTC (permalink / raw)
  To: hch, yukuai3, Yu Kuai; +Cc: linux-block, linux-kernel, yi.zhang, yangerkun


On Tue, 06 Jun 2023 09:14:38 +0800, Yu Kuai wrote:
> Recursive spin_lock/unlock_irq() is not safe, because spin_unlock_irq()
> will enable irq unconditionally:
> 
> spin_lock_irq	queue_lock	-> disable irq
> spin_lock_irq	ioc->lock
> spin_unlock_irq ioc->lock	-> enable irq
> /*
>  * AA dead lock will be triggered if current context is preempted by irq,
>  * and irq try to hold queue_lock again.
>  */
> spin_unlock_irq queue_lock
> 
> [...]

Applied, thanks!

[1/1] blk-ioc: fix recursive spin_lock/unlock_irq() in ioc_clear_queue()
      commit: a7cfa0af0c88353b4eb59db5a2a0fbe35329b3f9

Best regards,
-- 
Jens Axboe




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

end of thread, other threads:[~2023-06-07 13:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-06  1:14 [PATCH -next] blk-ioc: fix recursive spin_lock/unlock_irq() in ioc_clear_queue() Yu Kuai
2023-06-07  5:33 ` Christoph Hellwig
2023-06-07 13:52 ` Jens Axboe

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.