From owner-freebsd-drivers@FreeBSD.ORG Sat Apr 7 15:15:27 2012 Return-Path: Delivered-To: drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id E7811106564A; Sat, 7 Apr 2012 15:15:27 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id 7383B8FC15; Sat, 7 Apr 2012 15:15:27 +0000 (UTC) Received: from skuns.kiev.zoral.com.ua (localhost [127.0.0.1]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id q37FFESo031367; Sat, 7 Apr 2012 18:15:14 +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.5/8.14.5) with ESMTP id q37FFEtH088081; Sat, 7 Apr 2012 18:15:14 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5/Submit) id q37FFEOC088080; Sat, 7 Apr 2012 18:15:14 +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: Sat, 7 Apr 2012 18:15:14 +0300 From: Konstantin Belousov To: Nathan Whitehorn Message-ID: <20120407151514.GW2358@deviant.kiev.zoral.com.ua> References: <20120407125056.GS2358@deviant.kiev.zoral.com.ua> <4F80579B.4040205@freebsd.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="CN5+qz79j8MMBHjt" Content-Disposition: inline In-Reply-To: <4F80579B.4040205@freebsd.org> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: current@freebsd.org, drivers@freebsd.org Subject: Re: device_attach(9) and driver initialization 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: Sat, 07 Apr 2012 15:15:28 -0000 --CN5+qz79j8MMBHjt Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Apr 07, 2012 at 10:04:59AM -0500, Nathan Whitehorn wrote: > On 04/07/12 07:50, Konstantin Belousov wrote: > >Hello, > >there seems to be a problem with device attach sequence offered by newbu= s. > >Basically, when device attach method is executing, device is not fully > >initialized yet. Also the device state in the newbus part of the world > >is DS_ALIVE. There is definitely no shattering news in the statements, > >but drivers that e.g. create devfs node to communicate with consumers > >are prone to a race. > > > >If /dev node is created inside device attach method, then usermode > >can start calling cdevsw methods before device fully initialized itself. > >Even more, if device tries to use newbus helpers in cdevsw methods, > >like device_busy(9), then panic occurs "called for unatteched device". > >I get reports from users about this issues, to it is not something > >that only could happen. > > > >I propose to add DEVICE_AFTER_ATTACH() driver method, to be called > >from newbus right after device attach finished and newbus considers > >the device fully initialized. Driver then could create devfs node > >in the after_attach method instead of attach. Please see the patch below. > > >=20 > Something like this would also be very useful for drivers that need to=20 > interact across the device tree, if newbus called it only after all=20 > drivers have been attached. Drivers that need to see other potentially=20 > attached drivers now need to do some hacks with SYSINIT. Would it be=20 > possible to do this? I don't think it changes the functionality you need. I am definitely fine with postponing a call further, but I am not sure how to define that point and how to implement your proposal. I am mostly thinking of the case of kld being loaded, since for compiled-in drivers, there is simply no usermode to make the havoc during attach. For the boot time attachments, I am not sure when to declare the end. E.g. USB does asynchronous device discovery. Could you prototype a change that would do what you propose ? --CN5+qz79j8MMBHjt Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (FreeBSD) iEYEARECAAYFAk+AWgIACgkQC3+MBN1Mb4hlswCghMA1W9QGOErIQUXaukNrBxIb D74AoJ9vcwS2c3f5JPGkfU3zdhrqe7zP =v3zv -----END PGP SIGNATURE----- --CN5+qz79j8MMBHjt--