From: Tejun Heo <htejun@gmail.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: 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>,
Dmitry Torokhov <dmitry.torokhov@gmail.com>
Subject: Re: [PATCH RFD] alternative kobject release wait mechanism
Date: Thu, 19 Apr 2007 00:34:26 +0900 [thread overview]
Message-ID: <46263A82.1030703@gmail.com> (raw)
In-Reply-To: <Pine.LNX.4.44L0.0704181032060.12246-100000@iolanthe.rowland.org>
Hello,
Alan Stern wrote:
> On Wed, 18 Apr 2007, Tejun Heo wrote:
>
>> Hello, all.
>>
>> Agreed with the problem but I'm not very enthusiastic for adding
>> kobj->owner. How about the following? exit() routines will have to
>> do device_unregister_wait() instead of device_unregister(). On return
>> from it, it's guaranteed that all references to it are dropped and
>> ->release is finished. The caller is responsible for avoiding
>> deadlock, of course.
>
> There's a problem with this approach.
>
> Many drivers, especially those for hot-pluggable buses, register and
> unregister devices dynamically. These events can occur in time-critical
> situations, where the driver cannot afford to wait for all the references
> to be dropped when unregistering a device. It's okay to wait in a module
> exit routine, but to make things work the routine would have to wait for
> references to _all_ unregistered objects to go away, not just the
> references for the objects it unregisters at exit time.
>
> So let's see what changes are needed to make the approach workable. We
> will have to maintain a count of objects whose release methods haven't
> been called yet. The count has to be incremented every time an object is
> unregistered (or registered, it doesn't matter which) and decremented
> _after_ the release method returns -- meaning somewhere in the driver
> core. When the count goes to zero, the exit routine is then allowed to
> terminate.
>
> Hmmm, this is beginning to sound like a module-wide refcount which serves
> to block mod->exit(). In fact, it sounds almost identical to what
> Cornelia wrote, except that the refcount refers only to devices rather
> than arbitrary kobjects (and except that the blockage just before
> mod->exit returns instead of just after). You can see where I'm
> leading...
The goal of immediate-disconnect is to remove such lingering reference
counts so that device_unregister() or driver detach puts the last
reference count.
You tell a higher layer that a device is going away, on return from the
function, that layer isn't gonna access the device anymore. ie. On
return from the unregistration function, the upper layer shouldn't have
any reference to the device. If you unregister from all layers a device
is registered to, you are left with only 1 reference which you put with
device_unregister(). After all are converted, reference count doesn't
mean much. struct device isn't a reference counted object anymore.
I don't think this is gonna be too difficult to do. I think I can
convert block layer and IDE/SCSI drivers without too much problem.
Dunno much about other layers tho.
> Incidentally, Tejun, I'm all in favor of a immediate-detach driver model
> approach. Unfortunately it's impossible to realize fully, although we
> could come much closer than we are now.
>
> Here's an example where immediate-detach cannot be implemented. A driver
> binds to a device and uses that device is a kernel thread. The thread
> carries out certain operations which require it to hold the device
> semaphore (because, for example, they need to be mutually exclusive with
> unbind).
>
> The driver's remove() method is called with the semaphore held. If the
> thread tries to lock the semaphore at the same time and blocks, there is
> no way at all for the remove() method to force the thread to drop its
> reference.
>
> This isn't merely a theoretical example. The USB hub driver works in
> exactly this way.
Dunno if I understood the problem right but can't we do the following?
remove()
{
acquire sem;
device_del();
release sem;
device_put_wait();
}
--
tejun
next prev parent reply other threads:[~2007-04-18 15:34 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 [this message]
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
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=46263A82.1030703@gmail.com \
--to=htejun@gmail.com \
--cc=cornelia.huck@de.ibm.com \
--cc=dmitry.torokhov@gmail.com \
--cc=greg@kroah.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 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.