tech-kern archive

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

Module and device configuration locking [was Re: Modules loading modules?]



Sorry for not replying sooner.

Please don't add a generic recursive lock facility, it would be abused.

I'd like something roughly like the following.  I think this should
also cover major configuration tasks such as device attach and detach,
so it wouldn't really be module specific.  The naming is a poor suggestion.

void
sysconfig_lock(void)
{

        if (mutex_owned(&sysconfig_mutex)) {
                /*
                 * At this point it's OK for the thread to hold other
                 * locks, since the system configuration lock was the
                 * first taken on the way in.
                 */
                sysconfig_recurse++;
                return;
        }
        /*
         * I don't remember the correct argument sequence to the
         * following, but basically we need to assert that NO locks,
         * sleep or spin, other than kernel_lock are held,
         * as the system configuration lock would be the outermost
         * lock in the system.
         */
        LOCKDEBUG_BARRIER(...);
        mutex_enter(&sysconfig_mutex);
        KASSERT(sysconfig_recurse == 0);
}

For the boot autoconfig path where you have things being driven by the
kernel, this would work OK.  Situations where there's a kthread or
something attaching and detaching devices on the fly are a bit different,
since they likely have local atomicity requirements (need to take device
private locks).  There you'd probably need the caller to take the lock.
USB comes to mind (along with some hardware RAID drivers that do hotplug
attach/detach).

Thoughts?



Home | Main Index | Thread Index | Old Index