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=1796288970; b=3rRK/4xVnL9WsnfiZf0mbFSrl0FLMWFq6T5WYNRHd1aaN87o+apd+U5n5IzcXWVhg4wV rPgghjT5l7wBGP2J4a5TzYAZ2Es03YCMfwbq9+MDjJtH16OGeKEr3N6dWp2J7TNAa2En0 6g1qCCWaxz9W0288rxgrE97JRhnVqFfW0ImV/gtyOvZtyGLFYa+8ZfeTaKqYIqXsBNiRm yBaT+E342VHam3X87T3XKoEzhJIMEVvEj/0KLavLPgsn0Ir9mt3dOzVDfMT6PogzMbap3 ORDZxmtbSJIbGnKs9SOUyXnXgjsN0OaAbART9FT5mNVlbi54bXaS/9Dg6grXrz/teCg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796288970; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=UpoFkh7+xcC4JLmrh9fy3o8EOLzeHpZCpef8UG5YzEs=; b=t6f2BurPKmVflsE4UdncG9ln5Pk7e6xczOIaYCEVkHCRy8YcXH/Vpj9sgmwdAdQlX+b4 AkExtMHznvPLQZIJ3S93n5aX1QmqzSkm0z2+S2JFxfEKNQ0K3m6T8DhPrYBtLENB/ZDys XBnGZZJ3gmM4lfB9xXY62LlXqPz0nxARM0JWxVX1M7Upg7SqCirk8PrJjaqq8zEsqsVFK KNdHYqAoFa0moxpq8Gp0Pi8GC4T+YbXWfQ2TnoHgf90BUYfM2LkTqo6yGYmu55K7lo2bh vSfKEFQWr0K0qBbz5BOBvJq3PWwmOa2JlY9cYNOZopAfxYwLQ43VpUF5gbuxs2ryeFg== 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="RsXW/t5/"; 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 EB2E2606A322 for ; Thu, 3 Dec 2026 09:09:29 +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=RsXW/t5/ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63C791F000C1; Thu, 3 Dec 2026 09:09:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796288969; bh=UpoFkh7+xcC4JLmrh9fy3o8EOLzeHpZCpef8UG5YzEs=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=RsXW/t5/IP5cjFwXxBnhzO9ae+g0x0N8xyA8n8pjMUSAJnwX2UYZrCPzhB0klnxIW vHyIAG/Vo449pCK98Ze3f7Ej4Xa2foyDJhv6WJ453YaA6zlmCRXdYIXFZwQRtCL2pP 303tNjNgjVC9czXuqyd0MZ45WmNIpt7c54uv5hVx4Bi25GY0GtG/WQ0tmw5N/iFr6X OC3w4uj+ZDrAIPBKuUPfDDGV6X5gv9KEI5R7jOLQ4zYjxnSyULhPDYG4rVJZW6MYa/ /1NwweWchAjurzCzqVtz6a+Aa5e5kSobLUdK0UHsMVGtqWKmrJqW0YlTJ1EG3r3WwU o1SWV5hZ48ZTg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 4/4] ALSA: pcm: Don't reallocate for the same sized buffers Reply-To: sashiko-reviews@lists.linux.dev To: "Takashi Iwai" , linux-sound@vger.kernel.org In-Reply-To: <20261203084041.914026-5-tiwai@suse.de> References: <20261203084041.914026-1-tiwai@suse.de> <20261203084041.914026-5-tiwai@suse.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 09:09:29 +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: - [High] ALSA: pcm: same-size shortcut misses emu10k1 iommu_workaround on OSS mmap - [Low] ALSA: pcm: commit message omits mmap_count ordering rationale for shortcut -- commit 8fdd2c067f9f35e5db5a5b50be431e9113e37a29 Author: Takashi Iwai > ALSA: pcm: Don't reallocate for the same sized buffers > > When snd_pcm_lib_malloc_pages() is called with the same buffer size as > the current one, we don't have to reallocate. Go for a short cut. > > Link: https://lore.kernel.org/20261202140117.1164633-1-ahmedabdelmoumen05= @gmail.com > Reported-by: Ahmed Abdelmoemen > Cc: > Signed-off-by: Takashi Iwai [Severity: Low] Could the commit message mention the interaction with substream->mmap_count? snd_pcm_lib_malloc_pages() already skips reallocation when runtime->dma_buffer_p->bytes >=3D size. Placing this check first is needed= to bypass the mmap_count check from commit "ALSA: pcm: Prohibit buffer (re-)allocation/free during mmap" and preserve that ordering in backports. > diff --git a/sound/core/pcm_memory.c b/sound/core/pcm_memory.c > index 7aaa45f3bac14..2c610dc83044d 100644 > --- a/sound/core/pcm_memory.c > +++ b/sound/core/pcm_memory.c > @@ -431,6 +431,9 @@ int snd_pcm_lib_malloc_pages(struct snd_pcm_substream= *substream, size_t size) > runtime =3D substream->runtime; > card =3D substream->pcm->card; > =20 > + if (runtime->dma_area && runtime->dma_bytes =3D=3D size) > + return 0; /* no need to change */ > + > if (atomic_read(&substream->mmap_count)) > return -EBADFD; [Severity: High] Does the exact runtime->dma_bytes =3D=3D size check miss snd_emu10k1_playback_hw_params() when emu->iommu_workaround is enabled? When the device is behind a non-passthrough IOMMU, emu10k1 pads the allocation size by EMUPAGESIZE and trims runtime->dma_bytes afterwards: sound/pci/emu10k1/emupcm.c:snd_emu10k1_playback_hw_params() { ... err =3D snd_emu10k1_pcm_channel_alloc(epcm, type, count, channels); if (err < 0) return err; alloc_size =3D params_buffer_bytes(hw_params); if (emu->iommu_workaround) alloc_size +=3D EMUPAGESIZE; err =3D snd_pcm_lib_malloc_pages(substream, alloc_size); if (err < 0) return err; if (emu->iommu_workaround && runtime->dma_bytes >=3D EMUPAGESIZE) runtime->dma_bytes -=3D EMUPAGESIZE; ... } On a repeat OSS mmapped hw_params call with the same buffer size (for example via SNDCTL_DSP_CHANNELS), runtime->dma_bytes is EMUPAGESIZE smaller than size. The shortcut misses and falls through to -EBADFD. Because snd_emu10k1_pcm_channel_alloc() already replaced epcm->voices and snd_pcm_hw_params() skips hw_free and state rollback while mmapped, reducing channels from stereo to mono leaves runtime->channels stale at 2. A later snd_emu10k1_playback_prepare() then initializes evoice + 1, causing a NULL pointer dereference on (evoice + 1)->epcm or an out-of-bounds access past emu->voices[]. Note that relaxing this check to runtime->dma_buffer_p->bytes >=3D size without also setting runtime->dma_bytes =3D size would still break emupcm.c, which unconditionally subtracts EMUPAGESIZE on any non-negative return. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203084041.9140= 26-1-tiwai@suse.de?part=3D4