lkml.org 
[lkml]   [2018]   [Feb]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH 4.4 20/87] ALSA: pcm: Allow aborting mutex lock at OSS read/write loops
From
Date
On Mon, 2018-02-12 at 09:34 +0100, Takashi Iwai wrote:
> On Wed, 24 Jan 2018 00:35:48 +0100,
> Ben Hutchings wrote:
> >
> > On Mon, 2018-01-15 at 13:34 +0100, Greg Kroah-Hartman wrote:
> > > 4.4-stable review patch.  If anyone has any objections, please let me know.
> > >
> > > ------------------
> > >
> > > From: Takashi Iwai <tiwai@suse.de>
> > >
> > > commit 900498a34a3ac9c611e9b425094c8106bdd7dc1c upstream.
> > >
> > > PCM OSS read/write loops keep taking the mutex lock for the whole
> > > read/write, and this might take very long when the exceptionally high
> > > amount of data is given.  Also, since it invokes with mutex_lock(),
> > > the concurrent read/write becomes unbreakable.
> > >
> > > This patch tries to address these issues by replacing mutex_lock()
> > > with mutex_lock_interruptible(), and also splits / re-takes the lock
> > > at each read/write period chunk, so that it can switch the context
> > > more finely if requested.
> >
> > [...]
> > > @@ -1414,18 +1417,18 @@ static ssize_t snd_pcm_oss_write1(struct
> > >   xfer += tmp;
> > >   if ((substream->f_flags & O_NONBLOCK) != 0 &&
> > >       tmp != runtime->oss.period_bytes)
> > > - break;
> > > + tmp = -EAGAIN;
> > >   }
> > > + err:
> > > + mutex_unlock(&runtime->oss.params_lock);
> > > + if (tmp < 0)
> > > + break;
> > >   if (signal_pending(current)) {
> > >   tmp = -ERESTARTSYS;
> > > - goto err;
> > > + break;
> > >   }
> > > + tmp = 0;
> > >   }
> > > - mutex_unlock(&runtime->oss.params_lock);
> > > - return xfer;
> > > -
> > > - err:
> > > - mutex_unlock(&runtime->oss.params_lock);
> > >   return xfer > 0 ? (snd_pcm_sframes_t)xfer : tmp;
> > >  }
> >
> > [...]
> >
> > Some of the "goto err" statements in the loop are conditional on tmp <=
> > 0, but if tmp == 0 this will no longer terminate the loop.  Is that
> > intentional or a bug?
>
> The patch rather fixes the endless loop: the signal_pending() check is
> added after goto err, so that it aborts the loop properly.

Let me rephrase then: if snd_pcm_oss_write2() returns 0, does that
imply that signal_pending() is true? If there is any other reason that
it could return 0, then this appears to introduce a bug.

Ben.

--
Ben Hutchings
Software Developer, Codethink Ltd.

\
 
 \ /
  Last update: 2018-02-14 17:21    [W:0.127 / U:0.108 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site