Linux Sound subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vijendar Mukunda" <Vijendar.Mukunda@amd.com>
Cc: linux-sound@vger.kernel.org
Subject: Re: [PATCH v4 02/13] soundwire: amd: return response on IMM status cleanup timeout
Date: Mon, 26 Oct 2026 09:08:49 +0000	[thread overview]
Message-ID: <sashiko-outbox-184738@kernel.org> (raw)
In-Reply-To: <20261026044507.2310694-3-Vijendar.Mukunda@amd.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] soundwire: amd: unpolled IMM_RES_VALID clear in amd_sdw_send_cmd_get_resp()
--

commit 3a55a761f23cc08cf1a64f142c04e1aa78cc244d
Author: Vijendar Mukunda <Vijendar.Mukunda@amd.com>

soundwire: amd: return response on IMM status cleanup timeout

This commit changes amd_sdw_send_cmd_get_resp() to log an error, store the
read response, and return 0 when polling for AMD_SDW_IMM_RES_VALID to clear
times out. It relies on the bad-state check at the start of the next
invocation to clear the remaining AMD_SDW_IMM_RES_VALID bit.

> diff --git a/drivers/soundwire/amd_manager.c b/drivers/soundwire/amd_manager.c
> index 307cbfdb94422..0b83126b5ce6c 100644
> --- a/drivers/soundwire/amd_manager.c
> +++ b/drivers/soundwire/amd_manager.c
> @@ -285,11 +285,9 @@ static int amd_sdw_send_cmd_get_resp(struct amd_sdw_manager *amd_manager, u32 lo
>  	writel(AMD_SDW_IMM_RES_VALID, amd_manager->mmio + ACP_SW_IMM_CMD_STS);
>  	ret = readl_poll_timeout(amd_manager->mmio + ACP_SW_IMM_CMD_STS, sts,
>  				 !(sts & AMD_SDW_IMM_RES_VALID), ACP_DELAY_US, AMD_SDW_TIMEOUT);
> -	if (ret) {
> +	if (ret)
>  		dev_err(amd_manager->dev, "SDW%x cmd status retry failed\n",
>  			amd_manager->instance);
> -		return ret;
> -	}
>  	*response = ((u64)upper_resp << 32) | lower_resp;
>  	return 0;
>  }

[Severity: High]
When this cleanup poll for !(sts & AMD_SDW_IMM_RES_VALID) times out and
amd_sdw_send_cmd_get_resp() in drivers/soundwire/amd_manager.c returns 0,
can back-to-back commands read stale response data from
ACP_SW_IMM_RESP_UPPER_WORD and ACP_SW_IMM_RESP_LOWER_QWORD?

Callers such as amd_program_scp_addr() and amd_sdw_xfer_msg() issue multiple
commands in sequence:

sdw_transfer()
  do_transfer()
    amd_sdw_xfer_msg()
      amd_prep_msg()
        amd_program_scp_addr()
          amd_sdw_send_cmd_get_resp()
      _amd_sdw_xfer_msg()
        amd_sdw_send_cmd_get_resp()

On the immediate next call to amd_sdw_send_cmd_get_resp(), the bad-state
guard writes AMD_SDW_IMM_RES_VALID to ACP_SW_IMM_CMD_STS without polling for
!(sts & AMD_SDW_IMM_RES_VALID) before issuing the next command and polling
for (sts & AMD_SDW_IMM_RES_VALID):

	if (sts & AMD_SDW_IMM_RES_VALID) {
		dev_err(amd_manager->dev, "SDW%x manager is in bad state\n", amd_manager->instance);
		writel(AMD_SDW_IMM_RES_VALID, amd_manager->mmio + ACP_SW_IMM_CMD_STS);
	}
	writel(upper_data, amd_manager->mmio + ACP_SW_IMM_CMD_UPPER_WORD);
	writel(lower_data, amd_manager->mmio + ACP_SW_IMM_CMD_LOWER_QWORD);

	ret = readl_poll_timeout(amd_manager->mmio + ACP_SW_IMM_CMD_STS, sts,
				 (sts & AMD_SDW_IMM_RES_VALID), ACP_DELAY_US, AMD_SDW_TIMEOUT);

