Linux block layer
 help / color / mirror / Atom feed
From: Liu Song <liusong@linux.alibaba.com>
To: Christoph Hellwig <hch@infradead.org>
Cc: axboe@kernel.dk, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] blk-mq: avoid potential infinite loop in __blk_mq_alloc_request
Date: Fri, 22 Jul 2022 16:15:49 +0800	[thread overview]
Message-ID: <eb99b420-3e28-98c7-dacc-767d564661e2@linux.alibaba.com> (raw)
In-Reply-To: <Yto2sHfyiJITgYAn@infradead.org>

> On Fri, Jul 22, 2022 at 01:22:23PM +0800, Liu Song wrote:
>> From: Liu Song <liusong@linux.alibaba.com>
>>
>> If "blk_mq_get_tag" returns BLK_MQ_NO_TAG because the value of
>> "tags->nr_reserved_tags" is 0, it will fall into an infinite loop in
>> "__blk_mq_alloc_requests", so borrow BLK_MQ_REQ_NOWAIT to exit the loop.
> That means the driver calling blk_mq_alloc_request has a bug, and
> we should not work round that in the low level tag allocation path.
>
> If we want to be nice we can add a WARN_ON before going all the way
> down into the tag allocator, something like:
>
> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index 92aae03103b74..d6c7e2ece025f 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -520,6 +520,10 @@ struct request *blk_mq_alloc_request(struct request_queue *q, unsigned int op,
>   	struct request *rq;
>   	int ret;
>   
> +	if (WARN_ON_ONCE((flags & BLK_MQ_REQ_RESERVED) &&
> +			!q->tag_set->reserved_tags))
> +		return ERR_PTR(-EINVAL);
> +

Hi,

It is a reasonable approach to prevent abnormal alloc from going down,
but this is a very rare exception after all, and above modification is 
checked
every alloc request, which seems to be a bit excessive overhead.

After the rare exception occurs and fix it, the impact on the alloc 
request will be lower.

Thanks

>   	ret = blk_queue_enter(q, flags);
>   	if (ret)
>   		return ERR_PTR(ret);


  reply	other threads:[~2022-07-22  8:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-22  5:22 [PATCH] blk-mq: avoid potential infinite loop in __blk_mq_alloc_request Liu Song
2022-07-22  5:33 ` Christoph Hellwig
2022-07-22  8:15   ` Liu Song [this message]
2022-07-22 16:08     ` Christoph Hellwig
2022-08-09 10:10       ` Liu Song

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eb99b420-3e28-98c7-dacc-767d564661e2@linux.alibaba.com \
    --to=liusong@linux.alibaba.com \
    --cc=axboe@kernel.dk \
    --cc=hch@infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox