Subject: Re: device tree traversal
To: Jachym Holecek <>
From: Garrett D'Amore <>
List: tech-kern
Date: 07/03/2006 22:22:57
Jachym Holecek wrote:
> # matthew green 2006-07-03:
>>    	/* Allocate recursion context of max depth 16, topdown dir. */
>>    	di = device_iterator_alloc(16, DIF_WAITOK | DIF_TOPDOWN);
>> why have this '16' limit at all?  i don't see why it's necessary
>> or even a good idea.
> The idea was to avoid any allocation in device_iterator_foreach(),
> so that it could be used from interrupt context if needed (ie.
> in config_{de,}activate()) -- we probably want to avoid allocations
> within hardintrs.
> I can see two possibilities:
>   1. Just use realloc (we already cache dvi_flags, so we could pass
>      M_{WAITOK,NOWAIT} correctly).
>   2. Be aware of maximum device tree depth, allocate say 1.5 of that
>      to be safe.
> What do you think?
> 	-- Jachym

I'm of the considered opinion that we should use M_WAITOK, and not
support this iteration in interrupt context.  The only case I can think
of for interrupt context device tree traversal is hot detach (removal of
a PCMCIA card, for example, or removal of a USB node.)

From what I can tell, those busses that support "hot detach" (without
user interaction) do so without necessarily requiring a clean detach
notification in the driver.  Indeed, in the case of PCMCIA some
controllers don't even bother to issue an interrupt on removal, but the
OS has to poll for it.  And  on other hardware, the interrupt for the
PCMCIA detach doesn't necessarily block the interrupts triggered by the
device hardware.

I am unaware of any buses besides pcmcia and USB/firewire which are
designed to support hot detach without advance notification to the
driver.  Indeed, even Cardbus doesn't support this properly -- a detach
notification is required from userland _before_ physical removal in
order to guarantee safe operation.

All this means, I think, is that it is pointless to try to solve the
problem of device tree iteration in interrupt context.  There maybe
other cases for it, but unless/until there are, I'd prefer to avoid
trying support device tree iteration in interrupt context.  (Because you
know as soon as you "try" to do this, then some idiot is going to use
this for something like device _attach_, or for some other unrelated and
unnecessary purpose.  We should be doing as little as possible in
interrupt context.)

Just my opinion. :-)

    -- Garrett

Garrett D'Amore, Principal Software Engineer
Tadpole Computer / Computing Technologies Division,
General Dynamics C4 Systems
Phone: 951 325-2134  Fax: 951 325-2191