From: sashiko-bot@kernel.org
To: "Neil Armstrong" <neil.armstrong@linaro.org>
Cc: linux-sound@vger.kernel.org, devicetree@vger.kernel.org,
robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v3 15/19] ASoC: qcom: lpass: allocate LPM buffer memory to DAIs
Date: Fri, 04 Dec 2026 17:33:31 +0000 [thread overview]
Message-ID: <sashiko-outbox-250324@kernel.org> (raw)
In-Reply-To: <20261204-topic-sm8650-el2-v3-15-8384ef0ac751@linaro.org>
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 <neil.armstrong@linaro.org>
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 device *dev,
> data->codec_dma_enable = 1;
> if (is_wsa_cdc_dma_port(id))
> data->wsa_enable = 1;
> + else if (!is_rxtx_cdc_dma_port(id))
> + data->va_enable = 1;
> } else if (is_mi2s_port_id(id)) {
> unsigned int port_id = 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-platform.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_soc_component *component,
> {
> struct snd_soc_pcm_runtime *soc_runtime = snd_soc_substream_to_rtd(substream);
> struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(soc_runtime, 0);
> + struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
> unsigned int dai_id = cpu_dai->driver->id;
>
> - 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);
>
> 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 >= PAGE_SIZE, the sub-page offset is truncated on 16 KiB
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 irq, void *data)
> return IRQ_HANDLED;
> }
>
> +static int lpass_platform_prealloc_lpm_mi2s_buffer(struct snd_soc_component *component,
> + struct snd_pcm *pcm, int dai_id)
> +{
> + struct lpass_data *drvdata = snd_soc_component_get_drvdata(component);
> + unsigned int port_id = 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] == LPASS_VA_CDC_LPM)
> + addr = drvdata->va_cdc_dma_lpm_buf;
> + else
> + addr = drvdata->rxtx_cdc_dma_lpm_buf;
> + addr += drvdata->mi2s_lpm_offset[port_id];
> +
> + /* Playback and capture buffers are allocated one after the other */
> + for (dir = SNDRV_PCM_STREAM_PLAYBACK; dir <= SNDRV_PCM_STREAM_CAPTURE; dir++) {
> + substream = pcm->streams[dir].substream;
> + if (!substream)
> + continue;
> +
> + buf = &substream->dma_buffer;
> + buf->dev.dev = pcm->card->dev;
> + buf->dev.type = SNDRV_DMA_TYPE_CONTINUOUS;
> + buf->private_data = NULL;
> + buf->bytes = lpass_platform_lpm_mi2s_hardware.buffer_bytes_max;
> + buf->addr = addr + dir * LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE;
> + buf->area = (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 = 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 = {
>
> };
>
> +static int lpass_platform_allocate_lpm(struct lpass_data *drvdata)
> +{
> + u32 rxtx_cdc_dma_lpm_remain = drvdata->rxtx_cdc_dma_lpm_size;
> + u32 va_cdc_dma_lpm_remain = drvdata->va_cdc_dma_lpm_size;
> + u32 rxtx_cdc_dma_lpm_offset = 0;
> + u32 va_cdc_dma_lpm_offset = 0;
> + int port_id;
> +
> + if (drvdata->codec_dma_enable) {
> + drvdata->rxtx_lpm_offset = rxtx_cdc_dma_lpm_offset;
> + rxtx_cdc_dma_lpm_offset += LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 2;
> + rxtx_cdc_dma_lpm_remain -= LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 2;
> +
> + if (drvdata->va_enable) {
> + drvdata->va_lpm_offset = va_cdc_dma_lpm_offset;
> + va_cdc_dma_lpm_offset += LPASS_VA_CDC_DMA_LPM_BUFF_SIZE;
> + va_cdc_dma_lpm_remain -= LPASS_VA_CDC_DMA_LPM_BUFF_SIZE;
> + }
> +
> + if (drvdata->wsa_enable) {
> + drvdata->wsa_lpm_offset = rxtx_cdc_dma_lpm_offset;
> + rxtx_cdc_dma_lpm_offset += LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 2;
> + rxtx_cdc_dma_lpm_remain -= 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 = 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 == 0 alongside an
LPASS_VA_CDC_LPM MI2S port.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-topic-sm8650-el2-v3-0-8384ef0ac751@linaro.org?part=15
next prev parent reply other threads:[~2026-12-04 17:33 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 15:53 [PATCH v3 00/19] arm64: qcom: enable SM8650 audio without ADSP firmware Neil Armstrong
2026-12-04 15:53 ` [PATCH v3 01/19] ASoC: qcom: lpass-cpu: fix RXTX WRDMA current address register readability Neil Armstrong
2026-12-04 15:53 ` [PATCH v3 02/19] ASoC: qcom: lpass-platform: disable the RXTX & VA DMA interrupts on stop Neil Armstrong
2026-12-04 15:53 ` [PATCH v3 03/19] ASoC: dt-bindings: qcom,lpass: add Senary & Septenary MI2S ids Neil Armstrong
2026-12-04 15:53 ` [PATCH v3 04/19] ASoC: dt-bindings: qcom,lpass: add WSA RX and TX channels ids Neil Armstrong
2026-12-04 15:53 ` [PATCH v3 05/19] ASoC: dt-bindings: qcom,lpass-*-macro: document less clock when ADSP is not used Neil Armstrong
2026-12-04 16:20 ` sashiko-bot
2026-12-04 15:53 ` [PATCH v3 06/19] ASoC: dt-bindings: qcom,lpass-cpu: document the SM8650 LPASS Neil Armstrong
2026-12-04 15:53 ` [PATCH v3 07/19] ASoC: codecs: lpass-wsa-macro: handle the macro & dcodec power domains Neil Armstrong
2026-12-04 15:53 ` [PATCH v3 08/19] ASoC: qcom: lpass-cpu: get the optional codec_mem3 clock Neil Armstrong
2026-12-04 15:53 ` [PATCH v3 09/19] ASoC: qcom: lpass: add support for optional WSA interface Neil Armstrong
2026-12-04 16:49 ` sashiko-bot
2026-12-04 15:53 ` [PATCH v3 10/19] ASoC: qcom: lpass-cdc-dma: add support for WSA codec DMA Neil Armstrong
2026-12-04 16:47 ` sashiko-bot
2026-12-04 15:53 ` [PATCH v3 11/19] ASoC: qcom: lpass: prepare to handle multiple lpaifs for i2s Neil Armstrong
2026-12-04 15:53 ` [PATCH v3 12/19] ASoC: qcom: lpass: add support for MI2S_SENARY & MI2S_SEPTENARY Neil Armstrong
2026-12-04 15:53 ` [PATCH v3 13/19] ASoC: qcom: lpass: support mapping I2S ports to multiple LPAIFs Neil Armstrong
2026-12-04 17:10 ` sashiko-bot
2026-12-04 15:53 ` [PATCH v3 14/19] ASoC: qcom: lpass: support LPM memory type for I2S LPAIFs Neil Armstrong
2026-12-04 17:08 ` sashiko-bot
2026-12-04 15:53 ` [PATCH v3 15/19] ASoC: qcom: lpass: allocate LPM buffer memory to DAIs Neil Armstrong
2026-12-04 17:33 ` sashiko-bot [this message]
2026-12-04 15:53 ` [PATCH v3 16/19] ASoC: qcom: lpass: enable the right codec_mem clock when usin LPM memory Neil Armstrong
2026-12-04 17:28 ` sashiko-bot
2026-12-04 15:53 ` [PATCH v3 17/19] ASoC: qcom: add SM8650 LPASS CPU driver Neil Armstrong
2026-12-04 17:42 ` sashiko-bot
2026-12-04 15:53 ` [PATCH v3 18/19] ASoC: qcom: sdw: allow LPASS_CDC_DMA_WSA_RX0 as soundwire dai Neil Armstrong
2026-12-04 17:52 ` sashiko-bot
2026-12-04 15:53 ` [PATCH v3 19/19] ASoC: qcom: sc8280xp: allow using the sc8280xp card with lpass-cpu Neil Armstrong
2026-12-04 17:54 ` sashiko-bot
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-250324@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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