Skip to contentSkip to conversation

blk-iocost: fix lockdep warning on blkcg->lock

PATCH Applied Ming Lei 3 participants 7 messages Aug 3, 2021 – Aug 10, 2021

Subsystems (2)
lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH 1/1 blk-iocost: fix lockdep warning on blkcg->lock

blkcg->lock depends on q->queue_lock which may depend on another driver lock required in irq context, one example is dm-thin:

	Chain exists of:
	  &pool->lock#3 --> &q->queue_lock --> &blkcg->lock
	 Possible interrupt unsafe locking scenario:

	       CPU0                    CPU1
	       ----                    ----
	  lock(&blkcg->lock);
	                               local_irq_disable();
	                               lock(&pool->lock#3);
	                               lock(&q->queue_lock);
	  <Interrupt>
	    lock(&pool->lock#3);

Fix the issue by using spin_lock_irq(&blkcg->lock) in ioc_weight_write().

---
 block/blk-iocost.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
block/blk-iocost.c +4 -4
index 5fac3757e6e0..0e56557cacf2 100644
@@ -3061,19 +3061,19 @@ static ssize_t ioc_weight_write(struct kernfs_open_file *of, char *buf,
 		if (v < CGROUP_WEIGHT_MIN || v > CGROUP_WEIGHT_MAX)
 			return -EINVAL;
 
-		spin_lock(&blkcg->lock);
+		spin_lock_irq(&blkcg->lock);
 		iocc->dfl_weight = v * WEIGHT_ONE;
 		hlist_for_each_entry(blkg, &blkcg->blkg_list, blkcg_node) {
 			struct ioc_gq *iocg = blkg_to_iocg(blkg);
 
 			if (iocg) {
-				spin_lock_irq(&iocg->ioc->lock);
+				spin_lock(&iocg->ioc->lock);
 				ioc_now(iocg->ioc, &now);
 				weight_updated(iocg, &now);
-				spin_unlock_irq(&iocg->ioc->lock);
+				spin_unlock(&iocg->ioc->lock);
 			}
 		}
-		spin_unlock(&blkcg->lock);
+		spin_unlock_irq(&blkcg->lock);
 
 		return nbytes;
 	}
Signature · 1 line
2.31.1
maintainer
#1 lore raw
Quoted 17 lines · Ming Lei

blkcg->lock depends on q->queue_lock which may depend on another driver lock required in irq context, one example is dm-thin:

	Chain exists of:
	  &pool->lock#3 --> &q->queue_lock --> &blkcg->lock
	 Possible interrupt unsafe locking scenario:

	       CPU0                    CPU1
	       ----                    ----
	  lock(&blkcg->lock);
	                               local_irq_disable();
	                               lock(&pool->lock#3);
	                               lock(&q->queue_lock);
	  <Interrupt>
	    lock(&pool->lock#3);
Quoted 1 line

Fix the issue by using spin_lock_irq(&blkcg->lock) in ioc_weight_write().

This looks fine to me for blk-iocost, but block/blk-cgroup.c:blkg_create() also looks like it gets the IRQ state of the same lock wrong?

Signature · 1 line
Jens Axboe
maintainer
#2 lore raw
Quoted 18 lines · Jens Axboe
Quoted 17 lines · Ming Lei

blkcg->lock depends on q->queue_lock which may depend on another driver lock required in irq context, one example is dm-thin:

	Chain exists of:
	  &pool->lock#3 --> &q->queue_lock --> &blkcg->lock
	 Possible interrupt unsafe locking scenario:

	       CPU0                    CPU1
	       ----                    ----
	  lock(&blkcg->lock);
	                               local_irq_disable();
	                               lock(&pool->lock#3);
	                               lock(&q->queue_lock);
	  <Interrupt>
	    lock(&pool->lock#3);
Quoted 4 lines
Quoted 1 line

Fix the issue by using spin_lock_irq(&blkcg->lock) in ioc_weight_write().

This looks fine to me for blk-iocost, but block/blk-cgroup.c:blkg_create() also looks like it gets the IRQ state of the same lock wrong?

Ah, that one is under the queue lock, so irqs are already disabled.

Signature · 1 line
Jens Axboe
author
#3 lore raw
In reply to Jens Axboe
Quoted 18 lines · Jens Axboe
Quoted 17 lines · Ming Lei

blkcg->lock depends on q->queue_lock which may depend on another driver lock required in irq context, one example is dm-thin:

	Chain exists of:
	  &pool->lock#3 --> &q->queue_lock --> &blkcg->lock
	 Possible interrupt unsafe locking scenario:

	       CPU0                    CPU1
	       ----                    ----
	  lock(&blkcg->lock);
	                               local_irq_disable();
	                               lock(&pool->lock#3);
	                               lock(&q->queue_lock);
	  <Interrupt>
	    lock(&pool->lock#3);
Quoted 4 lines
Quoted 1 line

Fix the issue by using spin_lock_irq(&blkcg->lock) in ioc_weight_write().

This looks fine to me for blk-iocost, but block/blk-cgroup.c:blkg_create() also looks like it gets the IRQ state of the same lock wrong?

blkg_create() is called with irq disabled in all three callers:
blkg_lookup_create(), blkg_conf_prep() and blkcg_init_queue().

Signature · 1 line
Ming
maintainer
#4 lore raw
Quoted 19 lines · Ming Lei
Quoted 18 lines · Jens Axboe
Quoted 17 lines · Ming Lei

blkcg->lock depends on q->queue_lock which may depend on another driver lock required in irq context, one example is dm-thin:

	Chain exists of:
	  &pool->lock#3 --> &q->queue_lock --> &blkcg->lock
	 Possible interrupt unsafe locking scenario:

	       CPU0                    CPU1
	       ----                    ----
	  lock(&blkcg->lock);
	                               local_irq_disable();
	                               lock(&pool->lock#3);
	                               lock(&q->queue_lock);
	  <Interrupt>
	    lock(&pool->lock#3);
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Fix the issue by using spin_lock_irq(&blkcg->lock) in ioc_weight_write().

This looks fine to me for blk-iocost, but block/blk-cgroup.c:blkg_create() also looks like it gets the IRQ state of the same lock wrong?

blkg_create() is called with irq disabled in all three callers:
blkg_lookup_create(), blkg_conf_prep() and blkcg_init_queue().

Yes I know, see email sent 1 min after the one you're replying to.

Signature · 1 line
Jens Axboe
maintainer Acked-by on v1 1/1
#5 lore raw
In reply to Ming Lei
Quoted 17 lines · Ming Lei

blkcg->lock depends on q->queue_lock which may depend on another driver lock required in irq context, one example is dm-thin:

	Chain exists of:
	  &pool->lock#3 --> &q->queue_lock --> &blkcg->lock
	 Possible interrupt unsafe locking scenario:

	       CPU0                    CPU1
	       ----                    ----
	  lock(&blkcg->lock);
	                               local_irq_disable();
	                               lock(&pool->lock#3);
	                               lock(&q->queue_lock);
	  <Interrupt>
	    lock(&pool->lock#3);
Quoted 6 lines

Fix the issue by using spin_lock_irq(&blkcg->lock) in ioc_weight_write().

Thanks.

Signature · 1 line
tejun
maintainer Applied
#6 lore raw
In reply to Ming Lei
Quoted 17 lines · Ming Lei

blkcg->lock depends on q->queue_lock which may depend on another driver lock required in irq context, one example is dm-thin:

	Chain exists of:
	  &pool->lock#3 --> &q->queue_lock --> &blkcg->lock
	 Possible interrupt unsafe locking scenario:

	       CPU0                    CPU1
	       ----                    ----
	  lock(&blkcg->lock);
	                               local_irq_disable();
	                               lock(&pool->lock#3);
	                               lock(&q->queue_lock);
	  <Interrupt>
	    lock(&pool->lock#3);
Quoted 1 line

Fix the issue by using spin_lock_irq(&blkcg->lock) in ioc_weight_write().

Applied, thanks.

Signature · 1 line
Jens Axboe