Revert "ALSA: pcm: Fix potential AB/BA lock with buffer_mutex and mmap_lock"
This reverts commit 7777744e92
.
It breaks the kernel abi so revert it for now. We will add it back
later at the next kabi update.
Bug: 161946584
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: I09fe568c08e50679adf930aadb79a8544789af81
This commit is contained in:
parent
93d8bbeafb
commit
990e8bd6d9
|
@ -399,7 +399,6 @@ struct snd_pcm_runtime {
|
|||
struct fasync_struct *fasync;
|
||||
bool stop_operating; /* sync_stop will be called */
|
||||
struct mutex buffer_mutex; /* protect for buffer changes */
|
||||
atomic_t buffer_accessing; /* >0: in r/w operation, <0: blocked */
|
||||
|
||||
/* -- private section -- */
|
||||
void *private_data;
|
||||
|
|
|
@ -970,7 +970,6 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
|
|||
|
||||
runtime->status->state = SNDRV_PCM_STATE_OPEN;
|
||||
mutex_init(&runtime->buffer_mutex);
|
||||
atomic_set(&runtime->buffer_accessing, 0);
|
||||
|
||||
substream->runtime = runtime;
|
||||
substream->private_data = pcm->private_data;
|
||||
|
|
|
@ -1905,9 +1905,11 @@ static int wait_for_avail(struct snd_pcm_substream *substream,
|
|||
if (avail >= runtime->twake)
|
||||
break;
|
||||
snd_pcm_stream_unlock_irq(substream);
|
||||
mutex_unlock(&runtime->buffer_mutex);
|
||||
|
||||
tout = schedule_timeout(wait_time);
|
||||
|
||||
mutex_lock(&runtime->buffer_mutex);
|
||||
snd_pcm_stream_lock_irq(substream);
|
||||
set_current_state(TASK_INTERRUPTIBLE);
|
||||
switch (runtime->status->state) {
|
||||
|
@ -2201,6 +2203,7 @@ snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream,
|
|||
|
||||
nonblock = !!(substream->f_flags & O_NONBLOCK);
|
||||
|
||||
mutex_lock(&runtime->buffer_mutex);
|
||||
snd_pcm_stream_lock_irq(substream);
|
||||
err = pcm_accessible_state(runtime);
|
||||
if (err < 0)
|
||||
|
@ -2255,15 +2258,10 @@ snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream,
|
|||
err = -EINVAL;
|
||||
goto _end_unlock;
|
||||
}
|
||||
if (!atomic_inc_unless_negative(&runtime->buffer_accessing)) {
|
||||
err = -EBUSY;
|
||||
goto _end_unlock;
|
||||
}
|
||||
snd_pcm_stream_unlock_irq(substream);
|
||||
err = writer(substream, appl_ofs, data, offset, frames,
|
||||
transfer);
|
||||
snd_pcm_stream_lock_irq(substream);
|
||||
atomic_dec(&runtime->buffer_accessing);
|
||||
if (err < 0)
|
||||
goto _end_unlock;
|
||||
err = pcm_accessible_state(runtime);
|
||||
|
@ -2293,6 +2291,7 @@ snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream,
|
|||
if (xfer > 0 && err >= 0)
|
||||
snd_pcm_update_state(substream, runtime);
|
||||
snd_pcm_stream_unlock_irq(substream);
|
||||
mutex_unlock(&runtime->buffer_mutex);
|
||||
return xfer > 0 ? (snd_pcm_sframes_t)xfer : err;
|
||||
}
|
||||
EXPORT_SYMBOL(__snd_pcm_lib_xfer);
|
||||
|
|
|
@ -672,24 +672,6 @@ static int snd_pcm_hw_params_choose(struct snd_pcm_substream *pcm,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* acquire buffer_mutex; if it's in r/w operation, return -EBUSY, otherwise
|
||||
* block the further r/w operations
|
||||
*/
|
||||
static int snd_pcm_buffer_access_lock(struct snd_pcm_runtime *runtime)
|
||||
{
|
||||
if (!atomic_dec_unless_positive(&runtime->buffer_accessing))
|
||||
return -EBUSY;
|
||||
mutex_lock(&runtime->buffer_mutex);
|
||||
return 0; /* keep buffer_mutex, unlocked by below */
|
||||
}
|
||||
|
||||
/* release buffer_mutex and clear r/w access flag */
|
||||
static void snd_pcm_buffer_access_unlock(struct snd_pcm_runtime *runtime)
|
||||
{
|
||||
mutex_unlock(&runtime->buffer_mutex);
|
||||
atomic_inc(&runtime->buffer_accessing);
|
||||
}
|
||||
|
||||
#if IS_ENABLED(CONFIG_SND_PCM_OSS)
|
||||
#define is_oss_stream(substream) ((substream)->oss.oss)
|
||||
#else
|
||||
|
@ -700,16 +682,14 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream,
|
|||
struct snd_pcm_hw_params *params)
|
||||
{
|
||||
struct snd_pcm_runtime *runtime;
|
||||
int err, usecs;
|
||||
int err = 0, usecs;
|
||||
unsigned int bits;
|
||||
snd_pcm_uframes_t frames;
|
||||
|
||||
if (PCM_RUNTIME_CHECK(substream))
|
||||
return -ENXIO;
|
||||
runtime = substream->runtime;
|
||||
err = snd_pcm_buffer_access_lock(runtime);
|
||||
if (err < 0)
|
||||
return err;
|
||||
mutex_lock(&runtime->buffer_mutex);
|
||||
snd_pcm_stream_lock_irq(substream);
|
||||
switch (runtime->status->state) {
|
||||
case SNDRV_PCM_STATE_OPEN:
|
||||
|
@ -827,7 +807,7 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream,
|
|||
snd_pcm_lib_free_pages(substream);
|
||||
}
|
||||
unlock:
|
||||
snd_pcm_buffer_access_unlock(runtime);
|
||||
mutex_unlock(&runtime->buffer_mutex);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -872,9 +852,7 @@ static int snd_pcm_hw_free(struct snd_pcm_substream *substream)
|
|||
if (PCM_RUNTIME_CHECK(substream))
|
||||
return -ENXIO;
|
||||
runtime = substream->runtime;
|
||||
result = snd_pcm_buffer_access_lock(runtime);
|
||||
if (result < 0)
|
||||
return result;
|
||||
mutex_lock(&runtime->buffer_mutex);
|
||||
snd_pcm_stream_lock_irq(substream);
|
||||
switch (runtime->status->state) {
|
||||
case SNDRV_PCM_STATE_SETUP:
|
||||
|
@ -893,7 +871,7 @@ static int snd_pcm_hw_free(struct snd_pcm_substream *substream)
|
|||
snd_pcm_set_state(substream, SNDRV_PCM_STATE_OPEN);
|
||||
cpu_latency_qos_remove_request(&substream->latency_pm_qos_req);
|
||||
unlock:
|
||||
snd_pcm_buffer_access_unlock(runtime);
|
||||
mutex_unlock(&runtime->buffer_mutex);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1378,15 +1356,12 @@ static int snd_pcm_action_nonatomic(const struct action_ops *ops,
|
|||
|
||||
/* Guarantee the group members won't change during non-atomic action */
|
||||
down_read(&snd_pcm_link_rwsem);
|
||||
res = snd_pcm_buffer_access_lock(substream->runtime);
|
||||
if (res < 0)
|
||||
goto unlock;
|
||||
mutex_lock(&substream->runtime->buffer_mutex);
|
||||
if (snd_pcm_stream_linked(substream))
|
||||
res = snd_pcm_action_group(ops, substream, state, false);
|
||||
else
|
||||
res = snd_pcm_action_single(ops, substream, state);
|
||||
snd_pcm_buffer_access_unlock(substream->runtime);
|
||||
unlock:
|
||||
mutex_unlock(&substream->runtime->buffer_mutex);
|
||||
up_read(&snd_pcm_link_rwsem);
|
||||
return res;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue