From owner-svn-src-head@FreeBSD.ORG Tue Feb 12 07:42:29 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 4AC46209; Tue, 12 Feb 2013 07:42:29 +0000 (UTC) (envelope-from hselasky@c2i.net) Received: from swip.net (mailfe01.c2i.net [212.247.154.2]) by mx1.freebsd.org (Postfix) with ESMTP id 50364A17; Tue, 12 Feb 2013 07:42:27 +0000 (UTC) X-T2-Spam-Status: No, hits=-0.2 required=5.0 tests=ALL_TRUSTED, BAYES_50 Received: from [176.74.213.204] (account mc467741@c2i.net HELO laptop015.hselasky.homeunix.org) by mailfe01.swip.net (CommuniGate Pro SMTP 5.4.4) with ESMTPA id 380354343; Tue, 12 Feb 2013 08:42:20 +0100 From: Hans Petter Selasky To: John Baldwin Subject: Re: svn commit: r246614 - head/sys/dev/usb/wlan Date: Tue, 12 Feb 2013 08:43:32 +0100 User-Agent: KMail/1.13.7 (FreeBSD/9.1-STABLE; KDE/4.8.4; amd64; ; ) References: <201302101036.r1AAaHs1022034@svn.freebsd.org> <201302111133.02161.jhb@freebsd.org> In-Reply-To: <201302111133.02161.jhb@freebsd.org> X-Face: ?p&W)c(+80hU; '{.$5K+zq{oC6y| /D'an*6mw>j'f:eBsex\Gi, Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Feb 2013 07:42:29 -0000 On Monday 11 February 2013 17:33:02 John Baldwin wrote: > On Sunday, February 10, 2013 5:36:17 am Hans Petter Selasky wrote: > > Author: hselasky > > Date: Sun Feb 10 10:36:16 2013 > > New Revision: 246614 > > URL: http://svnweb.freebsd.org/changeset/base/246614 > > > > Log: > > - Streamline detach logic in wlan drivers, so that > > > > freed memory cannot be used during detach. > > > > - Remove all panic() calls from the urtw driver because > > > > panic() is not appropriate here. > > > > - Remove redundant checks for device detached in > > > > device detach callbacks. > > > > - Use DEVMETHOD_END to mark end of device methods. > > Using a detached flag to bail from ioctl generally means you are doing > things wrong in detach. The correct solution is to always detach your > ifnet first, then start tearing down other state. In general with device > detach routines the first order of business is removing external > references such as character devices, ifnets, etc. and only start shutting > down the hardware and releasing state once those steps have completed. Hi, What I can do to solve the problem is to lock a mutex while detaching. Is the ifnet detach routine non-blocking? Why do I say that? It is because we are in a chicken-egg situation. USB is feeding data into ifnet and ifnet is feeding data into USB. Each stack is running under its own lock. The current approach is: 1) Stop data traffic in both directions 2) Make sure no more init happens (ioctl fix) 3) Free USB and IFNET. I see currently no way I can atomically stop all traffic and prevent futher init at the same time, while holding a single mutex. Do you? --HPS