[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <Pine.LNX.4.44L0.1501261335000.1257-100000@iolanthe.rowland.org>
Date: Mon, 26 Jan 2015 13:38:23 -0500 (EST)
From: Alan Stern <stern@...land.harvard.edu>
To: Christoph Hellwig <hch@...radead.org>
cc: Tejun Heo <tj@...nel.org>, Bart Van Assche <bvanassche@....org>,
James Bottomley <jbottomley@...allels.com>,
Hannes Reinecke <hare@...e.de>,
"linux-scsi@...r.kernel.org" <linux-scsi@...r.kernel.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Kernel development list <linux-kernel@...r.kernel.org>
Subject: Re: sysfs methods can race with ->remove
On Mon, 26 Jan 2015, Christoph Hellwig wrote:
> On Thu, Jan 15, 2015 at 02:40:31PM -0500, Tejun Heo wrote:
> > > If a method is registered by the driver, then the driver will
> > > unregister it when the ->remove routine runs. I don't know for
> > > certain, but I would expect that the sysfs/kernfs core will make sure
> > > that any existing method calls complete before unregister returns.
> > > This would prevent races.
> >
> > Yes, attribute deletions are blocked till the on-going sysfs
> > read/write operations are finished and further rw accesses are failed.
>
> Btw, where do we do that? I did a walk through the code starting
> from device_del, but must have missed the obvious.
It happens in fs/kernfs/dir.c:kernfs_drain(). That routine is called
when a sysfs file is removed, and it waits until all ongoing read/write
operations are finished.
> > > The sriov_numvfs_store method does have the same problem, and so does
> > > the reset_store method (by way of pci_reset_function ->
> > > pci_dev_save_and_disable -> pci_reset_notify).
> > >
> > > Tejun, is my analysis correct? How should we fix these races?
> >
> > I'm not really following what the actual problem case is, so SCSI
> > subsystem store methods are derefing dev->driver without synchronizing
> > against detach events? If that's the case, the solution would be
> > synchronizing against attach/detach events? Sorry if I'm being
> > totally idiotic. I'm having a bit of hard time jumping right in. :)
>
> No problem. That's the basic situation we are talking about. I have
> a serie fixing some long standing issues in the device model integration
> in SCSI, and pointed out a possible issue in that area.
>
> So what is the proper lock to take to prevent ->remove from beeing
> called while in such a method? A mentioned about I tried to peel
> through all the layers of the onion^H^H^H^H^Hdriver core, but so far
> couldn't find anything obvious.
The proper lock is dev->mutex, as I mentioned in an earlier email
(http://marc.info/?l=linux-scsi&m=142176669519982&w=2). That lock is
held whenever a ->remove method is called.
Alan Stern
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists