LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] block: don't decrement flush request refcount if it's state is idle in flush_end_io()
@ 2021-08-08  7:03 Yu Kuai
  2021-08-08  8:44 ` Ming Lei
  2021-08-13  9:40 ` yukuai (C)
  0 siblings, 2 replies; 4+ messages in thread
From: Yu Kuai @ 2021-08-08  7:03 UTC (permalink / raw)
  To: axboe; +Cc: linux-block, linux-kernel, yukuai3, yi.zhang

flush_end_io() currently decrement request refcount unconditionally.
However, it's possible that the request is already idle and it's
refcount is zero since that flush_end_io() can be called concurrently.

For example, nbd_clear_que() can be called concurrently with normal
io completion or io timeout.

Thus check idle before decrement to avoid refcount_t underflow
warning.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
 block/blk-flush.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/block/blk-flush.c b/block/blk-flush.c
index 1002f6c58181..9b65dc43702c 100644
--- a/block/blk-flush.c
+++ b/block/blk-flush.c
@@ -222,7 +222,8 @@ static void flush_end_io(struct request *flush_rq, blk_status_t error)
 	/* release the tag's ownership to the req cloned from */
 	spin_lock_irqsave(&fq->mq_flush_lock, flags);
 
-	if (!refcount_dec_and_test(&flush_rq->ref)) {
+	if (blk_mq_rq_state(flush_rq) == MQ_RQ_IDLE ||
+	    !refcount_dec_and_test(&flush_rq->ref)) {
 		fq->rq_status = error;
 		spin_unlock_irqrestore(&fq->mq_flush_lock, flags);
 		return;
-- 
2.31.1


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

* Re: [PATCH] block: don't decrement flush request refcount if it's state is idle in flush_end_io()
  2021-08-08  7:03 [PATCH] block: don't decrement flush request refcount if it's state is idle in flush_end_io() Yu Kuai
@ 2021-08-08  8:44 ` Ming Lei
  2021-08-13  9:40 ` yukuai (C)
  1 sibling, 0 replies; 4+ messages in thread
From: Ming Lei @ 2021-08-08  8:44 UTC (permalink / raw)
  To: Yu Kuai; +Cc: axboe, linux-block, linux-kernel, yi.zhang

On Sun, Aug 08, 2021 at 03:03:30PM +0800, Yu Kuai wrote:
> flush_end_io() currently decrement request refcount unconditionally.
> However, it's possible that the request is already idle and it's
> refcount is zero since that flush_end_io() can be called concurrently.
> 
> For example, nbd_clear_que() can be called concurrently with normal
> io completion or io timeout.
> 
> Thus check idle before decrement to avoid refcount_t underflow
> warning.
> 
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> ---
>  block/blk-flush.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/block/blk-flush.c b/block/blk-flush.c
> index 1002f6c58181..9b65dc43702c 100644
> --- a/block/blk-flush.c
> +++ b/block/blk-flush.c
> @@ -222,7 +222,8 @@ static void flush_end_io(struct request *flush_rq, blk_status_t error)
>  	/* release the tag's ownership to the req cloned from */
>  	spin_lock_irqsave(&fq->mq_flush_lock, flags);
>  
> -	if (!refcount_dec_and_test(&flush_rq->ref)) {
> +	if (blk_mq_rq_state(flush_rq) == MQ_RQ_IDLE ||
> +	    !refcount_dec_and_test(&flush_rq->ref)) {

It is driver's bug to finish one already ended request, so please
fix the driver instead.

Thanks,
Ming


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

* Re: [PATCH] block: don't decrement flush request refcount if it's state is idle in flush_end_io()
  2021-08-08  7:03 [PATCH] block: don't decrement flush request refcount if it's state is idle in flush_end_io() Yu Kuai
  2021-08-08  8:44 ` Ming Lei
@ 2021-08-13  9:40 ` yukuai (C)
  2021-08-13 12:34   ` yukuai (C)
  1 sibling, 1 reply; 4+ messages in thread
From: yukuai (C) @ 2021-08-13  9:40 UTC (permalink / raw)
  To: axboe; +Cc: linux-block, linux-kernel, yi.zhang

Hi, jens

Can you please consider to apply this patch?

Thanks
Kuai

On 2021/08/08 15:03, Yu Kuai wrote:
> flush_end_io() currently decrement request refcount unconditionally.
> However, it's possible that the request is already idle and it's
> refcount is zero since that flush_end_io() can be called concurrently.
> 
> For example, nbd_clear_que() can be called concurrently with normal
> io completion or io timeout.
> 
> Thus check idle before decrement to avoid refcount_t underflow
> warning.
> 
> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
> ---
>   block/blk-flush.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/block/blk-flush.c b/block/blk-flush.c
> index 1002f6c58181..9b65dc43702c 100644
> --- a/block/blk-flush.c
> +++ b/block/blk-flush.c
> @@ -222,7 +222,8 @@ static void flush_end_io(struct request *flush_rq, blk_status_t error)
>   	/* release the tag's ownership to the req cloned from */
>   	spin_lock_irqsave(&fq->mq_flush_lock, flags);
>   
> -	if (!refcount_dec_and_test(&flush_rq->ref)) {
> +	if (blk_mq_rq_state(flush_rq) == MQ_RQ_IDLE ||
> +	    !refcount_dec_and_test(&flush_rq->ref)) {
>   		fq->rq_status = error;
>   		spin_unlock_irqrestore(&fq->mq_flush_lock, flags);
>   		return;
> 

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

* Re: [PATCH] block: don't decrement flush request refcount if it's state is idle in flush_end_io()
  2021-08-13  9:40 ` yukuai (C)
@ 2021-08-13 12:34   ` yukuai (C)
  0 siblings, 0 replies; 4+ messages in thread
From: yukuai (C) @ 2021-08-13 12:34 UTC (permalink / raw)
  To: axboe; +Cc: linux-block, linux-kernel, yi.zhang

Please ignore this email, I reply to the wrong wmail.

Sincerely apologize
Kuai

在 2021/08/13 17:40, yukuai (C) 写道:
> Hi, jens
> 
> Can you please consider to apply this patch?
> 
> Thanks
> Kuai
> 
> On 2021/08/08 15:03, Yu Kuai wrote:
>> flush_end_io() currently decrement request refcount unconditionally.
>> However, it's possible that the request is already idle and it's
>> refcount is zero since that flush_end_io() can be called concurrently.
>>
>> For example, nbd_clear_que() can be called concurrently with normal
>> io completion or io timeout.
>>
>> Thus check idle before decrement to avoid refcount_t underflow
>> warning.
>>
>> Signed-off-by: Yu Kuai <yukuai3@huawei.com>
>> ---
>>   block/blk-flush.c | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/block/blk-flush.c b/block/blk-flush.c
>> index 1002f6c58181..9b65dc43702c 100644
>> --- a/block/blk-flush.c
>> +++ b/block/blk-flush.c
>> @@ -222,7 +222,8 @@ static void flush_end_io(struct request *flush_rq, 
>> blk_status_t error)
>>       /* release the tag's ownership to the req cloned from */
>>       spin_lock_irqsave(&fq->mq_flush_lock, flags);
>> -    if (!refcount_dec_and_test(&flush_rq->ref)) {
>> +    if (blk_mq_rq_state(flush_rq) == MQ_RQ_IDLE ||
>> +        !refcount_dec_and_test(&flush_rq->ref)) {
>>           fq->rq_status = error;
>>           spin_unlock_irqrestore(&fq->mq_flush_lock, flags);
>>           return;
>>
> .
> 

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

end of thread, other threads:[~2021-08-13 12:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-08  7:03 [PATCH] block: don't decrement flush request refcount if it's state is idle in flush_end_io() Yu Kuai
2021-08-08  8:44 ` Ming Lei
2021-08-13  9:40 ` yukuai (C)
2021-08-13 12:34   ` yukuai (C)

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