From owner-freebsd-current@FreeBSD.ORG Sat Apr 7 21:34:13 2012 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 93E80106564A; Sat, 7 Apr 2012 21:34:13 +0000 (UTC) (envelope-from julian@freebsd.org) Received: from vps1.elischer.org (vps1.elischer.org [204.109.63.16]) by mx1.freebsd.org (Postfix) with ESMTP id 4629B8FC0A; Sat, 7 Apr 2012 21:34:13 +0000 (UTC) Received: from julian-mac.elischer.org (c-67-180-24-15.hsd1.ca.comcast.net [67.180.24.15]) (authenticated bits=0) by vps1.elischer.org (8.14.5/8.14.5) with ESMTP id q37LYBpg019961 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Sat, 7 Apr 2012 14:34:12 -0700 (PDT) (envelope-from julian@freebsd.org) Message-ID: <4F80B2FE.1030007@freebsd.org> Date: Sat, 07 Apr 2012 14:34:54 -0700 From: Julian Elischer User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.4; en-US; rv:1.9.2.28) Gecko/20120306 Thunderbird/3.1.20 MIME-Version: 1.0 To: Konstantin Belousov References: <20120407125056.GS2358@deviant.kiev.zoral.com.ua> <4F80579B.4040205@freebsd.org> <20120407151514.GW2358@deviant.kiev.zoral.com.ua> In-Reply-To: <20120407151514.GW2358@deviant.kiev.zoral.com.ua> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: drivers@freebsd.org, Nathan Whitehorn , current@freebsd.org Subject: Re: device_attach(9) and driver initialization X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Apr 2012 21:34:13 -0000 On 4/7/12 8:15 AM, Konstantin Belousov wrote: > 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 newbus. >>> 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. >>> >> Something like this would also be very useful for drivers that need to >> interact across the device tree, if newbus called it only after all >> drivers have been attached. Drivers that need to see other potentially >> attached drivers now need to do some hacks with SYSINIT. Would it be >> 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. no, Geom starts tasting disk devices as as soon as you make the device. > 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 ?