From owner-freebsd-drivers@FreeBSD.ORG Tue Jul 3 16:35:17 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 F12C116A468 for ; Tue, 3 Jul 2007 16:35:17 +0000 (UTC) (envelope-from daniel@roe.ch) Received: from calvin.roe.ch (calvin.roe.ch [213.144.141.26]) by mx1.freebsd.org (Postfix) with ESMTP id A3A4813C4AE for ; Tue, 3 Jul 2007 16:35:17 +0000 (UTC) (envelope-from daniel@roe.ch) Received: from d212-53-102-185.cust.tele2.ch ([212.53.102.185] helo=dragon.roe.ch) by calvin.roe.ch (envelope-from ) with ESMTPS (TLSv1:AES256-SHA:256) id 1I5lI4-0001xG-7r for freebsd-drivers@freebsd.org; Tue, 03 Jul 2007 18:31:48 +0200 Received: from roe by dragon.roe.ch (envelope-from ) with LOCAL id 1I5lLP-0006l2-00 for freebsd-drivers@freebsd.org; Tue, 03 Jul 2007 18:35:15 +0200 Date: Tue, 3 Jul 2007 18:35:15 +0200 From: Daniel Roethlisberger To: freebsd-drivers@freebsd.org Message-ID: <20070703163515.GA21591@dragon.roe.ch> Mail-Followup-To: freebsd-drivers@freebsd.org References: <20070702120131.GB5161@dragon.roe.ch> <20070702124104.GO2268@deviant.kiev.zoral.com.ua> <20070702162058.GA12423@dragon.roe.ch> <20070703094306.GD2200@deviant.kiev.zoral.com.ua> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20070703094306.GD2200@deviant.kiev.zoral.com.ua> User-Agent: Mutt/1.5.4i DomainKey-Status: (calvin.roe.ch) DomainKey-Result: (calvin.roe.ch) 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: Tue, 03 Jul 2007 16:35:18 -0000 Kostik Belousov 2007-07-03: > On Mon, Jul 02, 2007 at 06:20:58PM +0200, Daniel Roethlisberger wrote: > > Kostik Belousov 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 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. > > > 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. > > > > RELENG_6, sorry for not mentioning. > > > > > > 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. > > > > 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. Hum, that's not what I meant, sorry for not being clear. I understand the implications of the fix. But since the fix was not MFCed, why aren't there drivers in RELENG_6 crashing on this issue? Why don't I see more workarounds like mine in RELENG_6 drivers? That's what I wondered. Since my driver now works flawlessly, it doesn't really matter. > 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. -Dan -- Daniel Roethlisberger