Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Michael Reeves" <michael.reeves077@gmail.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org,
	dmitry.torokhov@gmail.com, linux-input@vger.kernel.org,
	conor+dt@kernel.org
Subject: Re: [PATCH v4 05/10] mailbox: apple: Add DockChannel FIFO controller
Date: Fri, 25 Sep 2026 12:18:50 +0000	[thread overview]
Message-ID: <20260925121851.4E4F41F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260925-apple-mtp-keyboard-final-v4-5-304c267518f4@gmail.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] irq: infinite IRQ storm on early/spurious TX interrupt
- [High] mailbox: TOCTOU race loses TX completion interrupt
- [High] mailbox: missed RX interrupt on startup drops pre-existing data
--

commit cccb050135d4c52daf05b87f17ad880ef928b912
Author: Michael Reeves <michael.reeves077@gmail.com>

mailbox: apple: Add DockChannel FIFO controller

This adds a driver for Apple's DockChannel hardware FIFO used by coprocessors.
It exposes the FIFO pair as a Linux mailbox channel and handles interrupts
in a thread.

> diff --git a/drivers/mailbox/apple-dockchannel.c b/drivers/mailbox/apple-dockchannel.c
> new file mode 100644
> --- /dev/null
> +++ b/drivers/mailbox/apple-dockchannel.c

[ ... ]

> +static void apple_dockchannel_irq_enable(struct apple_dockchannel *dc, u32 bits)
> +{
> +	/*
> +	 * IRQ_FLAG is write-to-clear. Clear stale latched flags before
> +	 * unmasking so the next interrupt reflects current FIFO state.
> +	 */
> +	writel_relaxed(bits, dc->irq_base + IRQ_FLAG);
> +	apple_dockchannel_irq_update(dc, bits, true);
> +}

[ ... ]

> +static int apple_dockchannel_send_data(struct mbox_chan *chan, void *data)
> +{

[ ... ]

> +	dc->tx_active = true;
> +
> +	apple_dockchannel_write(dc, msg->data, msg->len);
> +	writel_relaxed(APPLE_DOCKCHANNEL_FIFO_SIZE,
> +		       dc->config_base + CONFIG_TX_THRESH);
> +	apple_dockchannel_irq_enable(dc, dc->irq_tx);

[Severity: High]
If the coprocessor is fast enough to drain the FIFO before
apple_dockchannel_irq_enable() executes, the hardware might latch the
TX-empty interrupt flag.

Since apple_dockchannel_irq_enable() unconditionally writes to IRQ_FLAG
to clear latched flags, does this destroy a valid completion interrupt
and stall the channel permanently?

> +
> +	spin_unlock_irqrestore(&dc->lock, flags);
> +
> +	return 0;
> +}
> +
> +static int apple_dockchannel_startup(struct mbox_chan *chan)
> +{
> +	struct apple_dockchannel *dc = chan->con_priv;
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&dc->lock, flags);
> +	/*
> +	 * The mailbox framework has no per-client RX threshold. Use byte
> +	 * granularity because UART-style DockChannel clients require it.
> +	 */
> +	writel_relaxed(1, dc->config_base + CONFIG_RX_THRESH);
> +	apple_dockchannel_irq_enable(dc, dc->irq_rx);

[Severity: High]
During startup, apple_dockchannel_irq_enable() unconditionally clears
latched RX interrupts.

If the coprocessor sent data to the FIFO before the mailbox was opened,
does this clear the latched interrupt without reading the data? 

Since the FIFO is already above the threshold, this could strand pre-existing
data by not generating a new edge interrupt.

> +	spin_unlock_irqrestore(&dc->lock, flags);
> +
> +	enable_irq(dc->irq);
> +
> +	return 0;
> +}

[ ... ]

> +static irqreturn_t apple_dockchannel_irq_thread(int irq, void *data)
> +{

[ ... ]

> +	if (pending & dc->irq_tx) {
> +		if (apple_dockchannel_tx_empty(dc)) {
> +			apple_dockchannel_irq_disable(dc, dc->irq_tx);
> +			tx_done = dc->tx_active;
> +			dc->tx_active = false;
> +		} else {
> +			pending &= ~dc->irq_tx;
> +		}
> +	}
> +
> +	writel_relaxed(pending, dc->irq_base + IRQ_FLAG);

[ ... ]

> +	if (!(pending & dc->irq_rx))
> +		return pending ? IRQ_HANDLED : IRQ_NONE;

[Severity: High]
If the hardware triggers an early or spurious TX interrupt before the FIFO
is completely empty, apple_dockchannel_tx_empty() is false, which drops the
TX flag from the pending mask.

When pending is written back to IRQ_FLAG, the unmasked TX interrupt flag
is left uncleared in the hardware register.

If there is no RX interrupt pending, the function returns IRQ_NONE. Because
the interrupt is left asserted in hardware and unmasked at the controller,
will this cause an immediate re-trigger and an infinite IRQ storm?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260925-apple-mtp-keyboard-final-v4-0-304c267518f4@gmail.com?part=5

  reply	other threads:[~2026-09-25 12:18 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-25 12:09 [PATCH v4 00/10] Add support for Apple Silicon DockChannel internal keyboards Michael Reeves via B4 Relay
2026-09-25 12:09 ` [PATCH v4 01/10] dt-bindings: mailbox: apple: Add M3 ASC mailbox compatibles Michael Reeves via B4 Relay
2026-09-25 12:09 ` [PATCH v4 02/10] dt-bindings: mailbox: apple: Add DockChannel mailbox Michael Reeves via B4 Relay
2026-10-06 15:55   ` Rob Herring (Arm)
2026-09-25 12:09 ` [PATCH v4 03/10] dt-bindings: iommu: apple,dart: Add M3 compatibles Michael Reeves via B4 Relay
2026-09-25 12:09 ` [PATCH v4 04/10] dt-bindings: input: apple: Add DockChannel HID transport Michael Reeves via B4 Relay
2026-09-25 12:16   ` sashiko-bot
2026-10-06 16:00   ` Rob Herring
2026-10-06 18:09     ` Yureka Lilian
2026-10-06 18:50       ` Rob Herring
2026-09-25 12:09 ` [PATCH v4 05/10] mailbox: apple: Add DockChannel FIFO controller Michael Reeves via B4 Relay
2026-09-25 12:18   ` sashiko-bot [this message]
2026-09-25 12:09 ` [PATCH v4 06/10] soc: apple: rtkit: Add tracekit endpoint Michael Reeves via B4 Relay
2026-09-25 12:09 ` [PATCH v4 07/10] HID: apple: Add support for DockChannel HID keyboards Michael Reeves via B4 Relay
2026-09-25 12:09 ` [PATCH v4 08/10] HID: apple: Add DockChannel HID transport driver Michael Reeves via B4 Relay
2026-09-25 12:09 ` [PATCH v4 09/10] arm64: dts: apple: Add MTP DockChannel HID nodes Michael Reeves via B4 Relay
2026-09-25 12:09 ` [PATCH v4 10/10] arm64: dts: apple: Enable DockChannel HID on M2 and M3 laptops Michael Reeves via B4 Relay

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=20260925121851.4E4F41F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=michael.reeves077@gmail.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox