panic: sleeping thread owns a mutex

M. Warner Losh imp at bsdimp.com
Mon Apr 28 16:39:33 PDT 2003


In message: <200304282255.h3SMtuPi008021 at mta4.rcsntx.swbell.net>
            Jeffrey Hsu <hsu at FreeBSD.org> writes:
:   > Set a flag in your driver before you drop the wi lock that the
:   > wiintr() function can check and bail out immediately if it is set.
:   > For example:
: 
:   > foo_detach()
:   > {
:   >        ...
:   >        sc->sc_dead = 1;
:   >        FOO_UNLOCK(sc);			<--- Race 1
:   >        bus_teardown_intr(...)

We can't get an interrupt after this returns, and we're guaranteed
that the interrupt has terminated.

:   >        ...
: 	   mtx_destroy(&sc->sc_mtx);		<--- note this
:   > }
: 
:   > foo_intr()
:   > {
:   >        FOO_LOCK(sc);
:   >        if (sc->sc_dead) {
:   >                FOO_UNLOCK(sc);
:   >                return;
:   >        }
:   >	   ...
:   > }
: 
: The sc_dead flag doesn't protect against foo_intr() attempting to
: lock a mutex that has been destroyed.  fxp has the same problem
: and is one of the reasons, among others,  I wasn't too happy with
: the fxp softc locks introduced there.

Since this race isn't possible, the dead solution is sufficient to
guard against the Race 1 above.

: The solution I have in mind involves using the DEAD flag in the interrupt
: handler to defer destroying the mutex if the interrupt handler is active.

bus_teardown_inter already assures that.

Warner


More information about the freebsd-current mailing list