From: sashiko-bot@kernel.org
To: "Hanxiang Xu" <xuhx@hust.edu.cn>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH] ALSA: vx: serialize pipe lifecycle against the threaded IRQ pipe walker
Date: Wed, 02 Dec 2026 03:25:29 +0000 [thread overview]
Message-ID: <sashiko-outbox-244774@kernel.org> (raw)
In-Reply-To: <20261202101006.1-1-xuhx@hust.edu.cn>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] ALSA: vx: pipe->prepared not cleared for prepared streams on
hw_free or close
- [High] ALSA: vx: dangling pipe->substream in vx_pcm_playback_close()
with monitoring
--
commit 06ea28a410c475a5af72a771d6f540168a3d3d78
Author: Hanxiang Xu <xuhx@hust.edu.cn>
ALSA: vx: serialize pipe lifecycle against the threaded IRQ pipe walker
This commit adds chip->pcm_lock to serialize pipe allocation, freeing, and
threaded IRQ updates, and clears pipe->prepared on trigger STOP and SUSPEND.
> diff --git a/sound/drivers/vx/vx_pcm.c b/sound/drivers/vx/vx_pcm.c
> index d9b94580704aa..8d4fdf6c153b7 100644
> --- a/sound/drivers/vx/vx_pcm.c
> +++ b/sound/drivers/vx/vx_pcm.c
[ ... ]
> @@ -564,6 +565,7 @@ static int vx_pcm_playback_close(struct snd_pcm_substream *subs)
>
> pipe = subs->runtime->private_data;
>
> + guard(mutex)(&chip->pcm_lock);
> if (--pipe->references == 0) {
> chip->playback_pipes[pipe->number] = NULL;
> vx_free_pipe(chip, pipe);
[Severity: High]
When a playback pipe is shared with capture hardware monitoring, does
closing the playback substream leave a detached pipe->substream pointer
published in chip->playback_pipes[]?
When capture is open with monitoring enabled, pipe->references is 2 once
playback opens and sets pipe->substream = subs. If playback closes while
capture stays open, --pipe->references is 1, so pipe remains in
chip->playback_pipes[pipe->number] with pipe->substream still pointing at
subs. snd_pcm_release_substream() then calls snd_pcm_detach_substream(),
which frees subs->runtime and sets subs->runtime = NULL, so a subsequent
vx_pcm_update_intr() passing pipe && pipe->substream will dereference a
NULL subs->runtime in vx_pcm_playback_transfer().
Clearing pipe->substream = NULL and pipe->prepared = 0 under chip->pcm_lock
unconditionally in vx_pcm_playback_close() would avoid this.
> @@ -749,6 +751,7 @@ static int vx_pcm_trigger(struct snd_pcm_substream *subs, int cmd)
> vx_stop_pipe(chip, pipe);
> vx_stop_stream(chip, pipe);
> chip->pcm_running--;
> + pipe->prepared = 0;
> pipe->running = 0;
> break;
> case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
[Severity: High]
Can vx_pcm_update_intr() still read from a freed or NULL runtime->dma_area
when a stream in SNDRV_PCM_STATE_PREPARED is freed via hw_free or closed?
In the ALSA PCM core, snd_pcm_do_stop() only invokes
ops->trigger(SNDRV_PCM_TRIGGER_STOP) when snd_pcm_running(substream) is
true:
sound/core/pcm_native.c:snd_pcm_do_stop() {
if (substream->runtime->trigger_master == substream &&
snd_pcm_running(substream)) {
substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_STOP);
substream->runtime->stop_operating = true;
}
return 0; /* unconditionally stop all substreams */
}
If a stream was stopped and re-prepared (or if SNDRV_PCM_TRIGGER_START
failed after vx_pcm_playback_transfer() queued chunks), pipe->prepared is 1
while the stream is in SNDRV_PCM_STATE_PREPARED. On close (or
SNDRV_PCM_IOCTL_HW_FREE), do_hw_free() frees the managed vmalloc
runtime->dma_area buffer before vx_pcm_playback_close() takes
chip->pcm_lock:
CPU0 CPU1 (IRQ thread)
snd_pcm_release_substream()
snd_pcm_drop()
/* not running: trigger skipped */
do_hw_free()
snd_pcm_lib_free_pages()
/* vfrees runtime->dma_area */
vx_pcm_update_intr()
lock(&chip->pcm_lock)
vx_pcm_playback_transfer()
/* pipe->prepared == 1 */
vx_pseudo_dma_write()
/* reads freed dma_area */
vx_pcm_playback_close()
lock(&chip->pcm_lock)
Providing an .hw_free callback that clears pipe->prepared under
chip->pcm_lock (or gating transfers in vx_pcm_update_intr() on
pipe->running) would prevent vx_pcm_playback_transfer() from touching
runtime->dma_area once hw_free begins.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202101006.1-1-xuhx@hust.edu.cn?part=1
prev parent reply other threads:[~2026-12-02 3:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 2:10 [PATCH] ALSA: vx: serialize pipe lifecycle against the threaded IRQ pipe walker Hanxiang Xu
2026-12-02 3:25 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-244774@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=xuhx@hust.edu.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox