From: sashiko-bot@kernel.org
To: "Lakshay Piplani" <lakshay.piplani@nxp.com>
Cc: Frank.Li@kernel.org, robh@kernel.org, devicetree@vger.kernel.org,
"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
conor+dt@kernel.org, linux-i3c@lists.infradead.org
Subject: Re: [PATCH v18 2/8] i3c: master: Add controller-only device operation helpers
Date: Thu, 03 Sep 2026 06:35:10 +0000 [thread overview]
Message-ID: <20260903063510.5DF281F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260903062108.2712296-3-lakshay.piplani@nxp.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing memory barrier between `reinit_completion` and `atomic_read` can lead to an indefinite hang.
- [High] Use-after-free of `dev->ibi` and generic IBI pool if the controller fails to disable IBI.
- [High] Device address state corruption and resource collisions if reattach callback fails.
--
commit 6b2a9825b802ec5c65a800ad2b66b3cd53a9d304
Author: Lakshay Piplani <lakshay.piplani@nxp.com>
i3c: master: Add controller-only device operation helpers
The generic I3C device attach and IBI paths perform both core-level
bookkeeping and controller-specific operations. An I3C hub, however,
maintains a logical device descriptor on the virtual downstream bus and
a separate parent-facing descriptor used by the physical parent
controller.
> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index 9ea4726495ff6..b864fcbb1a594 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
[ ... ]
> @@ -1958,25 +2005,39 @@ int i3c_master_reattach_i3c_dev_locked(struct i3c_dev_desc *dev,
> I3C_ADDR_SLOT_FREE);
> }
>
> - if (master->ops->reattach_i3c_dev) {
> - ret = master->ops->reattach_i3c_dev(dev, old_dyn_addr);
> - if (ret) {
> - i3c_master_put_i3c_addrs(dev);
> - return ret;
> - }
> + ret = i3c_master_reattach_i3c_dev_controller_locked(dev, old_dyn_addr);
> + if (ret) {
> + i3c_master_put_i3c_addrs(dev);
> + return ret;
> }
[Severity: High]
This isn't a bug introduced by this patch, but on this error path, if the
reattach fails, we free the bus addresses by calling
i3c_master_put_i3c_addrs(dev), but we leave the device attached to the
master->bus.devs.i3c list.
If callers ignore the return value of the reattach function, couldn't this
physical device remain on the bus list while its address is marked as FREE,
leading to address collisions on the I3C bus during subsequent device
hot-joins or discoveries?
[ ... ]
> @@ -3963,14 +4072,9 @@ EXPORT_SYMBOL_GPL(i3c_dev_do_xfers_locked);
> */
> int i3c_dev_disable_ibi_locked(struct i3c_dev_desc *dev)
> {
> - struct i3c_master_controller *master;
> int ret;
>
> - if (!dev->ibi)
> - return -EINVAL;
> -
> - master = i3c_dev_get_master(dev);
> - ret = master->ops->disable_ibi(dev);
> + ret = i3c_dev_disable_ibi_controller_locked(dev);
> if (ret)
> return ret;
>
> @@ -3984,6 +4088,32 @@ int i3c_dev_disable_ibi_locked(struct i3c_dev_desc *dev)
> }
> EXPORT_SYMBOL_GPL(i3c_dev_disable_ibi_locked);
[Severity: High]
This is a pre-existing issue, but missing memory barriers in this function
can lead to an indefinite hang.
i3c_dev_disable_ibi_locked() calls:
reinit_completion(&dev->ibi->all_ibis_handled);
if (atomic_read(&dev->ibi->pending_ibis))
wait_for_completion(&dev->ibi->all_ibis_handled);
Because there is no memory barrier (such as smp_mb()) between
reinit_completion() (a non-volatile store) and atomic_read() (a volatile
read), weakly ordered CPUs could reorder the load of pending_ibis to execute
before the store to done.
If this happens, could this cause CPU 0 to sleep in wait_for_completion()
forever if CPU 1 completes the last IBI before CPU 0 commits done = 0?
[ ... ]
> @@ -4096,7 +4279,7 @@ void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev)
> dev_err(&master->dev, "Failed to disable IBI before freeing\n");
> }
>
> - master->ops->free_ibi(dev);
> + i3c_dev_free_ibi_controller_locked(dev);
>
> if (dev->ibi->wq) {
> destroy_workqueue(dev->ibi->wq);
[Severity: High]
This is a pre-existing issue, but this error path seems to unconditionally
free the IBI structures even if the hardware is still active.
In i3c_dev_free_ibi_locked(), if the controller fails to disable IBIs:
if (ret)
dev_err(&master->dev, "Failed to disable IBI before freeing\n");
}
i3c_dev_free_ibi_controller_locked(dev);
if (dev->ibi->wq) {
destroy_workqueue(dev->ibi->wq);
dev->ibi->wq = NULL;
}
kfree(dev->ibi);
Because the hardware interrupt might still fire if disabling fails, couldn't
a concurrent interrupt handler try to queue work to the destroyed
dev->ibi->wq, resulting in a use-after-free and potential kernel panic?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260903062108.2712296-1-lakshay.piplani@nxp.com?part=2
next prev parent reply other threads:[~2026-09-03 6:35 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 6:21 [PATCH v18 0/8] Add support for NXP P3H2x4x I3C hub driver Lakshay Piplani
2026-09-03 6:21 ` [PATCH v18 1/8] i3c: master: Add APIs for I3C hub support Lakshay Piplani
2026-09-03 6:34 ` sashiko-bot
2026-09-03 6:21 ` [PATCH v18 2/8] i3c: master: Add controller-only device operation helpers Lakshay Piplani
2026-09-03 6:35 ` sashiko-bot [this message]
2026-09-03 6:21 ` [PATCH v18 3/8] dt-bindings: i3c: Add NXP P3H2x4x i3c-hub support Lakshay Piplani
2026-09-03 6:21 ` [PATCH v18 4/8] mfd: p3h2x4x: Add driver for NXP P3H2x4x i3c hub and on-die regulator Lakshay Piplani
2026-09-03 6:35 ` sashiko-bot
2026-09-03 6:21 ` [PATCH v18 5/8] regulator: p3h2x4x: Add driver for on-die regulators in NXP P3H2x4x i3c hub Lakshay Piplani
2026-09-03 6:31 ` sashiko-bot
2026-09-03 6:21 ` [PATCH v18 6/8] i3c: hub: Add support for the I3C interface in the I3C hub Lakshay Piplani
2026-09-03 6:38 ` sashiko-bot
2026-09-03 6:21 ` [PATCH v18 7/8] i3c: hub: p3h2x4x: Add support for NXP P3H2x4x I3C hub functionality Lakshay Piplani
2026-09-03 6:21 ` [PATCH v18 8/8] i3c: hub: p3h2x4x: Add SMBus slave mode support Lakshay Piplani
2026-09-03 6:41 ` 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=20260903063510.5DF281F000E9@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=lakshay.piplani@nxp.com \
--cc=linux-i3c@lists.infradead.org \
--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