Linux Sound subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Bahadır Hamza Öztürk" <bahadirhamza2@gmail.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH v2] ASoC: amd: acp: add DMIC capture switch
Date: Fri, 04 Dec 2026 21:39:52 +0000	[thread overview]
Message-ID: <sashiko-outbox-250705@kernel.org> (raw)
In-Reply-To: <20261204211751.13825-1-bahadirhamza2@gmail.com>

Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [Medium] ASoC: amd: acp: prepare and resume gate DMIC without arming
  dmic_clearing
- [Medium] ASoC: amd: acp: acp_dmic_dai_trigger() and switch put miss
  PDM gate sync
- [Medium] ASoC: amd: acp: full-buffer memset and MMIO read in
  acp_dma_pointer()
- [Medium] ASoC: amd: acp: undocumented ACP_WOV_MISC_CTRL bit 5 written
  on all Renoir
- [Medium] ASoC: amd: acp: DMIC mute bypassed via mmap and full-buffer
  memset in hardirq
- [Low] ASoC: amd: acp: acp_pcm_probe() exposes DMIC switch without PDM
  hardware
--

commit 861aa6259e9d977790367dd9467eb2b0278ea46e
Author: Bahadır Hamza Öztürk <bahadirhamza2@gmail.com>

ASoC: amd: acp: add DMIC capture switch

This commit adds a "DMIC Capture Switch" mixer control for the ACP PDM
microphone.  While muted, it gates the PDM data input via bit 5 of
ACP_WOV_MISC_CTRL on Renoir and zeroes the capture DMA buffer on each
pointer query, continuing for 10 ms after unmuting to drop the decimator
step.

[ ... ]

> diff --git a/sound/soc/amd/acp/acp-pdm.c b/sound/soc/amd/acp/acp-pdm.c
> index 1bfc34c2aa536..0daa935a5b057 100644
> --- a/sound/soc/amd/acp/acp-pdm.c
> +++ b/sound/soc/amd/acp/acp-pdm.c
> @@ -40,6 +40,7 @@ static int acp_dmic_prepare(struct snd_pcm_substream *substream,
>  	dmic_ctrl = readl(chip->base + ACP_WOV_MISC_CTRL);
>  	dmic_ctrl |= PDM_MISC_CTRL_MASK;
>  	writel(dmic_ctrl, chip->base + ACP_WOV_MISC_CTRL);
> +	acp_dmic_update_gate(chip, READ_ONCE(chip->dmic_mute));

[Severity: Medium]
Does acp_dmic_prepare() (and set_acp_pdm_clk() on resume) leave
stream->dmic_clearing and stream->dmic_open_pos out of sync with the gate?

A freshly opened stream starts with dmic_clearing = false.  If the stream is
prepared while muted and unmuted before the first acp_dma_pointer() call,
acp_dmic_mute_update() clears PDM_MISC_DATA_GATE and immediately returns at
"else if (!stream->dmic_clearing)" without zeroing runtime->dma_area or
waiting ACP_DMIC_SETTLE_MS.  That delivers up to a full period of gated
full-scale negative samples plus the decimator unmute step on Renoir (or
live muted audio on other revisions) as a loud pop.

Re-preparing an already-open stream after stop or suspend also carries over
stale dmic_clearing and dmic_open_pos values, which can cut the settle
period short or zero the start of an unmuted capture.  Initializing both
fields from the mute state in prepare and resume would keep them in sync.

> diff --git a/sound/soc/amd/acp/acp-platform.c b/sound/soc/amd/acp/acp-platform.c
> index f2c8853775ad3..9deeb9d4d023d 100644
> --- a/sound/soc/amd/acp/acp-platform.c
> +++ b/sound/soc/amd/acp/acp-platform.c

[ ... ]

> +static void acp_dmic_mute_update(struct acp_chip_info *pdata,
> +				 struct snd_pcm_substream *substream,
> +				 struct acp_stream *stream, u64 total,
> +				 u32 buffersize)
> +{
> +	struct snd_pcm_runtime *runtime = substream->runtime;
> +	bool mute = READ_ONCE(pdata->dmic_mute);
> +	u32 settle;
> +
> +	acp_dmic_update_gate(pdata, mute);
> +
> +	if (mute) {
> +		stream->dmic_clearing = true;
> +		stream->dmic_open_pos = U64_MAX;
> +	} else if (!stream->dmic_clearing) {
> +		return;
> +	} else if (stream->dmic_open_pos == U64_MAX) {
> +		stream->dmic_open_pos = total;
> +	} else {
> +		settle = frames_to_bytes(runtime, runtime->rate / 1000 *
> +					 ACP_DMIC_SETTLE_MS);
> +		if (total < stream->dmic_open_pos ||
> +		    total - stream->dmic_open_pos >= settle)
> +			stream->dmic_clearing = false;
> +	}
> +
> +	memset(runtime->dma_area, 0, buffersize);
> +}

[Severity: Medium]
Is it safe to memset() the entire capture buffer on every acp_dma_pointer()
call?

acp_dma_pointer() runs in hardirq context from acp_irq_handler() while
holding chip->acp_lock and the PCM substream spinlock, and on every
userspace status/delay ioctl with interrupts disabled.  Zeroing up to 64 KiB
of coherent DMA memory on every call stalls sibling I2S streams and shared
IRQ handlers, skews the hardware-position timestamp taken right after
->pointer() in snd_pcm_update_hw_ptr0(), and overwrites already-captured
unread frames while userspace is reading them.

On Renoir, acp_dmic_update_gate() also does a redundant PCIe MMIO readl() on
every muted pointer call because it does not return early when
mute == pdata->dmic_gated.

[ ... ]

> +static int acp_dmic_switch_put(struct snd_kcontrol *kcontrol,
> +			       struct snd_ctl_elem_value *ucontrol)
> +{
> +	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
> +	struct acp_chip_info *pdata = dev_get_platdata(component->dev);
> +	bool mute = !ucontrol->value.integer.value[0];
> +
> +	if (mute == READ_ONCE(pdata->dmic_mute))
> +		return 0;
> +
> +	/* Applied by the next prepare or position read */
> +	WRITE_ONCE(pdata->dmic_mute, mute);
> +	return 1;
> +}

[Severity: Medium]
Can live microphone audio reach runtime->dma_area on Renoir because the
hardware gate is deferred out of acp_dmic_switch_put() and not synced in
acp_dmic_dai_trigger()?

If the switch is muted after acp_dmic_prepare() or while the stream is
paused, acp_dmic_dai_trigger() enables PDM DMA without setting
PDM_MISC_DATA_GATE, so up to a full period of live audio is written to
memory before the first acp_dma_pointer() call.  The same window occurs
after muting an already running stream, and unmuting between prepare and
SNDRV_PCM_TRIGGER_START leaves the gate set for the first period.

[ ... ]

> +static int acp_pcm_probe(struct snd_soc_component *component)
> +{
> +	struct snd_soc_dai *dai;
> +
> +	/* Only offer the switch when the PDM DAI is part of this component */
> +	for_each_component_dais(component, dai) {
> +		if (dai->driver->id == DMIC_INSTANCE)
> +			return snd_soc_add_component_controls(component,
> +							      acp_dmic_controls,
> +							      ARRAY_SIZE(acp_dmic_controls));
> +	}
> +
> +	return 0;
> +}

[Severity: Low]
Will this expose a non-functional "DMIC Capture Switch" on I2S-only ACP
configurations?

All four ACP platform drivers (acp-renoir.c, acp-rembrandt.c, acp63.c,
acp70.c) unconditionally include an acp-pdm-dmic entry with DMIC_INSTANCE in
their static DAI arrays, so the loop always matches even when no PDM
microphone is present.  Checking pdata->is_pdm_dev && pdata->is_pdm_config
here, as create_acp_platform_devs() in acp-pci.c does, would restrict the
control to platforms with PDM hardware.

> diff --git a/sound/soc/amd/acp/amd.h b/sound/soc/amd/acp/amd.h
> index 73a028e672462..e150706d00edd 100644
> --- a/sound/soc/amd/acp/amd.h
> +++ b/sound/soc/amd/acp/amd.h
> @@ -131,6 +131,11 @@
>  #define PDM_DEC_64              0x2
>  #define PDM_CLK_FREQ_MASK       0x07
>  #define PDM_MISC_CTRL_MASK      0x18
> +/*
> + * Not documented: with this bit set the PDM data input is gated and the
> + * decimator outputs a constant value instead of microphone data.
> + */
> +#define PDM_MISC_DATA_GATE      BIT(5)

[Severity: Medium]
Should an undocumented ACP_WOV_MISC_CTRL bit observed on a single laptop be
written across all ACP_RN_PCI_ID Renoir systems?

In 1-bit PDM, a constant all-zero bitstream decodes to full-scale negative
output, which is also consistent with a data-lane mux selecting an
unconnected lane or a clock/test mode rather than a dedicated mute gate.
Without hardware documentation confirming bit 5, setting it globally on
Renoir risks breaking PDM capture or failing to mute microphones wired to
other lanes on untested boards.

[ ... ]

> +static inline void acp_dmic_update_gate(struct acp_chip_info *pdata, bool mute)
> +{
> +	u32 ctrl, val;
> +
> +	if (pdata->acp_rev != ACP_RN_PCI_ID || (!mute && !pdata->dmic_gated))
> +		return;
> +
> +	ctrl = readl(pdata->base + ACP_WOV_MISC_CTRL);
> +	val = mute ? ctrl | PDM_MISC_DATA_GATE : ctrl & ~PDM_MISC_DATA_GATE;
> +	if (val != ctrl)
> +		writel(val, pdata->base + ACP_WOV_MISC_CTRL);
> +	pdata->dmic_gated = mute;
> +}

[Severity: Medium]
Does limiting hardware gating to ACP_RN_PCI_ID allow muted audio to leak
through mmap on Rembrandt, ACP63, and ACP70/71/72?

acp_pcm_probe() exposes "DMIC Capture Switch" on all those platforms, and
the ACP capture hardware advertises SNDRV_PCM_INFO_MMAP.  Because PDM DMA
continues writing live microphone samples into runtime->dma_area between
pointer queries while muted, an mmap client reading ahead of hw_ptr can
capture live audio while the switch and any UCM-linked mic mute LED report
muted; on Renoir, deferring the gate out of acp_dmic_switch_put() leaves the
same window until the next pointer read.

Relying on a full-buffer memset() in acp_dma_pointer() to clear the buffer
retroactively also adds hardirq spinlock latency in acp_irq_handler() under
chip->acp_lock and the PCM substream lock.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204211751.13825-1-bahadirhamza2@gmail.com?part=1

      reply	other threads:[~2026-12-04 21:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 21:17 [PATCH v2] ASoC: amd: acp: add DMIC capture switch Bahadır Hamza Öztürk
2026-12-04 21:39 ` sashiko-bot [this message]

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-250705@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bahadirhamza2@gmail.com \
    --cc=linux-sound@vger.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