From: "Dmitry Torokhov" <dmitry.torokhov@gmail.com>
To: "Alan Stern" <stern@rowland.harvard.edu>
Cc: "Tejun Heo" <htejun@gmail.com>,
"Cornelia Huck" <cornelia.huck@de.ibm.com>,
linux-kernel <linux-kernel@vger.kernel.org>,
"Greg K-H" <greg@kroah.com>,
"Rusty Russell" <rusty@rustcorp.com.au>
Subject: Re: [PATCH RFD] alternative kobject release wait mechanism
Date: Thu, 19 Apr 2007 14:39:40 -0400 [thread overview]
Message-ID: <d120d5000704191139m3caf4cfeqd95047d1c33faf64@mail.gmail.com> (raw)
In-Reply-To: <Pine.LNX.4.44L0.0704191254070.3413-100000@iolanthe.rowland.org>
On 4/19/07, Alan Stern <stern@rowland.harvard.edu> wrote:
> On Wed, 18 Apr 2007, Dmitry Torokhov wrote:
>
> > I am still do not understand why this is needed. Would it not be
> > simplier just to use a reference to struct device instead of embedding
> > it in a larger structure if their lifetimes are different and one does
> > not have a subsystem that takes care of releasing logic.
> >
> >
> > Pretty much drivers have 2 options:
> >
> > struct my_device {
> > void *private_data;
> > struct device dev;
> > };
>
> Actually people use dev_[gs]et_drvdata() instead of a separate
> private_data pointer. That way there's no need for the my_device
> container.
>
No, drvdata belongs to driver that is bound to a device. We are
talking about private data created and managed by driver that provides
device.
> > In this case ->release must live in a subsystem code; individual
> > drivers kfree(my_dev->private) and do any additional cleanup after
> > calling device_unregister(&my_dev->dev);
>
> That doesn't sound right. Generally the call to device_unregister() and
> the release method live in the same module. Maybe you meant to say
> individual drivers kfree(my_dev->private_data) and do any additional
> cleanup in their remove() routine.
Again, if we are talking about driver bound to a device then devices
->release() is irrelevant. If we are talking about driver that created
device then driver's ->remove() is irrelevant.
>
> This approach seems dangerous. Suppose there's mutex embedded in
> my_dev->private_data, and suppose some other thread is blocked waiting on
> that mutex when remove() is called. That other thread will then oops when
> my_dev->private_data is deallocated.
What other thread? I suppose it is module-local thread or
subsystem-local thread. Let's that particular subsystem take care of
it's own data and use its own ->release() when it is ready. What I
mean is there is no need to perform clean-up at once; every layer can
do its own cleanup.
>
> > Second option:
> >
> > struct my_device {
> > type member1;
> > type member2;
> >
> > struct device *dev;
> > };
> >
> > dev is coming from _device_create(). Driver core takes care of
> > releasing dev structure; driver does cleanup of my_device.
>
> Lots of drivers create devices dynamically without using device_create().
>
> More to the point, how does the driver clean up my_device? It probably
> has a reference count somewhere in my_device, especially if my_device is
> shared with other threads or other drivers. We then face exactly the same
> problem: What happens if the driver's module is unloaded before all the
> references to my_device are gone?
>
This is up to subsystem to ensure that it does not access dead devices.
> > With current sysfs orphaning attributes upon removal request there is
> > no issue of accessing driver-private data through references obtained
> > via ether embedded or referenced dev structure so everything is fine.
>
> Not so. There are other pathways besides sysfs which can cause a driver
> to access its data structures.
>
Which ones? These needs to be identified and treated with "immediate
disconnect" that you advocated earlier. Once active users of device's
services are gone you can zap it.
--
Dmitry
next prev parent reply other threads:[~2007-04-19 18:39 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-16 17:36 [Patch -mm 0/3] RFC: module unloading vs. release function Cornelia Huck
2007-04-16 18:30 ` Dmitry Torokhov
2007-04-16 18:47 ` Greg KH
2007-04-16 19:03 ` Dmitry Torokhov
2007-04-16 19:11 ` Greg KH
2007-04-16 20:20 ` Dmitry Torokhov
2007-04-16 19:38 ` Alan Stern
2007-04-16 19:47 ` Dmitry Torokhov
2007-04-16 19:52 ` Greg KH
2007-04-16 20:18 ` Dmitry Torokhov
2007-04-16 21:02 ` Alan Stern
2007-04-17 7:49 ` Cornelia Huck
2007-04-16 20:44 ` Alexey Dobriyan
2007-04-17 2:55 ` Rusty Russell
2007-04-17 7:36 ` Cornelia Huck
2007-04-16 18:53 ` Greg KH
2007-04-17 18:41 ` [PATCH RFD] alternative kobject release wait mechanism Tejun Heo
2007-04-17 18:49 ` Tejun Heo
2007-04-18 8:11 ` Cornelia Huck
2007-04-18 8:46 ` Tejun Heo
2007-04-18 9:35 ` Cornelia Huck
2007-04-18 9:55 ` Tejun Heo
2007-04-18 8:07 ` Cornelia Huck
2007-04-18 8:36 ` Tejun Heo
2007-04-18 14:53 ` Alan Stern
2007-04-18 15:26 ` Cornelia Huck
2007-04-18 15:34 ` Tejun Heo
2007-04-18 15:45 ` Tejun Heo
2007-04-18 19:07 ` Alan Stern
2007-04-20 5:27 ` Tejun Heo
2007-04-20 9:11 ` Cornelia Huck
2007-04-20 15:01 ` Alan Stern
2007-04-20 15:57 ` Dmitry Torokhov
2007-04-21 15:19 ` Alan Stern
2007-04-20 15:40 ` Alan Stern
2007-04-21 0:03 ` Greg KH
2007-04-21 21:36 ` Alan Stern
2007-04-22 17:40 ` Greg KH
2007-04-23 7:08 ` Cornelia Huck
2007-04-23 19:47 ` Alan Stern
2007-04-24 19:38 ` Alan Stern
2007-04-25 9:00 ` Cornelia Huck
2007-04-25 20:13 ` Alan Stern
2007-04-26 8:21 ` Cornelia Huck
2007-04-26 14:58 ` Alan Stern
2007-04-26 15:12 ` Cornelia Huck
2007-04-18 16:11 ` Alan Stern
2007-04-18 16:38 ` Tejun Heo
2007-04-18 16:41 ` Dmitry Torokhov
2007-04-19 12:51 ` Cornelia Huck
2007-04-19 13:13 ` Dmitry Torokhov
2007-04-19 13:48 ` Cornelia Huck
2007-04-19 14:21 ` Dmitry Torokhov
2007-04-20 5:59 ` Tejun Heo
2007-04-20 16:35 ` Dmitry Torokhov
2007-04-20 16:52 ` Tejun Heo
2007-04-20 17:59 ` Dmitry Torokhov
2007-04-23 6:40 ` Tejun Heo
2007-04-23 6:53 ` Greg KH
2007-04-19 17:19 ` Alan Stern
2007-04-19 18:39 ` Dmitry Torokhov [this message]
2007-04-19 22:37 ` Alan Stern
2007-04-20 16:35 ` Dmitry Torokhov
2007-04-21 15:30 ` Alan Stern
2007-04-18 15:06 ` Cornelia Huck
2007-04-18 16:06 ` Tejun Heo
2007-04-19 13:29 ` Cornelia Huck
2007-04-19 14:20 ` Alan Stern
2007-04-19 14:49 ` Cornelia Huck
2007-04-20 9:04 ` Cornelia Huck
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=d120d5000704191139m3caf4cfeqd95047d1c33faf64@mail.gmail.com \
--to=dmitry.torokhov@gmail.com \
--cc=cornelia.huck@de.ibm.com \
--cc=greg@kroah.com \
--cc=htejun@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rusty@rustcorp.com.au \
--cc=stern@rowland.harvard.edu \
/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
all inboxes | Powered by JetHome®