Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 07 Apr 2012 10:04:59 -0500
From:      Nathan Whitehorn <nwhitehorn@freebsd.org>
To:        Konstantin Belousov <kostikbel@gmail.com>
Cc:        current@freebsd.org, drivers@freebsd.org
Subject:   Re: device_attach(9) and driver initialization
Message-ID:  <4F80579B.4040205@freebsd.org>
In-Reply-To: <20120407125056.GS2358@deviant.kiev.zoral.com.ua>
References:  <20120407125056.GS2358@deviant.kiev.zoral.com.ua>

next in thread | previous in thread | raw e-mail | index | archive | help
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.
-Nathan



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4F80579B.4040205>