Date: Wed, 7 Jan 2004 00:27:33 -0800 (PST) From: Don Lewis <truckman@FreeBSD.org> To: bde@zeta.org.au Cc: shoesoft@gmx.net Subject: Re: sound/pcm/* bugs (was: Re: page fault panic tracked down (selwakeuppri()) - really sound/pcm/*) Message-ID: <200401070827.i078RX7E015971@gw.catspoiler.org> In-Reply-To: <20040107184629.H7587@gamplex.bde.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 7 Jan, Bruce Evans wrote: > On Tue, 6 Jan 2004, Don Lewis wrote: > >> [... lots of good stuff] >> I found another bug, though. Holding a mutex across a malloc() call is >> not allowed because malloc() can sleep, and sleeping while holding a >> mutex is not allowed. sndbuf_resize() sndbuf_remalloc() both call >> malloc() to allocate buffers, and sndbuf_alloc() and sndbuf_setup() call >> sndbuf_resize(). The problem is that chn_setblocksize() calls >> sndbuf_remalloc() while the channel mutex is held. We can't just unlock >> the mutex around the sndbuf_remalloc() call because the channel >> interrupt service routine could run while the buffer is being >> re-allocated. It would be best if the channel were to be shut down when >> re-allocating the buffer. This is likely to be messy since >> chn_setblocksize() is called from lots of different places. > > Er, its an M_NOWAIT malloc(), so it can't sleep. M_WAITOK malloc()s > in interrupt handlers would also be bugs, but that is not a problem > here for the same reason. Hmn, I totally missed that. That eliminates the problem of holding the mutex, but probably violates POLA if the sound stops playing because of a transient memory shortage. I also wonder what happens if the buffer goes away while the channel is running, but I'm not curious enough to dive back into the code. > There should be more checks for potential sleeps while holding a mutex. > > Bruce
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200401070827.i078RX7E015971>