All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: phucduc.bui@gmail.com
Cc: wsa+renesas@sang-engineering.com, conor+dt@kernel.org,
	robh@kernel.org, devicetree@vger.kernel.org, krzk+dt@kernel.org
Subject: Re: [PATCH v3 04/10] ASoC: renesas: fsi: Fix register access from in-flight IRQ after shutdown
Date: Mon, 11 May 2026 23:22:57 +0000	[thread overview]
Message-ID: <20260511232258.0E3B3C2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <20260510084303.122426-5-phucduc.bui@gmail.com>

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [Critical] Incomplete Fix / Unprotected Hardware Access in fsi_stream_transfer()
- [Critical] Uncleared Interrupt Status Causes Guaranteed Hang on Next IRQ
- [Critical] Pre-existing TOCTOU Race Leading to NULL Pointer Dereference in IRQ Handler
- [High] Data Race / TOCTOU on fsi->running_streams
- [High] State Tracking Variables Leak on START Failure
--

commit a5f51696dc0fd84e1f16198b25e33b2b5da818dc
Author: bui duc phuc <phucduc.bui@gmail.com>
Subject: ASoC: renesas: fsi: Fix register access from in-flight IRQ after shutdown

This commit attempts to fix a system hang caused by in-flight interrupt
handlers accessing hardware registers after the clocks are shut down. It
tracks running streams and adds early returns in the interrupt path when no
streams are active.

