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=1796405612; b=cPKnvsS27t7KTBFzGG2dHgzZmfE6Y+A9Yf3LLqgBpVbnWUxaVvMHNUr+hpiY7ADmQin4 l2hqBwIicWhAFsj2UQLZR7RSXmBJqgu2DNQE6aUstmw8/X7/rc36aUnfT3PNpdFsJU2rX JooJE8xzN9qBhoQ5xXxgFIz85APkKVrNZfXgpo8mS+vO0SWScKUCot3XRj0aBobOGtUUs +lX7ZPeh2vXSeriTOmoF+D/sK8AGYLhfzk5/kK4HXuqiiewJwtidmo3yNXrABzlSqTf4M wG/4Ujg8OJB8XZ1hj8QshityiSlNxf0DqL+YdeTUBsR1Pgc80GmYWJdwibkVr9HTBUQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796405612; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=fkvvsAEqJNsYwuWit3OoldKk/PcNI9sgrTCZrgpI7I8=; b=BjWy+N58JObdsItpJhL/P8A+yxEk/TpLCXgVGmkLMRKKRo7QLb3Yl5v5mIvoyanyN3Ya 2IhFtoh+dRB97ROSQx0TvdLHj7N83o+gcS2at1WoKARI6Kb8vNK+jlcqgn9v/30bNdkZg vH6LYYmkdA/mTsULVVwgvx5/rElkGlEIyzzqp+odaUT/LkCrDPGSW9KRVNmSXEdl3reeI 3vFwjkCkz4vUi25GddbjusvURTNRLy9ua/85cN2auvV1rgWuVA/akjjGEzBAKhwv4v2nj mt1XgPKVpBc7BpM3X9O1cWbRlYVLG4V31DFHlrQjo2z1sUHdoJgBQgbJVmKpMGu/tvA== 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=gLsfyGRv; 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 25366606A322; Fri, 4 Dec 2026 17:33:32 +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=gLsfyGRv Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB49D1F00936; Fri, 4 Dec 2026 17:33:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796405612; bh=fkvvsAEqJNsYwuWit3OoldKk/PcNI9sgrTCZrgpI7I8=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=gLsfyGRvWiOTfeFoJup2kpXiPc9gp/6Mas0YCYICoXJdKUZo8qxsZTLi0j0qz59Xe sGdTPnpzsfOUFnUIHz587m5uBG+fVL4M72ei3VO3xViUOE5GJNb0jX99wx53W71y8B bgMxMETVJtw0EwsDlYt3pmbhSPE+8paUqIRvXajUy2XVL0KeDS7z55bQDYSN5ddcbt oXNjbjRw5c73Na0dka4Cp9BQVZJmZJRQREigTRp6nIqsXatssy4WESGQwB4HpE9TYA /AsSqGIKlLNyhDg+6CUziO7306a1GZZUsYDh3NcuBlqQrm2jt3e724gUY1jTJCN2K+ ilviaQGOuqj1Q== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3 15/19] ASoC: qcom: lpass: allocate LPM buffer memory to DAIs Reply-To: sashiko-reviews@lists.linux.dev To: "Neil Armstrong" Cc: linux-sound@vger.kernel.org, devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org In-Reply-To: <20261204-topic-sm8650-el2-v3-15-8384ef0ac751@linaro.org> References: <20261204-topic-sm8650-el2-v3-0-8384ef0ac751@linaro.org> <20261204-topic-sm8650-el2-v3-15-8384ef0ac751@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 17:33:31 +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 6 potential issues to consider: - [High] ASoC: qcom: lpass: invalid free_pages_exact() on memremap() LPM MI2S buffer - [High] ASoC: qcom: lpass: sub-page LPM mmap truncation on 16K/64K page kernels - [High] ASoC: qcom: lpass: ungated VA/RXTX LPAIF claims collide with MI2S - [Medium] ASoC: qcom: lpass: integer underflow in lpass_platform_allocate_lpm() - [Medium] ASoC: qcom: lpass: unchecked memremap() in LPM MI2S buffer preallocation - [Medium] ASoC: qcom: lpass: unallocated LPM MI2S/VA ports alias LPM offset 0 -- commit 71c551f2b5aa91ab705a2ec65862eb114db212ae Author: Neil Armstrong ASoC: qcom: lpass: allocate LPM buffer memory to DAIs This commit dynamically allocates LPM buffer slices across Codec DMA and LPM-backed MI2S ports instead of using static offsets, and wires LPM MI2S streams to preallocate, copy, and mmap their DMA buffers in LPM memory. > diff --git a/sound/soc/qcom/lpass-cpu.c b/sound/soc/qcom/lpass-cpu.c > index a83507c2cd557..8b005a87d4088 100644 > --- a/sound/soc/qcom/lpass-cpu.c > +++ b/sound/soc/qcom/lpass-cpu.c > @@ -1169,6 +1169,8 @@ static void of_lpass_cpu_parse_dai_data(struct devi= ce *dev, > data->codec_dma_enable =3D 1; > if (is_wsa_cdc_dma_port(id)) > data->wsa_enable =3D 1; > + else if (!is_rxtx_cdc_dma_port(id)) > + data->va_enable =3D 1; > } else if (is_mi2s_port_id(id)) { > unsigned int port_id =3D mi2s_port_id(id); [Severity: High] Should va_enable also gate the VA LPAIF MMIO and IRQ setup, along with a matching rxtx_enable flag for the RXTX LPAIF? Under drvdata->codec_dma_enable, asoc_qcom_lpass_cpu_platform_probe() still unconditionally calls devm_platform_ioremap_resource_byname() for both "lpass-rxtx-lpaif" and "lpass-va-lpaif", and asoc_qcom_lpass_platform_register() unconditionally requests "lpass-irq-rxtxif" and "lpass-irq-vaif" without IRQF_SHARED. When a board enables Codec DMA on one LPAIF alongside an MI2S port on lpass-va-lpaif or lpass-rxtx-lpaif, lpass_cpu_init_lpaif() and lpass_platform_init_lpaif() request the same MMIO region and non-shared IRQ a second time, failing probe with -EBUSY. Without rxtx_enable, lpass_platform_allocate_lpm() also unconditionally deducts 16 KiB of RXTX LPM even when only VA or WSA Codec DMA is enabled. [ ... ] > diff --git a/sound/soc/qcom/lpass-platform.c b/sound/soc/qcom/lpass-platf= orm.c > index 5f6fc6063f3a8..d8726e1c52e62 100644 > --- a/sound/soc/qcom/lpass-platform.c > +++ b/sound/soc/qcom/lpass-platform.c [ ... ] > @@ -1038,9 +1070,10 @@ static int lpass_platform_pcmops_mmap(struct snd_s= oc_component *component, > { > struct snd_soc_pcm_runtime *soc_runtime =3D snd_soc_substream_to_rtd(su= bstream); > struct snd_soc_dai *cpu_dai =3D snd_soc_rtd_to_cpu(soc_runtime, 0); > + struct lpass_data *drvdata =3D snd_soc_component_get_drvdata(component); > unsigned int dai_id =3D cpu_dai->driver->id; > =20 > - if (is_cdc_dma_port(dai_id)) > + if (is_cdc_dma_port(dai_id) || is_lpm_mi2s_port(drvdata, dai_id)) > return lpass_platform_cdc_dma_mmap(substream, vma); > =20 > return snd_pcm_lib_default_mmap(substream, vma); [Severity: High] Does routing LPM MI2S streams to lpass_platform_cdc_dma_mmap() break mmap() and expose adjacent memory on 16 KiB or 64 KiB page kernels? lpass_platform_prealloc_lpm_mi2s_buffer() places 8 KiB playback and capture buffers back-to-back at 0x2000 spacing, and lpass_platform_allocate_lpm() places VA-LPM MI2S buffers after a 12 KiB VA Codec DMA buffer. Because lpass_platform_cdc_dma_mmap() shifts (runtime->dma_addr + offset) right by PAGE_SHIFT without checking PAGE_ALIGNED(runtime->dma_addr) or runtime->dma_bytes >=3D PAGE_SIZE, the sub-page offset is truncated on 16 K= iB or 64 KiB page ARM64 kernels: mmap() on capture maps the playback buffer instead, and snd_pcm_mmap_data() rounds dma_bytes up to PAGE_SIZE, letting unprivileged audio userspace map adjacent LPM streams or MMIO space outside the LPM resource. [ ... ] > @@ -1289,6 +1322,41 @@ static irqreturn_t lpass_platform_wsaif_irq(int ir= q, void *data) > return IRQ_HANDLED; > } > =20 > +static int lpass_platform_prealloc_lpm_mi2s_buffer(struct snd_soc_compon= ent *component, > + struct snd_pcm *pcm, int dai_id) > +{ > + struct lpass_data *drvdata =3D snd_soc_component_get_drvdata(component); > + unsigned int port_id =3D mi2s_port_id(dai_id); > + struct snd_pcm_substream *substream; > + struct snd_dma_buffer *buf; > + u32 addr; > + int dir; > + > + if (drvdata->mi2s_lpm[port_id] =3D=3D LPASS_VA_CDC_LPM) > + addr =3D drvdata->va_cdc_dma_lpm_buf; > + else > + addr =3D drvdata->rxtx_cdc_dma_lpm_buf; > + addr +=3D drvdata->mi2s_lpm_offset[port_id]; > + > + /* Playback and capture buffers are allocated one after the other */ > + for (dir =3D SNDRV_PCM_STREAM_PLAYBACK; dir <=3D SNDRV_PCM_STREAM_CAPTU= RE; dir++) { > + substream =3D pcm->streams[dir].substream; > + if (!substream) > + continue; > + > + buf =3D &substream->dma_buffer; > + buf->dev.dev =3D pcm->card->dev; > + buf->dev.type =3D SNDRV_DMA_TYPE_CONTINUOUS; > + buf->private_data =3D NULL; > + buf->bytes =3D lpass_platform_lpm_mi2s_hardware.buffer_bytes_max; > + buf->addr =3D addr + dir * LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE; > + buf->area =3D (unsigned char * __force)memremap(buf->addr, buf->bytes, > + MEMREMAP_WC); [Severity: High] Will PCM teardown pass this memremap() address to free_pages_exact()? lpass_component_driver has no .pcm_free callback to call memunmap() and clear buf->area. On driver unbind or card registration rollback, snd_pcm_free() -> snd_pcm_lib_preallocate_free_for_all() -> do_free_pages() sees a non-NULL dmab->area with SNDRV_DMA_TYPE_CONTINUOUS, hits WARN_ON in decrease_allocated_size(), and calls snd_dma_continuous_free() -> free_pages_exact() on the ioremap_wc() pointer, corrupting the page allocator or crashing while leaking the mapping. > + } > + > + return 0; > +} [Severity: Medium] Can memremap() return NULL here and cause a NULL pointer dereference in lpass_platform_copy()? lpass_platform_prealloc_lpm_mi2s_buffer() ignores a NULL return from memremap() and returns 0 with substream->dma_buffer.area left NULL. Because lpass_component_driver sets .copy =3D lpass_platform_copy, pcm_sanity_check() allows a NULL runtime->dma_area through to lpass_platform_copy(), which dereferences it on PCM read/write. If capture memremap() fails after playback succeeds, the playback mapping also needs memunmap() and clearing to NULL before returning -ENOMEM. [ ... ] > @@ -1460,6 +1531,66 @@ static const struct snd_soc_component_driver lpass= _component_driver =3D { > =20 > }; > =20 > +static int lpass_platform_allocate_lpm(struct lpass_data *drvdata) > +{ > + u32 rxtx_cdc_dma_lpm_remain =3D drvdata->rxtx_cdc_dma_lpm_size; > + u32 va_cdc_dma_lpm_remain =3D drvdata->va_cdc_dma_lpm_size; > + u32 rxtx_cdc_dma_lpm_offset =3D 0; > + u32 va_cdc_dma_lpm_offset =3D 0; > + int port_id; > + > + if (drvdata->codec_dma_enable) { > + drvdata->rxtx_lpm_offset =3D rxtx_cdc_dma_lpm_offset; > + rxtx_cdc_dma_lpm_offset +=3D LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 2; > + rxtx_cdc_dma_lpm_remain -=3D LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 2; > + > + if (drvdata->va_enable) { > + drvdata->va_lpm_offset =3D va_cdc_dma_lpm_offset; > + va_cdc_dma_lpm_offset +=3D LPASS_VA_CDC_DMA_LPM_BUFF_SIZE; > + va_cdc_dma_lpm_remain -=3D LPASS_VA_CDC_DMA_LPM_BUFF_SIZE; > + } > + > + if (drvdata->wsa_enable) { > + drvdata->wsa_lpm_offset =3D rxtx_cdc_dma_lpm_offset; > + rxtx_cdc_dma_lpm_offset +=3D LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 2; > + rxtx_cdc_dma_lpm_remain -=3D LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 2; > + } > + } [Severity: Medium] What happens if an LPM resource is smaller than the enabled codec DMA reservations? Because rxtx_cdc_dma_lpm_remain and va_cdc_dma_lpm_remain are unsigned u32 counters and are decremented without checking remaining capacity first, an undersized DT resource underflows near U32_MAX instead of returning -EINVAL. That defeats the MI2S bounds checks below and hands out physical addresses past the end of the LPM SRAM resource. > + > + if (!drvdata->mi2s_lpm_enable) > + return 0; > + > + for (port_id =3D 0; port_id < LPASS_MAX_MI2S_PORTS; port_id++) { > + if (!test_bit(port_id, &drvdata->lpaif_port_enable)) > + continue; [Severity: Medium] Can an MI2S port without a DT child node end up aliasing LPM offset 0? lpass_cpu_init_lpaif() initializes an entire multi-port LPAIF whenever any one of its ports is set in lpaif_port_enable, asoc_qcom_lpass_cpu_platform_probe() populates mi2s_lpaif[port_id] and mi2s_lpm[port_id] for all MI2S DAIs, and lpass_cpu_daiops_probe() only checks lpaif->drvdata. Because lpass_platform_allocate_lpm() skips ports not in lpaif_port_enable, mi2s_lpm_offset[port_id] remains 0, so lpass_platform_prealloc_lpm_mi2s_buffer() maps that sibling port on top of the DAI allocated at offset 0. The same aliasing happens if LPASS_CDC_DMA_VA_TX0 is linked with va_enable =3D=3D 0 alongside an LPASS_VA_CDC_LPM MI2S port. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204-topic-sm86= 50-el2-v3-0-8384ef0ac751@linaro.org?part=3D15