All of lore.kernel.org
 help / color / mirror / Atom feed
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 17/19] ASoC: qcom: add SM8650 LPASS CPU driver
Date: Fri, 04 Dec 2026 17:42:40 +0000	[thread overview]
Message-ID: <sashiko-outbox-250333@kernel.org> (raw)
In-Reply-To: <20261204-topic-sm8650-el2-v3-17-8384ef0ac751@linaro.org>

Thank you for your contribution! Sashiko AI review found 8 potential
issues to consider:
- [High] ASoC: qcom: codec_dma_enable MMIO/IRQ claims collide with
  SM8650 MI2S LPAIFs
- [High] ASoC: qcom: LPM memremap() mappings leak and hit
  free_pages_exact() on teardown
- [Medium] ASoC: qcom: u32 underflow in lpass_platform_allocate_lpm()
- [Medium] ASoC: qcom: unchecked memremap() in LPM prealloc causes NULL
  dereference
- [Medium] ASoC: qcom: sm8650 WRDMA channel range exceeds
  LPASS_MAX_CDC_DMA_CHANNELS
- [Medium] ASoC: qcom: lpass: missing CDC DMA regcache sync on
  suspend/resume
- [Low] ASoC: qcom: commit message omits Quaternary and Quinary MI2S
  DAIs
- [Low] ASoC: qcom: unsigned underflow in lpass_platform_allocate_lpm()
--

commit 7cec95248eea9dc0ea78ea2e92f97a7dcf6185dd
Author: Neil Armstrong <neil.armstrong@linaro.org>

ASoC: qcom: add SM8650 LPASS CPU driver

This commit adds the SM8650 LPASS CPU driver variant with MI2S, DP, and
codec DMA DAIs, their LPAIF instances, clocks, and LPM DMA buffer
configurations.

> Add the SM8650 lpass-cpu variant with the Primary, Secondary, Tertiary,
> Senary & Septenary MI2S, DP and codec DMA DAIs, their LPAIF instances,
> clocks and LPM DMA buffers.

[Severity: Low]
This isn't a bug, but the commit message omits Quaternary and Quinary
MI2S even though sm8650_lpass_cpu_dai_driver[] and
sm8650_lpaif_mi2s_desc[] define all seven MI2S interfaces (Primary
through Septenary).

> diff --git a/sound/soc/qcom/lpass-sm8650.c b/sound/soc/qcom/lpass-sm8650.c
> new file mode 100644
> index 0000000000000..53c155e1b6396
> --- /dev/null
> +++ b/sound/soc/qcom/lpass-sm8650.c
> @@ -0,0 +1,653 @@

[ ... ]

> +static int sm8650_lpass_dev_suspend(struct device *dev)
> +{
> +	struct lpass_data *drvdata = dev_get_drvdata(dev);
> +
> +	clk_bulk_disable_unprepare(drvdata->num_clks, drvdata->clks);
> +	return 0;
> +}
> +
> +static const struct dev_pm_ops sm8650_lpass_pm_ops = {
> +	SYSTEM_SLEEP_PM_OPS(sm8650_lpass_dev_suspend, sm8650_lpass_dev_resume)
> +};

[Severity: Medium]
Will CDC DMA streams lose their hardware DMA register state across system
suspend and resume?

lpass_platform_pcmops_suspend() and lpass_platform_pcmops_resume() in
sound/soc/qcom/lpass-platform.c only cache-only and regcache_sync()
hdmiif_map and lpaif[i].map, omitting rxtx_lpaif_map, va_lpaif_map, and
the newly exposed wsa_lpaif_map from commit "ASoC: qcom: lpass: add
support for optional WSA interface".

Because the CDC DMA descriptors advertise SNDRV_PCM_INFO_RESUME, resume
calls trigger(SNDRV_PCM_TRIGGER_RESUME) without prepare().  After LPASS
power collapse, LPAIF_DMABASE_REG, LPAIF_DMABUFF_REG, and LPAIF_DMAPER_REG
stay zeroed in hardware, breaking stream resume and pointer calculations.

[ ... ]

> +	{
> +		.reg_name = "lpass-rxtx-lpaif",
> +		.irq_name = "lpass-irq-rxtxif",
> +		.lpm_type = LPASS_RXTX_CDC_LPM,
> +		.port_desc = (const struct mi2s_port_desc[]) {
> +			{ .intf = 0, .id = MI2S_QUATERNARY, },
> +		},
> +		.port_desc_count = 1,
> +	},
> +	{
> +		.reg_name = "lpass-va-lpaif",
> +		.irq_name = "lpass-irq-vaif",
> +		.lpm_type = LPASS_VA_CDC_LPM,
> +		.port_desc = (const struct mi2s_port_desc[]) {
> +			{ .intf = 0, .id = MI2S_QUINARY, },
> +		},
> +		.port_desc_count = 1,
> +	},

[Severity: High]
Does enabling any Codec DMA DAI alongside MI2S_QUATERNARY or MI2S_QUINARY
fail probe with -EBUSY?

of_lpass_cpu_parse_dai_data() sets drvdata->codec_dma_enable for any
Codec DMA node (RXTX, VA, or WSA).  asoc_qcom_lpass_cpu_platform_probe()
then exclusively maps both lpass-rxtx-lpaif and lpass-va-lpaif via
devm_platform_ioremap_resource_byname().

lpass_cpu_init_lpaif() then tries to map the same region again for
MI2S_QUATERNARY or MI2S_QUINARY and fails probe with -EBUSY, even on
non-conflicting boards such as WSA Codec DMA with MI2S_QUATERNARY.

asoc_qcom_lpass_platform_register() hits the same -EBUSY conflict by
requesting lpass-irq-rxtxif and lpass-irq-vaif without IRQF_SHARED
whenever codec_dma_enable is set.  lpass_platform_allocate_lpm() also
unconditionally reserves 16 KiB for rxtx_lpm_offset when RXTX is unused.

> +	{
> +		.reg_name = "lpass-wsa-lpaif",
> +		.irq_name = "lpass-irq-wsaif",
> +		.lpm_type = LPASS_RXTX_CDC_LPM,
> +		.port_desc = (const struct mi2s_port_desc[]) {
> +			{ .intf = 0, .id = MI2S_SENARY, },
> +		},
> +		.port_desc_count = 1,
> +	},

[Severity: Medium]
Can rxtx_cdc_dma_lpm_remain underflow in lpass_platform_allocate_lpm()
when the DT LPM region is smaller than the Codec DMA reservation?