> diff --git a/sound/soc/renesas/fsi.c b/sound/soc/renesas/fsi.c
> index 94ab2e4908108..fc8428cb1ba73 100644
> --- a/sound/soc/renesas/fsi.c
> +++ b/sound/soc/renesas/fsi.c
> @@ -460,6 +463,9 @@ static int fsi_get_current_fifo_samples(struct fsi_priv *fsi,
>  
>  static void fsi_count_fifo_err(struct fsi_priv *fsi)
>  {
> +	if (fsi->running_streams == 0)
> +		return;
> +

Does this check completely protect against hardware access during shutdown?

The interrupt handler calls fsi_stream_transfer() before reaching
fsi_count_fifo_err() and fsi_irq_clear_status(). The fsi_stream_transfer()
function calls handlers that directly read hardware registers, such as
DOFF_ST inside fsi_get_current_fifo_samples(). Because this hardware access
remains completely unprotected by the new running_streams check, would an
in-flight interrupt handler still access the shut-down hardware and cause
the exact system hang this patch is intended to fix?

Additionally, is there a time-of-check to time-of-use data race when
evaluating fsi->running_streams here?

The value is read locklessly in the interrupt handler, while it is updated
under fsi->master->lock in the process context during fsi_dai_trigger().
An in-flight interrupt on one processor could evaluate running_streams > 0
locklessly and proceed. Concurrently, another processor could execute
fsi_dai_trigger(SNDRV_PCM_TRIGGER_STOP), acquire the lock, decrement the
counter to 0, and disable the hardware clocks. When the interrupt handler
resumes, it would execute hardware accesses on the disabled clock.

As a side note, there appears to be a pre-existing time-of-check to
time-of-use issue leading to a potential NULL pointer dereference in the
interrupt handler. In fsi_pio_transfer(), the handler calls
fsi_stream_is_working(), which temporarily takes master->lock to verify
io->substream != NULL. It then drops the lock and unconditionally
dereferences io->substream->runtime. Could a concurrent trigger stop on
another processor execute fsi_stream_quit() and set io->substream = NULL
between the check and the use, causing a kernel panic when the interrupt
handler resumes?

[ ... ]
> @@ -681,6 +687,9 @@ static void fsi_irq_clear_status(struct fsi_priv *fsi)
>  	u32 data = 0;
>  	struct fsi_master *master = fsi_get_master(fsi);
>  
> +	if (fsi->running_streams == 0)
> +		return;
> +

Can returning early here without clearing the interrupt status cause a
guaranteed hang on the next interrupt?

If an in-flight or delayed interrupt fires as the stream is shut down, the
handler skips clearing its port's interrupt bits in the shared master int_st
register. Because this register is shared between port A and port B, the
uncleared bit remains permanently asserted. When the other active port
subsequently generates an interrupt, fsi_interrupt() will read int_st, see
the stale bit for the shut-down port, and unconditionally call
fsi_stream_transfer() for it. This forces a hardware register access on the
shut-down port while its clocks are disabled.

[ ... ]
> @@ -1573,10 +1582,17 @@ static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd,
>  {
>  	struct fsi_priv *fsi = fsi_get_priv(substream);
>  	struct fsi_stream *io = fsi_stream_get(fsi, substream);
> +	bool need_shutdown = false;
>  	int ret = 0;
>  
>  	switch (cmd) {
>  	case SNDRV_PCM_TRIGGER_START:
> +		scoped_guard(spinlock_irqsave, &fsi->master->lock) {
> +			if (!io->running) {
> +				io->running = true;
> +				fsi->running_streams++;
> +			}
> +		}
>  		fsi_stream_init(fsi, io, substream);
>  		if (!ret)
>  			ret = fsi_hw_startup(fsi, io, dai->dev);

Does this leak the state tracking variables if the start sequence fails?

If fsi_hw_startup() or fsi_stream_start() fails and returns an error,
the framework aborts the start sequence and does not invoke
SNDRV_PCM_TRIGGER_STOP. Because the error handling path does not revert
io->running and decrement fsi->running_streams, these variables could
permanently leak. This would prevent running_streams from reaching 0 on
subsequent valid stops, permanently bypassing fsi_hw_shutdown() and leaving
the hardware clocks powered on indefinitely.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260510084303.122426-1-phucduc.bui@gmail.com?part=4

  parent reply	other threads:[~2026-05-11 23:22 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-10  8:42 [PATCH v3 00/10] ASoC: renesas: fsi: Fix system hang by adding SPU clock phucduc.bui
2026-05-10  8:42 ` [PATCH v3 01/10] ASoC: dt-bindings: renesas,fsi: add support multiple clocks phucduc.bui
2026-05-11  7:30   ` Geert Uytterhoeven
2026-05-11 10:25     ` Bui Duc Phuc
2026-05-11 20:45   ` sashiko-bot
2026-05-12  6:42     ` Bui Duc Phuc
2026-05-14 15:17       ` Rob Herring
2026-05-15  7:21         ` Geert Uytterhoeven
2026-05-15  6:46   ` Krzysztof Kozlowski
2026-05-15 10:20     ` Bui Duc Phuc
2026-05-15 10:41       ` Bui Duc Phuc
2026-05-15 11:15       ` Krzysztof Kozlowski
2026-05-10  8:42 ` [PATCH v3 02/10] arm: dts: renesas: r8a7740: Add clocks for FSI phucduc.bui
2026-05-11 22:03   ` sashiko-bot
2026-05-15  6:58     ` Bui Duc Phuc
2026-05-10  8:42 ` [PATCH v3 03/10] ASoC: renesas: fsi: Fix trigger stop ordering phucduc.bui
2026-05-11 22:44   ` sashiko-bot
2026-05-10  8:42 ` [PATCH v3 04/10] ASoC: renesas: fsi: Fix register access from in-flight IRQ after shutdown phucduc.bui
2026-05-11  1:52   ` Kuninori Morimoto
2026-05-11 23:22   ` sashiko-bot [this message]
2026-05-10  8:42 ` [PATCH v3 05/10] ASoC: renesas: fsi: Move fsi_clk_init() phucduc.bui
2026-05-10  8:42 ` [PATCH v3 06/10] ASoC: renesas: fsi: Add shared SPU clock support phucduc.bui
2026-05-11  1:56   ` Kuninori Morimoto
2026-05-12  3:09     ` Bui Duc Phuc
2026-05-10  8:43 ` [PATCH v3 07/10] ASoC: renesas: fsi: refactor clock initialization phucduc.bui
2026-05-10 12:30   ` Mark Brown
2026-05-11  1:59   ` Kuninori Morimoto
2026-05-11 10:21     ` Bui Duc Phuc
2026-05-11 23:47   ` sashiko-bot
2026-05-10  8:43 ` [PATCH v3 08/10] ASoC: renesas: fsi: add fsi_clk_prepare/unprepare() phucduc.bui
2026-05-11  2:03   ` Kuninori Morimoto
2026-05-11 23:44   ` sashiko-bot
2026-05-10  8:43 ` [PATCH v3 09/10] ASoC: renesas: fsi: Use clock prepare handling in startup/shutdown phucduc.bui
2026-05-11  2:04   ` Kuninori Morimoto
2026-05-11 10:22     ` Bui Duc Phuc
2026-05-12  0:09   ` sashiko-bot
2026-05-10  8:43 ` [PATCH v3 10/10] ASoC: renesas: fsi: Add SPU clock control in hw_startup/shutdown phucduc.bui
2026-05-11 23:58   ` 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=20260511232258.0E3B3C2BCB0@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=phucduc.bui@gmail.com \
    --cc=robh@kernel.org \
    --cc=sashiko@lists.linux.dev \
    --cc=wsa+renesas@sang-engineering.com \
    /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.