From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796227899; b=MUezSF2GVhNXk54SDmE72J8wxzFcf8dQN/ELWG1WKyFDVYP41SMSwZowu2V2TzgY7knS J/Ee+yokmrK0f63kABCsAVjOiX4J5M6GNirmn6pOztHo4swXYR7ZkFJTIeY2SXvJhxQBN RP3e6LbKrtutu6DUzb8BbTqwoRMpF7DoNYIHPNLniwGFd2NnL3sorT8ustSojteST8xv9 xaKTo4ZJhigAbWF3jQSlAMuIR/FNHHPsVcjBG4Co63haYUdpDFcusYFSGwZdsamIO6BzW gpfRs/6d6Nql7iVK2+irKjC14P+ogIG6rxNyidfhOj0MidXppZidma/yIx8rHGbetqg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796227899; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=mMZUk8K/lQTO47Su+QKSRqxGq4hGsfmsDWe5elMwExo=; b=tBwk/q2p7iDyLp/guCzjDW+/2OBW5xjn128K+dj7wtI568G0DvccXQE0PigvTb9sKtYn T3ZgZ9M5DuWHidB7DY07vdY10QBhEvXB0KCwbikT/CMyeapd5MNtPMmibg52TjDKa7ncG +ttc+IWyMyxIAF3fUyrIf5L2WmiUzHkd9/R1oZj+qh1rBnH34LocKivwuijBzRK6y1jmr orPV3auDVglOPJpbLNfo9QTeh1/n528JYbYxjPZSbL2ZqF/u5gJtlCR5gh4NVjUi1x6ES qpxB6/a2eew7wwfeQwHj/02Hf8IWuj7LSN+r8WHDD30krMM+teLWoWX1ePlk4UD71+Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LlWqkoIw; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74491606A31A for ; Wed, 2 Dec 2026 16:11:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LlWqkoIw Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4152A1F000C1; Wed, 2 Dec 2026 16:11:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796227899; bh=mMZUk8K/lQTO47Su+QKSRqxGq4hGsfmsDWe5elMwExo=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=LlWqkoIwgREKEU1iFcbqPzyfjwuKfuNwe7oxkqn+8IpnufrDxCRwcDCTKh3gdAvky 7WGpFDT5bcQJaD8dukyPxRGpiGqcG6XmcvJkY7Bmrj+x4ylYEIon5TRMuxrTTU79DI RKxc9MduAHhzk/oRxUA5ihWNdV1gii+Rq39oKFbTTNKrp1PayaOFln7wZiVQLSkhLp cz0CUttndFpxPIE2A7CaYmdsOKV4+d9TXWnG18vYOYIkSfYiDfzmiiGqFbLLLsdWvs +TWkder/RhA/KOC3gRolK+yuyK01+SPVYjh4QKUhCZOQpaqNxf3FeWcHQGxIZfMYlJ KR84zvodzbRFw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 2/4] ALSA: pcm: Reject hw_params with buffer size changes while mmapped Reply-To: sashiko-reviews@lists.linux.dev To: "Takashi Iwai" , linux-sound@vger.kernel.org In-Reply-To: <20261202155431.720872-3-tiwai@suse.de> References: <20261202155431.720872-1-tiwai@suse.de> <20261202155431.720872-3-tiwai@suse.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 16:11:36 +0000 X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] ALSA: pcm: unreachable mmap_count check in snd_pcm_hw_params() - [Low] ALSA: pcm: stale runtime->buffer_changed in snd_pcm_hw_params() when mmapped -- commit 29d0ead2858402673b9e78ea39c345b9d60787f7 Author: Takashi Iwai ALSA: pcm: Reject hw_params with buffer size changes while mmapped This commit restricts snd_pcm_hw_params() from changing the buffer size or reallocating managed DMA buffers while the substream buffer is mmapped. Link: https://lore.kernel.org/20261202140117.1164633-1-ahmedabdelmoumen05@g= mail.com > diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c > index 8967a6f649343..d306340ae9190 100644 > --- a/sound/core/pcm_native.c > +++ b/sound/core/pcm_native.c > @@ -800,6 +800,7 @@ static int snd_pcm_hw_params(struct snd_pcm_substream= *substream, > int err; > unsigned int bits; > snd_pcm_uframes_t frames; > + size_t buffer_bytes; > =20 > if (PCM_RUNTIME_CHECK(substream)) > return -ENXIO; > @@ -826,9 +827,17 @@ static int snd_pcm_hw_params(struct snd_pcm_substrea= m *substream, > if (err < 0) > goto _error; > =20 > - if (substream->managed_buffer_alloc) { > - err =3D snd_pcm_lib_malloc_pages(substream, > - params_buffer_bytes(params)); > + /* OSS still allows hw_params change during mmap -- except for the case > + * where the buffer size actually changes (that can go wrong with mmap). > + */ > + buffer_bytes =3D params_buffer_bytes(params); > + if (atomic_read(&substream->mmap_count)) { > + if (buffer_bytes !=3D frames_to_bytes(runtime, runtime->buffer_size)) { > + err =3D -EBADFD; > + goto _error; > + } [Severity: Medium] Can execution ever reach this substream->mmap_count check with a non-zero count? At the start of snd_pcm_hw_params(), hw_params_state_check(substream, true) is called while holding snd_pcm_buffer_access_lock(runtime), which prevents concurrent mmaps from starting. Since commit de57f471f664 ("ALSA: pcm: Prevent PCM hw_params & co during mmap on OSS, too") removed the !is_oss_stream(substream) exemption, hw_params_state_check() unconditionally returns -EBADFD whenever substream->mmap_count is non-zero: sound/core/pcm_native.c:hw_params_state_check() { ... case SNDRV_PCM_STATE_OPEN: case SNDRV_PCM_STATE_SETUP: case SNDRV_PCM_STATE_PREPARED: if (check_mmap && atomic_read(&substream->mmap_count)) return -EBADFD; return 0; ... } As a result, OSS streams with an active mmap are rejected at the top of snd_pcm_hw_params() even when the buffer size is unchanged, and this branch is dead code. > + } else if (substream->managed_buffer_alloc) { > + err =3D snd_pcm_lib_malloc_pages(substream, buffer_bytes); > if (err < 0) > goto _error; > runtime->buffer_changed =3D err > 0; [Severity: Low] When the substream->mmap_count branch is taken (for example, on a stable tree without de57f471f664 ("ALSA: pcm: Prevent PCM hw_params & co during mmap on OSS, too") or if hw_params_state_check() is updated to allow OSS streams), does skipping the managed_buffer_alloc branch leave runtime->buffer_changed stale? The initial pre-mmap allocation sets runtime->buffer_changed =3D 1, and nothing clears it when snd_pcm_lib_malloc_pages() is skipped. Driver ops->hw_params callbacks that check runtime->buffer_changed (such as sof_pcm_hw_params()) would then treat the unchanged mmapped buffer as newly reallocated. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202155431.7208= 72-1-tiwai@suse.de?part=3D2