Subject: Re: socreate()
To: Elad Efrat <elad@NetBSD.org>
From: Jason Thorpe <thorpej@shagadelic.org>
List: tech-kern
Date: 10/25/2006 14:59:50
On Oct 25, 2006, at 2:54 PM, Elad Efrat wrote:
> Jason Thorpe wrote:
>>
>> On Oct 25, 2006, at 2:41 PM, Elad Efrat wrote:
>>
>>> hi,
>>>
>>> can socreate() sleep? (I want to add a kauth(9) call in there to
>>> implement socket policies in one place)
>>
>> s = splsoftnet();
>> so = pool_get(&socket_pool, PR_WAITOK);
>>
>>
>>>
>>> I *think* someone mentioned something about that in some thread in
>>> the
>>> past; looking at the code it seems that if_gre.c:gre_kick(),
>>> called at
>>> IPL_NET, can call socreate().
>>
>> socreate() must never be called from interrupt context.
>
> okay then I perhaps don't understand the code.
>
> if_gre.c:gre_kick() says it "Must be called at IPL_NET" (and it is,
> from
> gre_ioctl(), right after splnet() was called). gre_kick() in turn
> calls
> kthread_create1() with 'func' being gre_thread(). in turn, that calls
> gre_thread1(), which can call gre_socreate1(), which can call
> socreate().
Perhaps it needs to be called at IPL_NET for other reasons, but so
long as it is never called from INTERRUPT context, it should be fine
(if suboptimal -- sigh, all of this spl baggage to wade through on the
way to a real MP kernel...)
> granted, I'm not familiar with neither the gre(4) code nor kernel
> threads, but is there any guarantee that the above won't result in at
> least some cases where socreate() is called at IPL_NET?
Being called at IPL_NET via an spl call is not the same as being
called from an IPL_NET interrupt handler.
>
> -e.
>
> --
> Elad Efrat
-- thorpej