From: Ming Lei <ming.lei@redhat.com>
To: Bart Van Assche <bvanassche@acm.org>
Cc: "Martin K . Petersen" <martin.petersen@oracle.com>,
"James E . J . Bottomley" <jejb@linux.vnet.ibm.com>,
linux-scsi@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
Hannes Reinecke <hare@suse.com>,
Johannes Thumshirn <jthumshirn@suse.de>,
Jason Yan <yanaijie@huawei.com>,
stable@vger.kernel.org
Subject: Re: [PATCH] sd: Fix a race between closing an sd device and sd I/O
Date: Tue, 26 Mar 2019 09:44:03 +0800 [thread overview]
Message-ID: <20190326014402.GD30669@ming.t460p> (raw)
In-Reply-To: <20190325170146.184414-1-bvanassche@acm.org>
On Mon, Mar 25, 2019 at 10:01:46AM -0700, Bart Van Assche wrote:
> The scsi_end_request() function calls scsi_cmd_to_driver() indirectly
> and hence needs the disk->private_data pointer. Avoid that that pointer
> is cleared before all affected I/O requests have finished. This patch
> avoids that the following crash occurs:
>
> Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
> Call trace:
> scsi_mq_uninit_cmd+0x1c/0x30
> scsi_end_request+0x7c/0x1b8
> scsi_io_completion+0x464/0x668
> scsi_finish_command+0xbc/0x160
> scsi_eh_flush_done_q+0x10c/0x170
> sas_scsi_recover_host+0x84c/0xa98 [libsas]
> scsi_error_handler+0x140/0x5b0
> kthread+0x100/0x12c
> ret_from_fork+0x10/0x18
>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Ming Lei <ming.lei@redhat.com>
> Cc: Hannes Reinecke <hare@suse.com>
> Cc: Johannes Thumshirn <jthumshirn@suse.de>
> Cc: Jason Yan <yanaijie@huawei.com>
> Cc: <stable@vger.kernel.org>
> Reported-by: Jason Yan <yanaijie@huawei.com>
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
> drivers/scsi/sd.c | 19 +++++++++++++------
> 1 file changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index ed34bfbc3844..0077880c0cc8 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -1416,11 +1416,6 @@ static void sd_release(struct gendisk *disk, fmode_t mode)
> scsi_set_medium_removal(sdev, SCSI_REMOVAL_ALLOW);
> }
>
> - /*
> - * XXX and what if there are packets in flight and this close()
> - * XXX is followed by a "rmmod sd_mod"?
> - */
> -
> scsi_disk_put(sdkp);
> }
>
> @@ -3483,9 +3478,21 @@ static void scsi_disk_release(struct device *dev)
> {
> struct scsi_disk *sdkp = to_scsi_disk(dev);
> struct gendisk *disk = sdkp->disk;
> -
> + struct request_queue *q = disk->queue;
> +
> ida_free(&sd_index_ida, sdkp->index);
>
> + /*
> + * Wait until all requests that are in progress have completed.
> + * This is necessary to avoid that e.g. scsi_end_request() crashes
> + * due to clearing the disk->private_data pointer. Wait from inside
> + * scsi_disk_release() instead of from sd_release() to avoid that
> + * freezing and unfreezing the request queue affects user space I/O
> + * in case multiple processes open a /dev/sd... node concurrently.
> + */
> + blk_mq_freeze_queue(q);
> + blk_mq_unfreeze_queue(q);
> +
> disk->private_data = NULL;
> put_disk(disk);
> put_device(&sdkp->device->sdev_gendev);
No, this way may cause big performance issue, see my previous comment:
https://marc.info/?l=linux-scsi&m=155321977714715&w=2
Thanks,
Ming
next prev parent reply other threads:[~2019-03-26 1:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-25 17:01 [PATCH] sd: Fix a race between closing an sd device and sd I/O Bart Van Assche
2019-03-26 1:44 ` Ming Lei [this message]
2019-03-26 1:56 ` Bart Van Assche
2019-03-26 6:45 ` Ming Lei
2019-03-26 7:39 ` Christoph Hellwig
2019-03-28 1:18 ` Martin K. Petersen
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=20190326014402.GD30669@ming.t460p \
--to=ming.lei@redhat.com \
--cc=bvanassche@acm.org \
--cc=hare@suse.com \
--cc=hch@lst.de \
--cc=jejb@linux.vnet.ibm.com \
--cc=jthumshirn@suse.de \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=stable@vger.kernel.org \
--cc=yanaijie@huawei.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.