* [PATCH] blk-iocost: fix lockdep warning on blkcg->lock
@ 2021-08-03 7:06 Ming Lei
2021-08-03 13:02 ` Jens Axboe
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Ming Lei @ 2021-08-03 7:06 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-block, Ming Lei, Tejun Heo, Bruno Goncalves
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().
Cc: Tejun Heo <tj@kernel.org>
Reported-by: Bruno Goncalves <bgoncalv@redhat.com>
Link: https://lore.kernel.org/linux-block/CA+QYu4rzz6079ighEanS3Qq_Dmnczcf45ZoJoHKVLVATTo1e4Q@mail.gmail.com/T/#u
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
block/blk-iocost.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/block/blk-iocost.c b/block/blk-iocost.c
index 5fac3757e6e0..0e56557cacf2 100644
--- a/block/blk-iocost.c
+++ b/block/blk-iocost.c
@@ -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;
}
--
2.31.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] blk-iocost: fix lockdep warning on blkcg->lock
2021-08-03 7:06 [PATCH] blk-iocost: fix lockdep warning on blkcg->lock Ming Lei
@ 2021-08-03 13:02 ` Jens Axboe
2021-08-03 13:03 ` Jens Axboe
2021-08-04 1:25 ` Ming Lei
2021-08-09 22:40 ` Tejun Heo
2021-08-10 2:00 ` Jens Axboe
2 siblings, 2 replies; 7+ messages in thread
From: Jens Axboe @ 2021-08-03 13:02 UTC (permalink / raw)
To: Ming Lei; +Cc: linux-block, Tejun Heo, Bruno Goncalves
On 8/3/21 1:06 AM, Ming Lei wrote:
> 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().
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?
--
Jens Axboe
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] blk-iocost: fix lockdep warning on blkcg->lock
2021-08-03 13:02 ` Jens Axboe
@ 2021-08-03 13:03 ` Jens Axboe
2021-08-04 1:25 ` Ming Lei
1 sibling, 0 replies; 7+ messages in thread
From: Jens Axboe @ 2021-08-03 13:03 UTC (permalink / raw)
To: Ming Lei; +Cc: linux-block, Tejun Heo, Bruno Goncalves
On 8/3/21 7:02 AM, Jens Axboe wrote:
> On 8/3/21 1:06 AM, Ming Lei wrote:
>> 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().
>
> 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.
--
Jens Axboe
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] blk-iocost: fix lockdep warning on blkcg->lock
2021-08-03 13:02 ` Jens Axboe
2021-08-03 13:03 ` Jens Axboe
@ 2021-08-04 1:25 ` Ming Lei
2021-08-04 1:34 ` Jens Axboe
1 sibling, 1 reply; 7+ messages in thread
From: Ming Lei @ 2021-08-04 1:25 UTC (permalink / raw)
To: Jens Axboe; +Cc: linux-block, Tejun Heo, Bruno Goncalves
On Tue, Aug 03, 2021 at 07:02:28AM -0600, Jens Axboe wrote:
> On 8/3/21 1:06 AM, Ming Lei wrote:
> > 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().
>
> 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().
--
Ming
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] blk-iocost: fix lockdep warning on blkcg->lock
2021-08-04 1:25 ` Ming Lei
@ 2021-08-04 1:34 ` Jens Axboe
0 siblings, 0 replies; 7+ messages in thread
From: Jens Axboe @ 2021-08-04 1:34 UTC (permalink / raw)
To: Ming Lei; +Cc: linux-block, Tejun Heo, Bruno Goncalves
On 8/3/21 7:25 PM, Ming Lei wrote:
> On Tue, Aug 03, 2021 at 07:02:28AM -0600, Jens Axboe wrote:
>> On 8/3/21 1:06 AM, Ming Lei wrote:
>>> 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().
>>
>> 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.
--
Jens Axboe
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] blk-iocost: fix lockdep warning on blkcg->lock
2021-08-03 7:06 [PATCH] blk-iocost: fix lockdep warning on blkcg->lock Ming Lei
2021-08-03 13:02 ` Jens Axboe
@ 2021-08-09 22:40 ` Tejun Heo
2021-08-10 2:00 ` Jens Axboe
2 siblings, 0 replies; 7+ messages in thread
From: Tejun Heo @ 2021-08-09 22:40 UTC (permalink / raw)
To: Ming Lei; +Cc: Jens Axboe, linux-block, Bruno Goncalves
On Tue, Aug 03, 2021 at 03:06:08PM +0800, Ming Lei wrote:
> 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().
>
> Cc: Tejun Heo <tj@kernel.org>
> Reported-by: Bruno Goncalves <bgoncalv@redhat.com>
> Link: https://lore.kernel.org/linux-block/CA+QYu4rzz6079ighEanS3Qq_Dmnczcf45ZoJoHKVLVATTo1e4Q@mail.gmail.com/T/#u
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
Acked-by: Tejun Heo <tj@kernel.org>
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] blk-iocost: fix lockdep warning on blkcg->lock
2021-08-03 7:06 [PATCH] blk-iocost: fix lockdep warning on blkcg->lock Ming Lei
2021-08-03 13:02 ` Jens Axboe
2021-08-09 22:40 ` Tejun Heo
@ 2021-08-10 2:00 ` Jens Axboe
2 siblings, 0 replies; 7+ messages in thread
From: Jens Axboe @ 2021-08-10 2:00 UTC (permalink / raw)
To: Ming Lei; +Cc: linux-block, Tejun Heo, Bruno Goncalves
On 8/3/21 1:06 AM, Ming Lei wrote:
> 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().
Applied, thanks.
--
Jens Axboe
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-08-10 2:00 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-03 7:06 [PATCH] blk-iocost: fix lockdep warning on blkcg->lock Ming Lei
2021-08-03 13:02 ` Jens Axboe
2021-08-03 13:03 ` Jens Axboe
2021-08-04 1:25 ` Ming Lei
2021-08-04 1:34 ` Jens Axboe
2021-08-09 22:40 ` Tejun Heo
2021-08-10 2:00 ` 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.