All of lore.kernel.org
 help / color / mirror / Atom feed
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>,
	"oleksandr@natalenko.name" <oleksandr@natalenko.name>,
	"martin.petersen@oracle.com" <martin.petersen@oracle.com>,
	"axboe@fb.com" <axboe@fb.com>
Subject: Re: [PATCH 8/9] block: allow to allocate req with REQF_PREEMPT when queue is frozen
Date: Sat, 2 Sep 2017 00:56:42 +0800	[thread overview]
Message-ID: <20170901165641.GC20709@ming.t460p> (raw)
In-Reply-To: <1504280618.14386.16.camel@wdc.com>

On Fri, Sep 01, 2017 at 03:43:39PM +0000, Bart Van Assche wrote:
> On Fri, 2017-09-01 at 11:55 +0800, Ming Lei wrote:
> > On Thu, Aug 31, 2017 at 10:50:25PM +0000, Bart Van Assche wrote:
> > > On Fri, 2017-09-01 at 01:27 +0800, Ming Lei wrote:
> > > > @@ -1413,9 +1414,17 @@ static struct request *blk_old_get_request(struct request_queue *q,
> > > >  	/* create ioc upfront */
> > > >  	create_io_context(gfp_mask, q->node);
> > > >  
> > > > -	ret = blk_queue_enter(q, !(gfp_mask & __GFP_DIRECT_RECLAIM));
> > > > +	/*
> > > > +	 * When queue is frozen, we still need to allocate req for
> > > > +	 * REQF_PREEMPT.
> > > > +	 */
> > > > +	if ((flags & BLK_MQ_REQ_PREEMPT) && blk_queue_is_frozen(q))
> > > > +		blk_queue_enter_live(q);
> > > > +	else
> > > > +		ret = blk_queue_enter(q, !(gfp_mask & __GFP_DIRECT_RECLAIM));
> > > 
> > > Sorry but I doubt that calling blk_queue_enter_live() from inside
> > > blk_old_get_request() is safe. Calling blk_queue_enter_live() is only safe
> > > before a request queue has been marked dead. What prevents a kernel thread
> > > that holds a reference on a request queue and that is running concurrently
> > > with blk_cleanup_queue() to call blk_old_get_request() after a queue has
> > > been marked dead?
> > 
> > I have sent one delta patch in list, which will only call
> > blk_queue_enter_live() iff SCSI device is in QUIESCE.
> 
> That wouldn't make this hack less ugly.
> 
> It is possible to trigger the running -> quiesce state transition through
> /sys/class/scsi_device/*/device/state and the quiesce -> removed transition
> through /sys/class/scsi_device/*/device/delete. An example:
> 
> modprobe scsi_debug delay=0 dev_size_mb=16
> lsscsi | grep scsi_debug
> cd /sys/class/scsi_device/8:0:0:0/device
> echo quiesce > state
> echo 1 > delete
> 
> So the code from your patch 8/9 can race against device removal.
> 
> I think we need a better approach than the REQ_PREEMPT hack. How about
> implementing resume as a callback by adding an additional function pointer
> to struct request_queue / struct blk_mq_ops instead of implementing it as
> a request? For SCSI devices races of resume against removal can e.g. be
> handled by checking the scsi_device_set_state() return value. That function
> namely does not allow the removing/removed to running state transition.

If there is race between resume vs. removal, that is nothing to do
this patchset.

We definitely need to prevent new requests from being allocated after
SCSI device is put into quiesce. I don't see another better way
than freezing queue, because it is the only available way to 
prevent new req allocation.

Actually there is race between normal freezing and the preempt freezing
in this patchset, and it will be fixed in V2.


-- 
Ming

  reply	other threads:[~2017-09-01 16:56 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-31 17:27 [PATCH 0/9] block/scsi: safe SCSI quiescing Ming Lei
2017-08-31 17:27 ` [PATCH 1/9] percpu-refcount: introduce percpu_ref_is_dead() Ming Lei
2017-08-31 23:07   ` Bart Van Assche
2017-08-31 23:07     ` Bart Van Assche
2017-09-01  3:49     ` Ming Lei
2017-09-01 13:59   ` Tejun Heo
2017-09-01 15:44     ` Bart Van Assche
2017-09-01 15:44       ` Bart Van Assche
2017-09-01 16:05     ` Ming Lei
2017-08-31 17:27 ` [PATCH 2/9] blk-mq: rename blk_mq_unfreeze_queue as blk_unfreeze_queue Ming Lei
2017-08-31 17:27 ` [PATCH 3/9] blk-mq: rename blk_mq_freeze_queue as blk_freeze_queue Ming Lei
2017-08-31 22:35   ` Bart Van Assche
2017-08-31 22:35     ` Bart Van Assche
2017-09-01  3:51     ` Ming Lei
2017-08-31 17:27 ` [PATCH 4/9] blk-mq: only run hw queues for blk-mq Ming Lei
2017-09-01  8:16   ` Johannes Thumshirn
2017-09-01  8:16     ` Johannes Thumshirn
2017-09-01 12:33     ` Ming Lei
2017-09-01 12:44       ` Johannes Thumshirn
2017-09-01 12:44         ` Johannes Thumshirn
2017-08-31 17:27 ` [PATCH 5/9] block: introduce blk_drain_queue() Ming Lei
2017-08-31 22:34   ` Bart Van Assche
2017-08-31 22:34     ` Bart Van Assche
2017-09-01  3:52     ` Ming Lei
2017-08-31 17:27 ` [PATCH 6/9] blk-mq: rename blk_mq_freeze_queue_wait as blk_freeze_queue_wait Ming Lei
2017-08-31 22:37   ` Bart Van Assche
2017-08-31 22:37     ` Bart Van Assche
2017-09-01  3:53     ` Ming Lei
2017-08-31 17:27 ` [PATCH 7/9] block: tracking request allocation with q_usage_counter Ming Lei
2017-08-31 17:27 ` [PATCH 8/9] block: allow to allocate req with REQF_PREEMPT when queue is frozen Ming Lei
2017-08-31 22:50   ` Bart Van Assche
2017-08-31 22:50     ` Bart Van Assche
2017-09-01  3:55     ` Ming Lei
2017-09-01 15:43       ` Bart Van Assche
2017-09-01 15:43         ` Bart Van Assche
2017-09-01 16:56         ` Ming Lei [this message]
2017-08-31 17:27 ` [PATCH 9/9] SCSI: freeze block queue when SCSI device is put into quiesce Ming Lei
2017-08-31 17:34 ` [PATCH 0/9] block/scsi: safe SCSI quiescing Oleksandr Natalenko
2017-08-31 17:34   ` Oleksandr Natalenko
2017-08-31 17:38   ` Ming Lei
2017-08-31 18:31     ` Oleksandr Natalenko
2017-08-31 18:31       ` Oleksandr Natalenko
2017-09-01  3:45       ` Ming Lei
2017-09-01  6:24         ` oleksandr
2017-09-01  6:30           ` Ming Lei

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=20170901165641.GC20709@ming.t460p \
    --to=ming.lei@redhat.com \
    --cc=Bart.VanAssche@wdc.com \
    --cc=axboe@fb.com \
    --cc=hch@infradead.org \
    --cc=jejb@linux.vnet.ibm.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.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 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.