tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: mutexes, IPL, tty locking



On Wed, Oct 21, 2009 at 01:19:22PM -0500, David Young wrote:
> There is something that confuses me about the TTY locking scheme, and I
> wonder if it is a bug in the kernel code or in my expectations?
> 
> Consider the following code.  The kernel defies my expectations at line
> 10, because the IPL is always IPL_HIGH, and at line 11, because the
> system panics.
> 
>      1  kmutex_t tty_lock, alldevs_mtx;
>      2  mutex_init(&tty_lock, MUTEX_DEFAULT, IPL_VM);
>      3  mutex_init(&alldevs_mtx, MUTEX_DEFAULT, IPL_HIGH);
>         
>      4  /* IPL == x */
>      5  mutex_enter(&tty_lock);
>      6  /* I expect for IPL to be max(x, IPL_VM) */
>      7  mutex_enter(&alldevs_mtx);
>      8  /* I expect for IPL to be max(x, IPL_HIGH) */

Presumable you mean max(x, IPL_VM, IPL_HIGH) but I guess IPL_HIGH >= IP_VM.

>      9  mutex_exit(&alldevs_mtx);
>     10  /* I expect for IPL to be max(x, IPL_VM) */
>     11  ttysleep(...);  /* panic: cpu_switchto: switching above IPL_SCHED (8) 
> */
>     12  mutex_exit(&tty_lock);
>     13  /* I expect for IPL to be x */

Hmmm.... I wonder where the old IPL is saved ?
(I've not looked to see!)

But the locking scheme ought to support releasing locks in other
that strict reverse order of acquisition. Which rather makes
saving the old IPL anywhere other than in the callers stack frame
rather difficult.

Of course, the above code is releasing in the 'easy' order!

        David

-- 
David Laight: david%l8s.co.uk@localhost


Home | Main Index | Thread Index | Old Index