From owner-freebsd-drivers@FreeBSD.ORG Mon Jul 2 12:56:46 2007 Return-Path: X-Original-To: freebsd-drivers@freebsd.org Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 37D1416A41F for ; Mon, 2 Jul 2007 12:56:46 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from relay02.kiev.sovam.com (relay02.kiev.sovam.com [62.64.120.197]) by mx1.freebsd.org (Postfix) with ESMTP id C3FD213C469 for ; Mon, 2 Jul 2007 12:56:45 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from [89.162.146.170] (helo=skuns.kiev.zoral.com.ua) by relay02.kiev.sovam.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.67) (envelope-from ) id 1I5LDV-000NXo-5g for freebsd-drivers@freebsd.org; Mon, 02 Jul 2007 15:41:23 +0300 Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by skuns.kiev.zoral.com.ua (8.14.1/8.14.1) with ESMTP id l62Cf1R1000176 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 2 Jul 2007 15:41:01 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.1/8.14.1) with ESMTP id l62Cf7hl037380 for ; Mon, 2 Jul 2007 15:41:07 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.1/8.14.1/Submit) id l62Cf5DW037375 for freebsd-drivers@freebsd.org; Mon, 2 Jul 2007 15:41:05 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 2 Jul 2007 15:41:04 +0300 From: Kostik Belousov To: freebsd-drivers@freebsd.org Message-ID: <20070702124104.GO2268@deviant.kiev.zoral.com.ua> References: <20070702120131.GB5161@dragon.roe.ch> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="1D2Sd8R3prdjrxgd" Content-Disposition: inline In-Reply-To: <20070702120131.GB5161@dragon.roe.ch> User-Agent: Mutt/1.4.2.2i X-Virus-Scanned: ClamAV version 0.90.2, clamav-milter version 0.90.2 on skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-1.4 required=5.0 tests=ALL_TRUSTED autolearn=failed version=3.1.8 X-Spam-Checker-Version: SpamAssassin 3.1.8 (2007-02-13) on skuns.kiev.zoral.com.ua X-Scanner-Signature: f7f1c38b0b2d7aeba17750d70212ab70 X-DrWeb-checked: yes X-SpamTest-Envelope-From: kostikbel@gmail.com X-SpamTest-Group-ID: 00000000 X-SpamTest-Header: Not Detected X-SpamTest-Info: Profiles 1187 [June 28 2007] X-SpamTest-Info: helo_type=3 X-SpamTest-Method: none X-SpamTest-Rate: 0 X-SpamTest-Status: Not detected X-SpamTest-Status-Extended: not_detected X-SpamTest-Version: SMTP-Filter Version 3.0.0 [0255], KAS30/Release Subject: Re: cdev destroy_dev() and detach races X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Jul 2007 12:56:46 -0000 --1D2Sd8R3prdjrxgd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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 run > into some difficulties involving detach races. This is a pccard driver > 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 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. Do you referring to RELENG_6 or CURRENT ? In CURRENT, destroy_devl() does 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 > 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 > 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). >=20 > 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.) >=20 > Thanks > -Dan >=20 >=20 > [1] http://dragon.roe.ch/~roe/cmx/ --1D2Sd8R3prdjrxgd Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (FreeBSD) iD8DBQFGiPJgC3+MBN1Mb4gRAg47AKDGrlvQwoPIlP1SUFxy52+OLjFYgwCdE85r g6Pr+/NoOaamXnOTYAXkeDQ= =fPfl -----END PGP SIGNATURE----- --1D2Sd8R3prdjrxgd--