public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <Bart.VanAssche@wdc.com>
To: "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>,
	"ming.lei@redhat.com" <ming.lei@redhat.com>,
	"martin.petersen@oracle.com" <martin.petersen@oracle.com>
Cc: Bart Van Assche <Bart.VanAssche@wdc.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 09:54:09 +0000	[thread overview]
Message-ID: <1506506047.2654.3.camel@wdc.com> (raw)
In-Reply-To: <20170927054853.6647-7-ming.lei@redhat.com>

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
waits for all commands to complete will wait forever due to the SCSI prep
function returning BLKPREP_DEFER.

Bart.

  reply	other threads:[~2017-09-27  9:54 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 [this message]
2017-09-27 10:14     ` Ming Lei
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=1506506047.2654.3.camel@wdc.com \
    --to=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=ming.lei@redhat.com \
    --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