* [PATCH] ASoC: soc-pcm: Track BE pause per FE-BE link
@ 2026-11-19 19:22 ` Suyuan Wang via B4 Relay
0 siblings, 0 replies; 4+ messages in thread
From: Suyuan Wang @ 2026-11-19 19:22 UTC (permalink / raw)
To: broonie, lgirdwood
Cc: yung-chuan.liao, peter.ujfalusi, pierre-louis.bossart,
linux-sound, ranjani.sridharan, tiwai, perex, linux-kernel
From: Suyuan Wang <stevewong@hust.edu.cn>
Commit 9995c1d096c8 ("ASoC: soc-pcm: improve BE transition for
PAUSE_RELEASE") counts paused FEs in be_pause and remembers in
fe->dpcm[stream].fe_pause that a FE is paused. But fe_pause is one
flag for the FE, while the pause it records is counted in each of its
BEs separately, and nothing tells which BEs hold this FE's pause. The
counts go wrong when a BE trigger fails or a FE has several BEs:
- When the BE PAUSE_RELEASE fails, fe_pause and be_pause are left
updated. The BE is still PAUSED, so the PAUSE_PUSH the PCM core
sends to undo the release skips it. After a retried release
be_pause is -1, and the next STOP sends PAUSE_PUSH to the BE instead
of STOP.
- When the BE PAUSE_PUSH fails, the PCM core undoes it with
PAUSE_RELEASE, which increments be_start although this FE never
left it. be_start ends up at 2 and STOP never stops the BE.
- When the release of one BE fails, the PAUSE_PUSH undo is also
applied to BEs that the release had not reached yet. For a BE shared
with a running FE that pauses it under the other FE.
- Compress offload can stop a paused stream directly. When two FEs
share a BE and the paused one is stopped while the other is
running, STOP takes the paused FE out of be_start a second time and
stops the BE under the running FE.
Keep the pause in struct snd_soc_dpcm, which links one FE to one BE,
instead:
- PAUSE_PUSH marks the link and skips a link that is already marked;
- PAUSE_RELEASE only releases a marked link;
- STOP drops the pause of a marked link instead of touching be_start;
- a failed BE trigger rolls back just that link.
When a suspended stream that was previously paused is prepared or
closed without first being resumed, no PAUSE_RELEASE or STOP trigger
is sent for that stream. START therefore consumes any pause left on
its link, and closing the link drops any remaining pause under the
BE stream lock.
Found with a static analysis tool and checked by hand.
Fixes: 9995c1d096c8 ("ASoC: soc-pcm: improve BE transition for PAUSE_RELEASE")
Cc: stable@vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
Compile tested on arm with clang (sound/soc builds, W=1 clean for
soc-pcm.c); not run on hardware.
I checked the bookkeeping with a model of the START, PAUSE_PUSH,
PAUSE_RELEASE and STOP branches, BE prepare/startup/close, and the
callers (single-substream undo, retries of the failed linked-group
member, and compressed streams without automatic undo, including
compress STOP from PAUSED). The model runs 14
sequences; with this patch every one ends with the BEs stopped and
be_start/be_pause back at 0. These sequences send the same BE commands
as before: start/pause/release/stop, pause then stop, the shared-BE
sequence from 9995c1d096c8, pause + system suspend + prepare + start +
stop, and pause + system suspend + close + reopen + start + stop. It is
a model of the counters, not a test on a device.
---
include/sound/soc-dpcm.h | 4 ++-
sound/soc/soc-pcm.c | 69 +++++++++++++++++++++++++++++++++++++-----------
2 files changed, 57 insertions(+), 16 deletions(-)
diff --git a/include/sound/soc-dpcm.h b/include/sound/soc-dpcm.h
index af24665e37e8..801ad83abfe8 100644
--- a/include/sound/soc-dpcm.h
+++ b/include/sound/soc-dpcm.h
@@ -73,6 +73,9 @@ struct snd_soc_dpcm {
/* link state */
enum snd_soc_dpcm_link_state state;
+ /* FE paused this BE: counted in be_pause, not in be_start */
+ bool paused;
+
/* list of BE and FE for this DPCM link */
struct list_head list_be;
struct list_head list_fe;
@@ -100,7 +103,6 @@ struct snd_soc_dpcm_runtime {
int be_start; /* refcount protected by BE stream pcm lock */
int be_pause; /* refcount protected by BE stream pcm lock */
- bool fe_pause; /* used to track STOP after PAUSE */
};
#define for_each_dpcm_fe(be, stream, _dpcm) \
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index ef8ccf52798e..cb8d23756b1e 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -1685,6 +1685,17 @@ void dpcm_be_dai_stop(struct snd_soc_pcm_runtime *fe, int stream,
if (!snd_soc_dpcm_can_be_update(fe, be, stream))
continue;
+ /*
+ * A pause may survive until close, e.g. after system suspend.
+ * Drop the pause this link still holds.
+ */
+ if (dpcm->paused) {
+ snd_pcm_stream_lock_irq(be_substream);
+ dpcm->paused = false;
+ be->dpcm[stream].be_pause--;
+ snd_pcm_stream_unlock_irq(be_substream);
+ }
+
if (be->dpcm[stream].users == 0) {
dev_err(be->dev, "ASoC: no users %s at close - state %s\n",
snd_pcm_direction_name(stream),
@@ -2220,7 +2231,7 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
int cmd)
{
struct snd_soc_pcm_runtime *be;
- bool pause_stop_transition;
+ bool was_paused;
struct snd_soc_dpcm *dpcm;
unsigned long flags;
int ret = 0;
@@ -2248,6 +2259,16 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
(be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED))
goto next;
+ /*
+ * A stream suspended while paused and prepared again
+ * starts without a PAUSE_RELEASE: drop its pause here.
+ */
+ was_paused = dpcm->paused;
+ if (was_paused) {
+ dpcm->paused = false;
+ be->dpcm[stream].be_pause--;
+ }
+
be->dpcm[stream].be_start++;
if (be->dpcm[stream].be_start != 1)
goto next;
@@ -2260,6 +2281,10 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
SNDRV_PCM_TRIGGER_START);
if (ret) {
be->dpcm[stream].be_start--;
+ if (was_paused) {
+ dpcm->paused = true;
+ be->dpcm[stream].be_pause++;
+ }
goto next;
}
@@ -2287,7 +2312,11 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
(be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED))
goto next;
- fe->dpcm[stream].fe_pause = false;
+ /* nothing to release if this FE didn't pause this BE */
+ if (!dpcm->paused)
+ goto next;
+
+ dpcm->paused = false;
be->dpcm[stream].be_pause--;
be->dpcm[stream].be_start++;
@@ -2297,6 +2326,8 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
ret = soc_pcm_trigger(be_substream, cmd);
if (ret) {
be->dpcm[stream].be_start--;
+ dpcm->paused = true;
+ be->dpcm[stream].be_pause++;
goto next;
}
@@ -2307,30 +2338,32 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
(be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED))
goto next;
- if (be->dpcm[stream].state == SND_SOC_DPCM_STATE_START)
+ /*
+ * A paused FE left be_start when it paused and only
+ * holds a pause on this BE.
+ */
+ was_paused = dpcm->paused;
+ if (was_paused) {
+ dpcm->paused = false;
+ be->dpcm[stream].be_pause--;
+ } else if (be->dpcm[stream].state == SND_SOC_DPCM_STATE_START) {
be->dpcm[stream].be_start--;
+ }
if (be->dpcm[stream].be_start != 0)
goto next;
- pause_stop_transition = false;
- if (fe->dpcm[stream].fe_pause) {
- pause_stop_transition = true;
- fe->dpcm[stream].fe_pause = false;
- be->dpcm[stream].be_pause--;
- }
-
if (be->dpcm[stream].be_pause != 0)
ret = soc_pcm_trigger(be_substream, SNDRV_PCM_TRIGGER_PAUSE_PUSH);
else
ret = soc_pcm_trigger(be_substream, SNDRV_PCM_TRIGGER_STOP);
if (ret) {
- if (be->dpcm[stream].state == SND_SOC_DPCM_STATE_START)
- be->dpcm[stream].be_start++;
- if (pause_stop_transition) {
- fe->dpcm[stream].fe_pause = true;
+ if (was_paused) {
+ dpcm->paused = true;
be->dpcm[stream].be_pause++;
+ } else if (be->dpcm[stream].state == SND_SOC_DPCM_STATE_START) {
+ be->dpcm[stream].be_start++;
}
goto next;
}
@@ -2361,7 +2394,11 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
goto next;
- fe->dpcm[stream].fe_pause = true;
+ /* this FE's pause is already counted on this BE */
+ if (dpcm->paused)
+ goto next;
+
+ dpcm->paused = true;
be->dpcm[stream].be_pause++;
be->dpcm[stream].be_start--;
@@ -2371,6 +2408,8 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
ret = soc_pcm_trigger(be_substream, cmd);
if (ret) {
be->dpcm[stream].be_start++;
+ dpcm->paused = false;
+ be->dpcm[stream].be_pause--;
goto next;
}
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH] ASoC: soc-pcm: Track BE pause per FE-BE link
@ 2026-11-19 19:22 ` Suyuan Wang via B4 Relay
0 siblings, 0 replies; 4+ messages in thread
From: Suyuan Wang via B4 Relay @ 2026-11-19 19:22 UTC (permalink / raw)
To: broonie, lgirdwood
Cc: yung-chuan.liao, peter.ujfalusi, pierre-louis.bossart,
linux-sound, ranjani.sridharan, tiwai, perex, linux-kernel
From: Suyuan Wang <stevewong@hust.edu.cn>
Commit 9995c1d096c8 ("ASoC: soc-pcm: improve BE transition for
PAUSE_RELEASE") counts paused FEs in be_pause and remembers in
fe->dpcm[stream].fe_pause that a FE is paused. But fe_pause is one
flag for the FE, while the pause it records is counted in each of its
BEs separately, and nothing tells which BEs hold this FE's pause. The
counts go wrong when a BE trigger fails or a FE has several BEs:
- When the BE PAUSE_RELEASE fails, fe_pause and be_pause are left
updated. The BE is still PAUSED, so the PAUSE_PUSH the PCM core
sends to undo the release skips it. After a retried release
be_pause is -1, and the next STOP sends PAUSE_PUSH to the BE instead
of STOP.
- When the BE PAUSE_PUSH fails, the PCM core undoes it with
PAUSE_RELEASE, which increments be_start although this FE never
left it. be_start ends up at 2 and STOP never stops the BE.
- When the release of one BE fails, the PAUSE_PUSH undo is also
applied to BEs that the release had not reached yet. For a BE shared
with a running FE that pauses it under the other FE.
- Compress offload can stop a paused stream directly. When two FEs
share a BE and the paused one is stopped while the other is
running, STOP takes the paused FE out of be_start a second time and
stops the BE under the running FE.
Keep the pause in struct snd_soc_dpcm, which links one FE to one BE,
instead:
- PAUSE_PUSH marks the link and skips a link that is already marked;
- PAUSE_RELEASE only releases a marked link;
- STOP drops the pause of a marked link instead of touching be_start;
- a failed BE trigger rolls back just that link.
When a suspended stream that was previously paused is prepared or
closed without first being resumed, no PAUSE_RELEASE or STOP trigger
is sent for that stream. START therefore consumes any pause left on
its link, and closing the link drops any remaining pause under the
BE stream lock.
Found with a static analysis tool and checked by hand.
Fixes: 9995c1d096c8 ("ASoC: soc-pcm: improve BE transition for PAUSE_RELEASE")
Cc: stable@vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
Compile tested on arm with clang (sound/soc builds, W=1 clean for
soc-pcm.c); not run on hardware.
I checked the bookkeeping with a model of the START, PAUSE_PUSH,
PAUSE_RELEASE and STOP branches, BE prepare/startup/close, and the
callers (single-substream undo, retries of the failed linked-group
member, and compressed streams without automatic undo, including
compress STOP from PAUSED). The model runs 14
sequences; with this patch every one ends with the BEs stopped and
be_start/be_pause back at 0. These sequences send the same BE commands
as before: start/pause/release/stop, pause then stop, the shared-BE
sequence from 9995c1d096c8, pause + system suspend + prepare + start +
stop, and pause + system suspend + close + reopen + start + stop. It is
a model of the counters, not a test on a device.
---
include/sound/soc-dpcm.h | 4 ++-
sound/soc/soc-pcm.c | 69 +++++++++++++++++++++++++++++++++++++-----------
2 files changed, 57 insertions(+), 16 deletions(-)
diff --git a/include/sound/soc-dpcm.h b/include/sound/soc-dpcm.h
index af24665e37e8..801ad83abfe8 100644
--- a/include/sound/soc-dpcm.h
+++ b/include/sound/soc-dpcm.h
@@ -73,6 +73,9 @@ struct snd_soc_dpcm {
/* link state */
enum snd_soc_dpcm_link_state state;
+ /* FE paused this BE: counted in be_pause, not in be_start */
+ bool paused;
+
/* list of BE and FE for this DPCM link */
struct list_head list_be;
struct list_head list_fe;
@@ -100,7 +103,6 @@ struct snd_soc_dpcm_runtime {
int be_start; /* refcount protected by BE stream pcm lock */
int be_pause; /* refcount protected by BE stream pcm lock */
- bool fe_pause; /* used to track STOP after PAUSE */
};
#define for_each_dpcm_fe(be, stream, _dpcm) \
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index ef8ccf52798e..cb8d23756b1e 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -1685,6 +1685,17 @@ void dpcm_be_dai_stop(struct snd_soc_pcm_runtime *fe, int stream,
if (!snd_soc_dpcm_can_be_update(fe, be, stream))
continue;
+ /*
+ * A pause may survive until close, e.g. after system suspend.
+ * Drop the pause this link still holds.
+ */
+ if (dpcm->paused) {
+ snd_pcm_stream_lock_irq(be_substream);
+ dpcm->paused = false;
+ be->dpcm[stream].be_pause--;
+ snd_pcm_stream_unlock_irq(be_substream);
+ }
+
if (be->dpcm[stream].users == 0) {
dev_err(be->dev, "ASoC: no users %s at close - state %s\n",
snd_pcm_direction_name(stream),
@@ -2220,7 +2231,7 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
int cmd)
{
struct snd_soc_pcm_runtime *be;
- bool pause_stop_transition;
+ bool was_paused;
struct snd_soc_dpcm *dpcm;
unsigned long flags;
int ret = 0;
@@ -2248,6 +2259,16 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
(be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED))
goto next;
+ /*
+ * A stream suspended while paused and prepared again
+ * starts without a PAUSE_RELEASE: drop its pause here.
+ */
+ was_paused = dpcm->paused;
+ if (was_paused) {
+ dpcm->paused = false;
+ be->dpcm[stream].be_pause--;
+ }
+
be->dpcm[stream].be_start++;
if (be->dpcm[stream].be_start != 1)
goto next;
@@ -2260,6 +2281,10 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
SNDRV_PCM_TRIGGER_START);
if (ret) {
be->dpcm[stream].be_start--;
+ if (was_paused) {
+ dpcm->paused = true;
+ be->dpcm[stream].be_pause++;
+ }
goto next;
}
@@ -2287,7 +2312,11 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
(be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED))
goto next;
- fe->dpcm[stream].fe_pause = false;
+ /* nothing to release if this FE didn't pause this BE */
+ if (!dpcm->paused)
+ goto next;
+
+ dpcm->paused = false;
be->dpcm[stream].be_pause--;
be->dpcm[stream].be_start++;
@@ -2297,6 +2326,8 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
ret = soc_pcm_trigger(be_substream, cmd);
if (ret) {
be->dpcm[stream].be_start--;
+ dpcm->paused = true;
+ be->dpcm[stream].be_pause++;
goto next;
}
@@ -2307,30 +2338,32 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
(be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED))
goto next;
- if (be->dpcm[stream].state == SND_SOC_DPCM_STATE_START)
+ /*
+ * A paused FE left be_start when it paused and only
+ * holds a pause on this BE.
+ */
+ was_paused = dpcm->paused;
+ if (was_paused) {
+ dpcm->paused = false;
+ be->dpcm[stream].be_pause--;
+ } else if (be->dpcm[stream].state == SND_SOC_DPCM_STATE_START) {
be->dpcm[stream].be_start--;
+ }
if (be->dpcm[stream].be_start != 0)
goto next;
- pause_stop_transition = false;
- if (fe->dpcm[stream].fe_pause) {
- pause_stop_transition = true;
- fe->dpcm[stream].fe_pause = false;
- be->dpcm[stream].be_pause--;
- }
-
if (be->dpcm[stream].be_pause != 0)
ret = soc_pcm_trigger(be_substream, SNDRV_PCM_TRIGGER_PAUSE_PUSH);
else
ret = soc_pcm_trigger(be_substream, SNDRV_PCM_TRIGGER_STOP);
if (ret) {
- if (be->dpcm[stream].state == SND_SOC_DPCM_STATE_START)
- be->dpcm[stream].be_start++;
- if (pause_stop_transition) {
- fe->dpcm[stream].fe_pause = true;
+ if (was_paused) {
+ dpcm->paused = true;
be->dpcm[stream].be_pause++;
+ } else if (be->dpcm[stream].state == SND_SOC_DPCM_STATE_START) {
+ be->dpcm[stream].be_start++;
}
goto next;
}
@@ -2361,7 +2394,11 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START)
goto next;
- fe->dpcm[stream].fe_pause = true;
+ /* this FE's pause is already counted on this BE */
+ if (dpcm->paused)
+ goto next;
+
+ dpcm->paused = true;
be->dpcm[stream].be_pause++;
be->dpcm[stream].be_start--;
@@ -2371,6 +2408,8 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
ret = soc_pcm_trigger(be_substream, cmd);
if (ret) {
be->dpcm[stream].be_start++;
+ dpcm->paused = false;
+ be->dpcm[stream].be_pause--;
goto next;
}
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] ASoC: soc-pcm: Track BE pause per FE-BE link
2026-11-19 19:22 ` Suyuan Wang via B4 Relay
(?)
@ 2026-11-19 19:44 ` sashiko-bot
2026-11-19 19:50 ` Wong Steve
-1 siblings, 1 reply; 4+ messages in thread
From: sashiko-bot @ 2026-11-19 19:44 UTC (permalink / raw)
To: Suyuan Wang; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] ASoC: soc-pcm: duplicate PAUSE_PUSH sent on STOP in
dpcm_be_dai_trigger()
- [Medium] ASoC: soc-pcm: stale pause count after prepare/hw_free in
dpcm_be_dai_trigger()
- [Medium] ASoC: soc-pcm: BE left in PAUSED state on close in
dpcm_be_dai_stop()
--
commit 30a052e7da7505ef9d19e12059b179dfd9931fe2
Author: Suyuan Wang <stevewong@hust.edu.cn>
ASoC: soc-pcm: Track BE pause per FE-BE link
This commit replaces the per-FE fe_pause boolean with a per-link paused
flag in struct snd_soc_dpcm so that BE pause refcounting and trigger rollbacks
are tracked per FE-BE link.
> diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
> index ef8ccf52798eb..cb8d23756b1e0 100644
> --- a/sound/soc/soc-pcm.c
> +++ b/sound/soc/soc-pcm.c
> @@ -1685,6 +1685,17 @@ void dpcm_be_dai_stop(struct snd_soc_pcm_runtime *fe, int stream,
> if (!snd_soc_dpcm_can_be_update(fe, be, stream))
> continue;
>
> + /*
> + * A pause may survive until close, e.g. after system suspend.
> + * Drop the pause this link still holds.
> + */
> + if (dpcm->paused) {
> + snd_pcm_stream_lock_irq(be_substream);
> + dpcm->paused = false;
> + be->dpcm[stream].be_pause--;
> + snd_pcm_stream_unlock_irq(be_substream);
> + }
> +
> if (be->dpcm[stream].users == 0) {
> dev_err(be->dev, "ASoC: no users %s at close - state %s\n",
> snd_pcm_direction_name(stream),
[Severity: Medium]
Can this leave the BE stuck in SND_SOC_DPCM_STATE_PAUSED when another idle FE
still has the shared BE open?
If FE1 is paused on a shared BE across system suspend and then closed while
FE2 is still open (be->dpcm[stream].users > 1), dpcm_be_dai_stop() drops
be->dpcm[stream].be_pause to 0 and returns early after decrementing users.
That leaves be->dpcm[stream].state at SND_SOC_DPCM_STATE_PAUSED with
be_start == 0 and be_pause == 0, causing later dpcm_be_dai_hw_params() calls
for FE2 to skip the BE because its state is not OPEN, HW_PARAMS, or HW_FREE.
> @@ -2220,7 +2231,7 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
> int cmd)
> {
> struct snd_soc_pcm_runtime *be;
> - bool pause_stop_transition;
> + bool was_paused;
> struct snd_soc_dpcm *dpcm;
> unsigned long flags;
> int ret = 0;
> @@ -2248,6 +2259,16 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
> (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED))
> goto next;
>
> + /*
> + * A stream suspended while paused and prepared again
> + * starts without a PAUSE_RELEASE: drop its pause here.
> + */
> + was_paused = dpcm->paused;
> + if (was_paused) {
> + dpcm->paused = false;
> + be->dpcm[stream].be_pause--;
> + }
> +
> be->dpcm[stream].be_start++;
> if (be->dpcm[stream].be_start != 1)
> goto next;
> @@ -2260,6 +2281,10 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
> SNDRV_PCM_TRIGGER_START);
> if (ret) {
> be->dpcm[stream].be_start--;
> + if (was_paused) {
> + dpcm->paused = true;
> + be->dpcm[stream].be_pause++;
> + }
> goto next;
> }
[Severity: Medium]
Does deferring pause cleanup until SNDRV_PCM_TRIGGER_START leave a stale
be->dpcm[stream].be_pause count after a suspended stream is prepared or
hw_freed?
When a paused FE is suspended and then recovered with snd_pcm_prepare() or
snd_pcm_drop() + snd_pcm_hw_free(), the FE transitions to PREPARE or HW_FREE
without sending PAUSE_RELEASE or STOP. Until that FE either starts or closes,
dpcm->paused remains true and be->dpcm[stream].be_pause stays elevated (and is
restored if SNDRV_PCM_TRIGGER_START fails). If another FE sharing the BE
starts and stops in the meantime, its STOP sees be_pause != 0 and sends
SNDRV_PCM_TRIGGER_PAUSE_PUSH instead of SNDRV_PCM_TRIGGER_STOP, leaving the BE
in SND_SOC_DPCM_STATE_PAUSED when no stream is paused.
[ ... ]
> @@ -2307,30 +2338,32 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
> (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED))
> goto next;
>
> - if (be->dpcm[stream].state == SND_SOC_DPCM_STATE_START)
> + /*
> + * A paused FE left be_start when it paused and only
> + * holds a pause on this BE.
> + */
> + was_paused = dpcm->paused;
> + if (was_paused) {
> + dpcm->paused = false;
> + be->dpcm[stream].be_pause--;
> + } else if (be->dpcm[stream].state == SND_SOC_DPCM_STATE_START) {
> be->dpcm[stream].be_start--;
> + }
>
> if (be->dpcm[stream].be_start != 0)
> goto next;
>
> - pause_stop_transition = false;
> - if (fe->dpcm[stream].fe_pause) {
> - pause_stop_transition = true;
> - fe->dpcm[stream].fe_pause = false;
> - be->dpcm[stream].be_pause--;
> - }
> -
> if (be->dpcm[stream].be_pause != 0)
> ret = soc_pcm_trigger(be_substream, SNDRV_PCM_TRIGGER_PAUSE_PUSH);
> else
> ret = soc_pcm_trigger(be_substream, SNDRV_PCM_TRIGGER_STOP);
[Severity: Medium]
Can SNDRV_PCM_TRIGGER_STOP send a duplicate SNDRV_PCM_TRIGGER_PAUSE_PUSH to a
BE that is already in SND_SOC_DPCM_STATE_PAUSED?
When be->dpcm[stream].state is already SND_SOC_DPCM_STATE_PAUSED,
be->dpcm[stream].be_start is 0. If two paused FEs share the BE (be_pause == 2)
and one of them is stopped, be_pause drops to 1 and execution falls through to
soc_pcm_trigger(be_substream, SNDRV_PCM_TRIGGER_PAUSE_PUSH) on the
already-paused BE. The same duplicate PAUSE_PUSH happens if STOP runs for an
unpaused FE (was_paused == false) while another FE holds the BE in
SND_SOC_DPCM_STATE_PAUSED, such as when snd_pcm_undo_start() sends STOP after a
failed start.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119-asoc-dpcm-pause-link-v1-1-5b97347b5771@gmail.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] ASoC: soc-pcm: Track BE pause per FE-BE link
2026-11-19 19:44 ` sashiko-bot
@ 2026-11-19 19:50 ` Wong Steve
0 siblings, 0 replies; 4+ messages in thread
From: Wong Steve @ 2026-11-19 19:50 UTC (permalink / raw)
To: sashiko-reviews; +Cc: linux-sound
Hi,
> - [Medium] ASoC: soc-pcm: duplicate PAUSE_PUSH sent on STOP in
> dpcm_be_dai_trigger()
> - [Medium] ASoC: soc-pcm: stale pause count after prepare/hw_free in
> dpcm_be_dai_trigger()
> - [Medium] ASoC: soc-pcm: BE left in PAUSED state on close in
> dpcm_be_dai_stop()
I went through the three cases with the code before this patch, and it
behaves the same way in each of them:
1. Closing a FE that was paused across a system suspend while another
FE keeps the shared BE open: before the patch the BE also stays
PAUSED (with be_pause still at 1), so the other FE's hw_params skips
it in the same way. The patch only drops the stale count.
2. A FE that was paused across a system suspend and then prepared but
not started: before the patch be_pause also stays at 1 until that FE
stops, so a STOP from another FE sharing the BE sends PAUSE_PUSH in
the same way.
3. STOP sending PAUSE_PUSH to a BE that is already PAUSED: the old code
does the same whenever be_pause is still non-zero after the stop.
So I don't think these are regressions from this patch, but they are
gaps in the same bookkeeping. If that's useful, I can send follow-up
patches to drop the link's pause when the FE is prepared, and to skip
the trigger in STOP when the BE is already PAUSED and still paused by
another FE. The close case would need the BE to be stopped from the
close path, which I'd rather discuss first.
Thanks,
Suyuan
<sashiko-bot@kernel.org> 于2026年11月20日周五 03:44写道:
>
> Thank you for your contribution! Sashiko AI review found 3 potential
> issues to consider:
> - [Medium] ASoC: soc-pcm: duplicate PAUSE_PUSH sent on STOP in
> dpcm_be_dai_trigger()
> - [Medium] ASoC: soc-pcm: stale pause count after prepare/hw_free in
> dpcm_be_dai_trigger()
> - [Medium] ASoC: soc-pcm: BE left in PAUSED state on close in
> dpcm_be_dai_stop()
> --
>
> commit 30a052e7da7505ef9d19e12059b179dfd9931fe2
> Author: Suyuan Wang <stevewong@hust.edu.cn>
>
> ASoC: soc-pcm: Track BE pause per FE-BE link
>
> This commit replaces the per-FE fe_pause boolean with a per-link paused
> flag in struct snd_soc_dpcm so that BE pause refcounting and trigger rollbacks
> are tracked per FE-BE link.
>
> > diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
> > index ef8ccf52798eb..cb8d23756b1e0 100644
> > --- a/sound/soc/soc-pcm.c
> > +++ b/sound/soc/soc-pcm.c
> > @@ -1685,6 +1685,17 @@ void dpcm_be_dai_stop(struct snd_soc_pcm_runtime *fe, int stream,
> > if (!snd_soc_dpcm_can_be_update(fe, be, stream))
> > continue;
> >
> > + /*
> > + * A pause may survive until close, e.g. after system suspend.
> > + * Drop the pause this link still holds.
> > + */
> > + if (dpcm->paused) {
> > + snd_pcm_stream_lock_irq(be_substream);
> > + dpcm->paused = false;
> > + be->dpcm[stream].be_pause--;
> > + snd_pcm_stream_unlock_irq(be_substream);
> > + }
> > +
> > if (be->dpcm[stream].users == 0) {
> > dev_err(be->dev, "ASoC: no users %s at close - state %s\n",
> > snd_pcm_direction_name(stream),
>
> [Severity: Medium]
> Can this leave the BE stuck in SND_SOC_DPCM_STATE_PAUSED when another idle FE
> still has the shared BE open?
>
> If FE1 is paused on a shared BE across system suspend and then closed while
> FE2 is still open (be->dpcm[stream].users > 1), dpcm_be_dai_stop() drops
> be->dpcm[stream].be_pause to 0 and returns early after decrementing users.
> That leaves be->dpcm[stream].state at SND_SOC_DPCM_STATE_PAUSED with
> be_start == 0 and be_pause == 0, causing later dpcm_be_dai_hw_params() calls
> for FE2 to skip the BE because its state is not OPEN, HW_PARAMS, or HW_FREE.
>
> > @@ -2220,7 +2231,7 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
> > int cmd)
> > {
> > struct snd_soc_pcm_runtime *be;
> > - bool pause_stop_transition;
> > + bool was_paused;
> > struct snd_soc_dpcm *dpcm;
> > unsigned long flags;
> > int ret = 0;
> > @@ -2248,6 +2259,16 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
> > (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED))
> > goto next;
> >
> > + /*
> > + * A stream suspended while paused and prepared again
> > + * starts without a PAUSE_RELEASE: drop its pause here.
> > + */
> > + was_paused = dpcm->paused;
> > + if (was_paused) {
> > + dpcm->paused = false;
> > + be->dpcm[stream].be_pause--;
> > + }
> > +
> > be->dpcm[stream].be_start++;
> > if (be->dpcm[stream].be_start != 1)
> > goto next;
> > @@ -2260,6 +2281,10 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
> > SNDRV_PCM_TRIGGER_START);
> > if (ret) {
> > be->dpcm[stream].be_start--;
> > + if (was_paused) {
> > + dpcm->paused = true;
> > + be->dpcm[stream].be_pause++;
> > + }
> > goto next;
> > }
>
> [Severity: Medium]
> Does deferring pause cleanup until SNDRV_PCM_TRIGGER_START leave a stale
> be->dpcm[stream].be_pause count after a suspended stream is prepared or
> hw_freed?
>
> When a paused FE is suspended and then recovered with snd_pcm_prepare() or
> snd_pcm_drop() + snd_pcm_hw_free(), the FE transitions to PREPARE or HW_FREE
> without sending PAUSE_RELEASE or STOP. Until that FE either starts or closes,
> dpcm->paused remains true and be->dpcm[stream].be_pause stays elevated (and is
> restored if SNDRV_PCM_TRIGGER_START fails). If another FE sharing the BE
> starts and stops in the meantime, its STOP sees be_pause != 0 and sends
> SNDRV_PCM_TRIGGER_PAUSE_PUSH instead of SNDRV_PCM_TRIGGER_STOP, leaving the BE
> in SND_SOC_DPCM_STATE_PAUSED when no stream is paused.
>
> [ ... ]
>
> > @@ -2307,30 +2338,32 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
> > (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED))
> > goto next;
> >
> > - if (be->dpcm[stream].state == SND_SOC_DPCM_STATE_START)
> > + /*
> > + * A paused FE left be_start when it paused and only
> > + * holds a pause on this BE.
> > + */
> > + was_paused = dpcm->paused;
> > + if (was_paused) {
> > + dpcm->paused = false;
> > + be->dpcm[stream].be_pause--;
> > + } else if (be->dpcm[stream].state == SND_SOC_DPCM_STATE_START) {
> > be->dpcm[stream].be_start--;
> > + }
> >
> > if (be->dpcm[stream].be_start != 0)
> > goto next;
> >
> > - pause_stop_transition = false;
> > - if (fe->dpcm[stream].fe_pause) {
> > - pause_stop_transition = true;
> > - fe->dpcm[stream].fe_pause = false;
> > - be->dpcm[stream].be_pause--;
> > - }
> > -
> > if (be->dpcm[stream].be_pause != 0)
> > ret = soc_pcm_trigger(be_substream, SNDRV_PCM_TRIGGER_PAUSE_PUSH);
> > else
> > ret = soc_pcm_trigger(be_substream, SNDRV_PCM_TRIGGER_STOP);
>
> [Severity: Medium]
> Can SNDRV_PCM_TRIGGER_STOP send a duplicate SNDRV_PCM_TRIGGER_PAUSE_PUSH to a
> BE that is already in SND_SOC_DPCM_STATE_PAUSED?
>
> When be->dpcm[stream].state is already SND_SOC_DPCM_STATE_PAUSED,
> be->dpcm[stream].be_start is 0. If two paused FEs share the BE (be_pause == 2)
> and one of them is stopped, be_pause drops to 1 and execution falls through to
> soc_pcm_trigger(be_substream, SNDRV_PCM_TRIGGER_PAUSE_PUSH) on the
> already-paused BE. The same duplicate PAUSE_PUSH happens if STOP runs for an
> unpaused FE (was_paused == false) while another FE holds the BE in
> SND_SOC_DPCM_STATE_PAUSED, such as when snd_pcm_undo_start() sends STOP after a
> failed start.
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20261119-asoc-dpcm-pause-link-v1-1-5b97347b5771@gmail.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-19 19:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 19:22 [PATCH] ASoC: soc-pcm: Track BE pause per FE-BE link Suyuan Wang
2026-11-19 19:22 ` Suyuan Wang via B4 Relay
2026-11-19 19:44 ` sashiko-bot
2026-11-19 19:50 ` Wong Steve
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.