tech-kern archive

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

Re: What's an "MPSAFE" driver need to do?

On 2/28/13 12:43 AM, Manuel Bouyer wrote:
> A driver not marked MPSAFE will be entered (especially
> its interrupt routine, but also from upper layers) with
> kernel_lock held. This is what makes spl(9) still work.

A nice clear example of this is in kern/subr_devsw.c, where userland
operations on device files are dispatched to their respective drivers.
Each place where the driver's function is called is bracketed with
DEV_LOCK/DEV_UNLOCK, e.g. this case implementing read(2):

>         DEV_LOCK(d);
>         rv = (*d->d_read)(dev, uio, flag);
>         DEV_UNLOCK(d);
>         return rv;

where DEV_LOCK acquires the kernel lock if the driver's device entry
doesn't have D_MPSAFE set:

> #define DEV_LOCK(d)                                             \
>         if ((mpflag = (d->d_flag & D_MPSAFE)) == 0) {           \
>                 KERNEL_LOCK(1, NULL);                           \
>         }

and KERNEL_LOCK() acquires a global lock, as well as doing a bunch of
other housekeeping.

Home | Main Index | Thread Index | Old Index