Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Shubham Patil" <shubhamsanjay.patil@amd.com>
Cc: linux-i3c@lists.infradead.org, conor+dt@kernel.org,
	devicetree@vger.kernel.org, Frank.Li@kernel.org, robh@kernel.org,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>
Subject: Re: [PATCH v3 2/3] i3c: master: amd: Add support for in-band interrupts
Date: Tue, 08 Sep 2026 10:00:14 +0000	[thread overview]
Message-ID: <20260908100015.109811F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260908094257.3196120-3-shubhamsanjay.patil@amd.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Eagerly draining the shared RX FIFO during a polled read transfer consumes in-flight IBI payloads, corrupting both the IBI and the transfer data.
- [High] Freeing the IBI pool before the workqueue is flushed causes a UAF and NULL pointer dereference if a stray IBI is queued after disable.
--

commit 4e71fd809febc81aa5e7bc809c1ce4fa618ec5a7
Author: Shubham Patil <shubhamsanjay.patil@amd.com>

i3c: master: amd: Add support for in-band interrupts

Add support for receiving and dequeueing I3C in-band interrupts. IBI
support is optional at synthesis time, so the ops are assembled at probe
time. The controller interrupt carries IBI events only.

> diff --git a/drivers/i3c/master/amd-i3c-master.c b/drivers/i3c/master/amd-i3c-master.c
> index ef5ad5abb788c..8a8ab3cd2fa40 100644
> --- a/drivers/i3c/master/amd-i3c-master.c
> +++ b/drivers/i3c/master/amd-i3c-master.c

[ ... ]

> @@ -606,14 +678,21 @@ static int xi3c_master_read(struct xi3c_master *master, struct xi3c_cmd *cmd)
>  		return ret;
>  	}
>  
> -	if (!(status_reg & XI3C_RD_FIFO_NOT_EMPTY_MASK))
> +	/*
> +	 * No data queued means this read produced none, unless what is queued
> +	 * is an IBI response that raced with it; xi3c_xfer_resp_available()
> +	 * consumes that case so the wait for our own data can continue.
> +	 */
> +	if (!(status_reg & XI3C_RD_FIFO_NOT_EMPTY_MASK) &&
> +	    xi3c_xfer_resp_available(master))
>  		return 0;
>  
>  	timeout = jiffies + msecs_to_jiffies(XI3C_XFER_TIMEOUT_MS);
>  
>  	/* Read data from rx fifo */
> -	while (cmd->rx_len > 0 && !xi3c_is_resp_available(master)) {
> +	while (cmd->rx_len > 0 && !xi3c_xfer_resp_available(master)) {

[Severity: High]
Could this loop eagerly consume in-flight IBI payloads and corrupt both the
IBI and the transfer data?

If a hardware target asserts an IBI right at the start of a read transfer,
its payload might stream into the shared RD_FIFO. Since the IBI's response
word is not posted to RESP_STATUS_FIFO until the transaction finishes, it
appears xi3c_xfer_resp_available() could return false here.

The polling loop would then execute xi3c_master_rd_from_rx_fifo(), blindly
draining the untagged IBI bytes from RD_FIFO into the transfer's buffer
before validating ownership. Later, when the IBI processing path
(xi3c_master_process_ibi) runs, it expects its payload to still be in the
RX FIFO and may underflow the FIFO or steal the transfer's actual data.

>  		if (time_after(jiffies, timeout)) {
>  			dev_err(master->dev, "XI3C read timeout\n");
>  			return -EIO;
>  		}
>  		xi3c_master_rd_from_rx_fifo(master, cmd);
>  		usleep_range(XI3C_POLL_INTERVAL_US, 2 * XI3C_POLL_INTERVAL_US);
>  	}

[ ... ]

> @@ -1052,9 +1243,338 @@ static void xi3c_master_bus_cleanup(struct i3c_master_controller *m)
> +static void xi3c_master_free_ibi(struct i3c_dev_desc *dev)
> +{
> +	struct xi3c_i3c_dev_data *data = i3c_dev_get_master_data(dev);
> +	struct i3c_master_controller *m = i3c_dev_get_master(dev);
> +	struct xi3c_master *master = to_xi3c_master(m);
> +	unsigned long flags;
> +
> +	spin_lock_irqsave(&master->ibi.lock, flags);
> +	master->ibi.slots[data->ibi_slot] = NULL;
> +	spin_unlock_irqrestore(&master->ibi.lock, flags);
> +
> +	/*
> +	 * Clearing the slot above keeps the IBI handler from finding this
> +	 * device, but a handler already running may be copying a payload into
> +	 * the pool. Wait for it to finish before the pool is freed below.
> +	 */
> +	synchronize_irq(master->irq);
> +
> +	i3c_generic_ibi_free_pool(data->ibi_pool);
> +	i3c_dev_set_master_data(dev, NULL);
> +	kfree(data);

[Severity: High]
Does freeing the IBI pool here before the workqueue is flushed create a
use-after-free and NULL pointer dereference risk?

During device teardown, it looks like an asynchronous IBI could race
with device removal. If the core calls xi3c_master_disable_ibi() and then
proceeds to call xi3c_master_free_ibi(), an IBI interrupt might concurrently
fire.

The IRQ handler calling xi3c_master_process_ibi() could unconditionally queue
a work item to dev->ibi->wq. By the time the core calls destroy_workqueue(),
which flushes the queue, the work item would reside in freed memory.

Furthermore, when the flushed work executes, it calls
xi3c_master_recycle_ibi_slot() which would dereference the now-NULL master
data:

xi3c_master_recycle_ibi_slot() {
    struct xi3c_i3c_dev_data *data = i3c_dev_get_master_data(dev);
    i3c_generic_ibi_recycle_slot(data->ibi_pool, slot);
}

> +}

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260908094257.3196120-1-shubhamsanjay.patil@amd.com?part=2

  reply	other threads:[~2026-09-08 10:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-08  9:42 [PATCH v3 0/3] i3c: master: amd: Add IBI and hot-join support Shubham Patil
2026-09-08  9:42 ` [PATCH v3 1/3] dt-bindings: i3c: xlnx: Add IBI and hot-join capability properties Shubham Patil
2026-09-08 17:54   ` Conor Dooley
2026-09-09 16:21     ` Frank Li
2026-09-10 11:36       ` Conor Dooley
2026-09-10 15:44         ` Frank Li
2026-09-08  9:42 ` [PATCH v3 2/3] i3c: master: amd: Add support for in-band interrupts Shubham Patil
2026-09-08 10:00   ` sashiko-bot [this message]
2026-09-08  9:42 ` [PATCH v3 3/3] i3c: master: amd: Add hot-join support Shubham Patil
2026-09-08  9:55   ` 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=20260908100015.109811F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-i3c@lists.infradead.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shubhamsanjay.patil@amd.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox