From owner-freebsd-arch@FreeBSD.ORG Mon Sep 14 13:13:37 2009 Return-Path: Delivered-To: arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 08995106566C; Mon, 14 Sep 2009 13:13:37 +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 CA96F8FC18; Mon, 14 Sep 2009 13:13:36 +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 7D4DA46B2D; Mon, 14 Sep 2009 09:13:36 -0400 (EDT) Received: from jhbbsd.hudson-trading.com (unknown [209.249.190.8]) by bigwig.baldwin.cx (Postfix) with ESMTPA id CA01D8A01B; Mon, 14 Sep 2009 09:13:35 -0400 (EDT) From: John Baldwin To: Hans Petter Selasky Date: Mon, 14 Sep 2009 08:52:48 -0400 User-Agent: KMail/1.9.7 References: <200909031340.n83Defkv034013@svn.freebsd.org> <200909080936.37603.jhb@freebsd.org> <200909121009.22931.hselasky@c2i.net> In-Reply-To: <200909121009.22931.hselasky@c2i.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200909140852.49192.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Mon, 14 Sep 2009 09:13:35 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.95.1 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.5 required=4.2 tests=AWL,BAYES_00,RDNS_NONE autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: Attilio Rao , arch@freebsd.org, freebsd-arch@freebsd.org Subject: Re: NEWBUS states (was Re: svn commit: r196779 - in head/sys: kern sys) X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Sep 2009 13:13:37 -0000 On Saturday 12 September 2009 4:09:21 am Hans Petter Selasky wrote: > On Tuesday 08 September 2009 15:36:37 John Baldwin wrote: > > On Friday 04 September 2009 6:46:03 pm Attilio Rao wrote: > > > We all agreed the one-state was the better option but it can't be done > > > in this way because of the device_is_attached() used in the detach > > > virtual functions. Using just one transition state will break > > > device_is_attached() in those parts. > > > The right fix, as pointed out in other e-mails, is to not use > > > device_is_attached() in detach virtual functions. The better fix, in > > > my idea would involve: > > > - replace the device_is_attached() usage in detach virtual functions, > > > with a more functional support > > > - use one-state transition > > > > > > But that is just too much job to push in before then 8.0-REL and if > > > that would mean to not commit a patch and make impossible a future > > > MFC, I prefer to go with a lesser-perfect-but-still-working-approach. > > > > Wait, all you need to MFC is the change to the enum. Fixing the various > > detach routines does _not_ have to be in 8.0. That could be merged after > > the release. > > Hi, > > http://svn.freebsd.org/viewvc/base/head/sys/kern/subr_bus.c?r1=196529&r2=196779 > > I'm sorry to say that the latest patches to subr_bus.c have broken USB. I've > got several reports on memory used after free, due to bus_generic_detach() > returning EBUSY when called from uhub_detach(). > > ... > bus_generic_detach(device_t dev) > { > device_t child; > int error; > > if (dev->state != DS_ATTACHED) > return (EBUSY); > > TAILQ_FOREACH(child, &dev->children, link) { > if ((error = device_detach(child)) != 0) > return (error); > } > > return (0); > } > > A fix for USB is available here: > > http://perforce.freebsd.org/chv.cgi?CH=168387 I think bus_generic_detach() needs to work when called from a foo_detach() routine, so I think you don't need the USB changes. Even if the new states get reintroduced bus_generic_detach() will still have to work correctly the way you had used it. -- John Baldwin