Linux Sound subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Takashi Iwai" <tiwai@suse.de>, linux-sound@vger.kernel.org
Subject: Re: [PATCH v2 3/3] ALSA: pcm: Avoid hw_params/hw_refine changes during PCM buffer access
Date: Thu, 19 Nov 2026 12:46:04 +0000	[thread overview]
Message-ID: <sashiko-outbox-223115@kernel.org> (raw)
In-Reply-To: <20261119122356.2134523-4-tiwai@suse.de>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] ALSA: pcm: missing buffer access gate in xferi frame ioctl
  handlers
--

commit 1d0a5a9306bc1367f12d8e1ee79c3cdcad53aa1b
Author: Takashi Iwai <tiwai@suse.de>

ALSA: pcm: Avoid hw_params/hw_refine changes during PCM buffer access

This commit acquires the PCM buffer access gate at the entry of the
non-interleaved frame transfer ioctls and PCM read/write file operations
to prevent concurrent hw_params or hw_free updates while accessing
runtime state.

> diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
> index 7d5e662b219bd..d028f03369e74 100644
> --- a/sound/core/pcm_native.c
> +++ b/sound/core/pcm_native.c
> @@ -3434,6 +3434,9 @@ static int snd_pcm_xfern_frames_ioctl(struct snd_pcm_substream *substream,
>  	void *bufs __free(kfree) = NULL;
>  	snd_pcm_sframes_t result;
>  
> +	SND_PCM_BUFFER_ACQUIRE(runtime, lock);
> +	if (SND_PCM_BUFFER_ACQUIRE_ERR(lock))
> +		return -EBUSY;
>  	if (snd_pcm_get_state(substream) == SNDRV_PCM_STATE_OPEN)
>  		return -EBADFD;
>  	if (runtime->channels > 128)

[Severity: Medium]
Should snd_pcm_xferi_frames_ioctl() and snd_pcm_ioctl_xferi_compat() also
acquire the buffer access gate with SND_PCM_BUFFER_ACQUIRE()?

__snd_pcm_lib_xfer() only calls snd_pcm_buffer_access_get() inside its
inner transfer loop around writer().  Until then, a concurrent
snd_pcm_hw_free() or snd_pcm_hw_params() can free runtime->dma_area
before transitioning runtime->state to SNDRV_PCM_STATE_OPEN, causing
pcm_sanity_check() to hit snd_BUG_ON(!substream->ops->copy &&
!runtime->dma_area), or modify runtime->access, runtime->channels and
other runtime parameters while __snd_pcm_lib_xfer() validates them or
sleeps in wait_for_avail():

CPU0                                  CPU1
snd_pcm_xferi_frames_ioctl()
  snd_pcm_get_state() != OPEN
                                      snd_pcm_hw_free()
                                        snd_pcm_buffer_access_lock()
                                        substream->ops->hw_free()
                                          runtime->dma_area = NULL
  snd_pcm_lib_write()
    __snd_pcm_lib_xfer()
      pcm_sanity_check()
        snd_BUG_ON(!substream->ops->copy &&
                   !runtime->dma_area)  <-- WARN / race
                                        runtime->state = SNDRV_PCM_STATE_OPEN

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119122356.2134523-1-tiwai@suse.de?part=3

      reply	other threads:[~2026-11-19 12:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 12:23 [PATCH v2 0/3] ALSA: PCM race and locking fixes Takashi Iwai
2026-11-19 12:23 ` [PATCH v2 1/3] ALSA: pcm: Fix potential ABBA deadlock at snd_pcm_action_nonatomic() Takashi Iwai
2026-11-19 12:23 ` [PATCH v2 2/3] ALSA: pcm: Simplify PCM buffer access gate with auto-cleanup helpers Takashi Iwai
2026-11-19 12:23 ` [PATCH v2 3/3] ALSA: pcm: Avoid hw_params/hw_refine changes during PCM buffer access Takashi Iwai
2026-11-19 12:46   ` 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-223115@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tiwai@suse.de \
    /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