From: Christoph Hellwig <hch@infradead.org>
To: Liu Song <liusong@linux.alibaba.com>
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: Thu, 21 Jul 2022 22:33:36 -0700 [thread overview]
Message-ID: <Yto2sHfyiJITgYAn@infradead.org> (raw)
In-Reply-To: <1658467343-55843-1-git-send-email-liusong@linux.alibaba.com>
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);
+
ret = blk_queue_enter(q, flags);
if (ret)
return ERR_PTR(ret);
next prev parent reply other threads:[~2022-07-22 5:33 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 [this message]
2022-07-22 8:15 ` Liu Song
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=Yto2sHfyiJITgYAn@infradead.org \
--to=hch@infradead.org \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liusong@linux.alibaba.com \
/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