iocost: don't nest spin_lock_irq in ioc_weight_write()
Subsystems (3)
PATCH 1/1 iocost: don't nest spin_lock_irq in ioc_weight_write()
This code causes a static analysis warning:
block/blk-iocost.c:2113 ioc_weight_write() error: double lock 'irq'
We disable IRQs in blkg_conf_prep() and re-enable them in blkg_conf_finish(). IRQ disable/enable should not be nested because that means the IRQs will be enabled at the first unlock instead of the second one.
--- block/blk-iocost.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
block/blk-iocost.c +2 -2
@@ -2110,10 +2110,10 @@ static ssize_t ioc_weight_write(struct kernfs_open_file *of, char *buf, goto einval; } -spin_lock_irq (&iocg->ioc->lock); +spin_lock (&iocg->ioc->lock); iocg->cfg_weight = v;weight_updated (iocg); -spin_unlock_irq (&iocg->ioc->lock); +spin_unlock (&iocg->ioc->lock);blkg_conf_finish (&ctx);return nbytes;
Signature · 1 line
2.20.1
Quoted 11 lines · Dan Carpenter
This code causes a static analysis warning:
block/blk-iocost.c:2113ioc_weight_write()error: double lock 'irq'We disable IRQs in
blkg_conf_prep()and re-enable them inblkg_conf_finish(). IRQ disable/enable should not be nested because that means the IRQs will be enabled at the first unlock instead of the second one.Fixes 7caa47151ab2 ("blkcg: implement blk-iocost")Signed-off-by Dan Carpenter <[email protected]>
Thanks.
Signature · 1 line
tejun
Jens Axboe
maintainerQuoted 8 lines · Dan Carpenter
This code causes a static analysis warning:
block/blk-iocost.c:2113ioc_weight_write()error: double lock 'irq'We disable IRQs in
blkg_conf_prep()and re-enable them inblkg_conf_finish(). IRQ disable/enable should not be nested because that means the IRQs will be enabled at the first unlock instead of the second one.
Applied for 5.3, thanks.
Signature · 1 line
Jens Axboe
Quoted 8 lines · Dan Carpenter
This code causes a static analysis warning:
block/blk-iocost.c:2113ioc_weight_write()error: double lock 'irq'We disable IRQs in
blkg_conf_prep()and re-enable them inblkg_conf_finish(). IRQ disable/enable should not be nested because that means the IRQs will be enabled at the first unlock instead of the second one.
Can you please also add a comment stating that irqs were disabled in blkg_conf_prep? Otherwise future readers will surely be scratching their heads trying to figure out why we do things two different ways in the same function.
Thanks!
Jeff
Quoted 24 lines
Fixes 7caa47151ab2 ("blkcg: implement blk-iocost")Signed-off-by Dan Carpenter <[email protected]>--- block/blk-iocost.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)block/blk-iocost.c +2
-2@@ -2110,10 +2110,10 @@ static ssize_t ioc_weight_write(struct kernfs_open_file *of, char *buf, goto einval; } -spin_lock_irq (&iocg->ioc->lock); +spin_lock (&iocg->ioc->lock); iocg->cfg_weight = v;weight_updated (iocg); -spin_unlock_irq (&iocg->ioc->lock); +spin_unlock (&iocg->ioc->lock);blkg_conf_finish (&ctx);return nbytes;
PATCH 1/1 iocost: add a comment about locking in ioc_weight_write()
It wasn't very clear that blkg_conf_prep() disables IRQ and that they are enabled in blkg_conf_finish() so this patch adds a comment about it.
---
I don't know if it's too late to fold this in with the previous patch?
block/blk-iocost.c | 2 ++ 1 file changed, 2 insertions(+)
block/blk-iocost.c +2 -0
@@ -2095,6 +2095,7 @@ static ssize_t ioc_weight_write(struct kernfs_open_file *of, char *buf,return nbytes; } +/* blkg_conf_prep() takes the q->queue_lock and disables IRQs */ ret =blkg_conf_prep (blkcg, &blkcg_policy_iocost, buf, &ctx);if (ret)return ret;
@@ -2115,6 +2116,7 @@ static ssize_t ioc_weight_write(struct kernfs_open_file *of, char *buf,weight_updated (iocg);spin_unlock (&iocg->ioc->lock); +/* blkg_conf_finish() unlocks the q->queue_lock and enables IRQs */ blkg_conf_finish (&ctx);return nbytes;
Signature · 1 line
2.20.1
Re: [PATCH] iocost: add a comment about locking in ioc_weight_write()
Quoted 4 lines · Dan Carpenter
It wasn't very clear that
blkg_conf_prep()disables IRQ and that they are enabled inblkg_conf_finish()so this patch adds a comment about it.Signed-off-by Dan Carpenter <[email protected]>
Thanks, Dan!
Quoted 25 lines
---
I don't know if it's too late to fold this in with the previous patch?block/blk-iocost.c | 2 ++ 1 file changed, 2 insertions(+)block/blk-iocost.c +2
-0@@ -2095,6 +2095,7 @@ static ssize_t ioc_weight_write(struct kernfs_open_file *of, char *buf,return nbytes; } +/* blkg_conf_prep() takes the q->queue_lock and disables IRQs */ ret =blkg_conf_prep (blkcg, &blkcg_policy_iocost, buf, &ctx);if (ret)return ret;@@ -2115,6 +2116,7 @@ static ssize_t ioc_weight_write(struct kernfs_open_file *of, char *buf,weight_updated (iocg);spin_unlock (&iocg->ioc->lock); +/* blkg_conf_finish() unlocks the q->queue_lock and enables IRQs */ blkg_conf_finish (&ctx);return nbytes;