From: Ming Lei <ming.lei@redhat.com>
To: Bart Van Assche <Bart.VanAssche@wdc.com>
Cc: "linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
"hch@infradead.org" <hch@infradead.org>,
"jejb@linux.vnet.ibm.com" <jejb@linux.vnet.ibm.com>,
"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
"axboe@fb.com" <axboe@fb.com>,
"martin.petersen@oracle.com" <martin.petersen@oracle.com>,
"martin@lichtvoll.de" <martin@lichtvoll.de>,
"jthumshirn@suse.de" <jthumshirn@suse.de>,
"oleksandr@natalenko.name" <oleksandr@natalenko.name>,
"cavery@redhat.com" <cavery@redhat.com>
Subject: Re: [PATCH V6 6/6] SCSI: set block queue at preempt only when SCSI device is put into quiesce
Date: Wed, 27 Sep 2017 18:14:55 +0800 [thread overview]
Message-ID: <20170927101447.GA1994@ming.t460p> (raw)
In-Reply-To: <1506506047.2654.3.camel@wdc.com>
On Wed, Sep 27, 2017 at 09:54:09AM +0000, Bart Van Assche wrote:
> On Wed, 2017-09-27 at 13:48 +0800, Ming Lei wrote:
> > @@ -2928,12 +2929,28 @@ scsi_device_quiesce(struct scsi_device *sdev)
> > {
> > int err;
> >
> > + /*
> > + * Simply quiesing SCSI device isn't safe, it is easy
> > + * to use up requests because all these allocated requests
> > + * can't be dispatched when device is put in QIUESCE.
> > + * Then no request can be allocated and we may hang
> > + * somewhere, such as system suspend/resume.
> > + *
> > + * So we set block queue in preempt only first, no new
> > + * normal request can enter queue any more, and all pending
> > + * requests are drained once blk_set_preempt_only()
> > + * returns. Only RQF_PREEMPT is allowed in preempt only mode.
> > + */
> > + blk_set_preempt_only(sdev->request_queue, true);
> > +
> > mutex_lock(&sdev->state_mutex);
> > err = scsi_device_set_state(sdev, SDEV_QUIESCE);
> > mutex_unlock(&sdev->state_mutex);
> >
> > - if (err)
> > + if (err) {
> > + blk_set_preempt_only(sdev->request_queue, false);
> > return err;
> > + }
> >
> > scsi_run_queue(sdev->request_queue);
> > while (atomic_read(&sdev->device_busy)) {
> > @@ -2964,6 +2981,8 @@ void scsi_device_resume(struct scsi_device *sdev)
> > scsi_device_set_state(sdev, SDEV_RUNNING) == 0)
> > scsi_run_queue(sdev->request_queue);
> > mutex_unlock(&sdev->state_mutex);
> > +
> > + blk_set_preempt_only(sdev->request_queue, false);
>
> You should have realized yourself that this code is racy. If a request is
> allocated just before scsi_device_quiesce() is called and dispatched just
> after the device state has been changed into SDEV_QUIESCE then the loop that
That won't happen, any requests allocated before blk_set_preempt_only(true)
will be drained. Any normal requests are prevented from being entering
queue after blk_set_preempt_only(true) returns.
Please look at blk_set_preempt_only():
+void blk_set_preempt_only(struct request_queue *q, bool preempt_only)
+{
+ blk_mq_freeze_queue(q);
+ if (preempt_only)
+ queue_flag_set_unlocked(QUEUE_FLAG_PREEMPT_ONLY, q);
+ else
+ queue_flag_clear_unlocked(QUEUE_FLAG_PREEMPT_ONLY, q);
+ blk_mq_unfreeze_queue(q);
+}
+EXPORT_SYMBOL(blk_set_preempt_only);
blk_set_preempt_only(true) is called before scsi_device_set_state(sdev, SDEV_QUIESCE),
then any requests will be drained by blk_mq_freeze_queue() inside
blk_set_preempt_only(), meantime new normal requests are prevented from
being entering queue.
Once blk_set_preempt_only() returns, only RQF_PREEMPT is allowed to
enter queue.
--
Ming
next prev parent reply other threads:[~2017-09-27 10:15 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-27 5:48 [PATCH V6 0/6] block/scsi: safe SCSI quiescing Ming Lei
2017-09-27 5:48 ` [PATCH V6 1/6] blk-mq: only run hw queues for blk-mq Ming Lei
2017-09-27 5:48 ` [PATCH V6 2/6] block: tracking request allocation with q_usage_counter Ming Lei
2017-09-27 6:10 ` Hannes Reinecke
2017-09-27 5:48 ` [PATCH V6 3/6] block: pass flags to blk_queue_enter() Ming Lei
2017-09-27 5:48 ` [PATCH V6 4/6] block: prepare for passing RQF_PREEMPT to request allocation Ming Lei
2017-09-27 5:48 ` [PATCH V6 5/6] block: support PREEMPT_ONLY Ming Lei
2017-09-27 5:48 ` [PATCH V6 6/6] SCSI: set block queue at preempt only when SCSI device is put into quiesce Ming Lei
2017-09-27 9:54 ` Bart Van Assche
2017-09-27 10:14 ` Ming Lei [this message]
2017-09-27 7:57 ` [PATCH V6 0/6] block/scsi: safe SCSI quiescing Martin Steigerwald
2017-09-27 8:27 ` Ming Lei
2017-09-27 8:52 ` Ming Lei
2017-09-28 8:11 ` Oleksandr Natalenko
2017-09-29 18:47 ` Martin Steigerwald
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=20170927101447.GA1994@ming.t460p \
--to=ming.lei@redhat.com \
--cc=Bart.VanAssche@wdc.com \
--cc=axboe@fb.com \
--cc=cavery@redhat.com \
--cc=hch@infradead.org \
--cc=jejb@linux.vnet.ibm.com \
--cc=jthumshirn@suse.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=martin@lichtvoll.de \
--cc=oleksandr@natalenko.name \
/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