All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sasha Finkelstein" <k@chaosmail.tech>
Cc: robh@kernel.org, devicetree@vger.kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v2 2/7] spmi: apple: Validate FIFO state
Date: Tue, 28 Jul 2026 09:41:33 +0000	[thread overview]
Message-ID: <20260728094134.4515E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260728-t603x-spmi-v2-2-f43e5f10e583@chaosmail.tech>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:

Pre-existing issues:
- [High] The driver detects and warns about extra data in the RX FIFO but fails to drain it, permanently desynchronizing subsequent SPMI transactions.
- [High] The driver silently discards the SPMI reply status word, ignoring command NACKs and parity errors.
- [High] The SPMI read and write commands lack mutual exclusion, leading to concurrent hardware accesses clobbering each other.
- [High] The driver polls hardware registers using a sleeping timeout macro (`readl_poll_timeout`), triggering kernel BUGs in atomic contexts.
--

--- Patch [2]: [PATCH v2 2/7] spmi: apple: Validate FIFO state ---
commit 6fe31783af0978f8c2699194bf6efebf6615ed3b
Author: Alba Mendez <me@alba.sh>

spmi: apple: Validate FIFO state

Check for data before reading the body of a reply, and check for
end of data afterwards.

> --- a/drivers/spmi/spmi-apple-controller.c
> +++ b/drivers/spmi/spmi-apple-controller.c
> @@ -78,6 +78,10 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,

[Severity: High]
This is a pre-existing issue, but does spmi_read_cmd() lack mutual exclusion?

Concurrent calls to the SPMI controller could interleave writes to the command
register and reads from the FIFO.

Could this unpredictably corrupt commands and steal words from each other's
streams during concurrent access by different subsystems?

[Severity: High]
This isn't a bug introduced by this patch, but the wait function called
before this read loop appears to sleep in atomic contexts.

Every SPMI read/write operation calls apple_spmi_wait_rx_not_empty(), which 
uses poll_reg() wrapped around readl_poll_timeout().

Since readl_poll_timeout() delegates to usleep_range(), wouldn't this trigger
a kernel BUG when SPMI client drivers issue commands from atomic contexts?

>  
>  	/* Read SPMI data reply */
>  	while (len_read < len) {

[Severity: High]
This is a pre-existing issue, but earlier in this function the status word is
discarded before the read loop:

drivers/spmi/spmi-apple-controller.c:spmi_read_cmd() {
	/* Discard SPMI reply status */
	readl(spmi->regs + SPMI_RSP_REG);
	...
}

Does this silently ignore command NACKs and parity errors on the wire?

> +		if (readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY) {
> +			dev_err(&ctrl->dev, "FIFO lacks reply data, controller stuck?\n");
> +			return -EIO;
> +		}
>  		rsp = readl(spmi->regs + SPMI_RSP_REG);
>  		i = 0;

[ ... ]

> @@ -86,6 +90,9 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
>  		}
>  	}
>  
> +	if (!(readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY))
> +		dev_warn(&ctrl->dev, "FIFO has extra data\n");

[Severity: High]
This isn't a bug introduced by this patch, but if the FIFO is left with extra
data here, will the next SPMI transaction's wait function return immediately?

If the driver pops the stale leftover data instead of waiting for its own reply,
it seems like this would permanently shift the data stream and break all
subsequent communication with the PMIC.

Should the extra data be drained here to prevent this?

> +
>  	return 0;
>  }
>  
> @@ -115,6 +122,9 @@ static int spmi_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,

[Severity: High]
This is a pre-existing issue, but similar to spmi_read_cmd(), does
spmi_write_cmd() also lack mutual exclusion for stateful bus transactions?

>  	/* Discard */
>  	readl(spmi->regs + SPMI_RSP_REG);

[Severity: High]
This isn't a bug introduced by this patch, but discarding the status word
here appears to hide write failures and parity errors.

> +	if (!(readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY))
> +		dev_warn(&ctrl->dev, "FIFO has extra data\n");

[Severity: High]
This is a pre-existing issue, but just like in spmi_read_cmd(), failing to
drain the extra data detected here could permanently desynchronize subsequent
SPMI transactions.

> +
>  	return 0;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260728-t603x-spmi-v2-0-f43e5f10e583@chaosmail.tech?part=2

  reply	other threads:[~2026-07-28  9:41 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-28  9:28 [PATCH v2 0/7] spmi: apple: Additional commands and interrupt support Sasha Finkelstein
2026-07-28  9:28 ` [PATCH v2 1/7] dt-bindings: spmi: apple,spmi: Add t603x Sasha Finkelstein
2026-07-28  9:33   ` sashiko-bot
2026-07-28  9:28 ` [PATCH v2 2/7] spmi: apple: Validate FIFO state Sasha Finkelstein
2026-07-28  9:41   ` sashiko-bot [this message]
2026-07-28  9:28 ` [PATCH v2 3/7] spmi: apple: check transaction status Sasha Finkelstein
2026-07-28  9:41   ` sashiko-bot
2026-07-28  9:28 ` [PATCH v2 4/7] spmi: apple: Implement remaining commands Sasha Finkelstein
2026-07-28  9:46   ` sashiko-bot
2026-07-28  9:28 ` [PATCH v2 5/7] spmi: apple: lock around FIFOs Sasha Finkelstein
2026-07-28  9:37   ` sashiko-bot
2026-07-28  9:28 ` [PATCH v2 6/7] spmi: apple: use IRQ for RX FIFO if possible Sasha Finkelstein
2026-07-28  9:42   ` sashiko-bot
2026-07-28  9:28 ` [PATCH v2 7/7] spmi: apple: interrupt controller functionality Sasha Finkelstein
2026-07-28  9:40   ` 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=20260728094134.4515E1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=k@chaosmail.tech \
    --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.