Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 2 Jul 2007 14:01:31 +0200
From:      Daniel Roethlisberger <daniel@roe.ch>
To:        freebsd-drivers@freebsd.org
Subject:   cdev destroy_dev() and detach races
Message-ID:  <20070702120131.GB5161@dragon.roe.ch>

next in thread | raw e-mail | index | archive | help
I have been doing some finishing work on my cmx driver [1] and have run
into some difficulties involving detach races.  This is a pccard driver
with a cdev interface, the device is a PCMCIA based smartcard reader.

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 drivers
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.

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.

How do other driver solve this problem?  I haven't found much
documentation on this, and I didn't find any suitable driver to use as a
guide (ideally a pccard driver with cdev interface, sleeps within
read/write handlers, running without Giant).

I'd be grateful if somebody could share any insight on this, or point me
to the appropriate documentation.  (Or any other comments on the cmx
driver code, for that matter.)

Thanks
-Dan


[1] http://dragon.roe.ch/~roe/cmx/

-- 
Daniel Roethlisberger <daniel@roe.ch>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070702120131.GB5161>