linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iocost: don't nest spin_lock_irq in ioc_weight_write()
@ 2019-10-31 10:53 Dan Carpenter
  2019-10-31 16:50 ` Tejun Heo
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Dan Carpenter @ 2019-10-31 10:53 UTC (permalink / raw)
  To: Jens Axboe, Tejun Heo; +Cc: linux-block, linux-kernel, kernel-janitors

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.

Fixes: 7caa47151ab2 ("blkcg: implement blk-iocost")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 block/blk-iocost.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/blk-iocost.c b/block/blk-iocost.c
index 2a3db80c1dce..a7ed434eae03 100644
--- a/block/blk-iocost.c
+++ b/block/blk-iocost.c
@@ -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;
-- 
2.20.1


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

* Re: [PATCH] iocost: don't nest spin_lock_irq in ioc_weight_write()
  2019-10-31 10:53 [PATCH] iocost: don't nest spin_lock_irq in ioc_weight_write() Dan Carpenter
@ 2019-10-31 16:50 ` Tejun Heo
  2019-10-31 17:38 ` Jens Axboe
  2019-11-01 15:39 ` Jeff Moyer
  2 siblings, 0 replies; 6+ messages in thread
From: Tejun Heo @ 2019-10-31 16:50 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Jens Axboe, linux-block, linux-kernel, kernel-janitors

On Thu, Oct 31, 2019 at 01:53:41PM +0300, Dan Carpenter wrote:
> 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.
> 
> Fixes: 7caa47151ab2 ("blkcg: implement blk-iocost")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Acked-by: Tejun Heo <tj@kernel.org>

Thanks.

-- 
tejun

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

* Re: [PATCH] iocost: don't nest spin_lock_irq in ioc_weight_write()
  2019-10-31 10:53 [PATCH] iocost: don't nest spin_lock_irq in ioc_weight_write() Dan Carpenter
  2019-10-31 16:50 ` Tejun Heo
@ 2019-10-31 17:38 ` Jens Axboe
  2019-11-01 15:39 ` Jeff Moyer
  2 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2019-10-31 17:38 UTC (permalink / raw)
  To: Dan Carpenter, Tejun Heo; +Cc: linux-block, linux-kernel, kernel-janitors

On 10/31/19 4:53 AM, Dan Carpenter wrote:
> 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.

Applied for 5.3, thanks.

-- 
Jens Axboe


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

* Re: [PATCH] iocost: don't nest spin_lock_irq in ioc_weight_write()
  2019-10-31 10:53 [PATCH] iocost: don't nest spin_lock_irq in ioc_weight_write() Dan Carpenter
  2019-10-31 16:50 ` Tejun Heo
  2019-10-31 17:38 ` Jens Axboe
@ 2019-11-01 15:39 ` Jeff Moyer
  2019-11-04 10:18   ` [PATCH] iocost: add a comment about locking " Dan Carpenter
  2 siblings, 1 reply; 6+ messages in thread
From: Jeff Moyer @ 2019-11-01 15:39 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Jens Axboe, Tejun Heo, linux-block, linux-kernel, kernel-janitors

Dan Carpenter <dan.carpenter@oracle.com> writes:

> 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.

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

>
> Fixes: 7caa47151ab2 ("blkcg: implement blk-iocost")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  block/blk-iocost.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/block/blk-iocost.c b/block/blk-iocost.c
> index 2a3db80c1dce..a7ed434eae03 100644
> --- a/block/blk-iocost.c
> +++ b/block/blk-iocost.c
> @@ -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;


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

* [PATCH] iocost: add a comment about locking in ioc_weight_write()
  2019-11-01 15:39 ` Jeff Moyer
@ 2019-11-04 10:18   ` Dan Carpenter
  2019-11-04 11:59     ` Jeff Moyer
  0 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2019-11-04 10:18 UTC (permalink / raw)
  To: Jens Axboe, Jeff Moyer; +Cc: linux-block, linux-kernel, kernel-janitors

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.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
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(+)

diff --git a/block/blk-iocost.c b/block/blk-iocost.c
index a7ed434eae03..c5a8703ca6aa 100644
--- a/block/blk-iocost.c
+++ b/block/blk-iocost.c
@@ -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;
 
-- 
2.20.1


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

* Re: [PATCH] iocost: add a comment about locking in ioc_weight_write()
  2019-11-04 10:18   ` [PATCH] iocost: add a comment about locking " Dan Carpenter
@ 2019-11-04 11:59     ` Jeff Moyer
  0 siblings, 0 replies; 6+ messages in thread
From: Jeff Moyer @ 2019-11-04 11:59 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: Jens Axboe, linux-block, linux-kernel, kernel-janitors

Dan Carpenter <dan.carpenter@oracle.com> writes:

> 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.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Reviewed-by: Jeff Moyer <jmoyer@redhat.com>

Thanks, Dan!

> ---
> 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(+)
>
> diff --git a/block/blk-iocost.c b/block/blk-iocost.c
> index a7ed434eae03..c5a8703ca6aa 100644
> --- a/block/blk-iocost.c
> +++ b/block/blk-iocost.c
> @@ -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;


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

end of thread, other threads:[~2019-11-04 11:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-31 10:53 [PATCH] iocost: don't nest spin_lock_irq in ioc_weight_write() Dan Carpenter
2019-10-31 16:50 ` Tejun Heo
2019-10-31 17:38 ` Jens Axboe
2019-11-01 15:39 ` Jeff Moyer
2019-11-04 10:18   ` [PATCH] iocost: add a comment about locking " Dan Carpenter
2019-11-04 11:59     ` Jeff Moyer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).