From: Mike Christie <mchristi@redhat.com>
To: Bart Van Assche <bvanassche@acm.org>,
Naohiro Aota <naohiro.aota@wdc.com>,
linux-scsi@vger.kernel.org, target-devel@vger.kernel.org
Cc: Nicholas Bellinger <nab@linux-iscsi.org>,
"Martin K . Petersen" <martin.petersen@oracle.com>
Subject: Re: [PATCH v2 1/2] scsi: target/tcm_loop: ignore already deleted scsi device
Date: Tue, 20 Aug 2019 12:19:25 -0500 [thread overview]
Message-ID: <5D5C2B9D.1070307@redhat.com> (raw)
In-Reply-To: <737dd6be-a8c9-492c-8057-1f16b3d90519@acm.org>
On 08/20/2019 10:43 AM, Bart Van Assche wrote:
> On 8/20/19 8:27 AM, Mike Christie wrote:
>> tcm loop does not take a reference to the scsi_device at creation/link
>> time then need to release at removal/unlink time. The above
>> scsi_device_put is for the successful scsi_device_lookup call. tcm loop
>> works like a scsi host driver that does its own scanning via
>> scsi_add_device (maybe similar to scsi drivers that are raid cards).
>> Like other host drivers it does not take a reference to the device when
>> it is added and relies on scsi-ml to handle all that for it before doing
>> operations like queuecommand.
>>
>> The leak is if you removed the scsi_device via the scsi ml sysfs
>> interface then there is no way to completely unlink the lio port because
>> if scsi_device_lookup fails we return from the function and do not do
>> not release our refcount on the tl_tpg_port_count.
>
> Hi Mike,
>
> Does this mean that you think that this patch is the right way to
> address the reported issue?
>
It fixes that very specific issue, but it leaves others. Maybe it could
be used in a patchset that builds on it?
I think we could hit issues like:
1. tcm_loop_port_unlink runs and releases tl_tpg_port_count count.
2. userspace initiated scan commands were in progress and complete.
target_fabric_port_unlink->core_dev_del_lun->core_tpg_remove_lun was
waiting for those last IOs and now completes and deletes the mapped lun
from lio.
3. scsi-ml scan completed before the unmapping and so now we have a
scsi_device but no lio lun mapping.
The problem with this is that:
1. We can hit mismatched settings like this:
A. We now have this scsi_device at LUN0, but no lio mapping. User thinks
everything got cleaned up ok, so they decide to map another lio lun.
B. tcm_loop_port_link just does a scsi_add_device which does
scsi_probe_and_add_lun with rescan=true. So the original scsi_device is
returned. It is not reprobed so whatever settings the old device has
will be used. Maybe that scsi_device was for a disk and now the user was
adding a CD.
2. And hit races like:
A. tl_tpg_port_count might now be zero so the tpg and nexus can be removed.
B. That removal can race with IO being sent to the scsi_device. If a
command has passed tcm_loop_submission_work's NULL tl_nexus check then
we will hit a NULL pointer crash later in the function.
next prev parent reply other threads:[~2019-08-20 17:19 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-20 9:04 [PATCH v2 1/2] scsi: target/tcm_loop: ignore already deleted scsi device Naohiro Aota
2019-08-20 9:04 ` [PATCH v2 2/2] scsi: target/tcm_loop: update upper limit of LUN Naohiro Aota
2019-08-20 14:02 ` [PATCH v2 1/2] scsi: target/tcm_loop: ignore already deleted scsi device Bart Van Assche
2019-08-20 15:27 ` Mike Christie
2019-08-20 15:43 ` Bart Van Assche
2019-08-20 17:19 ` Mike Christie [this message]
2019-08-22 6:51 ` Naohiro Aota
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=5D5C2B9D.1070307@redhat.com \
--to=mchristi@redhat.com \
--cc=bvanassche@acm.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=nab@linux-iscsi.org \
--cc=naohiro.aota@wdc.com \
--cc=target-devel@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).