Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: "Ewan D. Milne" <emilne@redhat.com>
To: Bart Van Assche <Bart.VanAssche@wdc.com>
Cc: "gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"zhaohongjiang@huawei.com" <zhaohongjiang@huawei.com>,
	"jthumshirn@suse.de" <jthumshirn@suse.de>,
	"hch@lst.de" <hch@lst.de>,
	"martin.petersen@oracle.com" <martin.petersen@oracle.com>,
	"hare@suse.de" <hare@suse.de>,
	"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	"yanaijie@huawei.com" <yanaijie@huawei.com>,
	"jejb@linux.vnet.ibm.com" <jejb@linux.vnet.ibm.com>,
	"miaoxie@huawei.com" <miaoxie@huawei.com>
Subject: Re: [PATCH] scsi: fix race condition when removing target
Date: Wed, 29 Nov 2017 14:20:29 -0500	[thread overview]
Message-ID: <1511983229.30220.19.camel@localhost.localdomain> (raw)
In-Reply-To: <1511982666.2671.25.camel@wdc.com>

On Wed, 2017-11-29 at 19:11 +0000, Bart Van Assche wrote:
> On Wed, 2017-11-29 at 13:49 -0500, Ewan D. Milne wrote:
> > because a get inside a destructor would *always* be wrong, no?
> 
> Hello Ewan,
> 
> That's not what we are discussing. What can happen with the SCSI core is that
> get_device() is called concurrently with the destructor. get_device() can be
> called concurrently with the destructor because the destructore removes a
> device from the siblings list and because the SCSI core can call get_device()
> for devices it finds on the siblings list. Personally I think that design is
> superior compared to removing a SCSI device from the sibling list before the
> last put_device() call because the approach followed in the SCSI core leads to
> a simpler implementation. However, it seems like the current get_device()
> implementation does not yet support the SCSI core design ...
> 
> Bart.

OK, well, I think the point still stands, though, once the refcount
goes to zero and the destructor is invoked, a get that then increments
the refcount seems fundamentally wrong to me.  Especially if a
subsequent put causes the destructor to be invoked *simultaneously*
*on another thread*.  The locking has to happen somewhere, why isn't
this done by the kobject?

Relying on the client code to get this right means that there are
opportunities all over the kernel for problems like this to happen,
just like here, where we inadvertently removed the state check that
prevented the get_device() call.

-Ewan

  reply	other threads:[~2017-11-29 19:20 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-29  3:05 [PATCH] scsi: fix race condition when removing target Jason Yan
2017-11-29  7:41 ` Hannes Reinecke
2017-11-29 16:18 ` Bart Van Assche
2017-11-29 16:20   ` hch
2017-11-29 17:39     ` Bart Van Assche
2017-11-30  1:18       ` Jason Yan
2017-11-30 16:08         ` Bart Van Assche
2017-11-30 16:40           ` gregkh
2017-11-30 23:56           ` James Bottomley
2017-12-01  1:12             ` Finn Thain
2017-12-01  8:40             ` Jason Yan
2017-12-01 14:41               ` Ewan D. Milne
2017-12-01 15:35               ` James Bottomley
2017-12-05 12:37                 ` Jason Yan
2017-12-05 15:37                   ` James Bottomley
2017-12-06  0:41                     ` Jason Yan
2017-12-06  2:07                       ` James Bottomley
2017-12-06  2:43                         ` Jason Yan
2017-11-29 17:39     ` gregkh
2017-11-29 18:49       ` Ewan D. Milne
2017-11-29 19:11         ` Bart Van Assche
2017-11-29 19:20           ` Ewan D. Milne [this message]
2017-11-29 19:50             ` Bart Van Assche
2017-11-29 17:39   ` gregkh
2017-11-29 17:47     ` Bart Van Assche
2017-11-29 16:31 ` James Bottomley
2017-11-29 16:34   ` Christoph Hellwig
2017-11-29 16:47     ` James Bottomley
2017-11-29 19:05 ` Ewan D. Milne

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=1511983229.30220.19.camel@localhost.localdomain \
    --to=emilne@redhat.com \
    --cc=Bart.VanAssche@wdc.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hare@suse.de \
    --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=miaoxie@huawei.com \
    --cc=yanaijie@huawei.com \
    --cc=zhaohongjiang@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox