From owner-freebsd-hackers@FreeBSD.ORG Tue Apr 26 15:46:41 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AC184106566B for ; Tue, 26 Apr 2011 15:46:41 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 46D6E8FC08 for ; Tue, 26 Apr 2011 15:46:41 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id D59AA46B09; Tue, 26 Apr 2011 11:46:40 -0400 (EDT) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 49AD38A027; Tue, 26 Apr 2011 11:46:40 -0400 (EDT) From: John Baldwin To: Hans Petter Selasky Date: Tue, 26 Apr 2011 11:43:32 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110325; KDE/4.5.5; amd64; ; ) References: <4DB695DB.1080505@chillt.de> <201104261037.17893.jhb@freebsd.org> <201104261642.17569.hselasky@c2i.net> In-Reply-To: <201104261642.17569.hselasky@c2i.net> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201104261143.32591.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.6 (bigwig.baldwin.cx); Tue, 26 Apr 2011 11:46:40 -0400 (EDT) Cc: freebsd-hackers@freebsd.org, Bartosz Fabianowski Subject: Re: Is there some implicit locking of device methods? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Apr 2011 15:46:41 -0000 On Tuesday, April 26, 2011 10:42:17 am Hans Petter Selasky wrote: > On Tuesday 26 April 2011 16:37:17 John Baldwin wrote: > > On Tuesday, April 26, 2011 10:27:14 am Warner Losh wrote: > > > On Apr 26, 2011, at 7:42 AM, John Baldwin wrote: > > > > - The Giant protection for new-bus should prevent attach/detach from > > > > running > > > > > > > > concurrently I believe (either that or the USB bus itself should > > > > ensure that the two instances of your device have seperate device_t > > > > instances with separate softc's, so current attach/detach should not > > > > matter except that they may both try to talk to the same hardware > > > > perhaps? In that case that is something the USB bus driver should > > > > fix by prevent a device from attaching at an existing address until > > > > any existing device at that address is fully detached). > > > > > > I thought that if we held Giant when we're about to go to sleep that we > > > drop it as a special case. So if any newbus-releated function sleeps, > > > we can have a situation where attach is running and detach gets called. > > > There is (or was) some code to cope with this in CardBus, iirc. I'm > > > surprised there isn't any in USB, since Hans was the one that alerted me > > > to this issue. > > > > Yes, Giant doesn't really provide too much help here. However, the real > > fix should be in the USB bus, and USB peripheral drivers should not have > > to worry about handling concurrent attach/detach (they can't really handle > > it safely anyway). > > Hi, > > All detach/attach/suspend/resume functions on a device tree belonging to the > same USB controller are executed from a single thread, which is called the > root HUB thread. Ok, that should work fine then to serialize the detach and attach. -- John Baldwin