Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 17 Mar 2008 13:10:14 -0700
From:      Alfred Perlstein <alfred@freebsd.org>
To:        John Baldwin <jhb@freebsd.org>
Cc:        stable@freebsd.org, freebsd-smp@freebsd.org
Subject:   Re: timeout/untimeout race conditions/crash [patch]
Message-ID:  <20080317201014.GA67856@elvis.mu.org>
In-Reply-To: <200803171127.20561.jhb@freebsd.org>
References:  <20080315024114.GD67856@elvis.mu.org> <200803171127.20561.jhb@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
* John Baldwin <jhb@freebsd.org> [080317 09:43] wrote:
> 
> This is not a bug.  Don't use untimeout(9) as it is not guaranteed to be 
> reliable.  Instead, use callout_*().  Your patch doesn't solve any races as 
> the driver detach routine needs to use callout_drain() and not just 
> callout_stop/untimeout anyways.  Fix your broken drivers.

I understand that some old Giant locked code can issue timeout/untimeout
without Giant held, which would certainly cause this issue to happen
and is uncorrectable, however, this is with completely Giant locked
code.

We are not trying to use timeout(9) for mpsafe code, this is old
code and relies upon Giant. 

Giant locked code should be timeout/untimeout safe.  As explained
in my email, there exists a condition where the Giant locked code
can have a timer fire even though proper Giant locking is observed.

For a Giant locked subsystem, one should be able to have the following
code work:

mtx_lock(&Giant);	/* formerly spl higher than softclock */
untimeout(&func, arg, &sc->handle);
free(sc);
mtx_unlock(&Giant);	/* formerly splx() */

Normally splsoftclock would completely block the timeout from firing
and this sort of code would be safe.  It is no longer safe due to
a BUG in the way that Giant is used.

Please reread the original mail to better understand the synopsis
of the problem.

thank you,
-Alfred



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080317201014.GA67856>