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 01:38:01 +0900 [thread overview]
Message-ID: <46264969.5050003@gmail.com> (raw)
In-Reply-To: <Pine.LNX.4.44L0.0704181149280.12246-100000@iolanthe.rowland.org>
Hello,
Alan Stern wrote:
> On Thu, 19 Apr 2007, Tejun Heo wrote:
>
>> The goal of immediate-disconnect is to remove such lingering reference
>> counts so that device_unregister() or driver detach puts the last
>> reference count.
>
> Yes, I understand. If you had immediate-disconnect then you wouldn't need
> device_unregister_wait(). In fact, you wouldn't need any reference counts
> at all. It would be guaranteed that when the unregister call returned,
> all references would be gone.
>
>> 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.
>
> No, no. You tell somebody (it might be a higher layer, it might be a
> lower layer, or it might be a same-height layer -- doesn't matter) that a
> device is going away.
Yeap, right. I higher, lower, same, whatever. I was using the term as
drivers usually register to upper layers.
> On return from the function, that layer isn't going
> to access the device any more, _nor_ will anyone else who has obtained a
> reference from that layer. This last clause is very important.
Agreed. That layer is responsible for managing lingering objects and
telling its users that the device is a zombie now.
>> 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.
>
> You have to convert more than layers (or core subsystems). You also have
> to audit and convert drivers. It will be tremendously difficult to do.
I definitely can be mis-assessing the problem. I'll first give a shot
at the block/SCSI layer. How about that?
> You did misunderstand. Here's what I was talking about:
>
> Driver A:
> ---------
> unregister_device(dev);
>
> /* inside the driver core */
> down(&dev->sem);
> if (dev->driver)
> dev->driver->remove(dev);
> up(&dev->sem);
> device_put(dev); /* or device_put_wait */
>
>
> Driver B:
> ---------
> void remove(struct device *dev)
> {
> struct my_device *mydev = dev_get_drvdata(dev);
>
> mydev->gone = 1;
> kref_put(&mydev->kref, my_device_release);
> }
>
>
> Driver B's kernel thread:
> -------------------------
> kref_get(&mydev->kref);
> down(&mydev->dev.sem);
> if (mydev->gone)
> goto finished;
> ...
> finished:
> up(&mydev->dev.sem);
> kref_put(&mydev->kref, my_device_release);
>
> Consider what happens if the kernel thread blocks on its down() while the
> remove() method is running. It will be impossible for Driver B to
> eliminate the reference to dev held by mydev and by the down() routine.
>
> In short, Driver B _can't_ provide an immediate detach. Not unless
> someone figures out a way to cancel a blocked down(). And do the same
> thing for other blocking primitives.
Ah.. I see. You're right in that driver B cannot wait for disconnect in
its remove routine in the above code but using a separate mutex to
protect ->gone should do the trick, so I don't think the above case is a
big problem. It's a pretty specific case which is easy to spot and update.
Thanks.
--
tejun
next prev parent reply other threads:[~2007-04-18 16:38 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 [this message]
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=46264969.5050003@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 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).