In sound/soc/qcom/lpass-platform.c (added in commit "ASoC: qcom: lpass:
allocate LPM buffer memory to DAIs"), lpass_platform_allocate_lpm()
subtracts LPASS_RXTX_CDC_DMA_LPM_BUFF_SIZE * 2 from the unsigned u32
rxtx_cdc_dma_lpm_remain (twice when wsa_enable is set) without checking
that enough space remains:

sound/soc/qcom/lpass-platform.c:lpass_platform_allocate_lpm() {
	...
	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 the region is undersized, rxtx_cdc_dma_lpm_remain wraps to a large
positive value, defeating the subsequent LPASS_RXTX_CDC_LPM capacity
check for SM8650 MI2S ports and causing memremap() and
io_remap_pfn_range() to map physical addresses beyond the LPM window.

[Severity: Low]
Can va_cdc_dma_lpm_remain similarly underflow in
lpass_platform_allocate_lpm() when drvdata->va_enable is set?

The subtraction of LPASS_VA_CDC_DMA_LPM_BUFF_SIZE from the unsigned u32
va_cdc_dma_lpm_remain is also unchecked, so an undersized VA LPM DT
region wraps around and bypasses the LPASS_VA_CDC_LPM bounds check for
MI2S_QUINARY, assigning out-of-bounds physical addresses to memremap().

> +	{
> +		.reg_name = "lpass-aud-lpaif",
> +		.irq_name = "lpass-irq-audif",
> +		.lpm_type = LPASS_RXTX_CDC_LPM,
> +		.port_desc = (const struct mi2s_port_desc[]) {
> +			{ .intf = 0, .id = MI2S_SEPTENARY, },
> +			{ .intf = 1, .id = MI2S_TERTIARY, },
> +		},
> +		.port_desc_count = 2,
> +	},

[Severity: Medium]
Can an unchecked memremap() failure for SM8650 LPM MI2S buffers cause a
NULL pointer dereference in lpass_platform_copy()?

lpass_platform_prealloc_lpm_mi2s_buffer() (and
lpass_platform_prealloc_cdc_dma_buffer()) in
sound/soc/qcom/lpass-platform.c store memremap(buf->addr, buf->bytes,
MEMREMAP_WC) in buf->area without checking for NULL and return 0.

Because lpass_component_driver supplies .copy = lpass_platform_copy,
ALSA's pcm_sanity_check() skips its !runtime->dma_area check, so a
subsequent PCM read or write passes NULL plus offset to
copy_from_iter_toio() or copy_to_iter_fromio().

[Severity: High]
Do the LPM memremap() mappings leak and trigger free_pages_exact() on an
I/O mapping during PCM teardown?

lpass_platform_prealloc_lpm_mi2s_buffer() and
lpass_platform_prealloc_cdc_dma_buffer() set buf->dev.type to
SNDRV_DMA_TYPE_CONTINUOUS and assign an unmanaged memremap() pointer to
buf->area, while lpass_component_driver provides no .pcm_free callback.

On teardown or unbind, snd_pcm_free() -> do_free_pages() hits
WARN_ON(card->total_pcm_alloc_bytes < bytes) and passes the memremap()
address to free_pages_exact() instead of memunmap(), leaking the mapping
and risking page-allocator corruption.

[ ... ]

> +	.rxtx_wrdma_channel_start	= 5,
> +	.rxtx_wrdma_channels		= 4,
> +	.va_wrdma_reg_base		= 0x1a000,
> +	.va_wrdma_reg_stride		= 0x1000,
> +	.va_wrdma_channel_start		= 5,
> +	.va_wrdma_channels		= 3,
> +	.va_irq_reg_base		= 0x9000,
> +	.va_irq_reg_stride		= 0x1000,
> +	.va_irq_ports			= 5,
> +	.wsa_irq_reg_base		= 0x9000,
> +	.wsa_irq_reg_stride		= 0x1000,
> +	.wsa_irq_ports			= 5,
> +	.wsa_wrdma_reg_base		= 0x1a000,
> +	.wsa_wrdma_reg_stride		= 0x1000,
> +	.wsa_wrdma_channel_start	= 5,
> +	.wsa_wrdma_channels		= 4,

[Severity: Medium]
Can these WRDMA channel counts overflow drvdata->rxtx_substream[] and
drvdata->wsa_substream[]?

With channel_start = 5 and channels = 4, sm8650_lpass_alloc_dma_channel()
can allocate channel 8, exceeding LPASS_MAX_CDC_DMA_CHANNELS (8).  Four
concurrently opened DAI links on LPASS_CDC_DMA_TX3 then write past
rxtx_substream[7] into va_substream[0] (or wsa_substream[8] into clks).

In addition, lpass_platform_rxtxif_irq() and lpass_platform_wsaif_irq()
only iterate up to LPASS_MAX_CDC_DMA_CHANNELS, so interrupts for channel
8 would never be serviced.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-topic-sm8650-el2-v3-0-8384ef0ac751@linaro.org?part=17

  reply	other threads:[~2026-12-04 17:42 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
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 [this message]
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-250333@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.