From: Bart Van Assche <bvanassche@acm.org>
To: Ming Lei <ming.lei@redhat.com>
Cc: "Martin K . Petersen" <martin.petersen@oracle.com>,
Jaegeuk Kim <jaegeuk@kernel.org>,
linux-scsi@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
Hannes Reinecke <hare@suse.de>,
John Garry <john.garry@huawei.com>,
Li Zhijian <lizhijian@fujitsu.com>
Subject: Re: [PATCH] scsi: core: Call blk_mq_free_tag_set() earlier
Date: Wed, 29 Jun 2022 14:49:27 -0700 [thread overview]
Message-ID: <8e464697-e179-19f7-e417-be089821a861@acm.org> (raw)
In-Reply-To: <YruoKUbpBZvAkZ4L@T590>
On 6/28/22 18:17, Ming Lei wrote:
> On Tue, Jun 28, 2022 at 10:56:12AM -0700, Bart Van Assche wrote:
>> There are two .exit_cmd_priv implementations. Both implementations use the
>> SCSI host pointer. Make sure that the SCSI host pointer is valid when
>> .exit_cmd_priv is called by moving the .exit_cmd_priv calls from
>> scsi_device_dev_release() to scsi_forget_host(). Moving
>> blk_mq_free_tag_set() from scsi_device_dev_release() to scsi_forget_host()
>> is safe because scsi_forget_host() drains all the request queues that use
>> the host tag set. This guarantees that no requests are in flight and also
>> that no new requests will be allocated from the host tag set.
>
> Not sure scsi_forget_host really drains all queues since it bypasses
> sdev which state is SDEV_DEL, so removal for this sdev could be
> in-progress, not done yet.
Ah, that's right. How about making scsi_forget_host() wait until all request
activity on the associated queues has stopped, e.g. by replacing the current
scsi_forget_host() implementation by the one below?
/**
* scsi_forget_host() - Remove all SCSI devices from a host.
* @shost: SCSI host to remove devices from.
*
* Removes all SCSI devices that have not yet been removed. For the SCSI devices
* for which removal started before scsi_forget_host(), wait until the
* associated request queue has reached the "dead" state. In that state it is
* guaranteed that no new requests will be allocated and also that no requests
* are in progress anymore.
*/
void scsi_forget_host(struct Scsi_Host *shost)
{
struct scsi_device *sdev;
might_sleep();
restart:
spin_lock_irq(shost->host_lock);
list_for_each_entry(sdev, &shost->__devices, siblings) {
if (sdev->sdev_state == SDEV_DEL &&
blk_queue_dead(sdev->request_queue)) {
continue;
}
if (sdev->sdev_state == SDEV_DEL) {
get_device(&sdev->sdev_gendev);
spin_unlock_irq(shost->host_lock);
while (!blk_queue_dead(sdev->request_queue))
msleep(10);
spin_lock_irq(shost->host_lock);
put_device(&sdev->sdev_gendev);
goto restart;
}
spin_unlock_irq(shost->host_lock);
__scsi_remove_device(sdev);
goto restart;
}
spin_unlock_irq(shost->host_lock);
}
Thanks,
Bart.
next prev parent reply other threads:[~2022-06-29 21:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-28 17:56 [PATCH] scsi: core: Call blk_mq_free_tag_set() earlier Bart Van Assche
2022-06-29 1:17 ` Ming Lei
2022-06-29 21:49 ` Bart Van Assche [this message]
2022-06-30 1:01 ` Ming Lei
2022-06-30 8:57 ` Ming Lei
2022-06-30 20:22 ` Bart Van Assche
2022-06-30 20:19 ` Bart Van Assche
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=8e464697-e179-19f7-e417-be089821a861@acm.org \
--to=bvanassche@acm.org \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=jaegeuk@kernel.org \
--cc=john.garry@huawei.com \
--cc=linux-scsi@vger.kernel.org \
--cc=lizhijian@fujitsu.com \
--cc=martin.petersen@oracle.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox