Date: Tue, 3 Jul 2007 12:43:06 +0300 From: Kostik Belousov <kostikbel@gmail.com> To: freebsd-drivers@freebsd.org Subject: Re: cdev destroy_dev() and detach races Message-ID: <20070703094306.GD2200@deviant.kiev.zoral.com.ua> In-Reply-To: <20070702162058.GA12423@dragon.roe.ch> References: <20070702120131.GB5161@dragon.roe.ch> <20070702124104.GO2268@deviant.kiev.zoral.com.ua> <20070702162058.GA12423@dragon.roe.ch>
next in thread | previous in thread | raw e-mail | index | archive | help
--EP0wieDxd4TSJjHq Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jul 02, 2007 at 06:20:58PM +0200, Daniel Roethlisberger wrote: > Kostik Belousov <kostikbel@gmail.com> 2007-07-02: > > On Mon, Jul 02, 2007 at 02:01:31PM +0200, Daniel Roethlisberger wrote: > > > I have been doing some finishing work on my cmx driver [1] and have r= un > > > into some difficulties involving detach races. This is a pccard driv= er > > > with a cdev interface, the device is a PCMCIA based smartcard reader. > > >=20 > > > Originally, I thought destroy_dev() would block until all threads have > > > left the cdevsw handlers. Then I found out that it would only do so = if > > > d_purge is set in cdevsw. However, there aren't an awful lot of driv= ers > > > using this. My attempts to use a d_purge handler resulted in crashes > > > within kern/kern_conf.c when having an endless cat loop running while > > > detaching the device. > > Do you referring to RELENG_6 or CURRENT ? In CURRENT, destroy_devl() do= es > > sleep until there is any thread that grabbed thread reference. Look at = the > > rev. 1.199 of kern_conf.c. On the other hand, this was never MFCed, and > > cause some other troubles that are being worked on. >=20 > RELENG_6, sorry for not mentioning. >=20 > > > The solution I am using now is that I sleep in detach() until > > > cdev->si_threadcount is 0. This seems to have done the trick, but I > > > still have to do more testing to be sure. > > This looks like a workaround. >=20 > Why don't all the other drivers in RELENG_6 need some kind of workaround > to detach reliably? Did I just look at the wrong drivers? The problem you described is a bug in RELENG_6. The fix changes devfs infrastructure instead of modyfing all the drivers. One of the reason why the fix (rev. 1.199 of kern_conf.c) it is not MFCed is some undesirable consequences, in particular, interaction with drivers calling destroy_dev() from cdev methods. --EP0wieDxd4TSJjHq Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (FreeBSD) iD8DBQFGihoqC3+MBN1Mb4gRAkRSAJ9qgEJTrKbxhwezzlsrhM1W8s8EQQCgvd7L jW6NDILNgW1ERu6Qaql5R9s= =Ret0 -----END PGP SIGNATURE----- --EP0wieDxd4TSJjHq--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070703094306.GD2200>