public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Cen Zhang <zzzccc427@gmail.com>
Cc: perex@perex.cz, chleroy@kernel.org, tiwai@suse.com,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
	baijiaju1990@gmail.com, r33s3n6@gmail.com, gality369@gmail.com,
	zhenghaoran154@gmail.com, hanguidong02@gmail.com,
	ziyuzhang201@gmail.com
Subject: Re: [PATCH v2] ALSA: pcm: oss: use proper stream lock for runtime->state access
Date: Mon, 16 Mar 2026 18:06:34 +0100	[thread overview]
Message-ID: <87jyvb7lgl.wl-tiwai@suse.de> (raw)
In-Reply-To: <20260316085047.2876451-1-zzzccc427@gmail.com>

On Mon, 16 Mar 2026 09:50:47 +0100,
Cen Zhang wrote:
> 
> __snd_pcm_set_state() writes runtime->state under the PCM stream lock.
> However, the OSS I/O functions snd_pcm_oss_write3(), snd_pcm_oss_read3(),
> snd_pcm_oss_writev3() and snd_pcm_oss_readv3() read runtime->state
> without holding the stream lock, only holding oss.params_lock (a
> different mutex that does not synchronize with the stream lock).
> 
> Since __snd_pcm_set_state() is called from IRQ context (e.g.,
> snd_pcm_period_elapsed -> snd_pcm_update_state -> __snd_pcm_xrun ->
> snd_pcm_stop -> snd_pcm_post_stop) while the OSS read/write paths
> run in process context, these are concurrent accesses that constitute
> a data race.
> 
> Rather than using READ_ONCE()/WRITE_ONCE() barriers, introduce a
> snd_pcm_get_state() helper that reads runtime->state under the stream
> lock, matching the locking discipline used elsewhere in the PCM layer.
> Also export snd_pcm_set_state() for completeness.
> 
> Use snd_pcm_get_state() in all four OSS I/O functions, caching the
> result in a local variable where the same snapshot is used for
> multiple comparisons to avoid taking the lock repeatedly.
> 
> Signed-off-by: Cen Zhang <zzzccc427@gmail.com>

Applied to for-next branch now.  Thanks.


Takashi

      reply	other threads:[~2026-03-16 17:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-16  8:50 [PATCH v2] ALSA: pcm: oss: use proper stream lock for runtime->state access Cen Zhang
2026-03-16 17:06 ` Takashi Iwai [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=87jyvb7lgl.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=baijiaju1990@gmail.com \
    --cc=chleroy@kernel.org \
    --cc=gality369@gmail.com \
    --cc=hanguidong02@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=r33s3n6@gmail.com \
    --cc=tiwai@suse.com \
    --cc=zhenghaoran154@gmail.com \
    --cc=ziyuzhang201@gmail.com \
    --cc=zzzccc427@gmail.com \
    /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