All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yufen Yu <yuyufen@huawei.com>
To: Ming Lei <ming.lei@redhat.com>
Cc: <axboe@kernel.dk>, <linux-block@vger.kernel.org>, <hch@lst.de>
Subject: Re: [PATCH] block: quiesce queue before freeing queue
Date: Fri, 15 Jan 2021 16:32:03 +0800	[thread overview]
Message-ID: <1b970f10-dc2e-0003-b708-d48e7ee17750@huawei.com> (raw)
In-Reply-To: <20210115073529.GA396337@T590>



On 2021/1/15 15:35, Ming Lei wrote:
> On Fri, Jan 15, 2021 at 01:43:52AM -0500, Yufen Yu wrote:
>> There is a race beteewn blk_mq_run_hw_queue() and cleanup queue,
>> which can cause use-after-free as following:

>>
>> diff --git a/block/blk-core.c b/block/blk-core.c
>> index 7663a9b94b80..f8a038d19c89 100644
>> --- a/block/blk-core.c
>> +++ b/block/blk-core.c
>> @@ -392,6 +392,18 @@ void blk_cleanup_queue(struct request_queue *q)
>>   
>>   	blk_queue_flag_set(QUEUE_FLAG_DEAD, q);
>>   
>> +	/*
>> +	 * make sure all in-progress dispatch are completed because
>> +	 * blk_freeze_queue() can only complete all requests, and
>> +	 * dispatch may still be in-progress since we dispatch requests
>> +	 * from more than one contexts.
>> +	 *
>> +	 * We rely on driver to deal with the race in case that queue
>> +	 * initialization isn't done.
>> +	 */
>> +	if (queue_is_mq(q) && blk_queue_init_done(q))
>> +		blk_mq_quiesce_queue(q);
> 
> No, please don't do that. We had several slow boot reports before caused by
> by synchronize_rcu() in blk_cleanup_queue(), since blk_cleanup_queue()
> is called for in-existed queues, which number can be quite big.

Thanks to point out this. But, can't blk_queue_init_done will avoid calling
synchronize_rcu() for inexistent queues?

Thanks,
Yufen


      reply	other threads:[~2021-01-15  8:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-15  6:43 [PATCH] block: quiesce queue before freeing queue Yufen Yu
2021-01-15  7:35 ` Ming Lei
2021-01-15  8:32   ` Yufen Yu [this message]

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=1b970f10-dc2e-0003-b708-d48e7ee17750@huawei.com \
    --to=yuyufen@huawei.com \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=ming.lei@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.