Because clearing AMD_SDW_IMM_RES_VALID requires an asynchronous hardware
handshake that already failed to complete within AMD_SDW_TIMEOUT on the
previous command, won't AMD_SDW_IMM_RES_VALID still be set when
readl_poll_timeout() immediately checks (sts & AMD_SDW_IMM_RES_VALID),
causing it to succeed on the stale bit and read the previous command's
response registers? Should the bad-state guard also poll until
!(sts & AMD_SDW_IMM_RES_VALID) before writing the new command words?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261026044507.2310694-1-Vijendar.Mukunda@amd.com?part=2

  reply	other threads:[~2026-10-26  9:08 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-26  4:43 [PATCH v4 00/13] soundwire: amd: SoundWire manager driver bug fixes Vijendar Mukunda
2026-10-26  4:43 ` [PATCH v4 01/13] soundwire: amd: fix SDW command timeout return value handling Vijendar Mukunda
2026-10-26  4:43 ` [PATCH v4 02/13] soundwire: amd: return response on IMM status cleanup timeout Vijendar Mukunda
2026-10-26  9:08   ` sashiko-bot [this message]
2026-10-26 12:13     ` Mukunda,Vijendar
2026-10-26 13:45       ` Mukunda,Vijendar
2026-10-26  4:43 ` [PATCH v4 03/13] soundwire: amd: cache ping slave status to avoid spurious disconnect on timeout Vijendar Mukunda
2026-10-26  4:43 ` [PATCH v4 04/13] soundwire: amd: assert msg_lock is held in amd_sdw_read_ping_status() Vijendar Mukunda
2026-10-26  4:43 ` [PATCH v4 05/13] soundwire: amd: fix work drain ordering in remove path Vijendar Mukunda
2026-10-26  9:27   ` sashiko-bot
2026-10-27  8:18     ` Mukunda,Vijendar
2026-10-26  4:43 ` [PATCH v4 06/13] soundwire: amd: pm_runtime guard " Vijendar Mukunda
2026-10-26  4:43 ` [PATCH v4 07/13] soundwire: amd: fix ctx leak when sdw_amd_startup() fails Vijendar Mukunda
2026-10-26  9:48   ` sashiko-bot
2026-10-27  4:46     ` Mukunda,Vijendar
2026-10-26  4:43 ` [PATCH v4 08/13] soundwire: amd: propagate amd_init_sdw_manager() error on resume Vijendar Mukunda
2026-10-26  4:43 ` [PATCH v4 09/13] soundwire: amd: drop amd_deinit_sdw_manager() in POWER_OFF suspend Vijendar Mukunda
2026-10-26  4:43 ` [PATCH v4 10/13] soundwire: amd: replace >= ACP70 with explicit switch/case in PM paths Vijendar Mukunda
2026-10-26  4:43 ` [PATCH v4 11/13] soundwire: amd: fix interrupt gate and work drain ordering in PM ops Vijendar Mukunda
2026-10-26 10:27   ` sashiko-bot
2026-10-27  8:28     ` Mukunda,Vijendar
2026-10-26  4:43 ` [PATCH v4 12/13] soundwire: amd: fix IRQ thread dropping STATUS_0TO7 on simultaneous wake Vijendar Mukunda
2026-10-26 10:42   ` sashiko-bot
2026-10-27  3:48     ` Mukunda,Vijendar
2026-10-26  4:43 ` [PATCH v4 13/13] soundwire: amd: fix STATUS_8TO11 double-clear race in wake handler Vijendar Mukunda

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-184738@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Vijendar.Mukunda@amd.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